@aztec/bb-prover 0.0.1-commit.9372f48 → 0.0.1-commit.949a33fd8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +5 -4
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +6 -6
  4. package/dest/bb/execute.d.ts +2 -1
  5. package/dest/bb/execute.d.ts.map +1 -1
  6. package/dest/bb/execute.js +18 -1
  7. package/dest/config.d.ts +12 -1
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/instrumentation.d.ts +1 -1
  10. package/dest/instrumentation.d.ts.map +1 -1
  11. package/dest/instrumentation.js +12 -4
  12. package/dest/prover/client/bb_private_kernel_prover.d.ts +1 -1
  13. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  14. package/dest/prover/client/bb_private_kernel_prover.js +18 -6
  15. package/dest/verifier/batch_chonk_verifier.d.ts +45 -0
  16. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  17. package/dest/verifier/batch_chonk_verifier.js +232 -0
  18. package/dest/verifier/index.d.ts +2 -1
  19. package/dest/verifier/index.d.ts.map +1 -1
  20. package/dest/verifier/index.js +1 -0
  21. package/dest/verifier/queued_chonk_verifier.d.ts +2 -3
  22. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  23. package/dest/verifier/queued_chonk_verifier.js +6 -5
  24. package/package.json +17 -16
  25. package/src/avm_proving_tests/avm_proving_tester.ts +8 -0
  26. package/src/bb/execute.ts +23 -1
  27. package/src/config.ts +11 -0
  28. package/src/instrumentation.ts +12 -4
  29. package/src/prover/client/bb_private_kernel_prover.ts +18 -5
  30. package/src/verifier/batch_chonk_verifier.ts +276 -0
  31. package/src/verifier/index.ts +1 -0
  32. package/src/verifier/queued_chonk_verifier.ts +6 -7
@@ -1,2 +1,3 @@
1
+ export * from './batch_chonk_verifier.js';
1
2
  export * from './bb_verifier.js';
2
3
  export * from './queued_chonk_verifier.js';
@@ -1,15 +1,14 @@
1
1
  import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec/stdlib/interfaces/server';
2
2
  import type { Tx } from '@aztec/stdlib/tx';
3
3
  import { type TelemetryClient } from '@aztec/telemetry-client';
4
- import type { BBConfig } from '../config.js';
5
4
  export declare class QueuedIVCVerifier implements ClientProtocolCircuitVerifier {
6
5
  private verifier;
7
6
  private telemetry;
8
7
  private logger;
9
8
  private queue;
10
9
  private metrics;
11
- constructor(config: BBConfig, verifier: ClientProtocolCircuitVerifier, telemetry?: TelemetryClient, logger?: import("@aztec/foundation/log").Logger);
10
+ constructor(verifier: ClientProtocolCircuitVerifier, concurrency: number, telemetry?: TelemetryClient, logger?: import("@aztec/foundation/log").Logger);
12
11
  verifyProof(tx: Tx): Promise<IVCProofVerificationResult>;
13
12
  stop(): Promise<void>;
14
13
  }
15
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicXVldWVkX2Nob25rX3ZlcmlmaWVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdmVyaWZpZXIvcXVldWVkX2Nob25rX3ZlcmlmaWVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLDZCQUE2QixFQUFFLDBCQUEwQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakgsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDM0MsT0FBTyxFQU1MLEtBQUssZUFBZSxFQUlyQixNQUFNLHlCQUF5QixDQUFDO0FBSWpDLE9BQU8sS0FBSyxFQUFFLFFBQVEsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQWlFN0MscUJBQWEsaUJBQWtCLFlBQVcsNkJBQTZCO0lBTW5FLE9BQU8sQ0FBQyxRQUFRO0lBQ2hCLE9BQU8sQ0FBQyxTQUFTO0lBQ2pCLE9BQU8sQ0FBQyxNQUFNO0lBUGhCLE9BQU8sQ0FBQyxLQUFLLENBQWM7SUFDM0IsT0FBTyxDQUFDLE9BQU8sQ0FBcUI7SUFFcEMsWUFDRSxNQUFNLEVBQUUsUUFBUSxFQUNSLFFBQVEsRUFBRSw2QkFBNkIsRUFDdkMsU0FBUyxHQUFFLGVBQXNDLEVBQ2pELE1BQU0seUNBQWtELEVBTWpFO0lBRVksV0FBVyxDQUFDLEVBQUUsRUFBRSxFQUFFLEdBQUcsT0FBTyxDQUFDLDBCQUEwQixDQUFDLENBSXBFO0lBRUQsSUFBSSxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFcEI7Q0FDRiJ9
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicXVldWVkX2Nob25rX3ZlcmlmaWVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdmVyaWZpZXIvcXVldWVkX2Nob25rX3ZlcmlmaWVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLDZCQUE2QixFQUFFLDBCQUEwQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakgsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDM0MsT0FBTyxFQU1MLEtBQUssZUFBZSxFQUlyQixNQUFNLHlCQUF5QixDQUFDO0FBbUVqQyxxQkFBYSxpQkFBa0IsWUFBVyw2QkFBNkI7SUFLbkUsT0FBTyxDQUFDLFFBQVE7SUFFaEIsT0FBTyxDQUFDLFNBQVM7SUFDakIsT0FBTyxDQUFDLE1BQU07SUFQaEIsT0FBTyxDQUFDLEtBQUssQ0FBYztJQUMzQixPQUFPLENBQUMsT0FBTyxDQUFxQjtJQUVwQyxZQUNVLFFBQVEsRUFBRSw2QkFBNkIsRUFDL0MsV0FBVyxFQUFFLE1BQU0sRUFDWCxTQUFTLEdBQUUsZUFBc0MsRUFDakQsTUFBTSx5Q0FBa0QsRUFNakU7SUFFWSxXQUFXLENBQUMsRUFBRSxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsMEJBQTBCLENBQUMsQ0FJcEU7SUFFSyxJQUFJLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUcxQjtDQUNGIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"queued_chonk_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/queued_chonk_verifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAML,KAAK,eAAe,EAIrB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAiE7C,qBAAa,iBAAkB,YAAW,6BAA6B;IAMnE,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IAPhB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAqB;IAEpC,YACE,MAAM,EAAE,QAAQ,EACR,QAAQ,EAAE,6BAA6B,EACvC,SAAS,GAAE,eAAsC,EACjD,MAAM,yCAAkD,EAMjE;IAEY,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAIpE;IAED,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAEpB;CACF"}
1
+ {"version":3,"file":"queued_chonk_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/queued_chonk_verifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAML,KAAK,eAAe,EAIrB,MAAM,yBAAyB,CAAC;AAmEjC,qBAAa,iBAAkB,YAAW,6BAA6B;IAKnE,OAAO,CAAC,QAAQ;IAEhB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IAPhB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAqB;IAEpC,YACU,QAAQ,EAAE,6BAA6B,EAC/C,WAAW,EAAE,MAAM,EACX,SAAS,GAAE,eAAsC,EACjD,MAAM,yCAAkD,EAMjE;IAEY,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAIpE;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAG1B;CACF"}
@@ -81,21 +81,22 @@ export class QueuedIVCVerifier {
81
81
  logger;
82
82
  queue;
83
83
  metrics;
84
- constructor(config, verifier, telemetry = getTelemetryClient(), logger = createLogger('bb-prover:queued_chonk_verifier')){
84
+ constructor(verifier, concurrency, telemetry = getTelemetryClient(), logger = createLogger('bb-prover:queued_chonk_verifier')){
85
85
  this.verifier = verifier;
86
86
  this.telemetry = telemetry;
87
87
  this.logger = logger;
88
88
  this.metrics = new IVCVerifierMetrics(this.telemetry, 'QueuedIVCVerifier');
89
89
  this.queue = new SerialQueue();
90
- this.logger.info(`Starting QueuedIVCVerifier with ${config.numConcurrentIVCVerifiers} concurrent verifiers`);
91
- this.queue.start(config.numConcurrentIVCVerifiers);
90
+ this.logger.info(`Starting QueuedIVCVerifier with ${concurrency} concurrent verifiers`);
91
+ this.queue.start(concurrency);
92
92
  }
93
93
  async verifyProof(tx) {
94
94
  const result = await this.queue.put(()=>this.verifier.verifyProof(tx));
95
95
  this.metrics.recordIVCVerification(result);
96
96
  return result;
97
97
  }
98
- stop() {
99
- return this.queue.end();
98
+ async stop() {
99
+ await this.queue.end();
100
+ await this.verifier.stop();
100
101
  }
101
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/bb-prover",
3
- "version": "0.0.1-commit.9372f48",
3
+ "version": "0.0.1-commit.949a33fd8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -69,27 +69,28 @@
69
69
  ]
70
70
  },
71
71
  "dependencies": {
72
- "@aztec/bb.js": "0.0.1-commit.9372f48",
73
- "@aztec/constants": "0.0.1-commit.9372f48",
74
- "@aztec/foundation": "0.0.1-commit.9372f48",
75
- "@aztec/noir-noirc_abi": "0.0.1-commit.9372f48",
76
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.9372f48",
77
- "@aztec/noir-types": "0.0.1-commit.9372f48",
78
- "@aztec/simulator": "0.0.1-commit.9372f48",
79
- "@aztec/stdlib": "0.0.1-commit.9372f48",
80
- "@aztec/telemetry-client": "0.0.1-commit.9372f48",
81
- "@aztec/world-state": "0.0.1-commit.9372f48",
72
+ "@aztec/bb.js": "0.0.1-commit.949a33fd8",
73
+ "@aztec/constants": "0.0.1-commit.949a33fd8",
74
+ "@aztec/foundation": "0.0.1-commit.949a33fd8",
75
+ "@aztec/noir-noirc_abi": "0.0.1-commit.949a33fd8",
76
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.949a33fd8",
77
+ "@aztec/noir-types": "0.0.1-commit.949a33fd8",
78
+ "@aztec/simulator": "0.0.1-commit.949a33fd8",
79
+ "@aztec/stdlib": "0.0.1-commit.949a33fd8",
80
+ "@aztec/telemetry-client": "0.0.1-commit.949a33fd8",
81
+ "@aztec/world-state": "0.0.1-commit.949a33fd8",
82
82
  "commander": "^12.1.0",
83
+ "msgpackr": "^1.11.2",
83
84
  "pako": "^2.1.0",
84
85
  "source-map-support": "^0.5.21",
85
86
  "tslib": "^2.4.0"
86
87
  },
87
88
  "devDependencies": {
88
- "@aztec/ethereum": "0.0.1-commit.9372f48",
89
- "@aztec/kv-store": "0.0.1-commit.9372f48",
90
- "@aztec/noir-contracts.js": "0.0.1-commit.9372f48",
91
- "@aztec/noir-test-contracts.js": "0.0.1-commit.9372f48",
92
- "@aztec/protocol-contracts": "0.0.1-commit.9372f48",
89
+ "@aztec/ethereum": "0.0.1-commit.949a33fd8",
90
+ "@aztec/kv-store": "0.0.1-commit.949a33fd8",
91
+ "@aztec/noir-contracts.js": "0.0.1-commit.949a33fd8",
92
+ "@aztec/noir-test-contracts.js": "0.0.1-commit.949a33fd8",
93
+ "@aztec/protocol-contracts": "0.0.1-commit.949a33fd8",
93
94
  "@jest/globals": "^30.0.0",
94
95
  "@types/jest": "^30.0.0",
95
96
  "@types/node": "^22.15.17",
@@ -10,6 +10,7 @@ import {
10
10
  import type { PublicTxResult } from '@aztec/simulator/server';
11
11
  import { AvmCircuitInputs, AvmCircuitPublicInputs, PublicSimulatorConfig } from '@aztec/stdlib/avm';
12
12
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { Gas } from '@aztec/stdlib/gas';
13
14
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
14
15
  import type { GlobalVariables } from '@aztec/stdlib/tx';
15
16
  import { NativeWorldStateService } from '@aztec/world-state';
@@ -211,6 +212,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
211
212
  privateInsertions?: TestPrivateInsertions,
212
213
  txLabel: string = 'unlabeledTx',
213
214
  disableRevertCheck: boolean = false,
215
+ gasLimits?: Gas,
214
216
  ): Promise<PublicTxResult> {
215
217
  const simTimer = new Timer();
216
218
  const simRes = await this.simulateTx(
@@ -221,6 +223,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
221
223
  feePayer,
222
224
  privateInsertions,
223
225
  txLabel,
226
+ gasLimits,
224
227
  );
225
228
  const simDuration = simTimer.ms();
226
229
  this.logger.info(`Simulation took ${simDuration} ms for tx ${txLabel}`);
@@ -247,6 +250,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
247
250
  teardownCall?: TestEnqueuedCall,
248
251
  feePayer?: AztecAddress,
249
252
  privateInsertions?: TestPrivateInsertions,
253
+ gasLimits?: Gas,
250
254
  ) {
251
255
  return await this.simProveVerify(
252
256
  sender,
@@ -258,6 +262,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
258
262
  privateInsertions,
259
263
  txLabel,
260
264
  true,
265
+ gasLimits,
261
266
  );
262
267
  }
263
268
 
@@ -265,6 +270,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
265
270
  appCall: TestEnqueuedCall,
266
271
  expectRevert?: boolean,
267
272
  txLabel: string = 'unlabeledTx',
273
+ gasLimits?: Gas,
268
274
  ) {
269
275
  await this.simProveVerify(
270
276
  /*sender=*/ AztecAddress.fromNumber(42),
@@ -275,6 +281,8 @@ export class AvmProvingTester extends PublicTxSimulationTester {
275
281
  /*feePayer=*/ undefined,
276
282
  /*privateInsertions=*/ undefined,
277
283
  txLabel,
284
+ /*disableRevertCheck=*/ false,
285
+ gasLimits,
278
286
  );
279
287
  }
280
288
  }
package/src/bb/execute.ts CHANGED
@@ -52,6 +52,8 @@ type BBExecResult = {
52
52
  signal: string | undefined;
53
53
  };
54
54
 
55
+ export const DEFAULT_BB_VERIFY_CONCURRENCY = 4;
56
+
55
57
  /**
56
58
  * Invokes the Barretenberg binary with the provided command and args
57
59
  * @param pathToBB - The path to the BB binary
@@ -101,6 +103,16 @@ export function executeBB(
101
103
  }, timeout);
102
104
  }
103
105
 
106
+ // Forward termination signals so bb doesn't survive as an orphan when the node parent exits.
107
+ const forwardSignal = (signal: NodeJS.Signals) => {
108
+ if (bb.pid) {
109
+ bb.kill(signal);
110
+ }
111
+ };
112
+ process.on('SIGINT', forwardSignal);
113
+ process.on('SIGTERM', forwardSignal);
114
+ process.on('SIGHUP', forwardSignal);
115
+
104
116
  readline.createInterface({ input: bb.stdout }).on('line', logger);
105
117
  readline.createInterface({ input: bb.stderr }).on('line', logger);
106
118
 
@@ -108,6 +120,9 @@ export function executeBB(
108
120
  if (timeoutId) {
109
121
  clearTimeout(timeoutId);
110
122
  }
123
+ process.off('SIGINT', forwardSignal);
124
+ process.off('SIGTERM', forwardSignal);
125
+ process.off('SIGHUP', forwardSignal);
111
126
  if (resultParser(exitCode)) {
112
127
  resolve({ status: BB_RESULT.SUCCESS, exitCode, signal });
113
128
  } else {
@@ -398,7 +413,14 @@ export async function verifyProof(
398
413
  '--disable_zk',
399
414
  ...getArgs(ultraHonkFlavor),
400
415
  ];
401
- return await verifyProofInternal(pathToBB, `verify`, args, logger);
416
+
417
+ let concurrency = DEFAULT_BB_VERIFY_CONCURRENCY;
418
+
419
+ if (process.env.VERIFY_HARDWARE_CONCURRENCY) {
420
+ concurrency = parseInt(process.env.VERIFY_HARDWARE_CONCURRENCY, 10);
421
+ }
422
+
423
+ return await verifyProofInternal(pathToBB, `verify`, args, logger, concurrency);
402
424
  }
403
425
 
404
426
  export async function verifyAvmProof(
package/src/config.ts CHANGED
@@ -3,8 +3,19 @@ export interface BBConfig {
3
3
  bbWorkingDirectory: string;
4
4
  /** Whether to skip tmp dir cleanup for debugging purposes */
5
5
  bbSkipCleanup: boolean;
6
+ /** Max concurrent verifications for the RPC verifier (QueuedIVCVerifier). */
6
7
  numConcurrentIVCVerifiers: number;
8
+ /** Thread count for the RPC IVC verifier. */
7
9
  bbIVCConcurrency: number;
10
+ /**
11
+ * Upper bound on proofs per batch for the peer chonk batch verifier.
12
+ * Proofs are verified immediately as they arrive — this only caps how many
13
+ * can accumulate while a batch is already being processed.
14
+ * Default 16: at 4 cores, a full batch of 16 verifies in ~245ms wall time.
15
+ */
16
+ bbChonkVerifyMaxBatch: number;
17
+ /** Thread count for the peer batch verifier parallel reduce. Default 6 to leave cores for the rest of the node. */
18
+ bbChonkVerifyConcurrency: number;
8
19
  }
9
20
 
10
21
  export interface ACVMConfig {
@@ -58,10 +58,18 @@ export class ProverInstrumentation {
58
58
  circuitName: CircuitName,
59
59
  timerOrMS: Timer | number,
60
60
  ) {
61
- const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
62
- this[metric].record(s, {
63
- [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
64
- });
61
+ // Simulation duration is stored in ms, while the others are stored in seconds
62
+ if (metric === 'simulationDuration') {
63
+ const ms = typeof timerOrMS === 'number' ? timerOrMS : timerOrMS.ms();
64
+ this[metric].record(Math.trunc(ms), {
65
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
66
+ });
67
+ } else {
68
+ const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
69
+ this[metric].record(s, {
70
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
71
+ });
72
+ }
65
73
  }
66
74
 
67
75
  /**
@@ -278,23 +278,36 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
278
278
  this.log.info(`Generating ClientIVC proof...`);
279
279
  const barretenberg = await Barretenberg.initSingleton({
280
280
  ...this.options,
281
- logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
281
+ logger: this.options.logger?.verbose,
282
282
  });
283
283
  const backend = new AztecClientBackend(
284
284
  executionSteps.map(step => ungzip(step.bytecode)),
285
285
  barretenberg,
286
+ executionSteps.map(step => step.functionName),
286
287
  );
287
288
 
288
- const [proof] = await backend.prove(
289
+ // Use compressed prove path to get both proof fields and compressed proof bytes
290
+ const result = await backend.prove(
289
291
  executionSteps.map(step => ungzip(serializeWitness(step.witness))),
290
292
  executionSteps.map(step => step.vk),
293
+ { compress: true },
291
294
  );
292
295
  this.log.info(`Generated ClientIVC proof`, {
293
296
  eventName: 'client-ivc-proof-generation',
294
297
  duration: timer.ms(),
295
- proofSize: proof.length,
298
+ proofSize: result.proofFields.length,
299
+ compressedSize: result.compressedProof?.length,
296
300
  });
297
- return ChonkProofWithPublicInputs.fromBufferArray(proof);
301
+
302
+ // Create ChonkProofWithPublicInputs from the flat field elements
303
+ const proofWithPubInputs = ChonkProofWithPublicInputs.fromBufferArray(result.proofFields);
304
+
305
+ // Attach compressed proof bytes to the ChonkProof (without public inputs).
306
+ // The compressed bytes are for the full proof WITH public inputs from bb;
307
+ // when deserializing, the decompressor will strip them to match CHONK_PROOF_LENGTH.
308
+ proofWithPubInputs.compressedProof = result.compressedProof ? Buffer.from(result.compressedProof) : undefined;
309
+
310
+ return proofWithPubInputs;
298
311
  }
299
312
 
300
313
  public async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
@@ -303,7 +316,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
303
316
  ...this.options,
304
317
  logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
305
318
  });
306
- const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg);
319
+ const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName]);
307
320
  const gateCount = await backend.gates();
308
321
  return gateCount[0];
309
322
  }
@@ -0,0 +1,276 @@
1
+ import { BackendType, Barretenberg } from '@aztec/bb.js';
2
+ import { FifoFrameReader } from '@aztec/foundation/fifo';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { SerialQueue } from '@aztec/foundation/queue';
5
+ import { Timer } from '@aztec/foundation/timer';
6
+ import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
7
+ import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec/stdlib/interfaces/server';
8
+ import type { Tx } from '@aztec/stdlib/tx';
9
+
10
+ import { Unpackr } from 'msgpackr';
11
+ import { execFile } from 'node:child_process';
12
+ import { unlinkSync } from 'node:fs';
13
+ import { unlink } from 'node:fs/promises';
14
+ import * as os from 'node:os';
15
+ import * as path from 'node:path';
16
+ import { promisify } from 'node:util';
17
+
18
+ import type { BBConfig } from '../config.js';
19
+
20
+ const execFileAsync = promisify(execFile);
21
+
22
+ /** Result from the FIFO, matching the C++ VerifyResult struct. */
23
+ interface FifoVerifyResult {
24
+ request_id: number;
25
+ status: number;
26
+ error_message: string;
27
+ time_in_verify_ms: number;
28
+ }
29
+
30
+ /** Maps client protocol artifacts used for chonk verification to VK indices. */
31
+ const CHONK_VK_ARTIFACTS = ['HidingKernelToRollup', 'HidingKernelToPublic'] as const;
32
+
33
+ interface PendingRequest {
34
+ resolve: (result: IVCProofVerificationResult) => void;
35
+ reject: (error: Error) => void;
36
+ totalTimer: Timer;
37
+ }
38
+
39
+ /**
40
+ * Batch verifier for Chonk IVC proofs. Uses the bb batch verifier service
41
+ * which batches IPA verification into a single SRS MSM for better throughput.
42
+ *
43
+ * Architecture:
44
+ * - Spawns a persistent `bb msgpack run` process via Barretenberg (native backend)
45
+ * - Sends proofs via the msgpack RPC protocol (ChonkBatchVerifierQueue)
46
+ * - Receives results via a named FIFO pipe (async, out-of-order)
47
+ * - Bisects batch failures to isolate individual bad proofs
48
+ */
49
+ export class BatchChonkVerifier implements ClientProtocolCircuitVerifier {
50
+ private bb!: Barretenberg;
51
+ private fifoPath: string;
52
+ private nextRequestId = 0;
53
+ private pendingRequests = new Map<number, PendingRequest>();
54
+ private sendQueue: SerialQueue;
55
+ private fifoReader: FifoFrameReader;
56
+ private logger = createLogger('bb-prover:batch_chonk_verifier');
57
+ /** Maps artifact name to VK index in the batch verifier. */
58
+ private vkIndexMap = new Map<string, number>();
59
+ /** Bound cleanup handler for process exit signals. */
60
+ private exitCleanup: (() => void) | null = null;
61
+
62
+ private constructor(
63
+ private config: Pick<BBConfig, 'bbChonkVerifyConcurrency'> & Partial<Pick<BBConfig, 'bbBinaryPath'>>,
64
+ private vkBuffers: Uint8Array[],
65
+ private batchSize: number,
66
+ private label: string,
67
+ ) {
68
+ this.fifoPath = path.join(os.tmpdir(), `bb-batch-${label}-${process.pid}-${Date.now()}.fifo`);
69
+ this.fifoReader = new FifoFrameReader();
70
+ this.sendQueue = new SerialQueue();
71
+ this.sendQueue.start(1);
72
+ }
73
+
74
+ /** Create and start a BatchChonkVerifier using the protocol circuit VKs. */
75
+ static async new(config: BBConfig, batchSize: number, label: string): Promise<BatchChonkVerifier> {
76
+ const vkBuffers: Uint8Array[] = [];
77
+ const vkIndexMap = new Map<string, number>();
78
+ for (const artifact of CHONK_VK_ARTIFACTS) {
79
+ const vk = ProtocolCircuitVks[artifact];
80
+ if (!vk) {
81
+ throw new Error(`Missing VK for ${artifact}`);
82
+ }
83
+ vkIndexMap.set(artifact, vkBuffers.length);
84
+ vkBuffers.push(vk.keyAsBytes);
85
+ }
86
+ const verifier = new BatchChonkVerifier(config, vkBuffers, batchSize, label);
87
+ verifier.vkIndexMap = vkIndexMap;
88
+ await verifier.start();
89
+ return verifier;
90
+ }
91
+
92
+ /** Create and start a BatchChonkVerifier with custom VKs (for testing). */
93
+ static async newForTesting(
94
+ config: Pick<BBConfig, 'bbChonkVerifyConcurrency'> & Partial<Pick<BBConfig, 'bbBinaryPath'>>,
95
+ vks: Uint8Array[],
96
+ batchSize: number,
97
+ ): Promise<BatchChonkVerifier> {
98
+ const verifier = new BatchChonkVerifier(config, vks, batchSize, 'test');
99
+ for (let i = 0; i < vks.length; i++) {
100
+ verifier.vkIndexMap.set(String(i), i);
101
+ }
102
+ await verifier.start();
103
+ return verifier;
104
+ }
105
+
106
+ private async start(): Promise<void> {
107
+ this.logger.info('Starting BatchChonkVerifier');
108
+
109
+ this.bb = await Barretenberg.new({
110
+ bbPath: this.config.bbBinaryPath,
111
+ backend: BackendType.NativeUnixSocket,
112
+ });
113
+ await this.bb.initSRSChonk();
114
+
115
+ await execFileAsync('mkfifo', [this.fifoPath]);
116
+ this.registerExitCleanup();
117
+
118
+ await this.bb.chonkBatchVerifierStart({
119
+ vks: this.vkBuffers,
120
+ numCores: this.config.bbChonkVerifyConcurrency || 0,
121
+ batchSize: this.batchSize,
122
+ fifoPath: this.fifoPath,
123
+ });
124
+
125
+ this.startFifoReader();
126
+ this.logger.info('BatchChonkVerifier started', { fifoPath: this.fifoPath });
127
+ }
128
+
129
+ public verifyProof(tx: Tx): Promise<IVCProofVerificationResult> {
130
+ const circuit = tx.data.forPublic ? 'HidingKernelToPublic' : 'HidingKernelToRollup';
131
+ const vkIndex = this.vkIndexMap.get(circuit);
132
+ if (vkIndex === undefined) {
133
+ throw new Error(`No VK index for circuit ${circuit}`);
134
+ }
135
+ const proofWithPubInputs = tx.chonkProof.attachPublicInputs(tx.data.publicInputs().toFields());
136
+ const proofFields = proofWithPubInputs.fieldsWithPublicInputs.map(f => f.toBuffer());
137
+ return this.enqueueProof(vkIndex, proofFields);
138
+ }
139
+
140
+ /** Enqueue raw proof fields for verification. Used directly by tests with custom VKs. */
141
+ public enqueueProof(vkIndex: number, proofFields: Uint8Array[]): Promise<IVCProofVerificationResult> {
142
+ const totalTimer = new Timer();
143
+ const requestId = this.nextRequestId++;
144
+
145
+ const resultPromise = new Promise<IVCProofVerificationResult>((resolve, reject) => {
146
+ this.pendingRequests.set(requestId, { resolve, reject, totalTimer });
147
+ });
148
+
149
+ void this.sendQueue
150
+ .put(async () => {
151
+ await this.bb.chonkBatchVerifierQueue({
152
+ requestId,
153
+ vkIndex,
154
+ proofFields,
155
+ });
156
+ })
157
+ .catch(err => {
158
+ const pending = this.pendingRequests.get(requestId);
159
+ if (pending) {
160
+ this.pendingRequests.delete(requestId);
161
+ pending.reject(err instanceof Error ? err : new Error(String(err)));
162
+ }
163
+ });
164
+
165
+ return resultPromise;
166
+ }
167
+
168
+ public async stop(): Promise<void> {
169
+ this.logger.info('Stopping BatchChonkVerifier');
170
+
171
+ // Stop accepting new proofs
172
+ await this.sendQueue.end();
173
+
174
+ // Stop the bb service (flushes remaining proofs)
175
+ try {
176
+ await this.bb.chonkBatchVerifierStop({});
177
+ } catch (err) {
178
+ this.logger.warn(`Error stopping batch verifier service: ${err}`);
179
+ }
180
+
181
+ // Stop FIFO reader
182
+ this.fifoReader.stop();
183
+
184
+ // Clean up FIFO file and deregister exit handler
185
+ await unlink(this.fifoPath).catch(() => {});
186
+ this.deregisterExitCleanup();
187
+
188
+ // Reject any remaining pending requests
189
+ for (const [id, pending] of this.pendingRequests) {
190
+ pending.reject(new Error('BatchChonkVerifier stopped'));
191
+ this.pendingRequests.delete(id);
192
+ }
193
+
194
+ // Destroy bb process
195
+ await this.bb.destroy();
196
+
197
+ this.logger.info('BatchChonkVerifier stopped');
198
+ }
199
+
200
+ private startFifoReader(): void {
201
+ const unpackr = new Unpackr({ useRecords: false });
202
+
203
+ this.fifoReader.on('frame', (payload: Buffer) => {
204
+ try {
205
+ const result = unpackr.unpack(payload) as FifoVerifyResult;
206
+ this.handleResult(result);
207
+ } catch (err) {
208
+ this.logger.error(`FIFO: failed to decode msgpack result: ${err}`);
209
+ }
210
+ });
211
+
212
+ this.fifoReader.on('error', (err: Error) => {
213
+ this.logger.error(`FIFO reader error: ${err}`);
214
+ });
215
+
216
+ this.fifoReader.on('end', () => {
217
+ this.logger.debug('FIFO reader: stream ended');
218
+ for (const [id, pending] of this.pendingRequests) {
219
+ pending.reject(new Error('FIFO stream ended unexpectedly'));
220
+ this.pendingRequests.delete(id);
221
+ }
222
+ });
223
+
224
+ this.fifoReader.start(this.fifoPath);
225
+ }
226
+
227
+ private handleResult(result: FifoVerifyResult): void {
228
+ const pending = this.pendingRequests.get(result.request_id);
229
+ if (!pending) {
230
+ this.logger.warn(`Received result for unknown request_id=${result.request_id}`);
231
+ return;
232
+ }
233
+ this.pendingRequests.delete(result.request_id);
234
+
235
+ const valid = result.status === 0; // VerifyStatus::OK
236
+ const durationMs = result.time_in_verify_ms;
237
+ const totalDurationMs = pending.totalTimer.ms();
238
+
239
+ const ivcResult: IVCProofVerificationResult = { valid, durationMs, totalDurationMs };
240
+
241
+ if (!valid) {
242
+ this.logger.warn(`Proof verification failed for request_id=${result.request_id}: ${result.error_message}`);
243
+ } else {
244
+ this.logger.debug(`Proof verified`, {
245
+ requestId: result.request_id,
246
+ durationMs: Math.ceil(durationMs),
247
+ totalDurationMs: Math.ceil(totalDurationMs),
248
+ });
249
+ }
250
+
251
+ pending.resolve(ivcResult);
252
+ }
253
+
254
+ private registerExitCleanup(): void {
255
+ // Signal handlers must be synchronous — unlinkSync is intentional here
256
+ this.exitCleanup = () => {
257
+ try {
258
+ unlinkSync(this.fifoPath);
259
+ } catch {
260
+ /* ignore */
261
+ }
262
+ };
263
+ process.on('exit', this.exitCleanup);
264
+ process.on('SIGINT', this.exitCleanup);
265
+ process.on('SIGTERM', this.exitCleanup);
266
+ }
267
+
268
+ private deregisterExitCleanup(): void {
269
+ if (this.exitCleanup) {
270
+ process.removeListener('exit', this.exitCleanup);
271
+ process.removeListener('SIGINT', this.exitCleanup);
272
+ process.removeListener('SIGTERM', this.exitCleanup);
273
+ this.exitCleanup = null;
274
+ }
275
+ }
276
+ }
@@ -1,2 +1,3 @@
1
+ export * from './batch_chonk_verifier.js';
1
2
  export * from './bb_verifier.js';
2
3
  export * from './queued_chonk_verifier.js';
@@ -16,8 +16,6 @@ import {
16
16
 
17
17
  import { createHistogram } from 'node:perf_hooks';
18
18
 
19
- import type { BBConfig } from '../config.js';
20
-
21
19
  class IVCVerifierMetrics {
22
20
  private ivcVerificationHistogram: Histogram;
23
21
  private ivcTotalVerificationHistogram: Histogram;
@@ -86,15 +84,15 @@ export class QueuedIVCVerifier implements ClientProtocolCircuitVerifier {
86
84
  private metrics: IVCVerifierMetrics;
87
85
 
88
86
  public constructor(
89
- config: BBConfig,
90
87
  private verifier: ClientProtocolCircuitVerifier,
88
+ concurrency: number,
91
89
  private telemetry: TelemetryClient = getTelemetryClient(),
92
90
  private logger = createLogger('bb-prover:queued_chonk_verifier'),
93
91
  ) {
94
92
  this.metrics = new IVCVerifierMetrics(this.telemetry, 'QueuedIVCVerifier');
95
93
  this.queue = new SerialQueue();
96
- this.logger.info(`Starting QueuedIVCVerifier with ${config.numConcurrentIVCVerifiers} concurrent verifiers`);
97
- this.queue.start(config.numConcurrentIVCVerifiers);
94
+ this.logger.info(`Starting QueuedIVCVerifier with ${concurrency} concurrent verifiers`);
95
+ this.queue.start(concurrency);
98
96
  }
99
97
 
100
98
  public async verifyProof(tx: Tx): Promise<IVCProofVerificationResult> {
@@ -103,7 +101,8 @@ export class QueuedIVCVerifier implements ClientProtocolCircuitVerifier {
103
101
  return result;
104
102
  }
105
103
 
106
- stop(): Promise<void> {
107
- return this.queue.end();
104
+ async stop(): Promise<void> {
105
+ await this.queue.end();
106
+ await this.verifier.stop();
108
107
  }
109
108
  }