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 Proofvalidates. Changing validate to check the index matches in addition to its current purpose, however, should be possible with little overhead.
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 theProof
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 theProof
validate
s. Changingvalidate
to check the index matches in addition to its current purpose, however, should be possible with little overhead.