Skip to content

refactor(stm): Ensuring type consistency for SNARK circuit - #3071

Merged
damrobi merged 12 commits into
mainfrom
damrobi/msnark/3036-stm-type-consistency
Mar 9, 2026
Merged

refactor(stm): Ensuring type consistency for SNARK circuit#3071
damrobi merged 12 commits into
mainfrom
damrobi/msnark/3036-stm-type-consistency

Conversation

@damrobi

@damrobi damrobi commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

Content

This PR includes modifications to the creation function of StmCircuit to ensure that the types received from the STM protocol fit in the types of the circuit.
It also includes tests and results on the impact of changing the types within the circuit on the numbers of constraints of the circuit. Those results are added to the SNARK MVP Book.

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
  • Documentation
    • No new TODOs introduced

Comments

Issue(s)

Closes to #3036

@damrobi damrobi self-assigned this Mar 6, 2026
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Fixed
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Fixed
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Fixed
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Fixed
@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown

Test Results

    5 files  ±0    190 suites  ±0   57m 23s ⏱️ +59s
2 653 tests +3  2 653 ✅ +3  0 💤 ±0  0 ❌ ±0 
9 505 runs  +3  9 505 ✅ +3  0 💤 ±0  0 ❌ ±0 

Results for commit 021a73d. ± Comparison against base commit 69caced.

♻️ This comment has been updated with latest results.

@damrobi
damrobi force-pushed the damrobi/msnark/3036-stm-type-consistency branch from a0abf46 to bf651f8 Compare March 6, 2026 10:42
@damrobi
damrobi temporarily deployed to testing-preview March 6, 2026 10:56 — with GitHub Actions Inactive
@damrobi
damrobi temporarily deployed to testing-preview March 6, 2026 11:13 — with GitHub Actions Inactive
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
@jpraynaud
jpraynaud requested review from Copilot and removed request for curiecrypt and hjeljeli32 March 6, 2026 12:10

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 updates the Halo2 STM circuit boundary to better align with STM protocol types by introducing a checked constructor that safely narrows STM u64 parameters into the circuit’s u32 internal representation, and updates golden tests accordingly.

Changes:

  • Removed the Halo2-local LotteryIndex alias and standardized on the crate-level LotteryIndex (u64).
  • Added StmCircuit::try_new(Parameters, merkle_tree_depth) to validate u64 -> u32 narrowing at circuit creation time.
  • Updated golden witness builders and cases to use LotteryIndex-compatible indices and updated circuit setup to use try_new.

Reviewed changes

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

Show a summary per file
File Description
mithril-stm/src/circuits/halo2/types.rs Removes Halo2-local LotteryIndex alias to avoid type divergence from STM domain types.
mithril-stm/src/circuits/halo2/circuit.rs Adds try_new for checked narrowing of STM parameters and updates witness index assignment to use LotteryIndex directly.
mithril-stm/src/circuits/halo2/golden/helpers.rs Updates golden helpers to use LotteryIndex in witness entries and constructs StmCircuit via try_new.
mithril-stm/src/circuits/halo2/golden/cases/positive.rs Adjusts test indices to remain compatible with LotteryIndex/u64-based APIs.
mithril-stm/src/circuits/halo2/golden/cases/negative.rs Adjusts negative test indices to remain compatible with LotteryIndex/u64-based APIs.

Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/golden/cases/positive.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/golden/cases/negative.rs Outdated
Comment thread mithril-stm/src/circuits/halo2/circuit.rs Outdated
@damrobi
damrobi temporarily deployed to testing-preview March 6, 2026 13:02 — with GitHub Actions Inactive
@damrobi
damrobi marked this pull request as ready for review March 6, 2026 13:44
@damrobi
damrobi requested review from curiecrypt and hjeljeli32 March 6, 2026 13:44

@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 temporarily deployed to testing-preview March 6, 2026 17:10 — with GitHub Actions Inactive

@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.

@curiecrypt curiecrypt 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.

can be merged

@damrobi
damrobi force-pushed the damrobi/msnark/3036-stm-type-consistency branch from af1e102 to 021a73d Compare March 9, 2026 15:56
@damrobi
damrobi temporarily deployed to testing-preview March 9, 2026 16:10 — with GitHub Actions Inactive
@damrobi
damrobi merged commit 925875b into main Mar 9, 2026
58 checks passed
@damrobi
damrobi deleted the damrobi/msnark/3036-stm-type-consistency branch March 9, 2026 16:16
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.

6 participants