use MapToScalarFieldBytes instead of .Bytes

This commit is contained in:
Kevaundray Wedderburn 2024-02-17 22:56:25 +00:00
parent 593e303485
commit 2f75c12e2e

View file

@ -305,16 +305,17 @@ func StorageSlotKeyWithEvaluatedAddress(evaluated *verkle.Point, storageKey []by
return GetTreeKeyWithEvaluatedAddress(evaluated, treeIndex, subIndex) return GetTreeKeyWithEvaluatedAddress(evaluated, treeIndex, subIndex)
} }
func pointToHash(evaluated *verkle.Point, suffix byte) []byte { // TODO: We can remove this method once https://github.com/ethereum/go-verkle/pull/428
// The output of Byte() is big endian for banderwagon. This // TODO is merged.
// introduces an imbalance in the tree, because hashes are // TODO: we would then be able to call `verkle.MapToScalarFieldBytes`
// elements of a 253-bit field. This means more than half the func MapToScalarFieldBytes(point *verkle.Point) [32]byte {
// tree would be empty. To avoid this problem, use a little var hashedPoint verkle.Fr
// endian commitment and chop the MSB. point.MapToScalarField(&hashedPoint)
bytes := evaluated.Bytes() return hashedPoint.BytesLE()
for i := 0; i < 16; i++ {
bytes[31-i], bytes[i] = bytes[i], bytes[31-i]
} }
func pointToHash(evaluated *verkle.Point, suffix byte) []byte {
bytes := MapToScalarFieldBytes(evaluated)
bytes[31] = suffix bytes[31] = suffix
return bytes[:] return bytes[:]
} }