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 polygon zkEVM bridge executor #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
90 changes: 90 additions & 0 deletions contracts/bridges/ZkEVMBridgeExecutor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.10;

import {L2BridgeExecutor} from './L2BridgeExecutor.sol';
import {IBridgeMessageReceiver} from '../dependencies/polygon-zkevm/IBridgeMessageReceiver.sol';

/**
* @title ZkEVMBridgeExecutor
* @author Aave
* @notice Implementation of the ZkEVM Bridge Executor, able to receive cross-chain transactions from Ethereum
*/
contract ZkEVMBridgeExecutor is L2BridgeExecutor, IBridgeMessageReceiver {
error UnauthorizedBridgeCaller();
error NotDirectlyCallable();
error InvalidOriginNetwork();
error InvalidMethodId();

address internal constant zkEVMBridge = 0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe;
uint32 internal constant _MAINNET_NETWORK_ID = 0;

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

modifier onlyBridge() {
if (msg.sender != zkEVMBridge) revert UnauthorizedBridgeCaller();
_;
}

/**
* @dev Constructor
*
* @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)
* @dev zkEVMBridge calls `onMessageReceived` with originSender, originNetwork and calldata. All of them are verified.
* But this also means we need queue function to not be callable, will always revert.
*/
constructor(
address ethereumGovernanceExecutor,
uint256 delay,
uint256 gracePeriod,
uint256 minimumDelay,
uint256 maximumDelay,
address guardian
)
L2BridgeExecutor(
ethereumGovernanceExecutor,
delay,
gracePeriod,
minimumDelay,
maximumDelay,
guardian
)
{
// Intentionally left blank
}

function onMessageReceived(
address originAddress,
uint32 originNetwork,
bytes calldata data
) external payable onlyBridge {
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);
}
}
14 changes: 14 additions & 0 deletions contracts/dependencies/polygon-zkevm/IBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.10;

/**
* @dev Define interface for PolygonZkEVM Bridge message receiver
*/
interface IBridgeMessageReceiver {
function onMessageReceived(
address originAddress,
uint32 originNetwork,
bytes memory data
) external payable;
}