Skip to content

Commit

Permalink
Merge branch 'main' into fix/etherscan-api-key-name
Browse files Browse the repository at this point in the history
  • Loading branch information
Sledro authored Sep 5, 2024
2 parents 6b526a2 + e42bb7b commit aed6a9d
Show file tree
Hide file tree
Showing 134 changed files with 53,985 additions and 443 deletions.
12 changes: 11 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ REPORT_GAS=true
COINMARKETCAP_API_KEY=

# Deploy script genesis block provider
LL_PROVIDER_URL=
LL_PROVIDER_URL=

# Bridge deployment
L1_RPC_URL=
L1_DEPLOYER_KEY=

L2_RPC_URL=
L2_DEPLOYER_KEY=

CANONICAL_STATE_CHAIN_ADDR=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
CHALLENGE_ADDR=0x0165878A594ca255338adfa4d48449f69242Eb8F
13 changes: 10 additions & 3 deletions .github/workflows/hardhat_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ jobs:
tests:
name: Run Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install packages
uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: "18.x"

- run: npm ci
shell: bash

- name: Run Tests
run: npm run test
run: npm run test
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
node_modules
.env
.DS_STORE

# Hardhat files
/cache
/artifacts
/hardhat-cache
/hardhat-artifacts

# TypeChain files
/typechain
Expand All @@ -19,4 +19,11 @@ node_modules
.env*
!.env.example

*.log
*.log

# Foundry files
/target
forge-artifacts
forge-cache
out.json
bloat*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ contract CanonicalStateChain is UUPSUpgradeable, OwnableUpgradeable {
/// @param epoch - Refers to a block number on the Ethereum blockchain
/// @param l2Height - The index of the Last L2 Block in this bundle.
/// @param prevHash - The hash of the previous block bundle.
/// @param stateRoot - The Stateroot after applying all the blocks in the Bundle.
/// @param outputRoot - The output root = keccack(version_hash || keccack(state_root || withdrawal_root || latest_block_hash))
/// @param celestiaPointers - Pointer to the blocks contents on celestia.
/// See `Span` from https://docs.celestia.org/developers/blobstream-offchain#defining-a-chain
struct Header {
uint64 epoch;
uint64 l2Height;
bytes32 prevHash;
bytes32 stateRoot;
bytes32 outputRoot;
CelestiaPointer[] celestiaPointers;
}

Expand Down Expand Up @@ -66,6 +66,18 @@ contract CanonicalStateChain is UUPSUpgradeable, OwnableUpgradeable {
/// @param challenge - The new challenge contract address.
event ChallengeChanged(address indexed challenge);

/// @notice Emitted when an output is proposed.
/// @param outputRoot The output root.
/// @param l2OutputIndex The index of the output in the l2Outputs array.
/// @param l2BlockNumber The L2 block number of the output root.
/// @param l1Timestamp The L1 timestamp when proposed.
event OutputProposed(
bytes32 indexed outputRoot,
uint256 indexed l2OutputIndex,
uint256 indexed l2BlockNumber,
uint256 l1Timestamp
);

/// @notice The address of the publisher. The publisher is the only address
/// that can add new blocks to the chain.
address public publisher;
Expand Down Expand Up @@ -164,6 +176,12 @@ contract CanonicalStateChain is UUPSUpgradeable, OwnableUpgradeable {
);

emit BlockAdded(chainHead);
emit OutputProposed(
_header.outputRoot,
chainHead,
_header.l2Height,
block.timestamp
);
}

/// @notice Returns the hash of a block header.
Expand All @@ -184,6 +202,21 @@ contract CanonicalStateChain is UUPSUpgradeable, OwnableUpgradeable {
return headers[chain[_index]];
}

struct Output {
bytes32 outputRoot;
uint64 timestamp;
}

function getL2Output(uint256 _index) public view returns (Output memory) {
bytes32 _hash = chain[_index];
return
Output(headers[_hash].outputRoot, headerMetadata[_hash].timestamp);
}

function startingTimestamp() public view returns (uint64) {
return headerMetadata[chain[0]].timestamp;
}

/// @notice Returns the block header at the head of the chain.
/// @return The block header.
function getHead() public view returns (Header memory) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/ChainOracle.sol → contracts/L1/ChainOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "./interfaces/IRLPReader.sol";
import "blobstream-contracts/src/lib/verifier/DAVerifier.sol";
import "blobstream-contracts/src/IDAOracle.sol";
import "./interfaces/ICanonicalStateChain.sol";
import "./lib/Lib_RLPEncode.sol";
import "../libraries/Lib_RLPEncode.sol";

/// @custom:proxied
/// @title ChainOracle
Expand Down
96 changes: 96 additions & 0 deletions contracts/L1/L1CrossDomainMessenger.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import {Predeploys} from "../libraries/Predeploys.sol";
import {Constants} from "../libraries/Constants.sol";
import {LightLinkPortal} from "./LightLinkPortal.sol";
import {CrossDomainMessenger} from "../universal/CrossDomainMessenger.sol";

/// @custom:proxied
/// @title L1CrossDomainMessenger
/// @notice The L1CrossDomainMessenger is a message passing interface between L1 and L2 responsible
/// for sending and receiving data on the L1 side. Users are encouraged to use this
/// interface instead of interacting with lower-level contracts directly.
contract L1CrossDomainMessenger is CrossDomainMessenger {
/// @notice Contract of the LightLinkPortal.
/// @custom:network-specific
LightLinkPortal public portal;

/// @notice Semantic version.
/// @custom:semver 2.4.0
string public constant version = "2.4.0";

address l2CrossDomainMessenger;

/// @notice Constructs the L1CrossDomainMessenger contract.
constructor() CrossDomainMessenger() {
initialize({_portal: LightLinkPortal(payable(address(0)))});
}

/// @notice Initializes the contract.
/// @param _portal Contract of the LightLinkPortal contract on this network.
function initialize(LightLinkPortal _portal) public initializer {
portal = _portal;
__CrossDomainMessenger_init({
_otherMessenger: CrossDomainMessenger(
Predeploys.L2_CROSS_DOMAIN_MESSENGER
)
});
}

/// @inheritdoc CrossDomainMessenger
function gasPayingToken()
internal
view
override
returns (address _addr, uint8 _decimals)
{
// (addr_, decimals_) = systemConfig.gasPayingToken();
// TODO: Uncomment the above line when the gas paying token is implemented.
_addr = Constants.ETHER;
_decimals = 18;
}

/// @notice Getter function for the LightLinkPortal contract on this chain.
/// Public getter is legacy and will be removed in the future. Use `portal()` instead.
/// @return Contract of the LightLinkPortal on this chain.
/// @custom:legacy
function PORTAL() external view returns (LightLinkPortal) {
return portal;
}

/// @inheritdoc CrossDomainMessenger
function _sendMessage(
address _to,
uint64 _gasLimit,
uint256 _value,
bytes memory _data
) internal override {
portal.depositTransaction{value: _value}({
_to: _to,
_value: _value,
_gasLimit: _gasLimit,
_isCreation: false,
_data: _data
});
}

/// @inheritdoc CrossDomainMessenger
function _isOtherMessenger() internal view override returns (bool) {
return
msg.sender == address(portal) &&
portal.l2Sender() == address(otherMessenger);
}

/// @inheritdoc CrossDomainMessenger
function _isUnsafeTarget(
address _target
) internal view override returns (bool) {
return _target == address(this) || _target == address(portal);
}

/// @inheritdoc CrossDomainMessenger
function paused() public view override returns (bool) {
return portal.paused();
}
}
Loading

0 comments on commit aed6a9d

Please sign in to comment.