Skip to content

Commit

Permalink
use more general language for cctp domain
Browse files Browse the repository at this point in the history
  • Loading branch information
hexonaut committed May 14, 2024
1 parent ede7a78 commit 8e5b368
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
51 changes: 29 additions & 22 deletions src/testing/CircleCCTPDomain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,61 @@ contract CircleCCTPDomain is BridgedDomain {

bytes32 private constant SENT_MESSAGE_TOPIC = keccak256("MessageSent(bytes)");

MessengerLike public constant L1_MESSENGER = MessengerLike(0x0a992d191DEeC32aFe36203Ad87D7d289a738F81);
MessengerLike public L2_MESSENGER;
MessengerLike public SOURCE_MESSENGER;
MessengerLike public DESTINATION_MESSENGER;

uint256 internal lastFromHostLogIndex;
uint256 internal lastToHostLogIndex;

constructor(StdChains.Chain memory _chain, Domain _hostDomain) Domain(_chain) BridgedDomain(_hostDomain) {
bytes32 name = keccak256(bytes(_chain.chainAlias));
if (name == keccak256("avalanche")) {
L2_MESSENGER = MessengerLike(0x8186359aF5F57FbB40c6b14A588d2A59C0C29880);
} else if (name == keccak256("optimism")) {
L2_MESSENGER = MessengerLike(0x4D41f22c5a0e5c74090899E5a8Fb597a8842b3e8);
} else if (name == keccak256("arbitrum_one")) {
L2_MESSENGER = MessengerLike(0xC30362313FBBA5cf9163F0bb16a0e01f01A896ca);
} else if (name == keccak256("base")) {
L2_MESSENGER = MessengerLike(0xAD09780d193884d503182aD4588450C416D6F9D4);
} else if (name == keccak256("polygon")) {
L2_MESSENGER = MessengerLike(0xF3be9355363857F3e001be68856A2f96b4C39Ba9);
} else {
revert("Unsupported chain");
}
SOURCE_MESSENGER = MessengerLike(_getMessengerFromChainAlias(_hostDomain.details().chainAlias));
DESTINATION_MESSENGER = MessengerLike(_getMessengerFromChainAlias(_chain.chainAlias));

// Set minimum required signatures to zero for both domains
selectFork();
vm.store(
address(L2_MESSENGER),
address(DESTINATION_MESSENGER),
bytes32(uint256(4)),
0
);
hostDomain.selectFork();
vm.store(
address(L1_MESSENGER),
address(SOURCE_MESSENGER),
bytes32(uint256(4)),
0
);

vm.recordLogs();
}

function _getMessengerFromChainAlias(string memory chainAlias) internal pure returns (address) {
bytes32 name = keccak256(bytes(chainAlias));
if (name == keccak256("mainnet")) {
return 0x0a992d191DEeC32aFe36203Ad87D7d289a738F81;
} else if (name == keccak256("avalanche")) {
return 0x8186359aF5F57FbB40c6b14A588d2A59C0C29880;
} else if (name == keccak256("optimism")) {
return 0x4D41f22c5a0e5c74090899E5a8Fb597a8842b3e8;
} else if (name == keccak256("arbitrum_one")) {
return 0xC30362313FBBA5cf9163F0bb16a0e01f01A896ca;
} else if (name == keccak256("base")) {
return 0xAD09780d193884d503182aD4588450C416D6F9D4;
} else if (name == keccak256("polygon")) {
return 0xF3be9355363857F3e001be68856A2f96b4C39Ba9;
} else {
revert("Unsupported chain");
}
}

function relayFromHost(bool switchToGuest) external override {
selectFork();

// Read all L1 -> L2 messages and relay them under CCTP fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
for (; lastFromHostLogIndex < logs.length; lastFromHostLogIndex++) {
Vm.Log memory log = logs[lastFromHostLogIndex];
if (log.topics[0] == SENT_MESSAGE_TOPIC && log.emitter == address(L1_MESSENGER)) {
L2_MESSENGER.receiveMessage(removeFirst64Bytes(log.data), "");
if (log.topics[0] == SENT_MESSAGE_TOPIC && log.emitter == address(SOURCE_MESSENGER)) {
DESTINATION_MESSENGER.receiveMessage(removeFirst64Bytes(log.data), "");
}
}

Expand All @@ -78,8 +85,8 @@ contract CircleCCTPDomain is BridgedDomain {
Vm.Log[] memory logs = RecordedLogs.getLogs();
for (; lastToHostLogIndex < logs.length; lastToHostLogIndex++) {
Vm.Log memory log = logs[lastToHostLogIndex];
if (log.topics[0] == SENT_MESSAGE_TOPIC && log.emitter == address(L2_MESSENGER)) {
L1_MESSENGER.receiveMessage(removeFirst64Bytes(log.data), "");
if (log.topics[0] == SENT_MESSAGE_TOPIC && log.emitter == address(DESTINATION_MESSENGER)) {
SOURCE_MESSENGER.receiveMessage(removeFirst64Bytes(log.data), "");
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/CCTPIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,29 @@ contract CircleCCTPIntegrationTest is IntegrationBaseTest {
host.selectFork();

MessageOrderingCCTP moHost = new MessageOrderingCCTP(
address(cctp.L1_MESSENGER()),
address(cctp.SOURCE_MESSENGER()),
guestDomain,
l1Authority
);

cctp.selectFork();

MessageOrderingCCTP moCCTP = new MessageOrderingCCTP(
address(cctp.L2_MESSENGER()),
address(cctp.DESTINATION_MESSENGER()),
hostDomain,
l1Authority
);

// Queue up some L2 -> L1 messages
vm.startPrank(l1Authority);
XChainForwarders.sendMessageCCTP(
address(cctp.L2_MESSENGER()),
address(cctp.DESTINATION_MESSENGER()),
hostDomain,
address(moHost),
abi.encodeWithSelector(MessageOrdering.push.selector, 3)
);
XChainForwarders.sendMessageCCTP(
address(cctp.L2_MESSENGER()),
address(cctp.DESTINATION_MESSENGER()),
hostDomain,
address(moHost),
abi.encodeWithSelector(MessageOrdering.push.selector, 4)
Expand Down Expand Up @@ -141,7 +141,7 @@ contract CircleCCTPIntegrationTest is IntegrationBaseTest {
moCCTP.handleReceiveMessage(0, bytes32(uint256(uint160(l1Authority))), abi.encodeWithSelector(MessageOrdering.push.selector, 999));

assertEq(moCCTP.sourceDomain(), 0);
vm.prank(address(cctp.L2_MESSENGER()));
vm.prank(address(cctp.DESTINATION_MESSENGER()));
vm.expectRevert("Receiver/invalid-sourceDomain");
moCCTP.handleReceiveMessage(1, bytes32(uint256(uint160(l1Authority))), abi.encodeWithSelector(MessageOrdering.push.selector, 999));
}
Expand Down

0 comments on commit 8e5b368

Please sign in to comment.