refactor(halo2): Decouple circuit from Midnight types - #3076
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the Halo2 circuit code to decouple it from direct Midnight library types. It introduces a circuit-local wrapper type CircuitBaseField and shared type aliases (CircuitBase, CircuitCurve) in types.rs, replaces duplicated per-file type F/C aliases with these shared types, consolidates error-to-synthesis conversion into to_synthesis_error in errors.rs, moves the STM→Halo2 Merkle path adapter from utils/mod.rs into a new adapters.rs, and inlines the field-limb split utilities from utils/mod.rs directly into gadgets.rs.
Changes:
- Introduced
CircuitBaseFieldnewtype wrapper andCircuitBase/CircuitCurveshared type aliases intypes.rs, replacing direct Midnight type re-exports and per-filetype F/Caliases - Extracted
to_synthesis_errorfromStmCircuit::synthesis_errorintoerrors.rs, sharing the error conversion acrosscircuit.rsandgadgets.rs - Moved the STM Merkle path→Halo2 witness adapter from
utils/mod.rsto the newadapters.rstest-only module, and inlined field-limb split helpers intogadgets.rs
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
mithril-stm/src/circuits/halo2/types.rs |
Adds CircuitBaseField wrapper type with arithmetic ops and From/Into conversions; introduces CircuitBase/CircuitCurve aliases; replaces JubjubBase-based type aliases |
mithril-stm/src/circuits/halo2/errors.rs |
Adds GadgetsFieldModulusParse/GadgetsFieldElementConversion variants; extracts to_synthesis_error function |
mithril-stm/src/circuits/halo2/gadgets.rs |
Inlines field-limb split helpers from utils/mod.rs; adopts shared F/C aliases from types.rs; uses to_synthesis_error |
mithril-stm/src/circuits/halo2/circuit.rs |
Adopts shared F/C aliases; inserts .into() conversions at wrapper boundary; uses to_synthesis_error |
mithril-stm/src/circuits/halo2/adapters.rs |
New test-only file housing the STM→Halo2 Merkle path TryFrom adapter |
mithril-stm/src/circuits/halo2/mod.rs |
Registers new adapters module; removes utils sub-module; tightens gadgets visibility to pub(crate) |
mithril-stm/src/circuits/halo2/golden/helpers.rs |
Uses CircuitBaseField via F alias; migrates Midnight type references to use new From/Into path |
mithril-stm/src/circuits/halo2/golden/cases/positive.rs |
Removes unused use ff::Field import |
mithril-stm/src/circuits/halo2/golden/cases/negative.rs |
Removes unused use ff::Field import |
mithril-stm/src/circuits/halo2/utils/mod.rs |
Deleted; content moved to gadgets.rs and adapters.rs |
619844f to
4bc9730
Compare
damrobi
left a comment
There was a problem hiding this comment.
I left a few minor comments.
4bc9730 to
b8657c5
Compare
jpraynaud
left a comment
There was a problem hiding this comment.
LGTM 👍
Just few final comments to be addressed before merging.
…ify module architecture
ae490a1 to
4bf9ee0
Compare
b4502f0 to
fbf9b8d
Compare
curiecrypt
left a comment
There was a problem hiding this comment.
LGTM 👍
I think it's better to address the duplicate functionality in the other PR. So, I marked the related conversation as resolved.
It can be merged 🚀
Content
This PR improves the Halo2 circuit code structure for by introducing decoupled circuit-local types.
This PR includes:
types.rs:CircuitBaseField,CircuitBase,CircuitCurveF/Caliases with shared types fromtypes.rsacross:circuit.rs,gadgets.rs,golden/helpers.rsFrom/Intoadapters.rs) for STM Merkle path → Halo2 witness conversion.utils/mod.rsby inlining field-limb split logic intogadgets.rsto_synthesis_errorinerrors.rsPre-submit checklist
Issue(s)
Closes #3037