From 8307988ddb025709102d4fe12f9ddc179e154453 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 2 Jun 2022 17:10:03 +0200 Subject: [PATCH 1/2] temp fix: little endian pedersen_hash --- trie/utils/verkle.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index f039ac5c0dde..d3585aca0477 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -70,7 +70,17 @@ func GetTreeKey(address []byte, treeIndex *uint256.Int, subIndex byte) []byte { cfg, _ := verkle.GetConfig() ret := cfg.CommitToPoly(poly[:], 0) - retb := ret.Bytes() + + // The output of Byte() is big engian for banderwagon. This + // introduces an inbalance in the tree, because hashes are + // elements of a 253-bit field. This means more than half the + // tree would be empty. To avoid this problem, use a little + // endian commitment and chop the MSB. + var retb [32]byte + retb = ret.Bytes() + for i := 0; i < 16; i++ { + retb[31-i], retb[i] = retb[i], retb[31-i] + } retb[31] = subIndex return retb[:] From cbe86f997f7163685b672a12e1be7cebc3033e9b Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 2 Jun 2022 18:33:44 +0200 Subject: [PATCH 2/2] adapt test --- trie/verkle_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trie/verkle_test.go b/trie/verkle_test.go index 13d987558e95..b5e17d347797 100644 --- a/trie/verkle_test.go +++ b/trie/verkle_test.go @@ -386,7 +386,7 @@ func TestReproduceCondrieuPoAStemConflictWithAnotherStem(t *testing.T) { func TestGetTreeKeys(t *testing.T) { addr := common.Hex2Bytes("71562b71999873DB5b286dF957af199Ec94617f7") - target := common.Hex2Bytes("0e19316be898a50719b7c321005583ddab6398f4e568d8efafb0619609700f00") + target := common.Hex2Bytes("e00f70099661b0afefd868e5f49863abdd83550021c3b71907a598e86b311900") key := utils.GetTreeKeyVersion(addr) t.Logf("key=%x", key) t.Logf("actualKey=%x", target)