@aztec/bb-prover 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448

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 (38) 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 +9 -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 +6 -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/prover/server/bb_prover.d.ts +1 -1
  16. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  17. package/dest/prover/server/bb_prover.js +1 -1
  18. package/dest/test/delay_values.js +1 -1
  19. package/dest/verifier/batch_chonk_verifier.d.ts +45 -0
  20. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  21. package/dest/verifier/batch_chonk_verifier.js +232 -0
  22. package/dest/verifier/index.d.ts +2 -1
  23. package/dest/verifier/index.d.ts.map +1 -1
  24. package/dest/verifier/index.js +1 -0
  25. package/dest/verifier/queued_chonk_verifier.d.ts +2 -3
  26. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  27. package/dest/verifier/queued_chonk_verifier.js +8 -7
  28. package/package.json +17 -16
  29. package/src/avm_proving_tests/avm_proving_tester.ts +12 -0
  30. package/src/bb/execute.ts +10 -1
  31. package/src/config.ts +11 -0
  32. package/src/instrumentation.ts +12 -4
  33. package/src/prover/client/bb_private_kernel_prover.ts +18 -5
  34. package/src/prover/server/bb_prover.ts +1 -0
  35. package/src/test/delay_values.ts +1 -1
  36. package/src/verifier/batch_chonk_verifier.ts +276 -0
  37. package/src/verifier/index.ts +1 -0
  38. package/src/verifier/queued_chonk_verifier.ts +8 -8
@@ -0,0 +1,232 @@
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 { Unpackr } from 'msgpackr';
8
+ import { execFile } from 'node:child_process';
9
+ import { unlinkSync } from 'node:fs';
10
+ import { unlink } from 'node:fs/promises';
11
+ import * as os from 'node:os';
12
+ import * as path from 'node:path';
13
+ import { promisify } from 'node:util';
14
+ const execFileAsync = promisify(execFile);
15
+ /** Maps client protocol artifacts used for chonk verification to VK indices. */ const CHONK_VK_ARTIFACTS = [
16
+ 'HidingKernelToRollup',
17
+ 'HidingKernelToPublic'
18
+ ];
19
+ /**
20
+ * Batch verifier for Chonk IVC proofs. Uses the bb batch verifier service
21
+ * which batches IPA verification into a single SRS MSM for better throughput.
22
+ *
23
+ * Architecture:
24
+ * - Spawns a persistent `bb msgpack run` process via Barretenberg (native backend)
25
+ * - Sends proofs via the msgpack RPC protocol (ChonkBatchVerifierQueue)
26
+ * - Receives results via a named FIFO pipe (async, out-of-order)
27
+ * - Bisects batch failures to isolate individual bad proofs
28
+ */ export class BatchChonkVerifier {
29
+ config;
30
+ vkBuffers;
31
+ batchSize;
32
+ label;
33
+ bb;
34
+ fifoPath;
35
+ nextRequestId;
36
+ pendingRequests;
37
+ sendQueue;
38
+ fifoReader;
39
+ logger;
40
+ /** Maps artifact name to VK index in the batch verifier. */ vkIndexMap;
41
+ /** Bound cleanup handler for process exit signals. */ exitCleanup;
42
+ constructor(config, vkBuffers, batchSize, label){
43
+ this.config = config;
44
+ this.vkBuffers = vkBuffers;
45
+ this.batchSize = batchSize;
46
+ this.label = label;
47
+ this.nextRequestId = 0;
48
+ this.pendingRequests = new Map();
49
+ this.logger = createLogger('bb-prover:batch_chonk_verifier');
50
+ this.vkIndexMap = new Map();
51
+ this.exitCleanup = null;
52
+ this.fifoPath = path.join(os.tmpdir(), `bb-batch-${label}-${process.pid}-${Date.now()}.fifo`);
53
+ this.fifoReader = new FifoFrameReader();
54
+ this.sendQueue = new SerialQueue();
55
+ this.sendQueue.start(1);
56
+ }
57
+ /** Create and start a BatchChonkVerifier using the protocol circuit VKs. */ static async new(config, batchSize, label) {
58
+ const vkBuffers = [];
59
+ const vkIndexMap = new Map();
60
+ for (const artifact of CHONK_VK_ARTIFACTS){
61
+ const vk = ProtocolCircuitVks[artifact];
62
+ if (!vk) {
63
+ throw new Error(`Missing VK for ${artifact}`);
64
+ }
65
+ vkIndexMap.set(artifact, vkBuffers.length);
66
+ vkBuffers.push(vk.keyAsBytes);
67
+ }
68
+ const verifier = new BatchChonkVerifier(config, vkBuffers, batchSize, label);
69
+ verifier.vkIndexMap = vkIndexMap;
70
+ await verifier.start();
71
+ return verifier;
72
+ }
73
+ /** Create and start a BatchChonkVerifier with custom VKs (for testing). */ static async newForTesting(config, vks, batchSize) {
74
+ const verifier = new BatchChonkVerifier(config, vks, batchSize, 'test');
75
+ for(let i = 0; i < vks.length; i++){
76
+ verifier.vkIndexMap.set(String(i), i);
77
+ }
78
+ await verifier.start();
79
+ return verifier;
80
+ }
81
+ async start() {
82
+ this.logger.info('Starting BatchChonkVerifier');
83
+ this.bb = await Barretenberg.new({
84
+ bbPath: this.config.bbBinaryPath,
85
+ backend: BackendType.NativeUnixSocket
86
+ });
87
+ await this.bb.initSRSChonk();
88
+ await execFileAsync('mkfifo', [
89
+ this.fifoPath
90
+ ]);
91
+ this.registerExitCleanup();
92
+ await this.bb.chonkBatchVerifierStart({
93
+ vks: this.vkBuffers,
94
+ numCores: this.config.bbChonkVerifyConcurrency || 0,
95
+ batchSize: this.batchSize,
96
+ fifoPath: this.fifoPath
97
+ });
98
+ this.startFifoReader();
99
+ this.logger.info('BatchChonkVerifier started', {
100
+ fifoPath: this.fifoPath
101
+ });
102
+ }
103
+ verifyProof(tx) {
104
+ const circuit = tx.data.forPublic ? 'HidingKernelToPublic' : 'HidingKernelToRollup';
105
+ const vkIndex = this.vkIndexMap.get(circuit);
106
+ if (vkIndex === undefined) {
107
+ throw new Error(`No VK index for circuit ${circuit}`);
108
+ }
109
+ const proofWithPubInputs = tx.chonkProof.attachPublicInputs(tx.data.publicInputs().toFields());
110
+ const proofFields = proofWithPubInputs.fieldsWithPublicInputs.map((f)=>f.toBuffer());
111
+ return this.enqueueProof(vkIndex, proofFields);
112
+ }
113
+ /** Enqueue raw proof fields for verification. Used directly by tests with custom VKs. */ enqueueProof(vkIndex, proofFields) {
114
+ const totalTimer = new Timer();
115
+ const requestId = this.nextRequestId++;
116
+ const resultPromise = new Promise((resolve, reject)=>{
117
+ this.pendingRequests.set(requestId, {
118
+ resolve,
119
+ reject,
120
+ totalTimer
121
+ });
122
+ });
123
+ void this.sendQueue.put(async ()=>{
124
+ await this.bb.chonkBatchVerifierQueue({
125
+ requestId,
126
+ vkIndex,
127
+ proofFields
128
+ });
129
+ }).catch((err)=>{
130
+ const pending = this.pendingRequests.get(requestId);
131
+ if (pending) {
132
+ this.pendingRequests.delete(requestId);
133
+ pending.reject(err instanceof Error ? err : new Error(String(err)));
134
+ }
135
+ });
136
+ return resultPromise;
137
+ }
138
+ async stop() {
139
+ this.logger.info('Stopping BatchChonkVerifier');
140
+ // Stop accepting new proofs
141
+ await this.sendQueue.end();
142
+ // Stop the bb service (flushes remaining proofs)
143
+ try {
144
+ await this.bb.chonkBatchVerifierStop({});
145
+ } catch (err) {
146
+ this.logger.warn(`Error stopping batch verifier service: ${err}`);
147
+ }
148
+ // Stop FIFO reader
149
+ this.fifoReader.stop();
150
+ // Clean up FIFO file and deregister exit handler
151
+ await unlink(this.fifoPath).catch(()=>{});
152
+ this.deregisterExitCleanup();
153
+ // Reject any remaining pending requests
154
+ for (const [id, pending] of this.pendingRequests){
155
+ pending.reject(new Error('BatchChonkVerifier stopped'));
156
+ this.pendingRequests.delete(id);
157
+ }
158
+ // Destroy bb process
159
+ await this.bb.destroy();
160
+ this.logger.info('BatchChonkVerifier stopped');
161
+ }
162
+ startFifoReader() {
163
+ const unpackr = new Unpackr({
164
+ useRecords: false
165
+ });
166
+ this.fifoReader.on('frame', (payload)=>{
167
+ try {
168
+ const result = unpackr.unpack(payload);
169
+ this.handleResult(result);
170
+ } catch (err) {
171
+ this.logger.error(`FIFO: failed to decode msgpack result: ${err}`);
172
+ }
173
+ });
174
+ this.fifoReader.on('error', (err)=>{
175
+ this.logger.error(`FIFO reader error: ${err}`);
176
+ });
177
+ this.fifoReader.on('end', ()=>{
178
+ this.logger.debug('FIFO reader: stream ended');
179
+ for (const [id, pending] of this.pendingRequests){
180
+ pending.reject(new Error('FIFO stream ended unexpectedly'));
181
+ this.pendingRequests.delete(id);
182
+ }
183
+ });
184
+ this.fifoReader.start(this.fifoPath);
185
+ }
186
+ handleResult(result) {
187
+ const pending = this.pendingRequests.get(result.request_id);
188
+ if (!pending) {
189
+ this.logger.warn(`Received result for unknown request_id=${result.request_id}`);
190
+ return;
191
+ }
192
+ this.pendingRequests.delete(result.request_id);
193
+ const valid = result.status === 0; // VerifyStatus::OK
194
+ const durationMs = result.time_in_verify_ms;
195
+ const totalDurationMs = pending.totalTimer.ms();
196
+ const ivcResult = {
197
+ valid,
198
+ durationMs,
199
+ totalDurationMs
200
+ };
201
+ if (!valid) {
202
+ this.logger.warn(`Proof verification failed for request_id=${result.request_id}: ${result.error_message}`);
203
+ } else {
204
+ this.logger.debug(`Proof verified`, {
205
+ requestId: result.request_id,
206
+ durationMs: Math.ceil(durationMs),
207
+ totalDurationMs: Math.ceil(totalDurationMs)
208
+ });
209
+ }
210
+ pending.resolve(ivcResult);
211
+ }
212
+ registerExitCleanup() {
213
+ // Signal handlers must be synchronous — unlinkSync is intentional here
214
+ this.exitCleanup = ()=>{
215
+ try {
216
+ unlinkSync(this.fifoPath);
217
+ } catch {
218
+ /* ignore */ }
219
+ };
220
+ process.on('exit', this.exitCleanup);
221
+ process.on('SIGINT', this.exitCleanup);
222
+ process.on('SIGTERM', this.exitCleanup);
223
+ }
224
+ deregisterExitCleanup() {
225
+ if (this.exitCleanup) {
226
+ process.removeListener('exit', this.exitCleanup);
227
+ process.removeListener('SIGINT', this.exitCleanup);
228
+ process.removeListener('SIGTERM', this.exitCleanup);
229
+ this.exitCleanup = null;
230
+ }
231
+ }
232
+ }
@@ -1,3 +1,4 @@
1
+ export * from './batch_chonk_verifier.js';
1
2
  export * from './bb_verifier.js';
2
3
  export * from './queued_chonk_verifier.js';
3
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy92ZXJpZmllci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsNEJBQTRCLENBQUMifQ==
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy92ZXJpZmllci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsa0JBQWtCLENBQUM7QUFDakMsY0FBYyw0QkFBNEIsQ0FBQyJ9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/verifier/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/verifier/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC"}
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicXVldWVkX2Nob25rX3ZlcmlmaWVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdmVyaWZpZXIvcXVldWVkX2Nob25rX3ZlcmlmaWVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLDZCQUE2QixFQUFFLDBCQUEwQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakgsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFD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AAC,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"}
@@ -1,6 +1,6 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
  import { SerialQueue } from '@aztec/foundation/queue';
3
- import { Attributes, Metrics, getTelemetryClient } from '@aztec/telemetry-client';
3
+ import { Attributes, Metrics, createUpDownCounterWithDefault, getTelemetryClient } from '@aztec/telemetry-client';
4
4
  import { createHistogram } from 'node:perf_hooks';
5
5
  class IVCVerifierMetrics {
6
6
  ivcVerificationHistogram;
@@ -19,7 +19,7 @@ class IVCVerifierMetrics {
19
19
  const meter = client.getMeter(name);
20
20
  this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME);
21
21
  this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME);
22
- this.ivcFailureCount = meter.createUpDownCounter(Metrics.IVC_VERIFIER_FAILURE_COUNT);
22
+ this.ivcFailureCount = createUpDownCounterWithDefault(meter, Metrics.IVC_VERIFIER_FAILURE_COUNT);
23
23
  this.aggDurationMetrics = {
24
24
  avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG),
25
25
  max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX),
@@ -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.e6bd8901",
3
+ "version": "0.0.1-commit.ec7ac5448",
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.e6bd8901",
73
- "@aztec/constants": "0.0.1-commit.e6bd8901",
74
- "@aztec/foundation": "0.0.1-commit.e6bd8901",
75
- "@aztec/noir-noirc_abi": "0.0.1-commit.e6bd8901",
76
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.e6bd8901",
77
- "@aztec/noir-types": "0.0.1-commit.e6bd8901",
78
- "@aztec/simulator": "0.0.1-commit.e6bd8901",
79
- "@aztec/stdlib": "0.0.1-commit.e6bd8901",
80
- "@aztec/telemetry-client": "0.0.1-commit.e6bd8901",
81
- "@aztec/world-state": "0.0.1-commit.e6bd8901",
72
+ "@aztec/bb.js": "0.0.1-commit.ec7ac5448",
73
+ "@aztec/constants": "0.0.1-commit.ec7ac5448",
74
+ "@aztec/foundation": "0.0.1-commit.ec7ac5448",
75
+ "@aztec/noir-noirc_abi": "0.0.1-commit.ec7ac5448",
76
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.ec7ac5448",
77
+ "@aztec/noir-types": "0.0.1-commit.ec7ac5448",
78
+ "@aztec/simulator": "0.0.1-commit.ec7ac5448",
79
+ "@aztec/stdlib": "0.0.1-commit.ec7ac5448",
80
+ "@aztec/telemetry-client": "0.0.1-commit.ec7ac5448",
81
+ "@aztec/world-state": "0.0.1-commit.ec7ac5448",
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.e6bd8901",
89
- "@aztec/kv-store": "0.0.1-commit.e6bd8901",
90
- "@aztec/noir-contracts.js": "0.0.1-commit.e6bd8901",
91
- "@aztec/noir-test-contracts.js": "0.0.1-commit.e6bd8901",
92
- "@aztec/protocol-contracts": "0.0.1-commit.e6bd8901",
89
+ "@aztec/ethereum": "0.0.1-commit.ec7ac5448",
90
+ "@aztec/kv-store": "0.0.1-commit.ec7ac5448",
91
+ "@aztec/noir-contracts.js": "0.0.1-commit.ec7ac5448",
92
+ "@aztec/noir-test-contracts.js": "0.0.1-commit.ec7ac5448",
93
+ "@aztec/protocol-contracts": "0.0.1-commit.ec7ac5448",
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';
@@ -44,6 +45,10 @@ class InterceptingLogger implements Logger {
44
45
  throw new Error('Not implemented');
45
46
  }
46
47
 
48
+ getBindings() {
49
+ return this.logger.getBindings();
50
+ }
51
+
47
52
  private intercept(level: LogLevel, msg: string, ...args: any[]) {
48
53
  this.logs.push(...msg.split('\n'));
49
54
  // Forward to the wrapped logger
@@ -207,6 +212,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
207
212
  privateInsertions?: TestPrivateInsertions,
208
213
  txLabel: string = 'unlabeledTx',
209
214
  disableRevertCheck: boolean = false,
215
+ gasLimits?: Gas,
210
216
  ): Promise<PublicTxResult> {
211
217
  const simTimer = new Timer();
212
218
  const simRes = await this.simulateTx(
@@ -217,6 +223,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
217
223
  feePayer,
218
224
  privateInsertions,
219
225
  txLabel,
226
+ gasLimits,
220
227
  );
221
228
  const simDuration = simTimer.ms();
222
229
  this.logger.info(`Simulation took ${simDuration} ms for tx ${txLabel}`);
@@ -243,6 +250,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
243
250
  teardownCall?: TestEnqueuedCall,
244
251
  feePayer?: AztecAddress,
245
252
  privateInsertions?: TestPrivateInsertions,
253
+ gasLimits?: Gas,
246
254
  ) {
247
255
  return await this.simProveVerify(
248
256
  sender,
@@ -254,6 +262,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
254
262
  privateInsertions,
255
263
  txLabel,
256
264
  true,
265
+ gasLimits,
257
266
  );
258
267
  }
259
268
 
@@ -261,6 +270,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
261
270
  appCall: TestEnqueuedCall,
262
271
  expectRevert?: boolean,
263
272
  txLabel: string = 'unlabeledTx',
273
+ gasLimits?: Gas,
264
274
  ) {
265
275
  await this.simProveVerify(
266
276
  /*sender=*/ AztecAddress.fromNumber(42),
@@ -271,6 +281,8 @@ export class AvmProvingTester extends PublicTxSimulationTester {
271
281
  /*feePayer=*/ undefined,
272
282
  /*privateInsertions=*/ undefined,
273
283
  txLabel,
284
+ /*disableRevertCheck=*/ false,
285
+ gasLimits,
274
286
  );
275
287
  }
276
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
@@ -398,7 +400,14 @@ export async function verifyProof(
398
400
  '--disable_zk',
399
401
  ...getArgs(ultraHonkFlavor),
400
402
  ];
401
- return await verifyProofInternal(pathToBB, `verify`, args, logger);
403
+
404
+ let concurrency = DEFAULT_BB_VERIFY_CONCURRENCY;
405
+
406
+ if (process.env.VERIFY_HARDWARE_CONCURRENCY) {
407
+ concurrency = parseInt(process.env.VERIFY_HARDWARE_CONCURRENCY, 10);
408
+ }
409
+
410
+ return await verifyProofInternal(pathToBB, `verify`, args, logger, concurrency);
402
411
  }
403
412
 
404
413
  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
  }
@@ -463,6 +463,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
463
463
  this.config.acvmWorkingDirectory,
464
464
  this.config.acvmBinaryPath,
465
465
  outputWitnessFile,
466
+ logger,
466
467
  );
467
468
 
468
469
  const artifact = getServerCircuitArtifact(circuitType);
@@ -35,7 +35,7 @@ export const PROOF_DELAY_MS: Record<ProvingRequestType, number> = {
35
35
  [ProvingRequestType.ROOT_ROLLUP]: 93_000,
36
36
  [ProvingRequestType.TX_MERGE_ROLLUP]: 10_000,
37
37
  [ProvingRequestType.PUBLIC_TX_BASE_ROLLUP]: 44_500,
38
- [ProvingRequestType.PUBLIC_VM]: 10_000,
38
+ [ProvingRequestType.PUBLIC_VM]: 180_000,
39
39
 
40
40
  // TBD
41
41
  [ProvingRequestType.BLOCK_MERGE_ROLLUP]: 15_000,