Skip to content
Merged
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
59 changes: 45 additions & 14 deletions op-bindings/bindings/l2tol1messagepasser.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions op-bindings/bindings/l2tol1messagepasser_more.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"math/big"
"os"
"path/filepath"
Expand Down Expand Up @@ -327,11 +326,8 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
return storage, errors.New("block base fee not set")
}

// Set the initial L2ToL1MessagePasser nonce to
// `type(uint32).max` to prevent nonce collisions
// with historical withdrawals.
storage["L2ToL1MessagePasser"] = state.StorageValues{
"nonce": math.MaxUint32,
"msgNonce": 0,
}
storage["L2CrossDomainMessenger"] = state.StorageValues{
"_initialized": 1,
Expand Down
18 changes: 9 additions & 9 deletions packages/contracts-bedrock/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ L2CrossDomainMessenger_Test:test_L2MessengerRelayMessageSucceeds() (gas: 53204)
L2CrossDomainMessenger_Test:test_L2MessengerRelayMessageToSystemContract() (gas: 36172)
L2CrossDomainMessenger_Test:test_L2MessengerRelayMessageV0Fails() (gas: 18870)
L2CrossDomainMessenger_Test:test_L2MessengerRelayShouldRevertIfPaused() (gas: 41596)
L2CrossDomainMessenger_Test:test_L2MessengerSendMessage() (gas: 122423)
L2CrossDomainMessenger_Test:test_L2MessengerTwiceSendMessage() (gas: 134632)
L2CrossDomainMessenger_Test:test_L2MessengerSendMessage() (gas: 122533)
L2CrossDomainMessenger_Test:test_L2MessengerTwiceSendMessage() (gas: 134716)
L2CrossDomainMessenger_Test:test_L2MessengerXDomainSenderReverts() (gas: 10568)
L2CrossDomainMessenger_Test:test_L2MessengerxDomainMessageSenderResets() (gas: 52615)
L2OutputOracleTest:testCannot_ProposeWithUnmatchedBlockhash() (gas: 29434)
Expand Down Expand Up @@ -118,13 +118,13 @@ L2StandardBridge_Test:test_finalizeBridgeETH_sendToMessengerReverts() (gas: 2396
L2StandardBridge_Test:test_finalizeBridgeETH_sendToSelfReverts() (gas: 23793)
L2StandardBridge_Test:test_finalizeDeposit() (gas: 89363)
L2StandardBridge_Test:test_initialize() (gas: 10536)
L2StandardBridge_Test:test_receive() (gas: 131820)
L2StandardBridge_Test:test_withdraw() (gas: 343951)
L2StandardBridge_Test:test_withdrawTo() (gas: 344680)
L2StandardBridge_Test:test_receive() (gas: 131862)
L2StandardBridge_Test:test_withdraw() (gas: 343984)
L2StandardBridge_Test:test_withdrawTo() (gas: 344713)
L2StandardBridge_Test:test_withdraw_onlyEOA() (gas: 251816)
L2ToL1MessagePasserTest:test_burn() (gas: 112530)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromContract() (gas: 70246)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromEOA() (gas: 75764)
L2ToL1MessagePasserTest:test_burn() (gas: 112594)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromContract() (gas: 70356)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromEOA() (gas: 75874)
LegacyERC20ETH_Test:test_approve() (gas: 10723)
LegacyERC20ETH_Test:test_burn() (gas: 10615)
LegacyERC20ETH_Test:test_crossDomain() (gas: 6339)
Expand Down Expand Up @@ -293,4 +293,4 @@ SequencerFeeVault_Test:test_constructor() (gas: 5459)
SequencerFeeVault_Test:test_minWithdrawalAmount() (gas: 5418)
SequencerFeeVault_Test:test_receive() (gas: 17316)
SequencerFeeVault_Test:test_revertWithdraw() (gas: 9343)
SequencerFeeVault_Test:test_withdraw() (gas: 135837)
SequencerFeeVault_Test:test_withdraw() (gas: 135879)
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/.storage-layout
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
+============================================================================================================================+
| sentMessages | mapping(bytes32 => bool) | 0 | 0 | 32 | contracts/L2/L2ToL1MessagePasser.sol:L2ToL1MessagePasser |
|--------------+--------------------------+------+--------+-------+----------------------------------------------------------|
| nonce | uint256 | 1 | 0 | 32 | contracts/L2/L2ToL1MessagePasser.sol:L2ToL1MessagePasser |
| msgNonce | uint240 | 1 | 0 | 30 | contracts/L2/L2ToL1MessagePasser.sol:L2ToL1MessagePasser |
+--------------+--------------------------+------+--------+-------+----------------------------------------------------------+

=======================
Expand Down
48 changes: 37 additions & 11 deletions packages/contracts-bedrock/contracts/L2/L2ToL1MessagePasser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.15;

import { Types } from "../libraries/Types.sol";
import { Hashing } from "../libraries/Hashing.sol";
import { Encoding } from "../libraries/Encoding.sol";
import { Burn } from "../libraries/Burn.sol";
import { Semver } from "../universal/Semver.sol";

Expand All @@ -20,6 +21,11 @@ contract L2ToL1MessagePasser is Semver {
*/
uint256 internal constant RECEIVE_DEFAULT_GAS_LIMIT = 100_000;

/**
* @notice Current message version identifier.
*/
uint16 public constant MESSAGE_VERSION = 1;

/**
* @notice Includes the message hashes for all withdrawals
*/
Expand All @@ -28,18 +34,18 @@ contract L2ToL1MessagePasser is Semver {
/**
* @notice A unique value hashed with each withdrawal.
*/
uint256 public nonce;
uint240 internal msgNonce;

/**
* @notice Emitted any time a withdrawal is initiated.
*
* @param nonce Unique value corresponding to each withdrawal.
* @param sender The L2 account address which initiated the withdrawal.
* @param target The L1 account address the call will be send to.
* @param value The ETH value submitted for withdrawal, to be forwarded to the target.
* @param gasLimit The minimum amount of gas that must be provided when withdrawing on L1.
* @param data The data to be forwarded to the target on L1.
* @param withdrawalHash The hash of the withdrawal.
* @param nonce Unique value corresponding to each withdrawal.
* @param sender The L2 account address which initiated the withdrawal.
* @param target The L1 account address the call will be send to.
* @param value The ETH value submitted for withdrawal, to be forwarded to the target.
* @param gasLimit The minimum amount of gas that must be provided when withdrawing.
* @param data The data to be forwarded to the target on L1.
* @param withdrawalHash The hash of the withdrawal.
*/
event MessagePassed(
uint256 indexed nonce,
Expand Down Expand Up @@ -96,7 +102,7 @@ contract L2ToL1MessagePasser is Semver {
) public payable {
bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction({
nonce: nonce,
nonce: messageNonce(),
sender: msg.sender,
target: _target,
value: msg.value,
Expand All @@ -107,9 +113,29 @@ contract L2ToL1MessagePasser is Semver {

sentMessages[withdrawalHash] = true;

emit MessagePassed(nonce, msg.sender, _target, msg.value, _gasLimit, _data, withdrawalHash);
emit MessagePassed(
messageNonce(),
msg.sender,
_target,
msg.value,
_gasLimit,
_data,
withdrawalHash
);

unchecked {
++nonce;
++msgNonce;
}
}

/**
* @notice Retrieves the next message nonce. Message version will be added to the upper two
* bytes of the message nonce. Message version allows us to treat messages as having
* different structures.
*
* @return Nonce of the next message to be sent, with added message version.
*/
function messageNonce() public view returns (uint256) {
return Encoding.encodeVersionedNonce(msgNonce, MESSAGE_VERSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
// MessagePassed event
vm.expectEmit(true, true, true, true);
emit MessagePassed(
messagePasser.nonce(),
messagePasser.messageNonce(),
address(L2Messenger),
address(L1Messenger),
0,
L2Messenger.baseGas(hex"ff", 100),
xDomainCallData,
Hashing.hashWithdrawal(
Types.WithdrawalTransaction({
nonce: messagePasser.nonce(),
nonce: messagePasser.messageNonce(),
sender: address(L2Messenger),
target: address(L1Messenger),
value: 0,
Expand Down
Loading