Skip to content
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
16 changes: 9 additions & 7 deletions src/domains/ArbitrumDomain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ contract ArbitrumDomain is BridgedDomain {
selectFork();

// Read all L1 -> L2 messages and relay them under Arbitrum fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
for (; lastFromHostLogIndex < logs.length; lastFromHostLogIndex++) {
Vm.Log memory log = logs[lastFromHostLogIndex];
Vm.Log[] memory logs = RecordedLogs.getLogs(lastFromHostLogIndex);
lastFromHostLogIndex += logs.length;
for (uint256 i = 0; i < logs.length; i++) {
Vm.Log memory log = logs[i];
if (log.topics[0] == MESSAGE_DELIVERED_TOPIC) {
// We need both the current event and the one that follows for all the relevant data
Vm.Log memory logWithData = logs[lastFromHostLogIndex + 1];
Vm.Log memory logWithData = logs[i + 1];
(,, address sender,,,) = abi.decode(log.data, (address, uint8, address, bytes32, uint256, uint64));
(address target, bytes memory message) = parseData(logWithData.data);
vm.startPrank(sender);
Expand Down Expand Up @@ -150,9 +151,10 @@ contract ArbitrumDomain is BridgedDomain {
hostDomain.selectFork();

// Read all L2 -> L1 messages and relay them under host fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
for (; lastToHostLogIndex < logs.length; lastToHostLogIndex++) {
Vm.Log memory log = logs[lastToHostLogIndex];
Vm.Log[] memory logs = RecordedLogs.getLogs(lastToHostLogIndex);
lastToHostLogIndex += logs.length;
for (uint256 i = 0; i < logs.length; i++) {
Vm.Log memory log = logs[i];
if (log.topics[0] == SEND_TO_L1_TOPIC) {
(address sender, address target, bytes memory message) = abi.decode(log.data, (address, address, bytes));
l2ToL1Sender = sender;
Expand Down
18 changes: 10 additions & 8 deletions src/domains/OptimismDomain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ contract OptimismDomain is BridgedDomain {
}

// Read all L1 -> L2 messages and relay them under Optimism fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
if (!isGoerli() && lastToHostLogIndex > lastFromHostLogIndex) lastFromHostLogIndex = lastToHostLogIndex;
for (; lastFromHostLogIndex < logs.length; lastFromHostLogIndex++) {
Vm.Log memory log = logs[lastFromHostLogIndex];
if (log.topics[0] == SENT_MESSAGE_TOPIC && (!isGoerli() || logs[lastFromHostLogIndex - 1].topics[0] == DEPOSIT_IDENTIFIER)) {
Vm.Log[] memory logs = RecordedLogs.getLogs(lastFromHostLogIndex);
lastFromHostLogIndex += logs.length;
for (uint256 i = 0; i < logs.length; i++) {
Vm.Log memory log = logs[i];
if (log.topics[0] == SENT_MESSAGE_TOPIC && (!isGoerli() || logs[i - 1].topics[0] == DEPOSIT_IDENTIFIER)) {
address target = address(uint160(uint256(log.topics[1])));
(address sender, bytes memory message, uint256 nonce, uint256 gasLimit) = abi.decode(log.data, (address, bytes, uint256, uint256));
vm.startPrank(malias);
Expand All @@ -105,11 +106,12 @@ contract OptimismDomain is BridgedDomain {

// Read all L2 -> L1 messages and relay them under Primary fork
// Note: We bypass the L1 messenger relay here because it's easier to not have to generate valid state roots / merkle proofs
Vm.Log[] memory logs = RecordedLogs.getLogs();
if (!isGoerli() && lastFromHostLogIndex > lastToHostLogIndex) lastToHostLogIndex = lastFromHostLogIndex;
for (; lastToHostLogIndex < logs.length; lastToHostLogIndex++) {
Vm.Log memory log = logs[lastToHostLogIndex];
if (log.topics[0] == SENT_MESSAGE_TOPIC && (!isGoerli() || logs[lastToHostLogIndex - 1].topics[0] == WITHDRAW_IDENTIFIER)) {
Vm.Log[] memory logs = RecordedLogs.getLogs(lastToHostLogIndex);
lastToHostLogIndex += logs.length;
for (uint256 i = 0; i < logs.length; i++) {
Vm.Log memory log = logs[i];
if (log.topics[0] == SENT_MESSAGE_TOPIC && (!isGoerli() || logs[i - 1].topics[0] == WITHDRAW_IDENTIFIER)) {
address target = address(uint160(uint256(log.topics[1])));
(address sender, bytes memory message,,) = abi.decode(log.data, (address, bytes, uint256, uint256));
// Set xDomainMessageSender
Expand Down
17 changes: 17 additions & 0 deletions src/domains/RecordedLogs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ contract RecordedLogsStorage {
return _logs;
}

function getLogs(uint256 startIndex) public view returns (Vm.Log[] memory) {
if (startIndex >= _logs.length) {
return new Vm.Log[](0);
}
Vm.Log[] memory logs = new Vm.Log[](_logs.length - startIndex);
for (uint256 i = startIndex; i < _logs.length; i++) {
logs[i - startIndex] = _logs[i];
}
return logs;
}

}

library RecordedLogs {
Expand Down Expand Up @@ -68,4 +79,10 @@ library RecordedLogs {
return STORAGE.getLogs();
}

function getLogs(uint256 startIndex) internal returns (Vm.Log[] memory) {
checkInitialized();
STORAGE.addLogs(vm.getRecordedLogs());
return STORAGE.getLogs(startIndex);
}

}