@@ -40,21 +40,29 @@ var (
40
40
codeStorageDelta = uint256 .NewInt (0 ).Sub (CodeOffset , HeaderStorageOffset )
41
41
)
42
42
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.
43
48
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.
46
56
verkle .FromLEBytes (& poly [1 ], address [:16 ])
47
57
verkle .FromLEBytes (& poly [2 ], address [16 :])
58
+
48
59
// little-endian, 32-byte aligned treeIndex
49
60
var index [32 ]byte
50
61
for i , b := range treeIndex .Bytes () {
51
62
index [len (treeIndex .Bytes ())- 1 - i ] = b
52
63
}
53
64
verkle .FromLEBytes (& poly [3 ], index [:16 ])
54
65
verkle .FromLEBytes (& poly [4 ], index [16 :])
55
- for i := 5 ; i < len (poly ); i ++ {
56
- verkle .CopyFr (& poly [i ], & verkle .FrZero )
57
- }
58
66
59
67
cfg , _ := verkle .GetConfig ()
60
68
ret := cfg .CommitToPoly (poly [:], 0 )
0 commit comments