Skip to content

Commit

Permalink
feat(L2toL2CDM): improve gas estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
tremarkley committed Oct 18, 2024
1 parent f99424d commit 6baaa61
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IL2ToL2CrossDomainMessenger } from "src/L2/interfaces/IL2ToL2CrossDomai
import { ISemver } from "src/universal/interfaces/ISemver.sol";
import { SafeCall } from "src/libraries/SafeCall.sol";
import { TransientReentrancyAware } from "src/libraries/TransientContext.sol";
import { Constants } from "src/libraries/Constants.sol";

/// @notice Thrown when a non-written slot in transient storage is attempted to be read from.
error NotEntered();
Expand Down Expand Up @@ -92,12 +93,6 @@ contract L2ToL2CrossDomainMessenger is IL2ToL2CrossDomainMessenger, ISemver, Tra
/// @param messageHash Hash of the message that was relayed.
event RelayedMessage(uint256 indexed source, uint256 indexed messageNonce, bytes32 indexed messageHash);

/// @notice Emitted whenever a message fails to be relayed on this chain.
/// @param source Chain ID of the source chain.
/// @param messageNonce Nonce associated with the messsage sent
/// @param messageHash Hash of the message that failed to be relayed.
event FailedRelayedMessage(uint256 indexed source, uint256 indexed messageNonce, bytes32 indexed messageHash);

/// @notice Retrieves the sender of the current cross domain message. If not entered, reverts.
/// @return sender_ Address of the sender of the current cross domain message.
function crossDomainMessageSender() external view onlyEntered returns (address sender_) {
Expand Down Expand Up @@ -204,7 +199,7 @@ contract L2ToL2CrossDomainMessenger is IL2ToL2CrossDomainMessenger, ISemver, Tra
successfulMessages[messageHash] = true;
emit RelayedMessage(source, nonce, messageHash);
} else {
emit FailedRelayedMessage(source, nonce, messageHash);
revert("L2ToL2CrossDomainMessenger: failed to relay message");
}

_storeMessageMetadata(0, address(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,6 @@ contract L2ToL2CrossDomainMessengerTest is Test {
address target = address(this);
bytes memory message = abi.encodeWithSelector(this.mockTargetReentrant.selector, _source2, _nonce, _sender2);

// Look for correct emitted event
vm.expectEmit(Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER);
emit L2ToL2CrossDomainMessenger.FailedRelayedMessage(
_source1, _nonce, keccak256(abi.encode(block.chainid, _source1, _nonce, _sender1, target, message))
);

// Ensure the target contract is called with the correct parameters
vm.expectCall({ callee: target, msgValue: _value, data: message });

Expand All @@ -426,6 +420,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
returnData: ""
});

vm.expectRevert("L2ToL2CrossDomainMessenger: failed to relay message");
hoax(Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER, _value);
l2ToL2CrossDomainMessenger.relayMessage{ value: _value }(id, sentMessage);

Expand Down Expand Up @@ -673,12 +668,6 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure that the target contract reverts
vm.mockCallRevert({ callee: _target, msgValue: _value, data: _message, revertData: abi.encode(false) });

// Look for correct emitted event
vm.expectEmit(Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER);
emit L2ToL2CrossDomainMessenger.FailedRelayedMessage(
_source, _nonce, keccak256(abi.encode(block.chainid, _source, _nonce, _sender, _target, _message))
);

ICrossL2Inbox.Identifier memory id =
ICrossL2Inbox.Identifier(Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER, _blockNum, _logIndex, _time, _source);
bytes memory sentMessage = abi.encodePacked(
Expand All @@ -693,6 +682,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
returnData: ""
});

vm.expectRevert("L2ToL2CrossDomainMessenger: failed to relay message");
hoax(Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER, _value);
l2ToL2CrossDomainMessenger.relayMessage{ value: _value }(id, sentMessage);
}
Expand Down

0 comments on commit 6baaa61

Please sign in to comment.