celestiaorg / nmt

Namespaced Merkle Tree
Apache License 2.0
107 stars 39 forks source link

feat!: adds input range check to optimize VerifyLeafHashes and VerifyInclusion methods #253

Closed staheri14 closed 2 months ago

staheri14 commented 2 months ago

This PR optimizes the VerifyLeafHashes and VerifyInclusion methods by ensuring that the size of the provided leaves or leaf hashes matches the proof range and, if not, making an early return in order to prevent unnecessary hashing operations that would otherwise occur. It introduces a breaking change by altering the behaviour of VerifyLeafHashes and VerifyInclusion. Previously, verification would succeed even if the provided leaves or leaf hashes exceeded the proof range, as long as the proof was valid and the extra leaves were appended at the end. In the new implementation, the verification will return false or an error in such cases.

staheri14 commented 2 months ago

[To the reviewers] The codecov error is not specific to this PR, I am investigating it.

rootulp commented 2 months ago

Thanks yea agreed the CodeCov issue isn't caused by this PR: https://github.com/celestiaorg/nmt/issues/250

staheri14 commented 2 months ago

Waiting on #255 to merge

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 66.50%. Comparing base (559fe2b) to head (a660fac).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #253 +/- ## ========================================== + Coverage 66.24% 66.50% +0.26% ========================================== Files 6 6 Lines 1022 1030 +8 ========================================== + Hits 677 685 +8 Misses 328 328 Partials 17 17 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.