diff options
Diffstat (limited to 'merkle.go')
| -rw-r--r-- | merkle.go | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -85,15 +85,15 @@ func (m *BFSMerkle) Build() []byte { func (m *BFSMerkle) Proof(id int64) [][]byte { proof := make([][]byte, m.height) proof[0] = make([]byte, hashSize) - m.ReadAt(proof[0], id*hashSize) - for i := 1; id > 0; i++ { - proof[i] = make([]byte, hashSize) - if id&1 == 0 { - m.ReadAt(proof[i], (id-1)*hashSize) - } else { - m.ReadAt(proof[i], (id+1)*hashSize) + m.ReadAt(proof[0], id*hashSize) // read the queried node + for height := int64(1); height < m.height; height++ { //construct the proof bottom-up + proof[height] = make([]byte, hashSize) + if id&1 == 0 { // right child, reading left sibling + m.ReadAt(proof[height], (id-1)*hashSize) + } else { // left child, reading right sibling + m.ReadAt(proof[height], (id+1)*hashSize) } - id = (id - 1) >> 1 + id = (id - 1) >> 1 // move to parent node } return proof } |
