Repository navigation
feat: add native and ERC20 Keccacheck proofs with beta SGX ceremony - #3
Merged
Merged
Conversation
ozwaldorf
changed the base branch from
opt/keccacheck-arkworks-integration
to
main
October 8, 2026 04:37
A node must not derive its own key: circuit_specific_setup leaves one party able to forge any statement, which spec 18.2's multiparty Phase 2 exists to prevent. load_proving_key reads a ceremony's output instead, kept as a separate function so the unsound path cannot be reached by omitting an argument, and validating point encodings once at load rather than trusting them per proof. verifying_key_constants derives the flat field elements the generated Solidity verifier compiles in. A node holds only the proving half but the escrow embeds the verifying half, so this lets it confirm the two came from the same setup before proving rather than discovering the mismatch as a rejected proof after fronting a transfer. A test pins the derivation against contracts/Verifier.sol. Tests share one key: setup is ~8.7 GiB, and four of them in parallel exhausted memory before reaching an assertion.
The statement carried a 180-block lease and a witness 100 blocks after bonding. EscrowBase sets executionDeadline = block.number + 25, so no caller that bonded through the contract could ever hold that state: the proof was only spendable by forging bond storage directly. Narrows the lease to 25 blocks and moves the witness inside it, so a fund/bond/collect chain reproduces the statement. The header's encoded number moves with it, since the relation binds the two. Regenerates proof.json and calldata.txt. Verifier.sol is unchanged: the constraint system did not move, only the witness.
The statement committed to 0x22..22, which no deployment produces. A consumer could only get the contract there by relocating it after construction, and that breaks bond(): the escrow caches its EIP-712 domain separator over address(this) at construction, so a moved copy rejects every signature written against its new address. Uses the address a CREATE from 0x01..01 at nonce 0 yields, so the escrow can be deployed where the proof expects it and the whole fund/bond/ collect chain runs. The intent commitment moves with it, since spec 8.3 binds the escrow.
load_proving_key had no inverse, so a caller that generated a key could not persist it. save_proving_key mirrors it, sharing the compressed flag the two must agree on, and serialize_verifying_key exposes the canonical bytes that identify a setup: hashing them gives a caller a fingerprint to check an untrusted proving key against without reproducing the setup. The key types are aliased so a consumer can name what Keys holds without depending on the arkworks crates directly.
Adds a transaction parser gadget and NativeCircuit, a second ConstraintSynthesizer proving native ETH settlements. The transaction gadget parses the three envelope shapes spec 12.6.1 admits (legacy, EIP-2930, EIP-1559), rejecting blob and set-code types. Their item counts differ and decode_list enforces an exact count, so all three are decoded speculatively under their own active flags and the to/value fields selected. NativeCircuit walks two tries under one key: the transaction trie for to/value and the receipt trie for status == 1. The receipt half is load-bearing, since a reverted transaction is still in the transactions trie. It also pins assetKind == 0, without which a token row could be collected by sending ETH. Two soundness bugs found by the negative tests: a zero-value transaction satisfied any commitment, because comparing the read byte against zero outside the payload is vacuous; and a non-canonical value let a prover shift the amount, because RLP canonicality does not cover integer minimality. Measured at 17,842,866 constraints against the ERC-20 relation's 10,426,684. That difference makes proving time identify the asset kind, which spec 12.9 forbids, so this is not yet shippable behind EscrowNative. Recorded in the README and the module docs. Header parsing now exposes transactionsRoot, which was already length-checked but never extracted.
Adds a transaction encoder covering all five EIP-2718 layouts including signature fields, a native collector that rebuilds both tries, and 100 real mainnet settlements across 34 blocks. The collector verifies each rebuilt root against the header's transactionsRoot and receiptsRoot. That check grades encode_transaction across whatever envelopes each block contains, which is the only practical way to validate five layouts and their signature encoding. The dataset covers both shapes the relation accepts, tagged by bare_send: 57 direct sends and 43 calls carrying value. All 57 bare sends satisfy NativeCircuit at the compiled bounds on real chain data. The two populations differ by an order of magnitude, and the difference decides the bounds. Measured cost against the buffer bound: 320 (p50) 12.6M constraints ~35 GB 448 (bare) 13.4M ~37 GB 1088 (p75) 30.8M ~86 GB 4224 (p90) 213.4M ~598 GB Synthesizing the largest fixture, a 21,501-byte receipt, was OOM-killed on a 94 GB machine. So a bound covering the observed maximum is not provable, and restricting native settlements to bare sends is a policy decision the enclave's pre-settlement check must make. Also corrects test/vectors/README.md, which listed four files that do not exist.
A node settles by sending ETH directly, so the native relation now enforces empty calldata rather than leaving data unconstrained. The reason is measured. A call carrying value delivers ETH exactly as a bare send does, which is why an earlier draft accepted it, but a call's payload is unbounded and its receipt may carry any number of logs. On mainnet that is 7KB transactions and 21KB receipts against a bare send's 122 and 393 bytes, and cost scales with every buffer bound across two trie arrays: 320 (p50) 12.6M constraints ~35 GB 448 (bare) 13.4M ~37 GB 1088 (p75) 30.8M ~86 GB 4224 (p90) 213.4M ~598 GB Synthesizing the largest fixture was OOM-killed on 94 GB. Unconstrained, the relation would accept settlements no machine can prove, which fails after the executor has already paid. Constraining it makes the compiled bounds structural instead of a policy the circuit trusts elsewhere. Tops the dataset up to 143 fixtures: 100 bare sends, all satisfied at the compiled bounds, plus the 43 value-carrying calls retained as rejection fixtures. Those are the evidence the constraint binds on real chain data rather than only on a synthetic case. The collector gains --bare, --merge and dedup by transaction hash so a top-up run keeps what a previous one collected.
Profiles the circuit and records two recoverable costs. Node hashing dominates: link-hash is 795,524 of ~1.29M per traversal level (62%), the traversal is ~76% of the circuit, so keccak over MPT nodes is ~47% of the whole thing. The compiled bounds are misaligned with the keccak rate. keccak256_var runs max/136 + 1 permutations regardless of real length, so cost steps at each multiple of 136 and a bound is cheapest at the largest value in its block. node_bytes = 544 is exactly 4*136, landing one byte into a fifth block and paying an extra permutation per node per trie for no headroom. Every other bound sits just past a step too. Aligning all four, with all 100 bare sends still inside every bound: compiled today 17,842,875 keccak-aligned 15,839,284 -11.2%, ~6 GB and depth 4->3 13,595,528 -24% total The alignment is free. The depth reduction is measured but not recommended: depth 4 holds 65,536 trie entries against depth 3's 4,096, and this is the bound where being wrong costs the executor. Neither is applied. Changing a compiled bound is a new circuit version under spec 18.4, so it belongs with setup and verifier regeneration.
NativeCircuit had no path to a proof: mirage_prover was hardwired to ReceiptCircuit, so the relation existed but nothing could consume it. Adds a native module mirroring the ERC-20 API, including a bounds check covering both tries -- the transaction side is the half with no ERC-20 equivalent, and the one a settlement carrying calldata trips first. measure-native replaces the derived native figures with measured ones. The 2.8 GB/M projection said ~50 GB; it actually peaks at 26 GB, so the benchmark constant does not hold across relation shapes. Proving is the tighter budget: 45.8s and 68.7s across two identical runs, against spec 19.7's 75s p95.
The native escrow cannot embed the ERC-20 verifier: Groth16's verifying key comes from the constraint system, so a native proof verifies against neither the other circuit's key nor its contract. Renders to NativeVerifier rather than Verifier, since the generator names every contract it emits Verifier and the two would collide in one compilation unit. Ships a real native proof and its calldata so the contract can be exercised rather than only compiled. 24,982 bytes of Solidity against the ERC-20 verifier's 4,858.
The Keccacheck provers record each linear combination's value during synthesis and read per-constraint values for the QAP witness map, skipping LC inlining and the matrix copy. Proofs are byte-identical to Groth16::prove; the native proving peak drops from 10.46 to 2.11 GiB and host time from ~25s to ~7s.
Sequential 256Ki-base chunks keep MSM key accesses local under EPC paging: native proving on sgx1 drops from 132.7s to ~84s. Hosts keep whole-key MSMs.
ozwaldorf
force-pushed
the
native-eth-relation
branch
from
October 9, 2026 05:55
abfd4e3 to
031908d
Compare
ozwaldorf
marked this pull request as ready for review
October 19, 2026 15:29
Raise MIN_INSTANCES to 4 so every batch derives a multi-element r before beta. Add spec-model, R1CS correspondence, Poseidon2 parameter and forgery tests, with named-check labels for test inspection.
EmperorOrokuSaki
approved these changes
Nov 16, 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.
Adds Groth16 proofs for native ETH, ERC20, and per-row batch settlement, with streaming synthesis and chunked MSMs for SGX.
The beta ceremony starts from the public Hermez Phase 1 transcript and performs a fresh Phase 2 contribution inside a standalone, non-debug SGX enclave. Its quote binds the input manifest and exact PK/VK hashes to the enclave measurement.
The private beta release contains both key pairs, quotes, attestation collateral, manifests, and checksums. Source revisions and key hashes are recorded in
crates/sgx-ceremony/releases/beta-20261104.json.The ceremony can be rerun after circuit changes. Existing exporters load the final keys through
MIRAGE_EXPORT_PROVING_KEYto generate matching Solidity verifiers and proof fixtures.This is a temporary SGX-based setup pending a public ceremony. It accepts the approved beta advisories INTEL-SA-00289 and INTEL-SA-00615. New keys require matching escrow verifiers; old seeded-key escrows are incompatible.
Both ceremony outputs passed hardware-run and independent local verification. Matching escrow tests passed 173/173; API tests passed 180 with 17 optional tests ignored. Sepolia Nomad and the fela3 API are deployed with these keys and verifiers; live API proof simulations and attestation verification passed.
Related: escrow #38, Nomad #138, API #103, SDK #15, frontend #342.