Bind challenge/response MMR proofs to the exact (leaf_index, leaf_count)#301
Draft
karolk91 wants to merge 4 commits into
Draft
Bind challenge/response MMR proofs to the exact (leaf_index, leaf_count)#301karolk91 wants to merge 4 commits into
karolk91 wants to merge 4 commits into
Conversation
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.
verify_mmr_proof(proof, root)never uses the challenged leaf index: it only checks that the leaf hashes to some peak and that the peaks bag to the root. A provider challenged on leafican defend with a valid proof for any leafjit still holds, so a challenge does not prove possession of the challenged chunk. Related gaps:Challengestores noleaf_count, so the response check has nothing to bind against.challenge_checkpointacceptsleaf_index >= leaf_count; under bound verification such a challenge is undefendable and resolves by timeout slash (griefing at the cost of one deposit).confirm_replica_syncrecords(start_seq, leaf_count) = (0, 0)for historical-root syncs, which bound verification would turn into undefendable replica challenges.Changes
verify_mmr_proof(proof, leaf_index, leaf_count, root)derives the expected peak index, path length, and per-level direction from(leaf_index, leaf_count)(mmr_leaf_position) and requires the climbed hash at the exact peak position.bag_peaksextracted; reused by the provider prover.Challenge.leaf_countadded, sourced per path: snapshot (challenge_checkpoint), signed commitment (challenge_offchain— a forged value fails signature verification), recorded sync range (challenge_replica).create_challengerejectsleaf_index >= leaf_count(LeafIndexOutOfRange).ReplicaSyncRecordis now{root, range: Option<(start_seq, leaf_count)>, block}; the range is recorded only for current-snapshot syncs, andchallenge_replicaonNonefails withReplicaSyncRangeUnknown.respond_to_challengeverifies bound; invalid proof still slashes immediately.commit()returnsleaf_countunder the same lock asmmr_root;/commit,/commitment,/delete,/checkpoint-signaturesign the realleaf_count.CommitResponse.leaf_countis required (noserde(default)).Tests
Proof substitution rejection, out-of-range creation, signed-leaf_count binding/forgery, replica range recording/refusal — primitives
test_verify_mmr_proof_*, pallettests/{challenge,replica}.rs, provider-nodechallenge_binds_leaf_index. Therespond_to_challenge_proofbenchmark now builds the bound-verify worst case (64 peaks, 63-level climb).Review notes
Challenge(new field),ProviderRole::Replica.last_sync(ReplicaSyncRecordshape).Errorvariants inserted mid-enum; later variant indices shift.crates/storage-subxtbindings,packages/papimetadata, weights.last_syncdecoder inprovider-node/src/subxt_client.rsassumes the pre-dev layout (blockoffset already misaligned on dev).