Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ZkEVMBridgeExecutor #10

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions src/executors/ZkEVMBridgeExecutor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.10;

import {L2BridgeExecutor} from "./L2BridgeExecutor.sol";

interface IZkEvmBridgeLike {
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
function bridgeMessage(
uint32 destinationNetwork,
address destinationAddress,
bool forceUpdateGlobalExitRoot,
bytes calldata metadata
) external payable;
}

interface IBridgeMessageReceiver {
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
function onMessageReceived(address originAddress, uint32 originNetwork, bytes memory data) external payable;
}

/**
* @title ZkEVMBridgeExecutor
* @notice Implementation of the ZkEVM Bridge Executor, able to receive cross-chain transactions from Ethereum
* @dev Queuing an ActionsSet into this Executor can only be done by the ZkEVM Bridge and having
* the EthereumGovernanceExecutor as the sender
*/
contract ZkEVMBridgeExecutor is L2BridgeExecutor, IBridgeMessageReceiver {
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
error UnauthorizedBridgeCaller();
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
error NotDirectlyCallable();
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
error InvalidOriginNetwork();
error InvalidMethodId();

uint32 internal constant _MAINNET_NETWORK_ID = 0;
0xdapper marked this conversation as resolved.
Show resolved Hide resolved

// Address of the ZkEVM bridge
address public immutable ZKEVM_BRIDGE;
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
address internal immutable zkEVMBridge;
0xdapper marked this conversation as resolved.
Show resolved Hide resolved

/// @inheritdoc L2BridgeExecutor
modifier onlyEthereumGovernanceExecutor() override {
revert NotDirectlyCallable();
_;
}

/**
* @dev Constructor
*
* @param bridge The address of the ZkEVM Bridge
* @param ethereumGovernanceExecutor The address of the EthereumGovernanceExecutor
* @param delay The delay before which an actions set can be executed
* @param gracePeriod The time period after a delay during which an actions set can be executed
* @param minimumDelay The minimum bound a delay can be set to
* @param maximumDelay The maximum bound a delay can be set to
* @param guardian The address of the guardian, which can cancel queued proposals (can be zero)
*/
constructor(
address bridge,
address ethereumGovernanceExecutor,
uint256 delay,
uint256 gracePeriod,
uint256 minimumDelay,
uint256 maximumDelay,
address guardian
) L2BridgeExecutor(ethereumGovernanceExecutor, delay, gracePeriod, minimumDelay, maximumDelay, guardian) {
zkEVMBridge = bridge;
}

function onMessageReceived(address originAddress, uint32 originNetwork, bytes calldata data) external payable {
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
if (originAddress != _ethereumGovernanceExecutor) {
revert UnauthorizedEthereumExecutor();
}
if (originNetwork != _MAINNET_NETWORK_ID) {
revert InvalidOriginNetwork();
}
bytes4 methodId = bytes4(data[0:4]);
if (methodId != this.queue.selector) {
revert InvalidMethodId();
}

(
address[] memory targets,
uint256[] memory values,
string[] memory signatures,
bytes[] memory calldatas,
bool[] memory withDelegatecalls
) = abi.decode(data[4:], (address[], uint256[], string[], bytes[], bool[]));

_queue(targets, values, signatures, calldatas, withDelegatecalls);
}
}
2 changes: 1 addition & 1 deletion test/ArbitrumCrosschainTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import 'forge-std/Test.sol';

import { Domain, ArbitrumDomain } from 'xchain-helpers/ArbitrumDomain.sol';
import { Domain, ArbitrumDomain } from 'xchain-helpers/testing/ArbitrumDomain.sol';
import { XChainForwarders } from 'xchain-helpers/XChainForwarders.sol';

import { ArbitrumBridgeExecutor } from '../src/executors/ArbitrumBridgeExecutor.sol';
Expand Down
4 changes: 2 additions & 2 deletions test/CrosschainTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.0;
import 'forge-std/Test.sol';
import 'forge-std/console.sol';

import { BridgedDomain } from 'xchain-helpers/BridgedDomain.sol';
import { Domain } from 'xchain-helpers/Domain.sol';
import { BridgedDomain } from 'xchain-helpers/testing/BridgedDomain.sol';
import { Domain } from 'xchain-helpers/testing/Domain.sol';

import { IL2BridgeExecutor, IExecutorBase } from '../src/interfaces/IL2BridgeExecutor.sol';

Expand Down
2 changes: 1 addition & 1 deletion test/GnosisCrosschainTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import 'forge-std/Test.sol';

import { Domain, GnosisDomain } from 'xchain-helpers/GnosisDomain.sol';
import { Domain, GnosisDomain } from 'xchain-helpers/testing/GnosisDomain.sol';
import { XChainForwarders } from 'xchain-helpers/XChainForwarders.sol';

import { IAMB, GnosisBridgeExecutor } from '../src/executors/GnosisBridgeExecutor.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/OptimismCrosschainTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import 'forge-std/Test.sol';

import { Domain, OptimismDomain } from 'xchain-helpers/OptimismDomain.sol';
import { Domain, OptimismDomain } from 'xchain-helpers/testing/OptimismDomain.sol';
import { XChainForwarders } from 'xchain-helpers/XChainForwarders.sol';

import { OptimismBridgeExecutor } from '../src/executors/OptimismBridgeExecutor.sol';
Expand Down
59 changes: 59 additions & 0 deletions test/ZkEVMBridgeExecutor.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';

import { Domain, ZkEVMDomain } from 'xchain-helpers/testing/ZkEVMDomain.sol';
import { XChainForwarders } from 'xchain-helpers/XChainForwarders.sol';

import { ZkEVMBridgeExecutor } from '../src/executors/ZkEVMBridgeExecutor.sol';

import { IL2BridgeExecutor } from '../src/interfaces/IL2BridgeExecutor.sol';

import { IPayload } from './interfaces/IPayload.sol';

import { CrosschainPayload, CrosschainTestBase } from './CrosschainTestBase.sol';

contract ZkEVMCrosschainPayload is CrosschainPayload {

constructor(IPayload _targetPayload, address _bridgeExecutor)
CrosschainPayload(_targetPayload, _bridgeExecutor) {}

function execute() external override {
XChainForwarders.sendMessageZkEVM(
bridgeExecutor,
encodeCrosschainExecutionMessage()
);
}

}

contract ZkEVMCrosschainTest is CrosschainTestBase {
address constant ZKEVM_BRIDGE = 0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe;

function deployCrosschainPayload(IPayload targetPayload, address bridgeExecutor)
public override returns (IPayload)
{
return IPayload(new ZkEVMCrosschainPayload(targetPayload, bridgeExecutor));
}

function setUp() public {
setChain("zkevm", ChainData("ZkEVM", 1101, "https://zkevm-rpc.com"));
hostDomain = new Domain(getChain('mainnet'));
bridgedDomain = new ZkEVMDomain(getChain('zkevm'), hostDomain);

bridgedDomain.selectFork();
bridgeExecutor = address(new ZkEVMBridgeExecutor(
ZKEVM_BRIDGE,
defaultL2BridgeExecutorArgs.ethereumGovernanceExecutor,
defaultL2BridgeExecutorArgs.delay,
defaultL2BridgeExecutorArgs.gracePeriod,
defaultL2BridgeExecutorArgs.minimumDelay,
defaultL2BridgeExecutorArgs.maximumDelay,
defaultL2BridgeExecutorArgs.guardian
));

hostDomain.selectFork();
}

}