Skip to content

Commit a4838ea

Browse files
authored
temp fix: little endian pedersen_hash (#103)
1 parent 5975b44 commit a4838ea

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

trie/utils/verkle.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ func GetTreeKey(address []byte, treeIndex *uint256.Int, subIndex byte) []byte {
7070

7171
cfg, _ := verkle.GetConfig()
7272
ret := cfg.CommitToPoly(poly[:], 0)
73-
retb := ret.Bytes()
73+
74+
// The output of Byte() is big engian for banderwagon. This
75+
// introduces an inbalance in the tree, because hashes are
76+
// elements of a 253-bit field. This means more than half the
77+
// tree would be empty. To avoid this problem, use a little
78+
// endian commitment and chop the MSB.
79+
var retb [32]byte
80+
retb = ret.Bytes()
81+
for i := 0; i < 16; i++ {
82+
retb[31-i], retb[i] = retb[i], retb[31-i]
83+
}
7484
retb[31] = subIndex
7585
return retb[:]
7686

trie/verkle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func TestReproduceCondrieuPoAStemConflictWithAnotherStem(t *testing.T) {
386386

387387
func TestGetTreeKeys(t *testing.T) {
388388
addr := common.Hex2Bytes("71562b71999873DB5b286dF957af199Ec94617f7")
389-
target := common.Hex2Bytes("0e19316be898a50719b7c321005583ddab6398f4e568d8efafb0619609700f00")
389+
target := common.Hex2Bytes("e00f70099661b0afefd868e5f49863abdd83550021c3b71907a598e86b311900")
390390
key := utils.GetTreeKeyVersion(addr)
391391
t.Logf("key=%x", key)
392392
t.Logf("actualKey=%x", target)

0 commit comments

Comments
 (0)