@@ -67,6 +67,8 @@ func (h *hasher) hash(n node, force bool) []byte {
67
67
if len (enc ) < 32 && ! force {
68
68
// Nodes smaller than 32 bytes are embedded directly in their parent.
69
69
// In such cases, return the raw encoded blob instead of the node hash.
70
+ // It's essential to deep-copy the node blob, as the underlying buffer
71
+ // of enc will be reused later.
70
72
buf := make ([]byte , len (enc ))
71
73
copy (buf , enc )
72
74
return buf
@@ -80,6 +82,8 @@ func (h *hasher) hash(n node, force bool) []byte {
80
82
if len (enc ) < 32 && ! force {
81
83
// Nodes smaller than 32 bytes are embedded directly in their parent.
82
84
// In such cases, return the raw encoded blob instead of the node hash.
85
+ // It's essential to deep-copy the node blob, as the underlying buffer
86
+ // of enc will be reused later.
83
87
buf := make ([]byte , len (enc ))
84
88
copy (buf , enc )
85
89
return buf
@@ -137,12 +141,11 @@ func (h *hasher) encodeFullNode(n *fullNode) []byte {
137
141
}
138
142
wg .Add (1 )
139
143
go func (i int ) {
140
- hasher := newHasher (false )
141
- if child := n .Children [i ]; child != nil {
142
- fn .Children [i ] = hasher .hash (child , false )
143
- }
144
- returnHasherToPool (hasher )
145
- wg .Done ()
144
+ defer wg .Done ()
145
+
146
+ h := newHasher (false )
147
+ defer returnHasherToPool (h )
148
+ fn .Children [i ] = h .hash (n .Children [i ], false )
146
149
}(i )
147
150
}
148
151
wg .Wait ()
@@ -196,6 +199,7 @@ func (h *hasher) hashDataTo(dst, data []byte) {
196
199
}
197
200
198
201
// proofHash is used to construct trie proofs, returning the rlp-encoded node blobs.
202
+ // Note, only resolved node (shortNode or fullNode) is expected for proofing.
199
203
func (h * hasher ) proofHash (original node ) []byte {
200
204
switch n := original .(type ) {
201
205
case * shortNode :
0 commit comments