Skip to content

test(contracts): prove and verify every mock circuit in a benchmark - #316

Draft
nicolasLuduena wants to merge 12 commits into
mainfrom
feat/192-proving-benchmark
Draft

nicolasLuduena wants to merge 12 commits into
mainfrom
feat/192-proving-benchmark

Conversation

@nicolasLuduena

Copy link
Copy Markdown
Member

Closes #192
Part of #309. PR 1 of 6 in the stack (#192 → #310 → #311 → #312 → #313 → #314).

Summary

npm run bench compiles the mocks with proving keys and proves every circuit of both mocks on a real proof server. It prints k, rows, proving key size, proof size, first and warm proving time, CPU time per warm proof and peak memory for each circuit.

npm run bench
  compile mocks with keys (npm run compact)
  capture()                         # simulator runs each circuit, keeps its proof data
  require captured circuits == artifacts/<mock>/keys/*.prover
  for each circuit
    fresh proof server container    # or PROOF_SERVER_URL: CPU and memory "not measured"
      GET /fetch-params/<k>         # parameters download outside the timings
      POST /check                   # wrong witness fails before proving
      POST /prove x (1 + BENCH_RUNS)   # server verifies each proof against the verifier key
      read cgroup cpu.stat / memory.peak
  wrong-key control                 # smallest circuit under another's verifier key → "Invalid proof"
  print table, fail if any circuit did not prove or the control was accepted
 packages/contracts/
+├── bench/
+│   ├── proving.bench.ts    # the run: capture, prove, control, report
+│   ├── proof-server.ts     # starts the pinned server in Docker, reads its cgroup
+│   ├── report.ts           # summarizes proofs, renders the table
+│   └── vitest.config.ts    # separate config: not in npm test or CI
 ├── test/
+│   ├── bench-report.test.ts
 │   └── helpers/sim.ts      # + callForProof()
 └── README.md               # + "Proving cost"
  • The Docker command is configurable (BENCH_DOCKER), and so is the parameter cache (BENCH_PARAMS, a named volume by default). See CONTRIBUTING's "Proving benchmark" section.
  • @midnight-ntwrk/ledger-v9 1.0.2 is a new dev dependency of contracts. It builds the /check and /prove payloads.
  • No changeset. The benchmark isn't in the published files, and the README change is docs only.

Evidence

The baseline run (npm run bench, current circuits, nothing optimized):

AMD Ryzen 7 5700G with Radeon Graphics, 16 threads, 31 GiB; proof server 9.0.0 (midnightntwrk/proof-server:9.0.0), a fresh container per circuit; 3 warm proofs per circuit.
The proof server verified every proof against its verifier key, and refused a proof under the wrong verifier key.

| Mock | Circuit | k | Rows | Proving key (MB) | Proof (B) | First proof (s) | Warm proof (s) | CPU per warm proof (s) | Peak memory (MB) |
|---|---|---|---|---|---|---|---|---|---|
| mock_attestation | verifyAttestation | 17 | 90,590 | 197.2 | 5,772 | 12.20 | 9.27 | 74.9 | 3162 |
| mock_attestation | openAndRead | 14 | 8,610 | 24.6 | 5,772 | 1.53 | 1.15 | 10.3 | 422 |
| mock_attestation | openAndReadPresence | 14 | 8,580 | 24.6 | 5,772 | 1.55 | 1.15 | 10.4 | 437 |
| mock_attestation | openAndRequireMetric0 | 14 | 8,570 | 24.6 | 5,772 | 1.56 | 1.15 | 10.5 | 446 |
| mock_attestation | openAndBindHost | 14 | 14,633 | 24.6 | 5,772 | 1.61 | 1.22 | 10.8 | 446 |
| mock_attestation_bytes | verifyAttestation | 17 | 94,609 | 197.2 | 5,772 | 12.43 | 9.34 | 75.1 | 3166 |
| mock_attestation_bytes | openAndReadBytes | 15 | 19,188 | 49.3 | 5,772 | 2.94 | 2.23 | 19.4 | 758 |

 ✓ proves and verifies every mock circuit 152186ms

The same benchmark pointed at a server it did not start (PROOF_SERVER_URL, 1 warm run):

...; proof server 9.0.0 at http://127.0.0.1:32794, not started by the benchmark, so CPU time and peak memory are not measured; ...
| mock_attestation | verifyAttestation | 17 | 90,590 | 197.2 | 5,772 | 12.36 | 9.43 | not measured | not measured |
...
 ✓ proves and verifies every mock circuit 94916ms
  • Before: the repo has no way to prove a circuit, and the README gives no cost.
    After: every circuit of both mocks proves and verifies, including openAndBindHost, and the README carries the table above.
  • npm test: 781 passed, 4 skipped (the live checks). The benchmark isn't collected. npm run types and npm run check pass.
  • bench-report.test.ts covers the warm median and CPU median, the cached-first-proof flag, the table line, and "not measured" when there is no server cgroup.

No verification skill in this repo.

Merge Danger

Door: two-way

A new command, docs and a dev dependency. Nothing shipped changes.

Blast Radius: contributors

MockSim.call now goes through a public run. Test behavior is unchanged. The README numbers come from this machine, and every later ticket in the stack regenerates them.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…ions

- Remove this run's proof server containers when the run is interrupted:
  the vitest process labels them and removes them on exit, since its
  watchdog SIGKILLs the worker; the worker also removes its container on
  SIGINT, SIGTERM and exit, and detaches those handlers in stop().
- Read the options once, before any server starts: BENCH_RUNS must be an
  integer of at least 1, a trailing slash on PROOF_SERVER_URL is dropped,
  a relative BENCH_OUT resolves against INIT_CWD, and zkir-v3 is the entry
  under ~/.compact that has the binary. A non-zero zkir-v3 exit fails.
- Never flag a fresh server's first proof as cached.
- Cover the even-length median and the empty warm list.
…hmark

# Conflicts:
#	package.json
#	packages/contracts/package.json
#	packages/contracts/tsconfig.json

This branch has not been deployed

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

contracts: measure and publish proving cost and key sizes

1 participant