@@ -17,7 +17,8 @@ import (
1717var (
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.
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+
99119func 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.
145170func 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 )
0 commit comments