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

[SC-452] Refactor forwarders and receivers #17

Merged
merged 50 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7dbdfe8
adding cctp support
hexonaut May 10, 2024
cf2c3c1
complete circle cctp
hexonaut May 10, 2024
ca6a389
remove get sender function as its pointless in this style of callback
hexonaut May 10, 2024
ede7a78
add polygon and avalanche support
hexonaut May 10, 2024
8e5b368
use more general language for cctp domain
hexonaut May 14, 2024
d3d7e21
rename some of the variables
hexonaut May 14, 2024
616c215
more var renaming; use l2 authority
hexonaut May 14, 2024
506ecc0
review fixes
hexonaut May 17, 2024
9bea858
convert domain into a struct + library; starting to split out bridges…
hexonaut May 18, 2024
418dbb4
more refactoring of bridge
hexonaut May 18, 2024
17c1b3d
part way through testing refactor
hexonaut May 20, 2024
5b03ea7
wip cctp
hexonaut May 20, 2024
f2c3076
Merge branch 'master' into SC-440-refactor-e2e
hexonaut May 20, 2024
2ece5a4
still wip for refactoring bridge testing
hexonaut May 20, 2024
1d966d5
large refactor to split out domains and bridges and move into library…
hexonaut May 24, 2024
17d300c
fix optimism
hexonaut May 24, 2024
8975d01
fix AMB
hexonaut May 29, 2024
46c876f
got arbitrum working
hexonaut May 29, 2024
7af6b4c
refactor XChainForwaders into separate libraries and support both dir…
hexonaut Jun 1, 2024
5540ccd
refactor receivers; started adjusting integration tests
hexonaut Jun 1, 2024
0040372
refactor integration tests
hexonaut Jun 3, 2024
d828811
fix all tests; update readme
hexonaut Jun 4, 2024
200b503
rm unused console
hexonaut Jun 5, 2024
5897ab7
Merge branch 'SC-440-refactor-e2e' into SC-452-refactor-forwards-rece…
hexonaut Jun 5, 2024
1928687
remove the chain specific helper functions
hexonaut Jun 5, 2024
5a8dcfc
add constructor tests for coverage
hexonaut Jun 5, 2024
75e24ce
remove constructor test; add diagram
hexonaut Jun 5, 2024
9d081f1
add unit tests for amb receiver
hexonaut Jun 5, 2024
747c428
add cctp unit test
hexonaut Jun 5, 2024
8190995
change cctp authority type
hexonaut Jun 5, 2024
05e3840
Merge branch 'SC-452-refactor-forwards-receivers' into SC-437-fix-cov…
hexonaut Jun 5, 2024
3fcbcce
update to new cctp receiver
hexonaut Jun 5, 2024
5669f7d
add arbitrum receiever unit tests
hexonaut Jun 5, 2024
dc07c16
add optimism test
hexonaut Jun 5, 2024
aade8f0
merge master
hexonaut Jun 7, 2024
9874e5c
use relative paths for library code
hexonaut Jun 8, 2024
46ee62c
fix for subsequent messages
hexonaut Jun 8, 2024
743b951
forge install: openzeppelin-contracts
hexonaut Jun 8, 2024
7eb7d7a
use fallback() instead of forward()
hexonaut Jun 8, 2024
bc5911a
Merge branch 'SC-452-refactor-forwards-receivers' into SC-437-fix-cov…
hexonaut Jun 8, 2024
842bf17
dont use absolute paths
hexonaut Jun 9, 2024
3e47e33
Merge branch 'SC-452-refactor-forwards-receivers' into SC-437-fix-cov…
hexonaut Jun 9, 2024
6be2397
fix tests to remove forward()
hexonaut Jun 9, 2024
177227a
move image up; more about the receiver; typo
hexonaut Jun 11, 2024
611fe91
formatting
hexonaut Jun 11, 2024
f222fe2
rm old unused commented out line
hexonaut Jun 11, 2024
eea3d6e
Merge branch 'SC-452-refactor-forwards-receivers' into SC-437-fix-cov…
hexonaut Jun 12, 2024
0c2893d
review fixes
hexonaut Jun 12, 2024
fd8a5f8
align
hexonaut Jun 12, 2024
1b6d35f
Merge pull request #18 from marsfoundation/SC-437-fix-coverage
hexonaut Jun 12, 2024
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
Prev Previous commit
Next Next commit
convert domain into a struct + library; starting to split out bridges…
… from the domains
  • Loading branch information
hexonaut committed May 18, 2024
commit 9bea858fee4b9a4fd6f4b228dbbfdec936273dba
54 changes: 40 additions & 14 deletions src/testing/Domain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,56 @@ pragma solidity >=0.8.0;
import { StdChains } from "forge-std/StdChains.sol";
import { Vm } from "forge-std/Vm.sol";

contract Domain {
struct Domain {
StdChains.Chain chain;
uint256 forkId;
}

library DomainHelpers {

Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));

StdChains.Chain private _details;
uint256 public forkId;
function createFork(StdChains.Chain memory chain, uint256 blockNumber) internal returns (Domain memory domain) {
domain = Domain({
chain: chain,
forkId: vm.createFork(chain.rpcUrl, blockNum)
});
}

function createFork(StdChains.Chain memory chain) internal returns (Domain memory domain) {
domain = Domain({
chain: chain,
forkId: vm.createFork(chain.rpcUrl)
});
}

function createSelectFork(StdChains.Chain memory chain, uint256 blockNumber) internal returns (Domain memory domain) {
domain = Domain({
chain: chain,
forkId: vm.createSelectFork(chain.rpcUrl, blockNum)
});
_assertExpectedRpc(chain);
}

constructor(StdChains.Chain memory _chain) {
_details = _chain;
forkId = vm.createFork(_chain.rpcUrl);
vm.makePersistent(address(this));
function createSelectFork(StdChains.Chain memory chain) internal returns (Domain memory domain) {
domain = Domain({
chain: chain,
forkId: vm.createSelectFork(chain.rpcUrl)
});
_assertExpectedRpc(chain);
}

function details() public view returns (StdChains.Chain memory) {
return _details;
function selectFork(Domain memory domain) internal {
vm.selectFork(domain.forkId);
_assertExpectedRpc(domain);
}

function selectFork() public {
vm.selectFork(forkId);
require(block.chainid == _details.chainId, string(abi.encodePacked(_details.chainAlias, " is pointing to the wrong RPC endpoint '", _details.rpcUrl, "'")));
function rollFork(Domain memory domain, uint256 blockNumber) internal {
vm.rollFork(domain.forkId, blockNumber);
}

function rollFork(uint256 blocknum) public {
vm.rollFork(forkId, blocknum);
function _assertExpectedRpc(StdChains.Chain memory chain) private {
require(block.chainid == chain.chainId, string(abi.encodePacked(chain.chainAlias, " is pointing to the wrong RPC endpoint '", chain.rpcUrl, "'")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity >=0.8.0;
import { StdChains } from "forge-std/StdChains.sol";
import { Vm } from "forge-std/Vm.sol";

import { Domain, BridgedDomain } from "./BridgedDomain.sol";
import { RecordedLogs } from "./RecordedLogs.sol";
import { Domain, DomainHelpers } from "src/testing/Domain.sol";
import { RecordedLogs } from "src/testing/utils/RecordedLogs.sol";

interface InboxLike {
function createRetryableTicket(
Expand Down Expand Up @@ -42,7 +42,9 @@ contract ArbSysOverride {

}

contract ArbitrumDomain is BridgedDomain {
contract ArbitrumNativeBridge is IBidirectionalBridge {

using DomainHelpers for *;

bytes32 private constant MESSAGE_DELIVERED_TOPIC = keccak256("MessageDelivered(uint256,bytes32,address,uint8,address,bytes32,uint256,uint64)");
bytes32 private constant SEND_TO_L1_TOPIC = keccak256("SendTxToL1(address,address,bytes)");
Expand All @@ -56,21 +58,28 @@ contract ArbitrumDomain is BridgedDomain {
uint256 internal lastFromHostLogIndex;
uint256 internal lastToHostLogIndex;

constructor(StdChains.Chain memory _chain, Domain _hostDomain) Domain(_chain) BridgedDomain(_hostDomain) {
bytes32 name = keccak256(bytes(_chain.chainAlias));
Domain public source;
Domain public destination;

constructor(Domain memory _source, Domain memory _destination) {
require(keccak256(bytes(destination.chain.chainAlias)) == keccak256("mainnet"), "Source must be Ethereum.");

bytes32 name = keccak256(bytes(destination.chain.chainAlias));
if (name == keccak256("arbitrum_one")) {
INBOX = InboxLike(0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f);
} else if (name == keccak256("arbitrum_one_goerli")) {
INBOX = InboxLike(0x6BEbC4925716945D46F0Ec336D5C2564F419682C);
} else if (name == keccak256("arbitrum_nova")) {
INBOX = InboxLike(0xc4448b71118c9071Bcb9734A0EAc55D18A153949);
} else {
revert("Unsupported chain");
}

_hostDomain.selectFork();
source = _source;
destination = _destination;

source.selectFork();
BRIDGE = BridgeLike(INBOX.bridge());
vm.recordLogs();
vm.makePersistent(address(this));

// Make this contract a valid outbox
address _rollup = BRIDGE.rollup();
Expand All @@ -87,15 +96,15 @@ contract ArbitrumDomain is BridgedDomain {
);

// Need to replace ArbSys contract with custom code to make it compatible with revm
selectFork();
destination.selectFork();
bytes memory bytecode = vm.getCode("ArbitrumDomain.sol:ArbSysOverride");
address deployed;
assembly {
deployed := create(0, add(bytecode, 0x20), mload(bytecode))
}
vm.etch(ARB_SYS, deployed.code);

_hostDomain.selectFork();
source.selectFork();
}

function parseData(bytes memory orig) private pure returns (address target, bytes memory message) {
Expand All @@ -108,8 +117,8 @@ contract ArbitrumDomain is BridgedDomain {
}
}

function relayFromHost(bool switchToGuest) external override {
selectFork();
function relayMessagesToSource(bool switchToDestinationFork) external override {
destination.selectFork();

// Read all L1 -> L2 messages and relay them under Arbitrum fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
Expand All @@ -131,13 +140,13 @@ contract ArbitrumDomain is BridgedDomain {
}
}

if (!switchToGuest) {
hostDomain.selectFork();
if (!switchToDestinationFork) {
source.selectFork();
}
}

function relayToHost(bool switchToHost) external override {
hostDomain.selectFork();
function relayMessagesToSource(bool switchToSourceFork) external override {
source.selectFork();

// Read all L2 -> L1 messages and relay them under host fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
Expand All @@ -155,8 +164,8 @@ contract ArbitrumDomain is BridgedDomain {
}
}

if (!switchToHost) {
selectFork();
if (!switchToSourceFork) {
destination.selectFork();
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/testing/bridges/IBidirectionalBridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.8.0;

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

interface IUnidirectionalBridge is IUnidirectionalBridge {
function relayMessagesToSource(bool switchToSourceFork) external;
}
6 changes: 6 additions & 0 deletions src/testing/bridges/IUnidirectionalBridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.8.0;

interface IUnidirectionalBridge {
function relayMessagesToDestination(bool switchToDestinationFork) external;
}
File renamed without changes.