SpinResearch / merkle.rs

:christmas_tree: Merkle tree in Rust
BSD 3-Clause "New" or "Revised" License
129 stars 23 forks source link

Add index field to Proof struct #42

Open psivesely opened 6 years ago

psivesely commented 6 years ago

Since for some use cases (see https://github.com/SpinResearch/merkle.rs/pull/36 and https://github.com/poanetwork/hbbft) knowing the index of a leaf inclusion proof is useful, it might be useful to add an index field to the Proof struct, instead of doing a separate expensive computation to find it. It should be very little additional computation to determine the index as well when already traversing a tree to create an inclusion proof.

When receiving a Proof over the wire from a 3rd party, you should not trust the index is correct, even if the Proof validates. Changing validate to check the index matches in addition to its current purpose, however, should be possible with little overhead.