[one-shot implementation for discussion, not for merging]: feat(midnight): add first-class Midnight proof support (native + EVM) via protocol/model extensions and SDK adapter#2
Open
jtcoolen wants to merge 31 commits intoEYBlockchain:mainfrom
Conversation
Align generated verifier source with Solidity 0.8.30 in the EVM codegen template. - Change the emitted contract pragma in SolidityAssemblyCode from 0.8.19 to 0.8.30.
Adjust local EVM execution helpers so oversized verifier contracts can be deployed and profiled in simulation. - Add serde_json dependency used by EVM utility flows. - Silence non-critical solc stderr output during bytecode compilation. - Relax revm code-size and gas-limit constraints in deploy_and_call for high-bytecode verifier benchmarks.
…ally Vendor the halo2-lib workspace under vendor/halo2-lib and route both axiom-crypto and jtcoolen halo2-lib sources to local halo2-base/halo2-ecc paths. This commit keeps the raw upstream snapshot state before applying the halo2-base BLS patches.
Apply upstream halo2-base commit 360a9d3 to the vendored tree so blsFr implements ScalarField in utils::scalar_field_impls.
Apply upstream halo2-base commit f56347d after 360a9d3, including 6-limb blsFq ScalarField support and halo2curves revision pinning in the vendored halo2-lib metadata.
Preserve the local vendored fix by reconstructing from little-endian bytes instead of assuming a [u64;4] representation.
Refresh Cargo.lock so halo2-base/halo2-ecc and halo2curves-axiom resolve to the pinned fork revisions deterministically.
Vendor halo2-base sources from jtcoolen/halo2-lib@f56347d without local modifications for reproducible builds.
Replace the hardcoded [u64;4] conversion with byte-based reconstruction so wider scalar fields are handled safely.
Migrate SDK proving/verifying type aliases and generic bounds from Bn256 to Bls12 across halo2 and EVM entry points.
Generalize EVM loader point encoding for wider base fields and update transcript IO sizing to distinguish proof-byte and EVM-memory representations.
Serialize G2 points as eight 32-byte words and update the EVM pairing call interface to consume the expanded layout.
Switch generated runtime precompile identifiers and calldata/returndata sizing to BLS12-381 G1/G2 operation layouts.
Use Prague EIP-2537 precompile addresses for BLS12-381 add, MSM, and pairing operations.
Remove the temporary legacy c1,c0 env-toggle path and keep a single canonical ordering for EVM pairing inputs.
Adjust limb decomposition parameters for BLS12-381 base-field arithmetic compatibility in halo2-ecc.
Align pinned toolchain with revm/alloy dependency MSRV requirements used by the BLS runtime path.
Update local EVM execution config/error reporting for Prague precompiles and tighten transcript runtime handling for allocated scalar/ec-point memory layout.
Update Cargo.lock to match runtime dependency/resolution changes introduced by the Prague revm hardening and toolchain alignment.
Capture solc stderr and include actionable diagnostics when bytecode generation fails or emits no output.
Keep the original arithmetization gate shape while moving the example flow to BLS12-381 params and EVM artifact generation/verification.
Factor reusable Halo2 layout and expression helpers so protocol builders can share remapping and selector logic. - Add shared system::halo2::layout and system::halo2::expression modules. - Switch Halo2 compiler internals to those helpers where metadata layout is unchanged. - Replace iter::repeat_n with explicit repeat().take() and simplify native assertion control flow.
Extend PLONK protocol metadata so verifier flows can represent transcript/layout variants without overloading legacy fields. - Add committed-instance and transcript extension fields on PlonkProtocol. - Extend quotient metadata with chunk base and optional fixed chunk count. - Wire Halo2 compiler defaults for the new metadata and re-export protocol types cleanly.
Extend PLONK proof parsing so protocols can hash committed-instance prefixes, bind optional instance lengths, and parse transcript extensions. - Add read_with_committed_instances entrypoint and shared committed-instance absorption flow. - Parse trailing challenges and extra commitments declared by protocol metadata. - Support ZnMinusOne quotient recombination and account for extra commitments in query indexing.
Add deterministic unit tests for committed-instance transcript absorption and placeholder behavior. - Verify committed-prefix plus hashed-length ordering in transcript writes. - Verify deterministic errors for committed layout mismatches. - Verify placeholder extension preserves declared instance-column layout.
Add Midnight-compatible KZG multiopen verification and expose an optional truncated challenge policy used by Midnight transcript variants. - Implement Midnight KZG PCS proof reader/verifier for native and EVM loaders. - Re-export Midnight PCS flavor from kzg modules and add truncated-challenges feature flag. - Add EVM scalar truncation helper used by truncated challenge verification flows.
… memory Harden EVM transcript absorption and decoding for identity points and non-contiguous memory sources. - Re-copy disjoint memory-backed scalars/points into contiguous transcript buffer when required. - Encode/decode point-at-infinity via EVM (0,0) sentinel consistently in native transcript flow. - Add regression tests for identity encoding/decoding behavior.
…ntics Optimize and harden EVM loader arithmetic paths used by generated verifiers. - Route multi-scalar multiplication through batched G1MSM precompile calls. - Add reusable staticcall helper, identity-safe constant point encoding, and zero-preserving scalar negation. - Rewrite batch inversion flow to be zero-safe for aliased inputs and deterministic in memory-backed execution.
Wire optional Midnight dependencies into the SDK while preserving default feature behavior for existing users. - Add Midnight optional dependencies and feature gate in snark-verifier-sdk Cargo manifest. - Forward truncated-challenges feature to snark-verifier for aligned transcript behavior. - Export midnight_adapter behind feature gating and update lockfile dependency graph.
Add SDK bridge primitives that map Midnight proof artifacts onto snark-verifier protocol and EVM verifier generation paths. - Add conversion helpers and bundle constructors for Midnight params/VK/proof/instances. - Add Midnight protocol builder preserving committed-instance, lookup, permutation, and trash layout semantics. - Expose Solidity/bytecode/calldata generation and optional revm verification via MidnightProofBundle.
Add a Midnight Poseidon example and transcript adapter that exercise proof generation, verification, and EVM verifier artifact generation. - Add Midnight EVM transcript hash helper with tests for scalar/point encoding behavior. - Add midnight_poseidon_evm example to prove/verify and emit Solidity, bytecode, and calldata artifacts. - Ignore generated Midnight artifact output directory and keep incidental example formatting tidy.
Author
|
Only the last 10 commits apply, the first 21 commits come from #1 |
This was referenced Feb 27, 2026
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.
[Only the last 10 commits apply, the first 21 commits come from #1]
Context / Motivation
Midnight proofs are not wire-compatible with vanilla Halo2 in several places:
(z^n / z)(vs Halo2’sz^n), with a fixed chunk count derived from Midnight domain configuration.You can understand this branch as:
Once the protocol language can encode the 5 differences above, the bulk of verification logic (native + EVM codegen) stays generic.
High-Level Design
Extend core PLONK protocol/proof structs to represent transcript/layout variants (the “protocol language”).
Keep legacy behavior as defaults so existing Halo2 flows remain unchanged.
Add a Midnight-specific KZG multiopen implementation (
KzgAs<_, Midnight>).Add a feature-gated SDK bridge that:
PlonkProtocol,Detailed Changes
1) Core protocol model extensions
File:
snark-verifier/src/verifier/plonk/protocol.rsProtocol metadata added
committed_instance_counthash_instance_lengthstrailing_challengesextra_commitmentsThese fields are the main abstraction pivot: Midnight is represented as protocol metadata rather than a forked verifier.
Quotient model extended
QuotientChunkBase::{Zn, ZnMinusOne}whereZnMinusOnecorresponds to(z^n / z)num_chunk_override: Option<usize>Behavior:
num_chunk()honors the explicit override when present.loaded,loaded_preprocessed_as_witness).Legacy behavior preserved
2) Proof parsing / verification updates
File:
snark-verifier/src/verifier/plonk/proof.rsCommitted instance handling (absorption order)
A committed-instance-aware flow now:
hash_instance_lengths=true.New parser entrypoint
read_with_committed_instances(...)supports caller-provided committed-instance commitments.Trailing challenges + extra commitments
After phase-driven witness/challenge parsing, the parser appends:
trailing_challengesextra_commitmentsCommitment indexing alignment
num_instancecolumn layout.Quotient recombination supports both bases
Verifier recombines quotient chunks using either:
z^n(Zn)(z^n / z)(ZnMinusOne)Tests added
3) Midnight KZG PCS flavor (multiopen)
Files:
snark-verifier/src/pcs/kzg.rssnark-verifier/src/pcs/kzg/multiopen.rssnark-verifier/src/pcs/kzg/multiopen/midnight.rsAdded:
Midnightmultiopen scheme andMidnightProofstruct.Transcript layout
x1, x2, f_com, x3, q_evals_on_x3, x4, piVerification routine
snark-verifieraccumulator conventionOptional: truncated challenges
truncated-challengesfeature applies 128-bit truncation policy for challenge powers (native + EVM loaders).4) EVM transcript/runtime correctness alignment
Files:
snark-verifier/src/system/halo2/transcript/evm.rssnark-verifier/src/loader/evm/loader.rssnark-verifier/src/loader/evm/code.rsFixes/hardening:
(0,0)(0,0)for identity0.8.305) SDK Midnight adapter (translation layer)
Files:
snark-verifier-sdk/src/midnight_adapter/*Added:
MidnightProofBundlefor constructing verification/codegen inputs from Midnight params/VK/proof/instancesMidnightProtocolBuildertranslating Midnight VK/CS intoPlonkProtocolMidnightProtocolBuilderguarantees:query/evaluation ordering matches Midnight transcript expectations
committed-instance semantics reflected in protocol metadata
inclusion of trash constraints + trash witness columns
quotient config:
chunk_base = ZnMinusOnenum_chunk_override = vk quotient degree(fixed chunk count from Midnight domain config)EVM parity design
build_evm_verifier_loader()replays the same generic proof read + verify flow overEvmLoader,so emitted runtime code is derived from verifier execution (not a hand-written special-case path).
6) Feature plumbing
Files:
snark-verifier-sdk/Cargo.tomlsnark-verifier-sdk/src/lib.rssnark-verifier/Cargo.tomlAdded:
midnightfeature gating Midnight deps + adapter moduletruncated-challengespassthrough from SDK to core7) End-to-end example
Files:
snark-verifier-sdk/examples/midnight_poseidon_evm.rssnark-verifier-sdk/examples/support/midnight_evm_transcript.rsExample demonstrates:
revmverification for gas/result sanityBackward Compatibility
Risks / Review Focus
MidnightProtocolBuilder.ZnMinusOne) and fixed chunk count override.(0,0)sentinel) across read/write/codegen.Testing
cargo check -p snark-verifier-sdk --features midnight,loader_evmcargo +1.88.0 check -p snark-verifier-sdk --features midnight,loader_evm,revmcargo +1.88.0 check -p snark-verifier-sdk --features midnight,loader_evm,revm,truncated-challengescargo run --example midnight_poseidon --features midnight -p snark-verifier-sdk(if present in local tree)RUN_REVM=1 cargo +1.88.0 run --example midnight_poseidon_evm --features midnight,loader_evm,revm -p snark-verifier-sdk