Skip to content

Commit

Permalink
add to L2Genesis Interop contracts (CrossL2Inbox, L2ToL2CrossDomainMe…
Browse files Browse the repository at this point in the history
…ssenger) (#10417)

* bedrock-devnet: add useInterop flag

* op-chain-ops: add useInterop flag

* op-node: add useInterop flag to config

* contracts-bedrock: add useInterop flag to Predeploy's getName

* contracts-bedrock: add useInterop flag to L2Genesis

* contracts-bedrock: add useInterop flag to Predeploy's test

* contracts-bedrock: add useInterop flag to Setup

* Revert "op-chain-ops: add useInterop flag"

This reverts commit 83c63cc.

* Revert "op-node: add useInterop flag to config"

This reverts commit c3617f9.

* Revert "bedrock-devnet: add useInterop flag"

This reverts commit 858257c.

* contracts-bedrock: use L1Block in Predeploys for L1BlockInterop

* contracts-bedrock: remove useInterop argument in Predeploys

* op-chain-ops: fix TestConfigDataMarshalUnmarshal

* contracts-bedrock: add CrossL2Inbox, L2ToL2CrossDomainMessenger to L2Genesis script

* contracts-bedrock: add tests for interop branch of L2Genesis

* Revert "op-chain-ops: fix TestConfigDataMarshalUnmarshal"

This reverts commit fbc60c1.
  • Loading branch information
0xfuturistic committed May 8, 2024
1 parent c41bb73 commit bd35e43
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
18 changes: 17 additions & 1 deletion packages/contracts-bedrock/scripts/L2Genesis.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ contract L2Genesis is Deployer {
vm.etch(addr, code);
EIP1967Helper.setAdmin(addr, Predeploys.PROXY_ADMIN);

if (Predeploys.isSupportedPredeploy(addr)) {
if (Predeploys.isSupportedPredeploy(addr, cfg.useInterop())) {
address implementation = Predeploys.predeployToCodeNamespace(addr);
console.log("Setting proxy %s implementation: %s", addr, implementation);
EIP1967Helper.setImplementation(addr, implementation);
Expand Down Expand Up @@ -231,6 +231,10 @@ contract L2Genesis is Deployer {
setSchemaRegistry(); // 20
setEAS(); // 21
setGovernanceToken(); // 42: OP (not behind a proxy)
if (cfg.useInterop()) {
setCrossL2Inbox(); // 22
setL2ToL2CrossDomainMessenger(); // 23
}
}

function setProxyAdmin() public {
Expand Down Expand Up @@ -441,6 +445,18 @@ contract L2Genesis is Deployer {
vm.resetNonce(address(eas));
}

/// @notice This predeploy is following the saftey invariant #2.
/// This contract has no initializer.
function setCrossL2Inbox() internal {
_setImplementationCode(Predeploys.CROSS_L2_INBOX);
}

/// @notice This predeploy is following the saftey invariant #2.
/// This contract has no initializer.
function setL2ToL2CrossDomainMessenger() internal {
_setImplementationCode(Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER);
}

/// @notice Sets all the preinstalls.
/// Warning: the creator-accounts of the preinstall contracts have 0 nonce values.
/// When performing a regular user-initiated contract-creation of a preinstall,
Expand Down
5 changes: 3 additions & 2 deletions packages/contracts-bedrock/src/libraries/Predeploys.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ library Predeploys {
}

/// @notice Returns true if the address is a defined predeploy that is embedded into new OP-Stack chains.
function isSupportedPredeploy(address _addr) internal pure returns (bool) {
function isSupportedPredeploy(address _addr, bool _useInterop) internal pure returns (bool) {
return _addr == LEGACY_MESSAGE_PASSER || _addr == DEPLOYER_WHITELIST || _addr == WETH
|| _addr == L2_CROSS_DOMAIN_MESSENGER || _addr == GAS_PRICE_ORACLE || _addr == L2_STANDARD_BRIDGE
|| _addr == SEQUENCER_FEE_WALLET || _addr == OPTIMISM_MINTABLE_ERC20_FACTORY || _addr == L1_BLOCK_NUMBER
|| _addr == L2_ERC721_BRIDGE || _addr == L1_BLOCK_ATTRIBUTES || _addr == L2_TO_L1_MESSAGE_PASSER
|| _addr == OPTIMISM_MINTABLE_ERC721_FACTORY || _addr == PROXY_ADMIN || _addr == BASE_FEE_VAULT
|| _addr == L1_FEE_VAULT || _addr == SCHEMA_REGISTRY || _addr == EAS || _addr == GOVERNANCE_TOKEN;
|| _addr == L1_FEE_VAULT || _addr == SCHEMA_REGISTRY || _addr == EAS || _addr == GOVERNANCE_TOKEN
|| (_useInterop && _addr == CROSS_L2_INBOX) || (_useInterop && _addr == L2_TO_L2_CROSS_DOMAIN_MESSENGER);
}

function isPredeployNamespace(address _addr) internal pure returns (bool) {
Expand Down
26 changes: 20 additions & 6 deletions packages/contracts-bedrock/test/L2Genesis.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,36 @@ contract L2GenesisTest is Test {
return abi.decode(vm.ffi(commands), (uint256));
}

/// @notice Tests the genesis predeploys setup using a temp file.
function test_genesis_predeploys() external {
withTempDump(_test_genesis_predeploys);
/// @notice Tests the genesis predeploys setup using a temp file for the case where useInterop is false.
function test_genesis_predeploys_notUsingInterop() external {
string memory path = tmpfile();
_test_genesis_predeploys(path, false);
deleteFile(path);
}

/// @notice Tests the genesis predeploys setup using a temp file for the case where useInterop is true.
function test_genesis_predeploys_usingInterop() external {
string memory path = tmpfile();
_test_genesis_predeploys(path, true);
deleteFile(path);
}

/// @notice Tests the genesis predeploys setup.
function _test_genesis_predeploys(string memory _path) internal {
function _test_genesis_predeploys(string memory _path, bool _useInterop) internal {
// Set the useInterop value
vm.mockCall(
address(genesis.cfg()), abi.encodeWithSelector(genesis.cfg().useInterop.selector), abi.encode(_useInterop)
);

// Set the predeploy proxies into state
genesis.setPredeployProxies();
genesis.writeGenesisAllocs(_path);

// 2 predeploys do not have proxies
assertEq(getCodeCount(_path, "Proxy.sol:Proxy"), Predeploys.PREDEPLOY_COUNT - 2);

// 17 proxies have the implementation set
assertEq(getPredeployCountWithSlotSet(_path, Constants.PROXY_IMPLEMENTATION_ADDRESS), 17);
// 19 proxies have the implementation set if useInterop is true and 17 if useInterop is false
assertEq(getPredeployCountWithSlotSet(_path, Constants.PROXY_IMPLEMENTATION_ADDRESS), _useInterop ? 19 : 17);

// All proxies except 2 have the proxy 1967 admin slot set to the proxy admin
assertEq(
Expand Down

0 comments on commit bd35e43

Please sign in to comment.