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 scroll integration #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
feat: add scroll integration
  • Loading branch information
zimpha committed Nov 21, 2023
commit 1e41d16bd170ab6c78657880b4d4314c766bb8e4
63 changes: 63 additions & 0 deletions src/executors/ScrollBridgeExecutor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.10;

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

interface ICrossDomainMessenger {
function xDomainMessageSender() external view returns (address);
}

/**
* @title ScrollBridgeExecutor
* @author Scroll
* @notice Implementation of the Scroll Bridge Executor, able to receive cross-chain transactions from Ethereum
* @dev Queuing an ActionsSet into this Executor can only be done by the Scroll L2 Cross Domain Messenger and having
* the EthereumGovernanceExecutor as xDomainMessageSender
*/
contract ScrollBridgeExecutor is L2BridgeExecutor {
// Address of the Scroll L2 Cross Domain Messenger, in charge of redirecting cross-chain transactions in L2
address public immutable L2_SCROLL_MESSENGER;

/// @inheritdoc L2BridgeExecutor
modifier onlyEthereumGovernanceExecutor() override {
if (
msg.sender != L2_SCROLL_MESSENGER ||
ICrossDomainMessenger(L2_SCROLL_MESSENGER)
.xDomainMessageSender() !=
_ethereumGovernanceExecutor
) revert UnauthorizedEthereumExecutor();
_;
}

/**
* @dev Constructor
*
* @param l2ScrollMessenger The address of the Scroll's `L2ScrollMessenger`.
* @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 l2ScrollMessenger,
address ethereumGovernanceExecutor,
uint256 delay,
uint256 gracePeriod,
uint256 minimumDelay,
uint256 maximumDelay,
address guardian
)
L2BridgeExecutor(
ethereumGovernanceExecutor,
delay,
gracePeriod,
minimumDelay,
maximumDelay,
guardian
)
{
L2_SCROLL_MESSENGER = l2ScrollMessenger;
}
}
2 changes: 1 addition & 1 deletion test/ArbitrumCrosschainTest.t.sol
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 2 additions & 2 deletions test/CrosschainTestBase.sol
Original file line number Diff line number Diff line change
@@ -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';

2 changes: 1 addition & 1 deletion test/GnosisCrosschainTest.t.sol
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion test/OptimismCrosschainTest.t.sol
Original file line number Diff line number Diff line change
@@ -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';
72 changes: 72 additions & 0 deletions test/ScrollCrossChainTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';

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

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

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

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

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

interface MessageQueueLike {
function estimateCrossDomainMessageFee(uint256 gasLimit) external view returns (uint256);
}

contract ScrollCrosschainPayload is CrosschainPayload {
address public constant L1_MESSAGE_QUEUE = 0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B;

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

function execute() external override {
XChainForwarders.sendMessageScrollMainnet(
bridgeExecutor,
encodeCrosschainExecutionMessage(),
1_000_000,
MessageQueueLike(L1_MESSAGE_QUEUE).estimateCrossDomainMessageFee(1_000_000)
);
}

}

contract ScrollCrosschainTest is CrosschainTestBase {

address public constant L2_SCROLL_MESSENGER = 0x781e90f1c8Fc4611c9b7497C3B47F99Ef6969CbC;

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

function setUp() public {
setChain(
"scroll",
ChainData("Scroll Chain", 534352, "https://rpc.scroll.io")
);

hostDomain = new Domain(getChain('mainnet'));
bridgedDomain = new ScrollDomain(getChain('scroll'), hostDomain);

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

hostDomain.selectFork();
vm.deal(L1_EXECUTOR, 100 ether);
}

}