Skip to content

refactor(stm): refactor error handling from Midnight library#3416

Merged
hjeljeli32 merged 6 commits into
mainfrom
hjeljeli32/3382-typed-circuit-errors
Jul 20, 2026
Merged

refactor(stm): refactor error handling from Midnight library#3416
hjeljeli32 merged 6 commits into
mainfrom
hjeljeli32/3382-typed-circuit-errors

Conversation

@hjeljeli32

@hjeljeli32 hjeljeli32 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Content

Typed StmCircuitError guard failures raised in the non-recursive (certificate) circuit's Relation::circuit implementation were flattened into plonk::Error::Synthesis(String) at the relation boundary (via to_synthesis_error), losing the error type and forcing callers and tests to rely on fragile string matching. Midnight zk 2.3.3 lets a relation surface its own error type end-to-end through the Relation::Error associated type (midnightntwrk/midnight-zk#248).

This types the certificate circuit's error boundary: the circuit returns StmCircuitError directly, the flattening adapter is removed, and the negative tests assert typed variants. The change is confined to the non-recursive circuit (circuits/halo2/).

Changes

  • Typed relation error: StmCertificateCircuit::Error is now StmCircuitError (was plonk::Error). A Backend(String) catch-all variant and a From<plonk::Error> conversion satisfy Midnight's new Relation::Error: From<plonk::Error> bound; backend/library errors convert into it while the circuit's own domain guards stay fully typed.
  • Removed the flattening adapter: to_synthesis_error is deleted for the non-recursive circuit. The relation (circuit.rs), witness assignment (witness_assignments.rs), and the gadget layer it feeds (merkle_path, comparison_helpers, comparison, lottery) now return StmCircuitError directly; standard-library plonk::Error values convert upward through From.
  • Typed source preserved for callers: the prover path keeps StmCircuitError downcastable through the anyhow source chain, so callers and tests match on typed variants instead of parsing synthesis message text.
  • Tests: removed the assert_proving_backend_message_contains string-matching helper; the six negative cases now assert exact StmCircuitError variants; the focused test-relation macro is parameterized by error type; and a From<plonk::Error> conversion unit test guards the trait contract.

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

Issue(s)

Closes #3382

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

Test Results

     5 files  ± 0     209 suites  ±0   42m 30s ⏱️ - 18m 36s
 3 340 tests +31   3 340 ✅ +31  0 💤 ±0  0 ❌ ±0 
11 072 runs  +37  11 072 ✅ +37  0 💤 ±0  0 ❌ ±0 

Results for commit 976d808. ± Comparison against base commit a8b7c9c.

♻️ This comment has been updated with latest results.

@jpraynaud
jpraynaud requested a review from Copilot July 17, 2026 08:08
@hjeljeli32
hjeljeli32 force-pushed the hjeljeli32/3382-typed-circuit-errors branch from 11eb64d to 5ba6b14 Compare July 17, 2026 08:12

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 upgrades the midnight-* dependencies and refactors STM Halo2 circuit/proof plumbing to preserve typed circuit errors (StmCircuitError) across the Relation::circuit boundary (removing prior string-based synthesis error flattening). It also updates IVC fixed-base handling and regenerates/updates golden assets accordingly.

Changes:

  • Upgrade midnight-circuits/curves/proofs/zk-stdlib and adapt call sites to new APIs (MidnightCircuit::from_relation(..., None), SRS downsizing, verifier params usage).
  • Preserve typed StmCircuitError end-to-end in the non-recursive certificate circuit and update negative tests to assert on typed variants.
  • Update IVC accumulator/fixed-base handling (prefix renames, removal of com_instance dummy entry, pre-flight MSM/fixed-base consistency check) and refresh related golden assets/tests.

Reviewed changes

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

Show a summary per file
File Description
mithril-stm/src/protocol/aggregate_signature/clerk.rs Adjust test setup to new MidnightCircuit/SRS downsizing API.
mithril-stm/src/protocol/aggregate_signature/ancillary_data.rs Update expected digest constant to match regenerated assets/behavior.
mithril-stm/src/proof_system/ivc_halo2_snark/verifier_setup.rs Remove tau_g2 storage/extraction; rely on verifier params and updated fixed-base prefixes.
mithril-stm/src/proof_system/ivc_halo2_snark/prover_setup.rs Add MSM/fixed-base pre-flight checks; construct accumulators via from_dual_msm; update prefixes.
mithril-stm/src/proof_system/ivc_halo2_snark/prover_input_helpers.rs Propagate new StmResult return from certificate_collapsed_accumulator.
mithril-stm/src/proof_system/ivc_halo2_snark/proof.rs Update accumulator verification to use verifier params; adjust tests accordingly.
mithril-stm/src/proof_system/halo2_snark/setup.rs Switch to MidnightCircuit::from_relation(..., None).k() and new SRS downsizing flow.
mithril-stm/src/proof_system/halo2_snark/proof.rs Refresh golden proof/verifier-data fixtures; add ignored generator test helper.
mithril-stm/src/circuits/halo2/witness_assignments.rs Return StmCircuitError from witness assignment helpers and propagate backend errors via From.
mithril-stm/src/circuits/halo2/tests/test_helpers.rs Parameterize test harness over relation error type; update circuit degree derivation.
mithril-stm/src/circuits/halo2/tests/golden/helpers.rs Remove backend string-matching helper; update proving error propagation and cost model calls.
mithril-stm/src/circuits/halo2/tests/golden/cases/negative.rs Convert negative tests from string matching to typed StmCircuitError assertions.
mithril-stm/src/circuits/halo2/mod.rs Update module docs to reflect backend error conversion (not synthesis flattening).
mithril-stm/src/circuits/halo2/keys.rs Update circuit degree discovery and expose degree as u32; adapt keygen sizing.
mithril-stm/src/circuits/halo2/key_serialization.rs Update test keygen path to new circuit degree/SRS handling.
mithril-stm/src/circuits/halo2/gadgets/unique_schnorr_signature.rs Update focused test relation macro usage with explicit error type.
mithril-stm/src/circuits/halo2/gadgets/merkle_path.rs Return StmCircuitError directly for guard failures; map backend assertion errors upward.
mithril-stm/src/circuits/halo2/gadgets/lottery.rs Return StmCircuitError for lottery gadget assertions; adjust focused tests.
mithril-stm/src/circuits/halo2/gadgets/comparison.rs Propagate StmCircuitError from comparison helpers and assertions.
mithril-stm/src/circuits/halo2/gadgets/comparison_helpers.rs Convert helper APIs to StmCircuitError for typed propagation.
mithril-stm/src/circuits/halo2/errors.rs Add backend catch-all + From<plonk::Error> to satisfy new Relation::Error bound; add unit test.
mithril-stm/src/circuits/halo2/circuit.rs Set Relation::Error = StmCircuitError; remove synthesis flattening; update cost model calls and chips.
mithril-stm/src/circuits/halo2/bench_helpers.rs Update cost model and MockProver API usage; update circuit degree calculation.
mithril-stm/src/circuits/halo2_ivc/witness_assignments.rs Rename VK name constants to fixed-base prefixes throughout witness assignment.
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/proof_verification.rs Use verifier params (not tau_g2) in accumulator checks.
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/mod.rs Rename extraction-focused module references to resolution-focused ones.
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/fixed_base_resolution.rs New tests for resolve_fixed_bases behavior/idempotency.
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/fixed_base_extraction.rs Removed extraction tests (superseded by resolution approach).
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/accumulator_verification.rs Use verifier params for accumulator checks.
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/accumulator_update.rs Update pipeline to from_dual_msm/verifier params; remove extract step assumptions.
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/accumulator_construction.rs Add negative test for fixed-base prefix mismatch detection.
mithril-stm/src/circuits/halo2_ivc/tests/off_circuit/accumulator_collapse.rs Align collapse tests with from_dual_msm + verifier params flow.
mithril-stm/src/circuits/halo2_ivc/tests/golden/positive.rs Update golden checks to pass verifier params into accumulator checks.
mithril-stm/src/circuits/halo2_ivc/tests/encoding/positive.rs Add golden serialization test for recursive proof accumulator bytes.
mithril-stm/src/circuits/halo2_ivc/tests/common/helpers.rs Update MockProver usage and accumulator construction via from_dual_msm; remove stored tau_g2.
mithril-stm/src/circuits/halo2_ivc/tests/common/generators/verification_key.rs Update circuit degree computation for new MidnightCircuit API.
mithril-stm/src/circuits/halo2_ivc/tests/common/generators/transitions.rs Update fixed-base prefix usage and accumulator construction via from_dual_msm.
mithril-stm/src/circuits/halo2_ivc/tests/common/generators/setup.rs Rename constants and fixed-base prefix usage in setup generators.
mithril-stm/src/circuits/halo2_ivc/tests/common/generators/proofs.rs Adjust proof generation call signature ordering.
mithril-stm/src/circuits/halo2_ivc/tests/common/generators/asset_generation.rs Update accumulator construction/checks to verifier params + from_dual_msm; add ignored asset generator.
mithril-stm/src/circuits/halo2_ivc/tests/common/asset_readers.rs Stop extracting/storing tau_g2 from embedded verifier params bytes.
mithril-stm/src/circuits/halo2_ivc/tests/assets/README.md Document new ignored asset-generation command.
mithril-stm/src/circuits/halo2_ivc/mod.rs Rename VK-name constants to fixed-base prefix constants; update foreign ECC chip imports.
mithril-stm/src/circuits/halo2_ivc/errors.rs Add error variant for MSM/fixed-base mismatch detection.
mithril-stm/src/circuits/halo2_ivc/constraint_builder.rs Update to ForeignWeierstrassEccChip API and verifier gadget prepare signature changes.
mithril-stm/src/circuits/halo2_ivc/config.rs Adapt IVC circuit configuration to new weierstrass foreign-ECC chip configuration API.
mithril-stm/src/circuits/halo2_ivc/accumulator.rs Remove com_instance dummy fixed base; add MSM/fixed-base consistency check helper.
mithril-stm/CHANGELOG.md Add 0.11.0 entry describing dependency upgrades and key/fixed-base changes.
mithril-stm/Cargo.toml Bump crate version and pin upgraded midnight-* crate versions.
mithril-common/Cargo.toml Update mithril-stm dependency version to 0.11.0.
docs/runbook/update-circuit-keys/README.md Update runbook checklist with nr_pow2range_cols guidance.
Cargo.lock Lockfile updates for upgraded dependencies and new transitive crates.

Comment thread mithril-stm/src/circuits/halo2/gadgets/comparison_helpers.rs
Comment thread mithril-stm/src/circuits/halo2_ivc/accumulator.rs
Comment thread mithril-stm/src/circuits/halo2_ivc/errors.rs
@hjeljeli32
hjeljeli32 temporarily deployed to testing-preview July 17, 2026 11:15 — with GitHub Actions Inactive
@hjeljeli32
hjeljeli32 temporarily deployed to testing-2-preview July 17, 2026 11:15 — with GitHub Actions Inactive

@damrobi damrobi 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 👍

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

Comment thread mithril-stm/src/circuits/halo2/tests/golden/helpers.rs Outdated
@hjeljeli32
hjeljeli32 force-pushed the hjeljeli32/3382-typed-circuit-errors branch from 5ba6b14 to 976d808 Compare July 20, 2026 22:59
@hjeljeli32
hjeljeli32 temporarily deployed to testing-2-preview July 20, 2026 23:34 — with GitHub Actions Inactive
@hjeljeli32
hjeljeli32 temporarily deployed to testing-preview July 20, 2026 23:34 — with GitHub Actions Inactive
@hjeljeli32
hjeljeli32 merged commit 936eadd into main Jul 20, 2026
90 of 92 checks passed
@hjeljeli32
hjeljeli32 deleted the hjeljeli32/3382-typed-circuit-errors branch July 20, 2026 23:41
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.

Refactor error handling from Midnight library

4 participants