diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 23:13:36 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 23:14:36 -0400 |
| commit | 7356dc77e0ea986dfd798e9d122e66131b804111 (patch) | |
| tree | 66ee53cc66d4b2cd3976f12b939e2a52ae3da3c7 | |
| parent | 27ff4c4aa4988c65caf6093b9dcc3c00f6c00743 (diff) | |
| download | pos-7356dc77e0ea986dfd798e9d122e66131b804111.tar.gz | |
Add some comments for proof extraction
| -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 } |
