Skip to content

refactor(stm): update PoP, protocol parameters and decoding functions - #3431

Merged
damrobi merged 14 commits into
mainfrom
damrobi/msnark/refactor-pop-snark-params-decoding
Jul 29, 2026
Merged

refactor(stm): update PoP, protocol parameters and decoding functions#3431
damrobi merged 14 commits into
mainfrom
damrobi/msnark/refactor-pop-snark-params-decoding

Conversation

@damrobi

@damrobi damrobi commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Content

This PR includes an update to the handling of the proof of possession of BLS keys, a modification of the checks done on the protocol parameters and a modification to the decoding function of the merkle tree path and concatenation proof.

Changes

  • Add checked arithmetic to legacy byte decoders (Merkle tree, batch commitment, ConcatenationProof, SingleSignature)
  • Validate phi_f is within (0, 1] before use in lottery/eligibility computations
  • Restrict KeyRegistration::register_by_entry to pub(crate) so external registration must go through register(), which always verifies proof of possession
  • Make ClosedKeyRegistration fields private with a pub(crate) constructor
  • Narrow RegistrationEntry/ClosedRegistrationEntry (types, constructors, methods) to pub(crate) and dropped RegistrationEntry's unused Serialize/Deserialize
  • Fix resulting lint warnings: #[allow(private_interfaces)] where a public error intentionally carries a now-private type, #[allow(dead_code)] on Merkle tree byte (de)serialization helpers that are test-only for now

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Crates versions are updated (if relevant)
    • CHANGELOG file is updated (if relevant)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • All check jobs of the CI have succeeded
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Comments

Issue(s)

@damrobi damrobi self-assigned this Jul 22, 2026
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

Test Results

     5 files  ± 0     209 suites  ±0   1h 31m 39s ⏱️ - 1h 42m 11s
 3 345 tests  - 56   3 345 ✅  - 56  0 💤 ±0  0 ❌ ±0 
11 096 runs   - 59  11 096 ✅  - 59  0 💤 ±0  0 ❌ ±0 

Results for commit 83390c5. ± Comparison against base commit bc9d8c1.

This pull request removes 60 and adds 4 tests. Note that renamed tests count towards both.
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::index_out_of_bounds
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::index_too_large_for_circuit_range
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::indices_not_increasing
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::leaf_merkle_path_mismatch
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::leaf_swap_keep_merkle_path
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::leaf_wrong_verification_key
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_corrupt_sibling
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_flip_position
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_length_long
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_length_short
…
mithril-stm ‑ proof_system::concatenation::eligibility::tests::is_lottery_won_rejects_max_ev_value
mithril-stm ‑ proof_system::concatenation::eligibility::tests::is_lottery_won_rejects_out_of_range_phi_f
mithril-stm ‑ proof_system::concatenation::eligibility::tests::is_lottery_won_rejects_zero_total_stake
mithril-stm ‑ proof_system::halo2_snark::eligibility::tests::compute_target_value_for_snark_lottery_rejects_out_of_range_phi_f

♻️ This comment has been updated with latest results.

@damrobi
damrobi force-pushed the damrobi/msnark/refactor-pop-snark-params-decoding branch from 7f5d023 to 98489af Compare July 24, 2026 07:18

@hjeljeli32 hjeljeli32 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far.

Comment thread mithril-stm/src/membership_commitment/merkle_tree/tree.rs Outdated

@hjeljeli32 hjeljeli32 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 2 additional comments.

Comment thread mithril-stm/src/membership_commitment/merkle_tree/tree.rs Outdated
Comment thread mithril-stm/src/protocol/error.rs Outdated
@damrobi
damrobi force-pushed the damrobi/msnark/refactor-pop-snark-params-decoding branch from e3fcba1 to b5d4db6 Compare July 27, 2026 09:26
@damrobi
damrobi marked this pull request as ready for review July 27, 2026 11:21
@jpraynaud
jpraynaud requested a review from Copilot July 27, 2026 14:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors parts of mithril-stm around registration/PoP enforcement and protocol parameter validation, and hardens several legacy byte decoders by switching to checked arithmetic to avoid panics/overflows during deserialization.

Changes:

  • Added checked offset arithmetic in multiple legacy decoders (Merkle tree / commitments, concatenation proof, single signature).
  • Validated phi_f is within (0, 1] and propagated errors through lottery/eligibility paths.
  • Tightened key-registration APIs to ensure external callers must go through PoP-verifying registration paths (plus associated visibility/documentation updates).

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mithril-stm/tests/test_extensions/protocol_phase.rs Update test registration flow to use KeyRegistration::register() (PoP-verifying).
mithril-stm/src/protocol/single_signature/signature.rs Harden single-signature legacy decoding with checked offsets; adjust tests for new encapsulation.
mithril-stm/src/protocol/single_signature/signature_registered_party.rs Restrict access to registered-party payload inside signature wrapper; update tests accordingly.
mithril-stm/src/protocol/participant/initializer.rs Use ClosedKeyRegistration accessor instead of direct field access.
mithril-stm/src/protocol/mod.rs Stop publicly re-exporting RegistrationEntry; keep it crate-visible where needed.
mithril-stm/src/protocol/key_registration/registration_entry.rs Make RegistrationEntry crate-private and remove serde derives to prevent unverified external construction.
mithril-stm/src/protocol/key_registration/register.rs Make register_by_entry crate-private; encapsulate ClosedKeyRegistration fields and provide crate accessor(s).
mithril-stm/src/protocol/key_registration/mod.rs Narrow RegistrationEntry re-export to pub(crate).
mithril-stm/src/protocol/key_registration/closed_registration_entry.rs Make ClosedRegistrationEntry::new private to ensure construction flows through verified paths.
mithril-stm/src/protocol/error.rs Silence private_interfaces warning on a public error carrying a now-private type.
mithril-stm/src/proof_system/halo2_snark/mod.rs Update call sites to use ClosedKeyRegistration accessor.
mithril-stm/src/proof_system/halo2_snark/eligibility.rs Add (0, 1] validation for phi_f and tests for invalid values.
mithril-stm/src/proof_system/halo2_snark/aggregate_key.rs Use ClosedKeyRegistration accessor for total stake.
mithril-stm/src/proof_system/concatenation/single_signature.rs Propagate phi_f validation errors from lottery checks.
mithril-stm/src/proof_system/concatenation/signer.rs Make lottery check fallible (StmResult) and propagate errors.
mithril-stm/src/proof_system/concatenation/proof.rs Harden concatenation-proof legacy decoding with checked offsets.
mithril-stm/src/proof_system/concatenation/eligibility.rs Validate phi_f and make is_lottery_won fallible; add tests for invalid values.
mithril-stm/src/proof_system/concatenation/aggregate_key.rs Use ClosedKeyRegistration accessor for total stake.
mithril-stm/src/membership_commitment/merkle_tree/tree.rs Harden MerkleTree legacy decoding with checked arithmetic; adjust lint-handling around (de)serialization helpers.
mithril-stm/src/membership_commitment/merkle_tree/commitment.rs Harden batch commitment verification arithmetic with checked ops.
mithril-stm/src/lib.rs Update public docs/imports to reflect new registration API (no public RegistrationEntry).
mithril-stm/README.md Update README example to use KeyRegistration::register().
mithril-stm/examples/key_registration.rs Update example to use KeyRegistration::register().
mithril-stm/CHANGELOG.md Add a new release entry describing the refactor/validation/decoder hardening.
mithril-stm/benches/stm.rs Update benches to use KeyRegistration::register().
mithril-stm/benches/size_benches.rs Update benches to use KeyRegistration::register().

Comment thread mithril-stm/src/membership_commitment/merkle_tree/tree.rs Outdated
Comment thread mithril-stm/src/proof_system/concatenation/signer.rs
Comment thread mithril-stm/src/membership_commitment/merkle_tree/commitment.rs Outdated
Comment thread mithril-stm/CHANGELOG.md Outdated
@damrobi
damrobi force-pushed the damrobi/msnark/refactor-pop-snark-params-decoding branch from 83d45a6 to 36b7b29 Compare July 27, 2026 15:05
@damrobi
damrobi temporarily deployed to testing-2-preview July 28, 2026 06:32 — with GitHub Actions Inactive
@damrobi
damrobi temporarily deployed to testing-preview July 28, 2026 06:32 — with GitHub Actions Inactive
Comment thread mithril-stm/src/proof_system/concatenation/eligibility.rs Outdated
Comment thread mithril-stm/src/proof_system/concatenation/eligibility.rs Outdated
Comment thread mithril-stm/src/proof_system/concatenation/eligibility.rs Outdated
Comment thread mithril-stm/src/proof_system/halo2_snark/eligibility.rs Outdated
Comment thread mithril-stm/src/proof_system/halo2_snark/eligibility.rs Outdated
Comment thread mithril-stm/src/membership_commitment/merkle_tree/tree.rs Outdated
Comment thread mithril-stm/src/protocol/error.rs Outdated
Comment thread mithril-stm/src/membership_commitment/merkle_tree/commitment.rs Outdated
Comment thread mithril-stm/src/membership_commitment/merkle_tree/commitment.rs Outdated
Comment thread mithril-stm/src/protocol/key_registration/register.rs

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clippy found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@damrobi
damrobi force-pushed the damrobi/msnark/refactor-pop-snark-params-decoding branch from 95c67c0 to e150f0b Compare July 29, 2026 08:35
Comment thread mithril-stm/src/proof_system/concatenation/eligibility.rs Fixed
Comment thread mithril-stm/src/proof_system/concatenation/eligibility.rs Fixed
@damrobi
damrobi force-pushed the damrobi/msnark/refactor-pop-snark-params-decoding branch from eb86804 to 883bec1 Compare July 29, 2026 09:24
@damrobi
damrobi requested a review from jpraynaud July 29, 2026 09:30
@damrobi
damrobi temporarily deployed to testing-preview July 29, 2026 10:05 — with GitHub Actions Inactive
@damrobi
damrobi temporarily deployed to testing-2-preview July 29, 2026 10:05 — with GitHub Actions Inactive
Comment thread mithril-stm/src/proof_system/concatenation/eligibility.rs Fixed
@damrobi
damrobi force-pushed the damrobi/msnark/refactor-pop-snark-params-decoding branch from 28ac44a to 83390c5 Compare July 29, 2026 11:31
@damrobi
damrobi temporarily deployed to testing-2-preview July 29, 2026 13:08 — with GitHub Actions Inactive
@damrobi
damrobi temporarily deployed to testing-preview July 29, 2026 13:08 — with GitHub Actions Inactive

@jpraynaud jpraynaud left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@damrobi
damrobi merged commit 3254f5d into main Jul 29, 2026
91 of 92 checks passed
@damrobi
damrobi deleted the damrobi/msnark/refactor-pop-snark-params-decoding branch July 29, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants