Skip to content

Commit c9ffa89

Browse files
authored
cleanup: don't evaluate 0 coeffs in get_tree_key (ethereum#87)
1 parent ab87f5f commit c9ffa89

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

trie/utils/verkle.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,29 @@ var (
4040
codeStorageDelta = uint256.NewInt(0).Sub(CodeOffset, HeaderStorageOffset)
4141
)
4242

43+
// GetTreeKey performs both the work of the spec's get_tree_key function, and that
44+
// of pedersen_hash: it builds the polynomial in pedersen_hash without having to
45+
// create a mostly zero-filled buffer and "type cast" it to a 128-long 16-byte
46+
// array. Since at most the first 5 coefficients of the polynomial will be non-zero,
47+
// these 5 coefficients are created directly.
4348
func GetTreeKey(address []byte, treeIndex *uint256.Int, subIndex byte) []byte {
44-
var poly [256]fr.Element
45-
verkle.FromLEBytes(&poly[0], []byte{2, 64}) // little endian, 64 bytes
49+
var poly [5]fr.Element
50+
51+
// (2 + 256 * length) little endian, length = 64 bytes
52+
verkle.FromLEBytes(&poly[0], []byte{2, 64})
53+
54+
// 32-byte address, interpreted as two little endian
55+
// 16-byte numbers.
4656
verkle.FromLEBytes(&poly[1], address[:16])
4757
verkle.FromLEBytes(&poly[2], address[16:])
58+
4859
// little-endian, 32-byte aligned treeIndex
4960
var index [32]byte
5061
for i, b := range treeIndex.Bytes() {
5162
index[len(treeIndex.Bytes())-1-i] = b
5263
}
5364
verkle.FromLEBytes(&poly[3], index[:16])
5465
verkle.FromLEBytes(&poly[4], index[16:])
55-
for i := 5; i < len(poly); i++ {
56-
verkle.CopyFr(&poly[i], &verkle.FrZero)
57-
}
5866

5967
cfg, _ := verkle.GetConfig()
6068
ret := cfg.CommitToPoly(poly[:], 0)

0 commit comments

Comments
 (0)