Skip to content

feat: settlement proving as a library, enclave-buildable - #1

Closed
ozwaldorf wants to merge 4 commits into
mainfrom
feat/ceremony-key-loading
Closed

ozwaldorf wants to merge 4 commits into
mainfrom
feat/ceremony-key-loading

Conversation

@ozwaldorf

Copy link
Copy Markdown
Member

Prepares the circuit for use from the enclave, and records the step-2 relation as complete.

What changed

  • mirage_prover is a library, not just binaries. setup, prove, check_bounds, and load_proving_key for reading a ceremony's output. prove takes an RNG rather than seeding internally, since reusing proof randomness across settlements would defeat zero-knowledge; prove_seeded keeps exported artifacts byte-reproducible.
  • mirage_fixtures::chain promotes the JSON-RPC header/receipt encoders out of the collector binary, with inclusion_proof rebuilding the receipt trie. One implementation of consensus encoding rather than two.
  • Enclave-buildable. The Solidity exporter, trace printing, and the collector's ureq transport move behind features; rustls/ring do not build for Fortanix EDP. Verified: the whole stack compiles for x86_64-fortanix-unknown-sgx.
  • verifying_key_constants derives the flat field elements the generated verifier compiles in, pinned by a test against contracts/Verifier.sol.
  • Docs corrected: step 2 was recorded as "not written" while the relation proves and verifies on-chain.
  • Clippy clean across the workspace (was 32 warnings).

Fixed along the way

crates/relation/tests/mainnet.rs hardcoded witness_block_hash: [0x66; 32], which the header-binding constraints added in ead0999 can never satisfy. All 100 mainnet fixtures were failing at one constraint. Now derived from the header each fixture carries — 100/100 pass.

Measured

constraints 10,426,684
prove 21.4s, 15.5 GB peak
setup 33.4s, 8.7 GB peak
proving key 2.03 GiB compressed
on-chain verify 4,858 bytes, ~222.7k gas

Note EDP is not a blocker for arkworks. FINDINGS.md recorded that as an incompatibility; that judgment was about gnark (Go), and was never tested for arkworks. It builds, rayon included.

Not done

The multiparty Phase 2 ceremony (spec 18.2). setup remains circuit_specific_setup, a toy.

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

1 participant