Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ interface IL2ToL2CrossDomainMessenger {
/// @param messageNonce Nonce associated with the messsage sent
/// @param sender Address initiating this message call
/// @param message Message payload to call target with.
/// @param context Context of the message.
event SentMessage(
uint256 indexed destination, address indexed target, uint256 indexed messageNonce, address sender, bytes message
uint256 indexed destination,
address indexed target,
uint256 indexed messageNonce,
address sender,
bytes message,
bytes context
);

/// @notice Emitted whenever a message is successfully relayed on this chain.
Expand Down Expand Up @@ -116,13 +122,15 @@ interface IL2ToL2CrossDomainMessenger {
/// @param _sender Address that sent the message
/// @param _target Target contract or wallet address.
/// @param _message Message payload to call target with.
/// @param _context Context of the message.
/// @return messageHash_ The hash of the message being re-sent.
function resendMessage(
uint256 _destination,
uint256 _nonce,
address _sender,
address _target,
bytes calldata _message
bytes calldata _message,
bytes calldata _context
)
external
returns (bytes32 messageHash_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
"internalType": "bytes",
"name": "_message",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "_context",
"type": "bytes"
}
],
"name": "resendMessage",
Expand Down Expand Up @@ -302,6 +307,12 @@
"internalType": "bytes",
"name": "message",
"type": "bytes"
},
{
"indexed": false,
"internalType": "bytes",
"name": "context",
"type": "bytes"
}
],
"name": "SentMessage",
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/snapshots/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"sourceCodeHash": "0x83396cbd12a0c5c02e09a4d99c4b62ab4e9d9eb762745e63283e2e818a78a39c"
},
"src/L2/L2ToL2CrossDomainMessenger.sol:L2ToL2CrossDomainMessenger": {
"initCodeHash": "0xd997db3cb7c84c8c851719bcf561ef35eb660262b2f4093dd6a3d86c5426240f",
"sourceCodeHash": "0x33393a279f32ecd6641adf267b59413d86595357b4f50b8a09afb62b8fc7639c"
"initCodeHash": "0xdc587a5d2d6a105dd7fc3c0d41b2872e72714ecd274943dea9cfd44c0f0a0ec2",
"sourceCodeHash": "0xc6112743ecc38f8924c99e25f0ef91d793bc58eeb18773dad4382d317340daf6"
},
"src/L2/OperatorFeeVault.sol:OperatorFeeVault": {
"initCodeHash": "0x3d8c0d7736e8767f2f797da1c20c5fe30bd7f48a4cf75f376290481ad7c0f91f",
Expand Down
53 changes: 34 additions & 19 deletions packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,12 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
bytes32 internal constant CROSS_DOMAIN_MESSAGE_SOURCE_SLOT =
0x711dfa3259c842fffc17d6e1f1e0fc5927756133a2345ca56b4cb8178589fee7;

/// @notice Event selector for the SentMessage event. Will be removed in favor of reading
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer needed with the merged bugfix

// the `selector` property directly once crytic/slithe/#2566 is fixed.
bytes32 internal constant SENT_MESSAGE_EVENT_SELECTOR =
0x382409ac69001e11931a28435afef442cbfd20d9891907e8fa373ba7d351f320;

/// @notice Current message version identifier.
uint16 public constant messageVersion = uint16(0);

/// @notice Semantic version.
/// @custom:semver 1.2.0
string public constant version = "1.2.0";
/// @custom:semver 1.3.0
string public constant version = "1.3.0";

/// @notice Mapping of message hashes to boolean receipt values. Note that a message will only be present in this
/// mapping if it has successfully been relayed on this chain, and can therefore not be relayed again.
Expand All @@ -86,8 +81,14 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
/// @param messageNonce Nonce associated with the message sent
/// @param sender Address initiating this message call
/// @param message Message payload to call target with.
/// @param context Context of the message.
event SentMessage(
uint256 indexed destination, address indexed target, uint256 indexed messageNonce, address sender, bytes message
uint256 indexed destination,
address indexed target,
uint256 indexed messageNonce,
address sender,
bytes message,
bytes context
);

/// @notice Emitted whenever a message is successfully relayed on this chain.
Expand Down Expand Up @@ -145,19 +146,22 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
if (_target == Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER) revert MessageTargetL2ToL2CrossDomainMessenger();

uint256 nonce = messageNonce();
bytes memory context = "";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused, should there be a sendMessage(uint,address,bytes,bytes) in addition where the context can be set?


messageHash_ = Hashing.hashL2toL2CrossDomainMessage({
_destination: _destination,
_source: block.chainid,
_nonce: nonce,
_sender: msg.sender,
_target: _target,
_message: _message
_message: _message,
_context: context
});

sentMessages[messageHash_] = true;
msgNonce++;

emit SentMessage(_destination, _target, nonce, msg.sender, _message);
emit SentMessage(_destination, _target, nonce, msg.sender, _message, context);
}

/// @notice Re-emits a previously sent message event for old messages that haven't been
Expand All @@ -169,13 +173,15 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
/// @param _sender Address that sent the message
/// @param _target Target contract or wallet address.
/// @param _message Message payload to call target with.
/// @param _context The context of the message.
/// @return messageHash_ The hash of the message being re-sent.
function resendMessage(
uint256 _destination,
uint256 _nonce,
address _sender,
address _target,
bytes calldata _message
bytes calldata _message,
bytes calldata _context
)
external
returns (bytes32 messageHash_)
Expand All @@ -186,12 +192,13 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
_nonce: _nonce,
_sender: _sender,
_target: _target,
_message: _message
_message: _message,
_context: _context
});

if (!sentMessages[messageHash_]) revert InvalidMessage();

emit SentMessage(_destination, _target, _nonce, _sender, _message);
emit SentMessage(_destination, _target, _nonce, _sender, _message, _context);
}

/// @notice Relays a message that was sent by the other L2ToL2CrossDomainMessenger contract. Can only be executed
Expand All @@ -218,8 +225,8 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
ICrossL2Inbox(Predeploys.CROSS_L2_INBOX).validateMessage(_id, keccak256(_sentMessage));

// Decode the payload
(uint256 destination, address target, uint256 nonce, address sender, bytes memory message) =
_decodeSentMessagePayload(_sentMessage);
(uint256 destination, address target, uint256 nonce, address sender, bytes memory message, bytes memory context)
= _decodeSentMessagePayload(_sentMessage);

// Assert invariants on the message
if (destination != block.chainid) revert MessageDestinationNotRelayChain();
Expand All @@ -231,7 +238,8 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
_nonce: nonce,
_sender: sender,
_target: target,
_message: message
_message: message,
_context: context
});

if (successfulMessages[messageHash]) {
Expand Down Expand Up @@ -287,16 +295,23 @@ contract L2ToL2CrossDomainMessenger is ISemver, TransientReentrancyAware {
function _decodeSentMessagePayload(bytes calldata _payload)
internal
pure
returns (uint256 destination_, address target_, uint256 nonce_, address sender_, bytes memory message_)
returns (
uint256 destination_,
address target_,
uint256 nonce_,
address sender_,
bytes memory message_,
bytes memory context_
)
{
// Validate Selector (also reverts if LOG0 with no topics)
bytes32 selector = abi.decode(_payload[:32], (bytes32));
if (selector != SENT_MESSAGE_EVENT_SELECTOR) revert EventPayloadNotSentMessage();
if (selector != SentMessage.selector) revert EventPayloadNotSentMessage();

// Topics
(destination_, target_, nonce_) = abi.decode(_payload[32:128], (uint256, address, uint256));

// Data
(sender_, message_) = abi.decode(_payload[128:], (address, bytes));
(sender_, message_, context_) = abi.decode(_payload[128:], (address, bytes, bytes));
}
}
6 changes: 4 additions & 2 deletions packages/contracts-bedrock/src/libraries/Hashing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,22 @@ library Hashing {
/// @param _sender Address of the user who originally sent the message.
/// @param _target Address of the contract or wallet that the message is targeting on the destination chain.
/// @param _message The message payload to be relayed to the target on the destination chain.
/// @param _context The context of the message.
/// @return Hash of the encoded message parameters, used to uniquely identify the message.
function hashL2toL2CrossDomainMessage(
uint256 _destination,
uint256 _source,
uint256 _nonce,
address _sender,
address _target,
bytes memory _message
bytes memory _message,
bytes memory _context
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical to include here so that resendMessage works as intended

)
internal
pure
returns (bytes32)
{
return keccak256(abi.encode(_destination, _source, _nonce, _sender, _target, _message));
return keccak256(abi.encode(_destination, _source, _nonce, _sender, _target, _message, _context));
}

/// @notice Hashes a Super Root proof into a Super Root.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ISuperchainTokenBridge } from "interfaces/L2/ISuperchainTokenBridge.sol
/// @notice Integration test that checks that the `ExecutingMessage` event is emitted on crosschain mints.
contract ExecutingMessageEmittedTest is CommonTest {
bytes32 internal constant SENT_MESSAGE_EVENT_SELECTOR =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the selector property on the event itself rather than hardcoding it and needing it to change?

0x382409ac69001e11931a28435afef442cbfd20d9891907e8fa373ba7d351f320;
0x687289caffce8cccd179ad6b3eebf5b30d65912f573a6b50d0525642b073297e;

event ExecutingMessage(bytes32 indexed msgHash, Identifier id);

Expand Down Expand Up @@ -84,7 +84,7 @@ contract ExecutingMessageEmittedTest is CommonTest {
bytes memory message = abi.encodeCall(ISuperchainTokenBridge.relayERC20, (_token, _sender, _to, _amount));
bytes memory sentMessage = abi.encodePacked(
abi.encode(SENT_MESSAGE_EVENT_SELECTOR, block.chainid, SUPERCHAIN_TOKEN_BRIDGE, _nonce), // topics
abi.encode(_sender, message) // data
abi.encode(_sender, message, "") // data (no context)
);

// Mock `crossDomainMessageContext` call for it to succeed
Expand Down
Loading