From 2f75c12e2eb32ab3cf8f72677c65b41f766e4e69 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Sat, 17 Feb 2024 22:56:25 +0000 Subject: [PATCH] use `MapToScalarFieldBytes` instead of `.Bytes` --- trie/utils/verkle.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index ce059edc6438..481f48526738 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -305,16 +305,17 @@ func StorageSlotKeyWithEvaluatedAddress(evaluated *verkle.Point, storageKey []by return GetTreeKeyWithEvaluatedAddress(evaluated, treeIndex, subIndex) } +// TODO: We can remove this method once https://github.com/ethereum/go-verkle/pull/428 +// TODO is merged. +// TODO: we would then be able to call `verkle.MapToScalarFieldBytes` +func MapToScalarFieldBytes(point *verkle.Point) [32]byte { + var hashedPoint verkle.Fr + point.MapToScalarField(&hashedPoint) + return hashedPoint.BytesLE() +} + func pointToHash(evaluated *verkle.Point, suffix byte) []byte { - // The output of Byte() is big endian for banderwagon. This - // introduces an imbalance 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. - bytes := evaluated.Bytes() - for i := 0; i < 16; i++ { - bytes[31-i], bytes[i] = bytes[i], bytes[31-i] - } + bytes := MapToScalarFieldBytes(evaluated) bytes[31] = suffix return bytes[:] }