Fix divereged state root derived from VerifiedMultiProof#931
Merged
rphmeier merged 9 commits intoMay 12, 2026
Conversation
2 tasks
VerifiedMultiProof
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.
Essence of new test:
Symptom
verify_multi_proof_updatedisagreed with the prover's post-update root (session.finish().root()) on multi-proofs where any terminal carries ≥ 2 unique siblings on multi_proof.siblings. Old-root verification (verify_multi_proof) was unaffected — the divergence was entirely in the update step.Reproduced by four new tests in
nomt/tests/compute_root.rs(many_keys_round_trip,many_keys_inserts_only,many_keys_overwrites_only,many_keys_deletes_only), all of which use PRNG-distributed keys over 32 prior leaves. Smaller, structured-key tests passed because they produced terminal_n ≤ 1 for every terminal, which made the bug invisible.Root cause
nomt/core/src/proof/multi_proof.rs
Lines 640 to 645 in 5fa289a
(before the fix) passed reverse = true to CommonSiblings::extend when loading a terminal's unique-sibling tail onto the depth-labeled stack:
The
reverse = truebranch reversed the slice iteration but still labeled entries with ascending depths via start_depth + i:So for a terminal at depth 8 with terminal_n = 7, the stack ended up as
hash_and_compact_terminalthen pops from the top by descendingcur_layer (8, 7, …, 2).Because the labels were anti-correlated with the values, the first hash above the updated sub-trie combined the new leaf with the wrong sibling, and the error propagated to the root.
Why the storage convention forces
reverse = falsemulti_proof.siblings is stored ascending by depth. Five corroborating sites:
nomt/nomt/src/merkle/worker.rs
Line 425 in 5fa289a
siblings[depth - 1] = *actual_sibling.siblings[..unique_len].iter().rev()(only consistent with ascending storage).nomt/core/src/proof/path_proof.rs
Line 87 in 5fa289a
PathProof::verifyconsumes viaself.siblings.iter().rev().For hash_and_compact_terminal to pop deepest-first, the stack must be loaded shallowest-first. With ascending storage, that means iterating the slice forward — i.e., reverse = false. The bisection branch at the same call site (line 634) already passed false correctly; only the terminal branch was wrong.
(Aside: the doc comment on PathProof.siblings at core/src/proof/path_proof.rs:62 previously said "descending order by depth" — it contradicted the implementation and the adjacent hash_path comment at line 107. Corrected as part of this PR.)
Why existing tests missed it
Every existing
verify_updateunit test had terminal_n ≤ 1 for every terminal, whereiter().rev()is a no-op for ordering. Traced:nomt/tests/witness_check.rs::produced_witness_validitydoes exercise prover↔verifier round-trip on many keys, but throughproof::verify_update(the per-path verifier), which never touches CommonSiblings. The multi-proof update path was effectively untested for the positive case with non-trivial unique-sibling tails.Fix
Three changes, no API surface change:
Confirmed it fails under the old reversal and passes after the fix, closing the unit-level coverage gap.
CommonSiblingsis module-private and grep confirms no external callers, so removing the parameter is safe.