From 4b36e6637450021265e04d6cf023a7464bce8afd Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Wed, 13 Apr 2022 17:58:11 +0200 Subject: [PATCH] ensure 10-byte addresses are right-aligned in pedersen_hash (#99) Co-authored-by: Tanishq Jasoria --- trie/utils/verkle.go | 4 ++++ trie/verkle_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index d9fdd2fe4bc3..f039ac5c0dde 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -46,6 +46,10 @@ var ( // array. Since at most the first 5 coefficients of the polynomial will be non-zero, // these 5 coefficients are created directly. func GetTreeKey(address []byte, treeIndex *uint256.Int, subIndex byte) []byte { + if len(address) < 32 { + var aligned [32]byte + address = append(aligned[:32-len(address)], address...) + } var poly [5]fr.Element // (2 + 256 * length) little endian, length = 64 bytes diff --git a/trie/verkle_test.go b/trie/verkle_test.go index bdced3097d36..13d987558e95 100644 --- a/trie/verkle_test.go +++ b/trie/verkle_test.go @@ -17,10 +17,12 @@ package trie import ( + "bytes" "encoding/hex" "testing" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/trie/utils" "github.com/gballet/go-verkle" ) @@ -381,3 +383,14 @@ func TestReproduceCondrieuPoAStemConflictWithAnotherStem(t *testing.T) { t.Fatal("a proof-of-absence stem was declared, when there was no need") } } + +func TestGetTreeKeys(t *testing.T) { + addr := common.Hex2Bytes("71562b71999873DB5b286dF957af199Ec94617f7") + target := common.Hex2Bytes("0e19316be898a50719b7c321005583ddab6398f4e568d8efafb0619609700f00") + key := utils.GetTreeKeyVersion(addr) + t.Logf("key=%x", key) + t.Logf("actualKey=%x", target) + if !bytes.Equal(key, target) { + t.Fatalf("differing output %x != %x", key, target) + } +}