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 4 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
94 changes: 94 additions & 0 deletions src/executors/ZkEVMBridgeExecutor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.10;

import { BridgeExecutorBase } from "./BridgeExecutorBase.sol";
import { IL2BridgeExecutor } from "../interfaces/IL2BridgeExecutor.sol";

interface IZkEVMBridgeMessageReceiver {
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 BridgeExecutorBase, IZkEVMBridgeMessageReceiver {
error UnauthorizedBridgeCaller();
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
error InvalidOriginNetwork();
error InvalidMethodId();
error UnauthorizedEthereumExecutor();

/**
* @dev Emitted when the Ethereum Governance Executor is updated
* @param oldEthereumGovernanceExecutor The address of the old EthereumGovernanceExecutor
* @param newEthereumGovernanceExecutor The address of the new EthereumGovernanceExecutor
*
*/
event EthereumGovernanceExecutorUpdate(
address oldEthereumGovernanceExecutor, address newEthereumGovernanceExecutor
);

// Address of the Ethereum Governance Executor, which should be able to queue actions sets
address public ethereumGovernanceExecutor;

uint32 public immutable originNetworkId;

// Address of the ZkEVM bridge
address public immutable zkEVMBridge;

/**
* @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,
uint32 originNetworkId_
) BridgeExecutorBase(delay, gracePeriod, minimumDelay, maximumDelay, guardian) {
originNetworkId = originNetworkId_;
ethereumGovernanceExecutor = ethereumGovernanceExecutor_;
zkEVMBridge = bridge;
}

function onMessageReceived(address originAddress, uint32 originNetwork, bytes calldata data) external payable {
0xdapper marked this conversation as resolved.
Show resolved Hide resolved
if (msg.sender != zkEVMBridge) revert UnauthorizedBridgeCaller();
if (originAddress != ethereumGovernanceExecutor) revert UnauthorizedEthereumExecutor();
if (originNetwork != originNetworkId) revert InvalidOriginNetwork();
bytes4 methodId = bytes4(data[0:4]);
if (methodId != IL2BridgeExecutor.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);
}

/**
* @notice Update the address of the Ethereum Governance Executor
* @param ethereumGovernanceExecutor_ The address of the new EthereumGovernanceExecutor
*
*/
function updateEthereumGovernanceExecutor(address ethereumGovernanceExecutor_) external onlyThis {
emit EthereumGovernanceExecutorUpdate(ethereumGovernanceExecutor, ethereumGovernanceExecutor_);
ethereumGovernanceExecutor = ethereumGovernanceExecutor_;
}
}
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
60 changes: 60 additions & 0 deletions test/ZkEVMBridgeExecutor.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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,
0
));

hostDomain.selectFork();
}

}