@@ -3,10 +3,11 @@ package types
33import (
44 "crypto/ecdsa"
55 "errors"
6+ "math/big"
67
78 "github.com/ethereum/go-ethereum/common"
89 "github.com/ethereum/go-ethereum/crypto"
9- solsha3 "github.com/miguelmota /go-solidity-sha3 "
10+ "github.com/iden3 /go-iden3-crypto/keccak256 "
1011)
1112
1213// Batch represents the batch data that the sequencer will send to L1
@@ -30,39 +31,41 @@ type SequenceBanana struct {
3031// HashToSign returns the accumulated input hash of the sequence.
3132// Note that this is equivalent to what happens on the smart contract
3233func (s * SequenceBanana ) HashToSign () []byte {
33- currentHash := s .OldAccInputHash .Bytes ()
34+ v1 := s .OldAccInputHash .Bytes ()
3435 for _ , b := range s .Batches {
35- types := []string {
36- "bytes32" , // oldAccInputHash
37- "bytes32" , // currentTransactionsHash
38- "bytes32" , // forcedGlobalExitRoot or l1InfoRoot
39- "uint64" , // forcedTimestamp
40- "address" , // coinbase
41- "bytes32" , // forcedBlockHashL1
42- }
43- var values []interface {}
36+ v2 := b .L2Data
37+ var v3 , v4 []byte
4438 if b .ForcedTimestamp > 0 {
45- values = []interface {}{
46- currentHash ,
47- crypto .Keccak256 (b .L2Data ),
48- b .ForcedGER ,
49- b .ForcedTimestamp ,
50- b .Coinbase ,
51- b .ForcedBlockHashL1 ,
52- }
39+ v3 = b .ForcedGER .Bytes ()
40+ v4 = big .NewInt (0 ).SetUint64 (uint64 (b .ForcedTimestamp )).Bytes ()
5341 } else {
54- values = []interface {}{
55- currentHash ,
56- crypto .Keccak256 (b .L2Data ),
57- s .L1InfoRoot ,
58- s .MaxSequenceTimestamp ,
59- b .Coinbase ,
60- common.Hash {},
61- }
42+ v3 = s .L1InfoRoot .Bytes ()
43+ v4 = big .NewInt (0 ).SetUint64 (uint64 (s .MaxSequenceTimestamp )).Bytes ()
44+ }
45+ v5 := b .Coinbase .Bytes ()
46+ v6 := b .ForcedBlockHashL1 .Bytes ()
47+
48+ // Add 0s to make values 32 bytes long
49+ for len (v1 ) < 32 {
50+ v1 = append ([]byte {0 }, v1 ... )
51+ }
52+ v2 = keccak256 .Hash (v2 )
53+ for len (v3 ) < 32 {
54+ v3 = append ([]byte {0 }, v3 ... )
6255 }
63- currentHash = solsha3 .SoliditySHA3 (types , values )
56+ for len (v4 ) < 8 {
57+ v4 = append ([]byte {0 }, v4 ... )
58+ }
59+ for len (v5 ) < 20 {
60+ v5 = append ([]byte {0 }, v5 ... )
61+ }
62+ for len (v6 ) < 32 {
63+ v6 = append ([]byte {0 }, v6 ... )
64+ }
65+ v1 = keccak256 .Hash (v1 , v2 , v3 , v4 , v5 , v6 )
6466 }
65- return currentHash
67+
68+ return v1
6669}
6770
6871// Sign returns a signed sequence by the private key.
0 commit comments