feat: migrate bb-prover from direct binary execution to bb.js API#21564
feat: migrate bb-prover from direct binary execution to bb.js API#21564charlielye wants to merge 5 commits intonextfrom
Conversation
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>
|
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:
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). |
Summary
bb-proverserver-side proving and verification from spawningbbbinary viachild_process.spawn()to using the bb.js TypeScript API (Barretenbergclass viaNativeUnixSocketbackend)BBJsInstance/BBJsProverFactoryadapter layer inbb_js_backend.tschonkVerifyexecute.ts(-415 lines)What was migrated
bb provevia spawnapi.circuitProve()via bb.jsbb verifyvia spawnapi.circuitVerify()via bb.jsbb verify --scheme chonkvia spawn + temp filesapi.chonkVerify()via bb.jsBBJsInstanceapi.circuitStats()/api.chonkStats()BBJsInstanceapi.circuitWriteSolidityVerifier()Chonk verification migration detail
The bb.js
chonkVerifyAPI expects a structuredChonkProof(withmegaProof,goblinProof.mergeProof, etc.), but bb-prover stores proofs as a flatFr[]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 implementedsplitChonkProofToStructured()mirroring C++ChonkProof::from_field_elements().Test plan
🤖 Generated with Claude Code