Skip to content

feat: migrate bb-prover from direct binary execution to bb.js API#21564

Open
charlielye wants to merge 5 commits intonextfrom
cl/bb_js_api_migrate
Open

feat: migrate bb-prover from direct binary execution to bb.js API#21564
charlielye wants to merge 5 commits intonextfrom
cl/bb_js_api_migrate

Conversation

@charlielye
Copy link
Contributor

@charlielye charlielye commented Mar 14, 2026

Summary

  • Migrate bb-prover server-side proving and verification from spawning bb binary via child_process.spawn() to using the bb.js TypeScript API (Barretenberg class via NativeUnixSocket backend)
  • Eliminates temporary file I/O (writing/reading bytecode, witnesses, proofs, VKs to disk) and stdout-based result parsing. A fresh bb process is still spawned per proof to maintain parallelism, but communication happens via Unix socket instead of files.
  • Add new BBJsInstance / BBJsProverFactory adapter layer in bb_js_backend.ts
  • Add chonk sub-proof size constants to enable TypeScript-side flat-to-structured proof splitting for chonkVerify
  • Remove 6 dead functions from execute.ts (-415 lines)
  • AVM proving/verification remains file-based (no bb.js equivalent exists)

What was migrated

Operation Before After
UltraHonk proving bb prove via spawn api.circuitProve() via bb.js
UltraHonk verification bb verify via spawn api.circuitVerify() via bb.js
Chonk (IVC) verification bb verify --scheme chonk via spawn + temp files api.chonkVerify() via bb.js
Gate counting capability added to BBJsInstance api.circuitStats() / api.chonkStats()
Solidity contract gen capability added to BBJsInstance api.circuitWriteSolidityVerifier()

Chonk verification migration detail

The bb.js chonkVerify API expects a structured ChonkProof (with megaProof, goblinProof.mergeProof, etc.), but bb-prover stores proofs as a flat Fr[] array. The C++ code uses compile-time constants to split the flat representation. We added these constants to Noir/TS (CHONK_MEGA_ZK_PROOF_LENGTH_WITHOUT_PUB_INPUTS=407, CHONK_MERGE_PROOF_LENGTH=42, CHONK_ECCVM_PROOF_LENGTH=608, CHONK_TRANSLATOR_PROOF_LENGTH=483) and implemented splitChonkProofToStructured() mirroring C++ ChonkProof::from_field_elements().

Test plan

  • Chonk integration tests (8/8 passed)
  • Rollup IVC integration tests (1/1 passed)
  • E2E block building tests (18/18 passed, 1 skipped)

🤖 Generated with Claude Code

charlielye and others added 3 commits March 13, 2026 20:34
Replaces spawning `bb` binary via `child_process.spawn()` with the bb.js
TypeScript API for UltraHonk proving and verification. This eliminates
per-call process startup overhead, temporary file I/O, and subprocess
management for non-AVM operations.

- New `BBJsInstance` / `BBJsProverFactory` adapter in bb_js_backend.ts
- `BBNativeRollupProver` proving and verification now use bb.js API
- `BBCircuitVerifier.verifyProofForCircuit` uses bb.js API
- `ivc-integration/prove_native.ts` migrated to bb.js API
- In-memory proof parsing via `constructRecursiveProofFromBuffers`
- AVM and Chonk IVC verification remain as direct binary execution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…functions

Add chonk sub-proof size constants (MEGA_ZK=407, MERGE=42, ECCVM=608,
TRANSLATOR=483) to split flat proof fields into the structured ChonkProof
format expected by bb.js chonkVerify API. This mirrors the C++
ChonkProof::from_field_elements() logic in TypeScript.

Migrate BBCircuitVerifier.verifyProof() from file-based bb binary
verification to in-memory bb.js chonkVerify. Remove 6 dead functions
from execute.ts that were replaced by the bb.js API migration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BBApiException from bb.js propagates raw assertion messages instead of
the expected "Failed to generate/verify proof" messages. Wrap bb.js
calls in try-catch to maintain the error contract expected by tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Hey Charlie, this looks nice, just one comment for the AVM. We regularly use the following flow for all kinds of debugging, testing, benchmarking and iterating: we run some test (e.g., the avm bulk test). This test writes the avm inputs file and outputs the exact bb-avm command that you'd need to run. After that, we can just use that command (and that file) and operate 100% on the CLI/C++ side. We can then easily change the passed environment variables, concurrency, etc. IIUC, these changes would break that because the files wouldn't be written?

@charlielye
Copy link
Contributor Author

Hey Charlie, this looks nice, just one comment for the AVM. We regularly use the following flow for all kinds of debugging, testing, benchmarking and iterating: we run some test (e.g., the avm bulk test). This test writes the avm inputs file and outputs the exact bb-avm command that you'd need to run. After that, we can just use that command (and that file) and operate 100% on the CLI/C++ side. We can then easily change the passed environment variables, concurrency, etc. IIUC, these changes would break that because the files wouldn't be written?

Hey. Yep I was aware this might affect some debug flows. This is all vibe coded btw. Right now I think the AVM path is unaffected as there is no bb.js api for avm proving/verifying. But I was aware this might affect debug flows for the protocol circuits etc. I might make bb.js support avm stuff in future. But in either case, we want to maintain these kinds of useful reproducible flows. It still feels like this should be the responsiblity of bb.js, so I thought to either:

  • have another backend in bb.js that would maintain this CLI driven workflows. Selectable when you init the Barretenberg class (currently we support nativeshm, nativeuds, wasm, wasm-threads, etc).
  • Have a wrapper that could sit around any backend api, and would do a debug dump of the data in the right formats for the cli + print cli command.

Not sure if you have thoughts one way or other? But as I say, right now I think avm path is unaffected (but have not reviewed Claudes work yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants