fix(proof): verify inclusion proofs for leaves a deletion promoted above row 0 - #152
Open
eastagiletracker wants to merge 1 commit into
Open
Conversation
`calculate_hashes` builds its node list out of `self.targets`, which are positions in `MAX_FOREST_ROWS` space, and then pairs it with proof positions that are in the forest's own rows. Both spaces agree for targets at row 0, so this stays invisible until a deletion promotes a leaf: from then on that target sorts nowhere near its sibling and verification fails with `MissingSibling`, even though the proof is valid. Use the already-computed `translated` positions instead, which is what the `calculate_hashes_delete` twin does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes a one-line fix in
Proof::calculate_hashesso that an inclusion proof for a leaf that a deletion promoted above row 0 verifies instead of being rejected as invalid, which is theMemForesthalf of #150. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/385. You can sign in with your GitHub ID to claim ownership of the project.What goes wrong
calculate_hashescomputestranslated— the targets mapped fromMAX_FOREST_ROWSspace into the forest's own rows — and uses it forget_proof_positions, but then builds the node list that those proof hashes get paired with out of the untranslatedself.targets:translateis the identity at row 0, so the two spaces agree for as long as every target is a leaf sitting at the bottom of the forest and the mismatch stays invisible. It stops being invisible the moment a deletion promotes a leaf: with eight leaves, deleting leaf 0 moves leaf 1 up to row 1,MemForest::provecorrectly reports it as2^63instead of8, and that value then sorts past every entry inproof_positions, soget_nexthandscalculate_hashesthe wrong sibling.Stump::verifyreturnsErr(InvalidProof(MissingSibling(9)))for a proof that is perfectly good.calculate_hashes_delete, the twin used byStump::modify, already zipstranslated, which is why deleting a promoted leaf keeps working while proving one does not.The fix is to zip
translatedincalculate_hashestoo, so both halves of the function agree on which space they are in. Everything that reaches this code today passes row-0 targets, wheretranslatereturns the position unchanged, so nothing that works now changes behaviour.Reproducing and verifying
Both added tests fail on
mainat b7af3b7 with thesrc/proof/mod.rschange reverted and pass with it, socargo test --lib proof::tests::test_verify_promotedis enough to see it in either direction:test_verify_promoted_targetwalks the reported case end to end throughMemForestandStump— one promotion, a two-deletion promotion two rows up, a promoted target proved alongside one still at row 0, and a control assertion that an untouched leaf was never affected.test_verify_promoted_target_after_growthcovers the reason non-row-0 positions travel inMAX_FOREST_ROWSspace at all: it deletes, then grows the forest past a power of two, then proves the promoted leaf. Every step asserts that the forest's roots and the stump's still agree, so a test can't pass by both sides drifting together.cargo testonmainat b7af3b7 is 58 unit tests and 29 doc tests green; with this branch it is 60 and 29, the two new ones being the whole difference. Also green on--no-default-featuresand--all-features,cargo clippy --all-targets --all-featuresis clean, andcargo fmt --checkpasses.What this does not cover
The
Pollardvariant reported in the same issue is a separate root cause and is left alone here:Pollard::batch_prooffails insidePollard::get_poswithCouldNotUpgradeNodeafter any deletion, before verification is ever reached, becauseleaf_mapstill holds aWeakto a node the deletion dropped. It wants its own change rather than riding along with this one. Worth noting too that #140 rewrites the imports throughoutsrc/proof/mod.rs; it doesn't touch the lines here, but whichever lands second may want a look.How this was managed
We imported your issues and pull requests into a board — 144 stories and 7 labels — and worked this change on it as MemForest::prove returns invalid proofs for the sibling of a deleted leaf. The whole board is at https://eastagiletracker.com/projects/385.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com