Skip to content

Commit 8a05c96

Browse files
committed
fix endianness
1 parent 6131330 commit 8a05c96

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

cmd/ulxly/balanceandnullifiertreehelper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ulxly
22

33
import (
44
"bytes"
5+
"encoding/binary"
56
"fmt"
67
"math/big"
78
"strings"
@@ -289,3 +290,9 @@ func checkClaimCalldata(client *ethclient.Client, bridge common.Address, claimHa
289290
}
290291
return false, fmt.Errorf("claim not found")
291292
}
293+
294+
func Uint32ToBytesLittleEndian(num uint32) []byte {
295+
bytes := make([]byte, 4) // uint32 is 4 bytes
296+
binary.LittleEndian.PutUint32(bytes, num)
297+
return bytes
298+
}

cmd/ulxly/balanceandnullifiertreehelper_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/0xPolygon/polygon-cli/cmd/ulxly"
1111
"github.com/0xPolygon/polygon-cli/cmd/ulxly/testvectors"
1212
"github.com/ethereum/go-ethereum/common"
13+
"github.com/ethereum/go-ethereum/crypto"
1314
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
1516
)
@@ -137,3 +138,12 @@ func TestTokenString(t *testing.T) {
137138
assert.Equal(t, token2, newToken2)
138139
assert.Equal(t, token2.String(), newToken2.String())
139140
}
141+
142+
func TestCheckHash(t *testing.T) {
143+
balanceTreeRoot := common.HexToHash("0xb89931f7384aeddb5c136a679d54464007e2d828d4741bec626ff92aeb4b12d4")
144+
nullifierTreeRoot := common.HexToHash("0xe2c3ed4052eeb1d60514b4c38ece8d73a27f37fa5b36dcbf338e70de95798caa")
145+
ler_counter := uint32(0)
146+
147+
initPessimisticRoot := crypto.Keccak256Hash(balanceTreeRoot.Bytes(), nullifierTreeRoot.Bytes(), ulxly.Uint32ToBytesLittleEndian(ler_counter))
148+
assert.Equal(t, "0xc89c9c0f2ebd19afa9e5910097c43e56fb4aff3a06ddee8d7c9bae09bc769184", initPessimisticRoot.String())
149+
}

cmd/ulxly/ulxly.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232

3333
"github.com/0xPolygon/polygon-cli/bindings/ulxly"
3434
"github.com/0xPolygon/polygon-cli/bindings/ulxly/polygonrollupmanager"
35-
"github.com/0xPolygon/polygon-cli/bindings/ulxly/polygonzkevmglobalexitrootl2"
3635
"github.com/0xPolygon/polygon-cli/cmd/flag_loader"
3736
"github.com/rs/zerolog/log"
3837
"github.com/spf13/cobra"
@@ -373,20 +372,11 @@ func nullifierAndBalanceTree(args []string) error {
373372
if err != nil {
374373
return err
375374
}
376-
gerManagerAddress, err := bridgeV2.GlobalExitRootManager(&bind.CallOpts{Pending: false})
375+
ler_count, err := bridgeV2.LastUpdatedDepositCount(&bind.CallOpts{Pending: false})
377376
if err != nil {
378377
return err
379378
}
380-
gerManager, err := polygonzkevmglobalexitrootl2.NewPolygonzkevmglobalexitrootl2(gerManagerAddress, client)
381-
if err != nil {
382-
return err
383-
}
384-
var ler common.Hash
385-
ler, err = gerManager.LastRollupExitRoot(&bind.CallOpts{Pending: false})
386-
if err != nil {
387-
return err
388-
}
389-
log.Info().Msgf("Last Local Exit Root: %s", ler.String())
379+
log.Info().Msgf("Last LER count: %d", ler_count)
390380
balanceTreeRoot, err := computeBalanceTree(client, bridgeAddress, l2RawClaimsData, l2NetworkID, l2RawDepositsData)
391381
if err != nil {
392382
return err
@@ -395,7 +385,7 @@ func nullifierAndBalanceTree(args []string) error {
395385
if err != nil {
396386
return err
397387
}
398-
initPessimisticRoot := crypto.Keccak256Hash(balanceTreeRoot.Bytes(), nullifierTreeRoot.Bytes(), ler.Bytes())
388+
initPessimisticRoot := crypto.Keccak256Hash(balanceTreeRoot.Bytes(), nullifierTreeRoot.Bytes(), Uint32ToBytesLittleEndian(ler_count))
399389
fmt.Printf(`
400390
{
401391
"balanceTreeRoot": "%s",

0 commit comments

Comments
 (0)