Skip to content

Commit b38eac2

Browse files
committed
Deposit queue
1 parent f3b9f0c commit b38eac2

28 files changed

+241
-93
lines changed

op-node/rollup/derive/deposit_log.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
var (
1818
DepositEventABI = "TransactionDeposited(address,address,uint256,bytes)"
1919
DepositEventABIHash = crypto.Keccak256Hash([]byte(DepositEventABI))
20-
DepositEventVersion0 = common.Hash{}
20+
DepositEventVersion0 = uint64(0)
21+
DepositEventVersion1 = uint64(1)
2122
)
2223

2324
// UnmarshalDepositLogEvent decodes an EVM log entry emitted by the deposit contract into typed deposit data.
@@ -27,7 +28,7 @@ var (
2728
// event TransactionDeposited(
2829
// address indexed from,
2930
// address indexed to,
30-
// uint256 indexed version,
31+
// uint256 indexed nonceAndVersion,
3132
// bytes opaqueData
3233
// );
3334
//
@@ -51,7 +52,7 @@ func UnmarshalDepositLogEvent(ev *types.Log) (*types.DepositTx, error) {
5152
// indexed 1
5253
to := common.BytesToAddress(ev.Topics[2][12:])
5354
// indexed 2
54-
version := ev.Topics[3]
55+
nonceAndVersion := ev.Topics[3]
5556
// unindexed data
5657
// Solidity serializes the event's Data field as follows:
5758
// abi.encode(abi.encodPacked(uint256 mint, uint256 value, uint64 gasLimit, uint8 isCreation, bytes data))
@@ -83,19 +84,38 @@ func UnmarshalDepositLogEvent(ev *types.Log) (*types.DepositTx, error) {
8384
dep.From = from
8485
dep.IsSystemTransaction = false
8586

87+
_, version := unpackNonceAndVersion(nonceAndVersion)
88+
8689
var err error
8790
switch version {
8891
case DepositEventVersion0:
8992
err = unmarshalDepositVersion0(&dep, to, opaqueData)
93+
case DepositEventVersion1:
94+
err = unmarshalDepositVersion1(&dep, to, opaqueData)
9095
default:
91-
return nil, fmt.Errorf("invalid deposit version, got %s", version)
96+
return nil, fmt.Errorf("invalid deposit version, got %d", version)
9297
}
9398
if err != nil {
94-
return nil, fmt.Errorf("failed to decode deposit (version %s): %w", version, err)
99+
return nil, fmt.Errorf("failed to decode deposit (version %d): %w", version, err)
95100
}
96101
return &dep, nil
97102
}
98103

104+
func unpackNonceAndVersion(nonceAndVersion common.Hash) (nonce uint64, version uint64) {
105+
i := new(big.Int).SetBytes(nonceAndVersion[:])
106+
mask64 := new(big.Int).SetBytes(common.Hex2Bytes("ffffffffffffffff"))
107+
version = mask64.And(mask64, i).Uint64()
108+
nonce = i.Lsh(i, 128).Uint64()
109+
return
110+
}
111+
112+
func packNonceAndVersion(nonce uint64, version uint64) common.Hash {
113+
i := new(big.Int).SetUint64(nonce)
114+
i.Rsh(i, 128)
115+
i.Or(i, new(big.Int).SetUint64(version))
116+
return common.BytesToHash(i.Bytes())
117+
}
118+
99119
func unmarshalDepositVersion0(dep *types.DepositTx, to common.Address, opaqueData []byte) error {
100120
if len(opaqueData) < 32+32+8+1 {
101121
return fmt.Errorf("unexpected opaqueData length: %d", len(opaqueData))
@@ -140,6 +160,11 @@ func unmarshalDepositVersion0(dep *types.DepositTx, to common.Address, opaqueDat
140160
return nil
141161
}
142162

163+
func unmarshalDepositVersion1(dep *types.DepositTx, to common.Address, opaqueData []byte) error {
164+
// version 1 simply adds a nonce; the rest is the same
165+
return unmarshalDepositVersion0(dep, to, opaqueData)
166+
}
167+
143168
// MarshalDepositLogEvent returns an EVM log entry that encodes a TransactionDeposited event from the deposit contract.
144169
// This is the reverse of the deposit transaction derivation.
145170
func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.DepositTx) (*types.Log, error) {
@@ -151,7 +176,7 @@ func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.D
151176
DepositEventABIHash,
152177
eth.AddressAsLeftPaddedHash(deposit.From),
153178
toBytes,
154-
DepositEventVersion0,
179+
packNonceAndVersion(0, DepositEventVersion0),
155180
}
156181

157182
data := make([]byte, 64, 64+3*32)

op-node/rollup/derive/deposit_log_tob_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ func FuzzDeriveDepositsBadVersion(f *testing.F) {
188188
// Generate any topic but the deposit event versions we support.
189189
// TODO: As opposed to keeping this hardcoded, a method such as IsValidVersion(v) should be
190190
// used here.
191-
badTopic := DepositEventVersion0
192-
for badTopic == DepositEventVersion0 {
193-
typeProvider.Fuzz(&badTopic)
191+
badVersion := DepositEventVersion0
192+
for badVersion == DepositEventVersion0 {
193+
typeProvider.Fuzz(&badVersion)
194194
}
195195

196196
// Set our bad topic and update our state
197-
log.Topics[3] = badTopic
197+
log.Topics[3] = packNonceAndVersion(0, badVersion)
198198
hasBadDepositVersion = true
199199
}
200200
}

op-node/rollup/derive/system_config.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ var (
2727
var (
2828
ConfigUpdateEventABI = "ConfigUpdate(uint256,uint8,bytes)"
2929
ConfigUpdateEventABIHash = crypto.Keccak256Hash([]byte(ConfigUpdateEventABI))
30-
ConfigUpdateEventVersion0 = common.Hash{}
30+
ConfigUpdateEventVersion0 = uint64(0)
31+
ConfigUpdateEventVersion1 = uint64(1)
3132
)
3233

3334
// UpdateSystemConfigWithL1Receipts filters all L1 receipts to find config updates and applies the config updates to the given sysCfg
@@ -53,7 +54,7 @@ func UpdateSystemConfigWithL1Receipts(sysCfg *eth.SystemConfig, receipts []*type
5354
// parse log data for:
5455
//
5556
// event ConfigUpdate(
56-
// uint256 indexed version,
57+
// uint256 indexed nonceAndVersion,
5758
// UpdateType indexed updateType,
5859
// bytes data
5960
// );
@@ -66,10 +67,14 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
6667
}
6768

6869
// indexed 0
69-
version := ev.Topics[1]
70-
if version != ConfigUpdateEventVersion0 {
71-
return fmt.Errorf("unrecognized SystemConfig update event version: %s", version)
70+
_, version := unpackNonceAndVersion(ev.Topics[1])
71+
switch version {
72+
case ConfigUpdateEventVersion0:
73+
case ConfigUpdateEventVersion1:
74+
default:
75+
return fmt.Errorf("unrecognized SystemConfig update event version: %d", version)
7276
}
77+
7378
// indexed 1
7479
updateType := ev.Topics[2]
7580

op-node/rollup/derive/system_config_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestProcessSystemConfigUpdateLogEvent(t *testing.T) {
5757
log: &types.Log{
5858
Topics: []common.Hash{
5959
ConfigUpdateEventABIHash,
60-
ConfigUpdateEventVersion0,
60+
packNonceAndVersion(0, ConfigUpdateEventVersion0),
6161
SystemConfigUpdateUnsafeBlockSigner,
6262
},
6363
},
@@ -77,7 +77,7 @@ func TestProcessSystemConfigUpdateLogEvent(t *testing.T) {
7777
log: &types.Log{
7878
Topics: []common.Hash{
7979
ConfigUpdateEventABIHash,
80-
ConfigUpdateEventVersion0,
80+
packNonceAndVersion(0, ConfigUpdateEventVersion0),
8181
SystemConfigUpdateBatcher,
8282
},
8383
},
@@ -101,7 +101,7 @@ func TestProcessSystemConfigUpdateLogEvent(t *testing.T) {
101101
log: &types.Log{
102102
Topics: []common.Hash{
103103
ConfigUpdateEventABIHash,
104-
ConfigUpdateEventVersion0,
104+
packNonceAndVersion(0, ConfigUpdateEventVersion0),
105105
SystemConfigUpdateFeeScalars,
106106
},
107107
},
@@ -127,7 +127,7 @@ func TestProcessSystemConfigUpdateLogEvent(t *testing.T) {
127127
log: &types.Log{
128128
Topics: []common.Hash{
129129
ConfigUpdateEventABIHash,
130-
ConfigUpdateEventVersion0,
130+
packNonceAndVersion(0, ConfigUpdateEventVersion0),
131131
SystemConfigUpdateGasLimit,
132132
},
133133
},
@@ -151,7 +151,7 @@ func TestProcessSystemConfigUpdateLogEvent(t *testing.T) {
151151
log: &types.Log{
152152
Topics: []common.Hash{
153153
ConfigUpdateEventABIHash,
154-
ConfigUpdateEventVersion0,
154+
packNonceAndVersion(0, ConfigUpdateEventVersion0),
155155
SystemConfigUpdateFeeScalars,
156156
},
157157
},
@@ -191,7 +191,7 @@ func TestProcessSystemConfigUpdateLogEvent(t *testing.T) {
191191
log: &types.Log{
192192
Topics: []common.Hash{
193193
ConfigUpdateEventABIHash,
194-
ConfigUpdateEventVersion0,
194+
packNonceAndVersion(0, ConfigUpdateEventVersion0),
195195
SystemConfigUpdateEIP1559Params,
196196
},
197197
},

packages/contracts-bedrock/interfaces/L1/IOptimismPortal2.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface IOptimismPortal2 {
3838
event DisputeGameBlacklisted(IDisputeGame indexed disputeGame);
3939
event Initialized(uint8 version);
4040
event RespectedGameTypeSet(GameType indexed newGameType, Timestamp indexed updatedAt);
41-
event TransactionDeposited(address indexed from, address indexed to, uint256 indexed version, bytes opaqueData);
41+
event TransactionDeposited(address indexed from, address indexed to, uint256 indexed nonceAndVersion, bytes opaqueData);
4242
event WithdrawalFinalized(bytes32 indexed withdrawalHash, bool success);
4343
event WithdrawalProven(bytes32 indexed withdrawalHash, address indexed from, address indexed to);
4444
event WithdrawalProvenExtension1(bytes32 indexed withdrawalHash, address indexed proofSubmitter);
@@ -92,6 +92,7 @@ interface IOptimismPortal2 {
9292
function paused() external view returns (bool);
9393
function proofMaturityDelaySeconds() external view returns (uint256);
9494
function proofSubmitters(bytes32, uint256) external view returns (address);
95+
function transactionDepositedNonce() external view returns (uint256);
9596
function proveWithdrawalTransaction(
9697
Types.WithdrawalTransaction memory _tx,
9798
uint256 _disputeGameIndex,

packages/contracts-bedrock/interfaces/L1/IOptimismPortalInterop.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface IOptimismPortalInterop {
3939
event DisputeGameBlacklisted(IDisputeGame indexed disputeGame);
4040
event Initialized(uint8 version);
4141
event RespectedGameTypeSet(GameType indexed newGameType, Timestamp indexed updatedAt);
42-
event TransactionDeposited(address indexed from, address indexed to, uint256 indexed version, bytes opaqueData);
42+
event TransactionDeposited(address indexed from, address indexed to, uint256 indexed nonceAndVersion, bytes opaqueData);
4343
event WithdrawalFinalized(bytes32 indexed withdrawalHash, bool success);
4444
event WithdrawalProven(bytes32 indexed withdrawalHash, address indexed from, address indexed to);
4545
event WithdrawalProvenExtension1(bytes32 indexed withdrawalHash, address indexed proofSubmitter);
@@ -93,6 +93,7 @@ interface IOptimismPortalInterop {
9393
function paused() external view returns (bool);
9494
function proofMaturityDelaySeconds() external view returns (uint256);
9595
function proofSubmitters(bytes32, uint256) external view returns (address);
96+
function transactionDepositedNonce() external view returns (uint256);
9697
function proveWithdrawalTransaction(
9798
Types.WithdrawalTransaction memory _tx,
9899
uint256 _disputeGameIndex,

packages/contracts-bedrock/interfaces/L1/ISystemConfig.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface ISystemConfig {
2323
address gasPayingToken;
2424
}
2525

26-
event ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data);
26+
event ConfigUpdate(uint256 indexed nonceAndVersion, UpdateType indexed updateType, bytes data);
2727
event Initialized(uint8 version);
2828
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
2929

@@ -45,6 +45,7 @@ interface ISystemConfig {
4545
function gasLimit() external view returns (uint64);
4646
function eip1559Denominator() external view returns (uint32);
4747
function eip1559Elasticity() external view returns (uint32);
48+
function configUpdateNonce() external view returns (uint256);
4849
function gasPayingToken() external view returns (address addr_, uint8 decimals_);
4950
function gasPayingTokenName() external view returns (string memory name_);
5051
function gasPayingTokenSymbol() external view returns (string memory symbol_);

packages/contracts-bedrock/interfaces/L1/ISystemConfigInterop.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol";
55
import { IResourceMetering } from "interfaces/L1/IResourceMetering.sol";
66

77
interface ISystemConfigInterop {
8-
event ConfigUpdate(uint256 indexed version, ISystemConfig.UpdateType indexed updateType, bytes data);
8+
event ConfigUpdate(uint256 indexed nonceAndVersion, ISystemConfig.UpdateType indexed updateType, bytes data);
99
event Initialized(uint8 version);
1010
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
1111

@@ -27,6 +27,7 @@ interface ISystemConfigInterop {
2727
function gasLimit() external view returns (uint64);
2828
function eip1559Denominator() external view returns (uint32);
2929
function eip1559Elasticity() external view returns (uint32);
30+
function configUpdateNonce() external view returns (uint256);
3031
function gasPayingToken() external view returns (address addr_, uint8 decimals_);
3132
function gasPayingTokenName() external view returns (string memory name_);
3233
function gasPayingTokenSymbol() external view returns (string memory symbol_);

packages/contracts-bedrock/snapshots/.gas-snapshot

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ GasBenchMark_L1BlockInterop_SetValuesInterop:test_setL1BlockValuesInterop_benchm
44
GasBenchMark_L1BlockInterop_SetValuesInterop_Warm:test_setL1BlockValuesInterop_benchmark() (gas: 5144)
55
GasBenchMark_L1Block_SetValuesEcotone:test_setL1BlockValuesEcotone_benchmark() (gas: 158531)
66
GasBenchMark_L1Block_SetValuesEcotone_Warm:test_setL1BlockValuesEcotone_benchmark() (gas: 7597)
7-
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369235)
8-
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967442)
9-
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 564429)
10-
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4076577)
11-
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 467041)
12-
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3512790)
13-
GasBenchMark_L1StandardBridge_Finalize:test_finalizeETHWithdrawal_benchmark() (gas: 72667)
7+
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369292)
8+
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967499)
9+
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 564486)
10+
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4076634)
11+
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 466926)
12+
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3512847)
13+
GasBenchMark_L1StandardBridge_Finalize:test_finalizeETHWithdrawal_benchmark() (gas: 72667)

packages/contracts-bedrock/snapshots/abi/OptimismPortal2.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,19 @@
669669
"stateMutability": "view",
670670
"type": "function"
671671
},
672+
{
673+
"inputs": [],
674+
"name": "transactionDepositedNonce",
675+
"outputs": [
676+
{
677+
"internalType": "uint256",
678+
"name": "",
679+
"type": "uint256"
680+
}
681+
],
682+
"stateMutability": "view",
683+
"type": "function"
684+
},
672685
{
673686
"inputs": [],
674687
"name": "version",
@@ -745,7 +758,7 @@
745758
{
746759
"indexed": true,
747760
"internalType": "uint256",
748-
"name": "version",
761+
"name": "nonceAndVersion",
749762
"type": "uint256"
750763
},
751764
{

0 commit comments

Comments
 (0)