From 09dcaae497ca123b00a99b2ba30ab57643a6ba94 Mon Sep 17 00:00:00 2001 From: Xi Lin Date: Wed, 30 Nov 2022 17:45:22 +0800 Subject: [PATCH] fix: padding bytes in ComputeBatchID (#124) --- common/utils/contracts.go | 3 ++- common/utils/contracts_test.go | 8 ++++++++ common/version/version.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/utils/contracts.go b/common/utils/contracts.go index dcf7bb32f..f8cbbd0c5 100644 --- a/common/utils/contracts.go +++ b/common/utils/contracts.go @@ -10,9 +10,10 @@ import ( // ComputeBatchID compute a unique hash for a batch using "endBlockHash" & "endBlockHash in last batch" // & "batch height", following the logic in `_computeBatchId` in contracts/src/L1/rollup/ZKRollup.sol func ComputeBatchID(endBlockHash common.Hash, lastEndBlockHash common.Hash, index *big.Int) string { + indexBytes := make([]byte, 32) return crypto.Keccak256Hash( endBlockHash.Bytes(), lastEndBlockHash.Bytes(), - index.Bytes(), + index.FillBytes(indexBytes), ).String() } diff --git a/common/utils/contracts_test.go b/common/utils/contracts_test.go index 3b74065e4..f6eb0d1b1 100644 --- a/common/utils/contracts_test.go +++ b/common/utils/contracts_test.go @@ -1,6 +1,7 @@ package utils_test import ( + "math/big" "testing" "github.com/scroll-tech/go-ethereum/common" @@ -29,4 +30,11 @@ func TestComputeBatchID(t *testing.T) { expected := "0xafe1e714d2cd3ed5b0fa0a04ee95cd564b955ab8661c5665588758b48b66e263" actual := utils.ComputeBatchID(common.Hash{}, common.Hash{}, math.MaxBig256) assert.Equal(t, expected, actual) + + expected = "0xe05698242b035c0e4d1d58e8ab89507ac7a1403b17fd6a7ea87621a32674ec88" + actual = utils.ComputeBatchID( + common.HexToHash("0xfaef7761204f43c4ab2528a65fcc7ec2108709e5ebb646bdce9ce3c8862d3f25"), + common.HexToHash("0xe3abef08cce4b8a0dcc6b7e4dd11f32863007a86f46c1d136682b5d77bdf0f7a"), + big.NewInt(77233900)) + assert.Equal(t, expected, actual) } diff --git a/common/version/version.go b/common/version/version.go index b05f25485..49b760dfb 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "prealpha-v6.4" +var tag = "prealpha-v6.5" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok {