@@ -116,12 +116,6 @@ func (h *simdHasher) Hash(b []byte) ([]byte, error) {
116116 return doHash (h .baseHasher (), h .span , rootHash )
117117}
118118
119- // HashPadded is equivalent to Hash for the SIMD hasher since Hash already
120- // zero-fills the buffer. Exposed so the Hasher interface contract is satisfied.
121- func (h * simdHasher ) HashPadded (b []byte ) ([]byte , error ) {
122- return h .Hash (b )
123- }
124-
125119// Reset prepares the Hasher for reuse. The internal data buffer is not zeroed;
126120// any stale bytes past h.size are overwritten on the next Write and zero-filled
127121// on demand by Hash, so post-Reset inspection of the buffer may still see
@@ -130,90 +124,3 @@ func (h *simdHasher) Reset() {
130124 h .size = 0
131125 copy (h .span , zerospan )
132126}
133-
134- // Proof returns the inclusion proof of the i-th data segment.
135- func (h * simdHasher ) Proof (i int ) Proof {
136- // keep the original (segment-level) index around: callers identify the
137- // segment by its 0..127 position; we divide down to a leaf-node (section)
138- // index below for tree navigation.
139- index := i
140- if i < 0 || i > 127 {
141- panic ("segment index can only lie between 0-127" )
142- }
143- // two segments share one leaf section (32B + 32B hashed together),
144- // so the leaf-node index is i/2.
145- i = i / 2
146- n := h .bmt .leaves [i ]
147- isLeft := n .isLeft
148- // walk from the leaf's parent to the root, collecting the sister hash
149- // at each level along the way.
150- var sisters [][]byte
151- for n = n .parent ; n != nil ; n = n .parent {
152- sisters = append (sisters , n .getSister (isLeft ))
153- isLeft = n .isLeft
154- }
155-
156- // copy out the two segments that live in this leaf section. One is the
157- // segment being proven, the other is its immediate sister (the very first
158- // entry in the proof path, below the leaf level).
159- secsize := 2 * h .segmentSize
160- offset := i * secsize
161- section := make ([]byte , secsize )
162- copy (section , h .bmt .buffer [offset :offset + secsize ])
163- segment , firstSegmentSister := section [:h .segmentSize ], section [h .segmentSize :]
164- // if the original index is odd, the proven segment sits on the right,
165- // so swap which half is the segment and which is the sister.
166- if index % 2 != 0 {
167- segment , firstSegmentSister = firstSegmentSister , segment
168- }
169- // prepend the in-section sister so the proof list reads leaf-up: the
170- // first hop combines segment with firstSegmentSister, then walks upward.
171- sisters = append ([][]byte {firstSegmentSister }, sisters ... )
172- return Proof {segment , sisters , h .span , index }
173- }
174-
175- // Verify reconstructs the BMT root from a proof for the i-th segment.
176- func (h * simdHasher ) Verify (i int , proof Proof ) (root []byte , err error ) {
177- // rebuild the leaf section (two 32B segments concatenated) in the same
178- // order they were originally hashed. Even index → proven segment on the
179- // left, odd index → proven segment on the right.
180- var section []byte
181- if i % 2 == 0 {
182- section = append (append (section , proof .ProveSegment ... ), proof .ProofSegments [0 ]... )
183- } else {
184- section = append (append (section , proof .ProofSegments [0 ]... ), proof .ProveSegment ... )
185- }
186- // derive the leaf-node index from the segment index, mirroring Proof.
187- i = i / 2
188- n := h .bmt .leaves [i ]
189- hasher := h .baseHasher ()
190- isLeft := n .isLeft
191- // start by hashing the reconstructed section: this is the leaf-level
192- // hash that the proof path will lift up to the root.
193- root , err = doHash (hasher , section )
194- if err != nil {
195- return nil , err
196- }
197- n = n .parent
198-
199- // climb level by level, pairing the running hash with the sister from
200- // the proof. Orientation alternates based on whether we arrived at this
201- // node from its left or right child.
202- for _ , sister := range proof .ProofSegments [1 :] {
203- if isLeft {
204- root , err = doHash (hasher , root , sister )
205- } else {
206- root , err = doHash (hasher , sister , root )
207- }
208- if err != nil {
209- return nil , err
210- }
211- // advance to the next level; record which side we came from so the
212- // next hash pairs the operands in the correct order.
213- isLeft = n .isLeft
214- n = n .parent
215- }
216- // finally mix in the span to produce the chunk address, matching what
217- // Hash does at the top of the tree.
218- return doHash (hasher , proof .Span , root )
219- }
0 commit comments