@aztec/bb-prover 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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.
- package/dest/avm_proving_tests/avm_proving_tester.d.ts +4 -3
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +28 -6
- package/dest/bb/bb_js_backend.d.ts +1 -1
- package/dest/bb/bb_js_backend.d.ts.map +1 -1
- package/dest/bb/bb_js_backend.js +8 -2
- package/dest/prover/client/bb_private_kernel_prover.d.ts +13 -5
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/client/bb_private_kernel_prover.js +37 -9
- package/dest/prover/server/bb_prover.d.ts +3 -3
- package/dest/prover/server/bb_prover.d.ts.map +1 -1
- package/dest/prover/server/bb_prover.js +10 -8
- package/dest/test/test_circuit_prover.d.ts +3 -3
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +2 -2
- package/dest/verifier/batch_chonk_verifier.d.ts +13 -2
- package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -1
- package/dest/verifier/batch_chonk_verifier.js +210 -58
- package/package.json +16 -16
- package/src/avm_proving_tests/avm_proving_tester.ts +34 -6
- package/src/bb/bb_js_backend.ts +8 -2
- package/src/prover/client/bb_private_kernel_prover.ts +125 -17
- package/src/prover/server/bb_prover.ts +12 -18
- package/src/test/test_circuit_prover.ts +3 -5
- package/src/verifier/batch_chonk_verifier.ts +204 -65
|
@@ -3,7 +3,7 @@ import type { Tx } from '@aztec/stdlib/tx';
|
|
|
3
3
|
import type { BBConfig } from '../config.js';
|
|
4
4
|
/**
|
|
5
5
|
* Batch verifier for Chonk IVC proofs. Uses the bb batch verifier service
|
|
6
|
-
* which batches IPA verification into a
|
|
6
|
+
* which batches IPA verification into a constant number of SRS MSMs for better throughput.
|
|
7
7
|
*
|
|
8
8
|
* Architecture:
|
|
9
9
|
* - Spawns a persistent `bb msgpack run` process via Barretenberg (native backend)
|
|
@@ -17,6 +17,7 @@ export declare class BatchChonkVerifier implements ClientProtocolCircuitVerifier
|
|
|
17
17
|
private batchSize;
|
|
18
18
|
private label;
|
|
19
19
|
private bb;
|
|
20
|
+
private fifoDir;
|
|
20
21
|
private fifoPath;
|
|
21
22
|
private nextRequestId;
|
|
22
23
|
private pendingRequests;
|
|
@@ -27,6 +28,9 @@ export declare class BatchChonkVerifier implements ClientProtocolCircuitVerifier
|
|
|
27
28
|
private vkIndexMap;
|
|
28
29
|
/** Bound cleanup handler for process exit signals. */
|
|
29
30
|
private exitCleanup;
|
|
31
|
+
private stopped;
|
|
32
|
+
private fatalError;
|
|
33
|
+
private pendingDrainedResolvers;
|
|
30
34
|
private constructor();
|
|
31
35
|
/** Create and start a BatchChonkVerifier using the protocol circuit VKs. */
|
|
32
36
|
static new(config: BBConfig, batchSize: number, label: string): Promise<BatchChonkVerifier>;
|
|
@@ -37,9 +41,16 @@ export declare class BatchChonkVerifier implements ClientProtocolCircuitVerifier
|
|
|
37
41
|
/** Enqueue raw proof fields for verification. Used directly by tests with custom VKs. */
|
|
38
42
|
enqueueProof(vkIndex: number, proofFields: Uint8Array[]): Promise<IVCProofVerificationResult>;
|
|
39
43
|
stop(): Promise<void>;
|
|
44
|
+
private withTimeout;
|
|
40
45
|
private startFifoReader;
|
|
41
46
|
private handleResult;
|
|
42
47
|
private registerExitCleanup;
|
|
43
48
|
private deregisterExitCleanup;
|
|
49
|
+
private rejectPendingRequests;
|
|
50
|
+
private failVerifier;
|
|
51
|
+
private waitForPendingRequestsToDrain;
|
|
52
|
+
private notifyPendingDrained;
|
|
53
|
+
private cleanupFifo;
|
|
54
|
+
private cleanupFifoSync;
|
|
44
55
|
}
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
56
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmF0Y2hfY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QWU7Q0FXeEIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch_chonk_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/batch_chonk_verifier.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAU3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"batch_chonk_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/batch_chonk_verifier.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAU3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAwB7C;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,YAAW,6BAA6B;IAkBpE,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IApBf,OAAO,CAAC,EAAE,CAAgB;IAC1B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,eAAe,CAAqC;IAC5D,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,MAAM,CAAkD;IAChE,4DAA4D;IAC5D,OAAO,CAAC,UAAU,CAA6B;IAC/C,sDAAsD;IACtD,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,uBAAuB,CAAyB;IAExD,OAAO,eASN;IAED,4EAA4E;IAC5E,OAAa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAehG;IAED,2EAA2E;IAC3E,OAAa,aAAa,CACxB,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,0BAA0B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,EAC5F,GAAG,EAAE,UAAU,EAAE,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,kBAAkB,CAAC,CAO7B;YAEa,KAAK;IAiCZ,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAe9D;IAED,yFAAyF;IAClF,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAkDnG;IAEY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA+BjC;YAOa,WAAW;IAkBzB,OAAO,CAAC,eAAe;IA6BvB,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,6BAA6B;IA0BrC,OAAO,CAAC,oBAAoB;YASd,WAAW;IAUzB,OAAO,CAAC,eAAe;CAWxB"}
|
|
@@ -6,19 +6,21 @@ import { Timer } from '@aztec/foundation/timer';
|
|
|
6
6
|
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
|
|
7
7
|
import { Unpackr } from 'msgpackr';
|
|
8
8
|
import { execFile } from 'node:child_process';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { rmSync } from 'node:fs';
|
|
10
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
11
11
|
import * as os from 'node:os';
|
|
12
12
|
import * as path from 'node:path';
|
|
13
13
|
import { promisify } from 'node:util';
|
|
14
14
|
const execFileAsync = promisify(execFile);
|
|
15
|
+
const RESULT_TIMEOUT_MS = 5 * 60 * 1000;
|
|
16
|
+
const STOP_DRAIN_TIMEOUT_MS = 5_000;
|
|
15
17
|
/** Maps client protocol artifacts used for chonk verification to VK indices. */ const CHONK_VK_ARTIFACTS = [
|
|
16
18
|
'HidingKernelToRollup',
|
|
17
19
|
'HidingKernelToPublic'
|
|
18
20
|
];
|
|
19
21
|
/**
|
|
20
22
|
* Batch verifier for Chonk IVC proofs. Uses the bb batch verifier service
|
|
21
|
-
* which batches IPA verification into a
|
|
23
|
+
* which batches IPA verification into a constant number of SRS MSMs for better throughput.
|
|
22
24
|
*
|
|
23
25
|
* Architecture:
|
|
24
26
|
* - Spawns a persistent `bb msgpack run` process via Barretenberg (native backend)
|
|
@@ -31,6 +33,7 @@ const execFileAsync = promisify(execFile);
|
|
|
31
33
|
batchSize;
|
|
32
34
|
label;
|
|
33
35
|
bb;
|
|
36
|
+
fifoDir;
|
|
34
37
|
fifoPath;
|
|
35
38
|
nextRequestId;
|
|
36
39
|
pendingRequests;
|
|
@@ -39,17 +42,22 @@ const execFileAsync = promisify(execFile);
|
|
|
39
42
|
logger;
|
|
40
43
|
/** Maps artifact name to VK index in the batch verifier. */ vkIndexMap;
|
|
41
44
|
/** Bound cleanup handler for process exit signals. */ exitCleanup;
|
|
45
|
+
stopped;
|
|
46
|
+
fatalError;
|
|
47
|
+
pendingDrainedResolvers;
|
|
42
48
|
constructor(config, vkBuffers, batchSize, label){
|
|
43
49
|
this.config = config;
|
|
44
50
|
this.vkBuffers = vkBuffers;
|
|
45
51
|
this.batchSize = batchSize;
|
|
46
52
|
this.label = label;
|
|
53
|
+
this.fifoPath = '';
|
|
47
54
|
this.nextRequestId = 0;
|
|
48
55
|
this.pendingRequests = new Map();
|
|
49
56
|
this.logger = createLogger('bb-prover:batch_chonk_verifier');
|
|
50
57
|
this.vkIndexMap = new Map();
|
|
51
58
|
this.exitCleanup = null;
|
|
52
|
-
this.
|
|
59
|
+
this.stopped = false;
|
|
60
|
+
this.pendingDrainedResolvers = new Set();
|
|
53
61
|
this.fifoReader = new FifoFrameReader();
|
|
54
62
|
this.sendQueue = new SerialQueue();
|
|
55
63
|
this.sendQueue.start(1);
|
|
@@ -80,47 +88,91 @@ const execFileAsync = promisify(execFile);
|
|
|
80
88
|
}
|
|
81
89
|
async start() {
|
|
82
90
|
this.logger.info('Starting BatchChonkVerifier');
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
try {
|
|
92
|
+
this.bb = await Barretenberg.new({
|
|
93
|
+
bbPath: this.config.bbBinaryPath,
|
|
94
|
+
backend: BackendType.NativeUnixSocket
|
|
95
|
+
});
|
|
96
|
+
await this.bb.initSRSChonk();
|
|
97
|
+
// Keep the FIFO in a private directory so cleanup has a single owner.
|
|
98
|
+
this.fifoDir = await mkdtemp(path.join(os.tmpdir(), `bb-batch-${this.label}-${process.pid}-`));
|
|
99
|
+
this.fifoPath = path.join(this.fifoDir, 'results.fifo');
|
|
100
|
+
await execFileAsync('mkfifo', [
|
|
101
|
+
this.fifoPath
|
|
102
|
+
]);
|
|
103
|
+
this.registerExitCleanup();
|
|
104
|
+
this.startFifoReader();
|
|
105
|
+
await this.bb.chonkBatchVerifierStart({
|
|
106
|
+
vks: this.vkBuffers,
|
|
107
|
+
numCores: this.config.bbChonkVerifyConcurrency || 0,
|
|
108
|
+
batchSize: this.batchSize,
|
|
109
|
+
fifoPath: this.fifoPath
|
|
110
|
+
});
|
|
111
|
+
} catch (err) {
|
|
112
|
+
this.fifoReader.stop();
|
|
113
|
+
this.deregisterExitCleanup();
|
|
114
|
+
await this.cleanupFifo();
|
|
115
|
+
await this.bb?.destroy().catch(()=>{});
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
99
118
|
this.logger.info('BatchChonkVerifier started', {
|
|
100
119
|
fifoPath: this.fifoPath
|
|
101
120
|
});
|
|
102
121
|
}
|
|
103
122
|
verifyProof(tx) {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
const totalTimer = new Timer();
|
|
124
|
+
return (async ()=>{
|
|
125
|
+
const circuit = tx.data.forPublic ? 'HidingKernelToPublic' : 'HidingKernelToRollup';
|
|
126
|
+
const vkIndex = this.vkIndexMap.get(circuit);
|
|
127
|
+
if (vkIndex === undefined) {
|
|
128
|
+
throw new Error(`No VK index for circuit ${circuit}`);
|
|
129
|
+
}
|
|
130
|
+
const proofWithPubInputs = tx.chonkProof.attachPublicInputs(tx.data.publicInputs().toFields());
|
|
131
|
+
const proofFields = proofWithPubInputs.fieldsWithPublicInputs.map((f)=>f.toBuffer());
|
|
132
|
+
return await this.enqueueProof(vkIndex, proofFields);
|
|
133
|
+
})().catch((err)=>{
|
|
134
|
+
this.logger.warn(`Failed to verify Chonk proof for tx ${tx.getTxHash().toString()}: ${String(err)}`);
|
|
135
|
+
return {
|
|
136
|
+
valid: false,
|
|
137
|
+
durationMs: 0,
|
|
138
|
+
totalDurationMs: totalTimer.ms()
|
|
139
|
+
};
|
|
140
|
+
});
|
|
112
141
|
}
|
|
113
142
|
/** Enqueue raw proof fields for verification. Used directly by tests with custom VKs. */ enqueueProof(vkIndex, proofFields) {
|
|
143
|
+
if (this.stopped) {
|
|
144
|
+
return Promise.reject(new Error('BatchChonkVerifier stopped'));
|
|
145
|
+
}
|
|
146
|
+
if (this.fatalError) {
|
|
147
|
+
return Promise.reject(this.fatalError);
|
|
148
|
+
}
|
|
114
149
|
const totalTimer = new Timer();
|
|
115
150
|
const requestId = this.nextRequestId++;
|
|
116
151
|
const resultPromise = new Promise((resolve, reject)=>{
|
|
152
|
+
const timeout = setTimeout(()=>{
|
|
153
|
+
const pending = this.pendingRequests.get(requestId);
|
|
154
|
+
if (!pending) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.pendingRequests.delete(requestId);
|
|
158
|
+
pending.reject(new Error(`BatchChonkVerifier result timed out for request_id=${requestId}`));
|
|
159
|
+
this.notifyPendingDrained();
|
|
160
|
+
}, RESULT_TIMEOUT_MS);
|
|
161
|
+
// A pending result timer must never keep the host process alive on its own (e.g. an
|
|
162
|
+
// orphaned request at process exit); the FIFO reader keeps the loop alive while results
|
|
163
|
+
// are genuinely awaited.
|
|
164
|
+
timeout.unref();
|
|
117
165
|
this.pendingRequests.set(requestId, {
|
|
118
166
|
resolve,
|
|
119
167
|
reject,
|
|
120
|
-
totalTimer
|
|
168
|
+
totalTimer,
|
|
169
|
+
timeout
|
|
121
170
|
});
|
|
122
171
|
});
|
|
123
172
|
void this.sendQueue.put(async ()=>{
|
|
173
|
+
if (this.fatalError) {
|
|
174
|
+
throw this.fatalError;
|
|
175
|
+
}
|
|
124
176
|
await this.bb.chonkBatchVerifierQueue({
|
|
125
177
|
requestId,
|
|
126
178
|
vkIndex,
|
|
@@ -130,35 +182,62 @@ const execFileAsync = promisify(execFile);
|
|
|
130
182
|
const pending = this.pendingRequests.get(requestId);
|
|
131
183
|
if (pending) {
|
|
132
184
|
this.pendingRequests.delete(requestId);
|
|
185
|
+
clearTimeout(pending.timeout);
|
|
133
186
|
pending.reject(err instanceof Error ? err : new Error(String(err)));
|
|
187
|
+
this.notifyPendingDrained();
|
|
134
188
|
}
|
|
135
189
|
});
|
|
136
190
|
return resultPromise;
|
|
137
191
|
}
|
|
138
192
|
async stop() {
|
|
139
193
|
this.logger.info('Stopping BatchChonkVerifier');
|
|
140
|
-
|
|
141
|
-
await this.sendQueue.end();
|
|
142
|
-
// Stop the bb service (flushes remaining proofs)
|
|
194
|
+
this.stopped = true;
|
|
143
195
|
try {
|
|
144
|
-
|
|
196
|
+
// Stop accepting new proofs and flush the send queue. Bound it so an unresponsive
|
|
197
|
+
// native process can't block teardown of our own event-loop handles indefinitely.
|
|
198
|
+
await this.withTimeout(this.sendQueue.end(), STOP_DRAIN_TIMEOUT_MS, 'send queue flush');
|
|
199
|
+
// Stop the bb service (flushes remaining proofs).
|
|
200
|
+
await this.withTimeout(this.bb.chonkBatchVerifierStop({}), STOP_DRAIN_TIMEOUT_MS, 'chonkBatchVerifierStop');
|
|
201
|
+
// Native stop flushes callbacks; keep the FIFO open until those frames are observed.
|
|
202
|
+
const drained = await this.waitForPendingRequestsToDrain(STOP_DRAIN_TIMEOUT_MS);
|
|
203
|
+
if (!drained) {
|
|
204
|
+
this.rejectPendingRequests(new Error('Timed out waiting for BatchChonkVerifier results during stop'));
|
|
205
|
+
}
|
|
145
206
|
} catch (err) {
|
|
146
|
-
this.logger.warn(`Error
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.pendingRequests.delete(id);
|
|
207
|
+
this.logger.warn(`Error during BatchChonkVerifier graceful stop: ${err}`);
|
|
208
|
+
this.rejectPendingRequests(err instanceof Error ? err : new Error(String(err)));
|
|
209
|
+
} finally{
|
|
210
|
+
// Always release our own event-loop handles — the FIFO read stream (a blocking
|
|
211
|
+
// threadpool read that can't be unref'd), the unix socket, the native process, and the
|
|
212
|
+
// exit handler — so the host process exits cleanly even if the native backend is wedged.
|
|
213
|
+
this.fifoReader.stop();
|
|
214
|
+
this.deregisterExitCleanup();
|
|
215
|
+
await this.cleanupFifo();
|
|
216
|
+
await this.bb.destroy().catch((err)=>this.logger.warn(`Error destroying bb backend during stop: ${err}`));
|
|
157
217
|
}
|
|
158
|
-
// Destroy bb process
|
|
159
|
-
await this.bb.destroy();
|
|
160
218
|
this.logger.info('BatchChonkVerifier stopped');
|
|
161
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Races a promise against a timeout so a wedged native backend can't block teardown. The
|
|
222
|
+
* timer is unref'd so it never keeps the process alive; the underlying promise stays handled
|
|
223
|
+
* by the race even if the timeout wins, so it cannot surface as an unhandled rejection.
|
|
224
|
+
*/ async withTimeout(promise, timeoutMs, label) {
|
|
225
|
+
let timer;
|
|
226
|
+
const timeout = new Promise((_, reject)=>{
|
|
227
|
+
timer = setTimeout(()=>reject(new Error(`BatchChonkVerifier ${label} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
228
|
+
timer.unref();
|
|
229
|
+
});
|
|
230
|
+
try {
|
|
231
|
+
return await Promise.race([
|
|
232
|
+
promise,
|
|
233
|
+
timeout
|
|
234
|
+
]);
|
|
235
|
+
} finally{
|
|
236
|
+
if (timer) {
|
|
237
|
+
clearTimeout(timer);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
162
241
|
startFifoReader() {
|
|
163
242
|
const unpackr = new Unpackr({
|
|
164
243
|
useRecords: false
|
|
@@ -169,16 +248,18 @@ const execFileAsync = promisify(execFile);
|
|
|
169
248
|
this.handleResult(result);
|
|
170
249
|
} catch (err) {
|
|
171
250
|
this.logger.error(`FIFO: failed to decode msgpack result: ${err}`);
|
|
251
|
+
// A corrupt result stream cannot safely be matched to outstanding requests.
|
|
252
|
+
this.failVerifier(err instanceof Error ? err : new Error(String(err)));
|
|
172
253
|
}
|
|
173
254
|
});
|
|
174
255
|
this.fifoReader.on('error', (err)=>{
|
|
175
256
|
this.logger.error(`FIFO reader error: ${err}`);
|
|
257
|
+
this.failVerifier(err);
|
|
176
258
|
});
|
|
177
259
|
this.fifoReader.on('end', ()=>{
|
|
178
260
|
this.logger.debug('FIFO reader: stream ended');
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.pendingRequests.delete(id);
|
|
261
|
+
if (!this.stopped) {
|
|
262
|
+
this.failVerifier(new Error('FIFO stream ended unexpectedly'));
|
|
182
263
|
}
|
|
183
264
|
});
|
|
184
265
|
this.fifoReader.start(this.fifoPath);
|
|
@@ -190,6 +271,7 @@ const execFileAsync = promisify(execFile);
|
|
|
190
271
|
return;
|
|
191
272
|
}
|
|
192
273
|
this.pendingRequests.delete(result.request_id);
|
|
274
|
+
clearTimeout(pending.timeout);
|
|
193
275
|
const valid = result.status === 0; // VerifyStatus::OK
|
|
194
276
|
const durationMs = result.time_in_verify_ms;
|
|
195
277
|
const totalDurationMs = pending.totalTimer.ms();
|
|
@@ -208,25 +290,95 @@ const execFileAsync = promisify(execFile);
|
|
|
208
290
|
});
|
|
209
291
|
}
|
|
210
292
|
pending.resolve(ivcResult);
|
|
293
|
+
this.notifyPendingDrained();
|
|
211
294
|
}
|
|
212
295
|
registerExitCleanup() {
|
|
213
|
-
// Signal handlers must be synchronous — unlinkSync is intentional here
|
|
214
296
|
this.exitCleanup = ()=>{
|
|
215
|
-
|
|
216
|
-
unlinkSync(this.fifoPath);
|
|
217
|
-
} catch {
|
|
218
|
-
/* ignore */ }
|
|
297
|
+
this.cleanupFifoSync();
|
|
219
298
|
};
|
|
220
299
|
process.on('exit', this.exitCleanup);
|
|
221
|
-
process.on('SIGINT', this.exitCleanup);
|
|
222
|
-
process.on('SIGTERM', this.exitCleanup);
|
|
223
300
|
}
|
|
224
301
|
deregisterExitCleanup() {
|
|
225
302
|
if (this.exitCleanup) {
|
|
226
303
|
process.removeListener('exit', this.exitCleanup);
|
|
227
|
-
process.removeListener('SIGINT', this.exitCleanup);
|
|
228
|
-
process.removeListener('SIGTERM', this.exitCleanup);
|
|
229
304
|
this.exitCleanup = null;
|
|
230
305
|
}
|
|
231
306
|
}
|
|
307
|
+
rejectPendingRequests(error) {
|
|
308
|
+
for (const [id, pending] of Array.from(this.pendingRequests)){
|
|
309
|
+
pending.reject(error);
|
|
310
|
+
clearTimeout(pending.timeout);
|
|
311
|
+
this.pendingRequests.delete(id);
|
|
312
|
+
}
|
|
313
|
+
this.notifyPendingDrained();
|
|
314
|
+
}
|
|
315
|
+
failVerifier(error) {
|
|
316
|
+
if (!this.fatalError) {
|
|
317
|
+
this.fatalError = error;
|
|
318
|
+
}
|
|
319
|
+
this.rejectPendingRequests(error);
|
|
320
|
+
}
|
|
321
|
+
waitForPendingRequestsToDrain(timeoutMs) {
|
|
322
|
+
if (this.pendingRequests.size === 0) {
|
|
323
|
+
return Promise.resolve(true);
|
|
324
|
+
}
|
|
325
|
+
let timeout;
|
|
326
|
+
let onDrain;
|
|
327
|
+
const drained = new Promise((resolve)=>{
|
|
328
|
+
onDrain = ()=>resolve(true);
|
|
329
|
+
this.pendingDrainedResolvers.add(onDrain);
|
|
330
|
+
});
|
|
331
|
+
const timedOut = new Promise((resolve)=>{
|
|
332
|
+
timeout = setTimeout(()=>resolve(false), timeoutMs);
|
|
333
|
+
timeout.unref();
|
|
334
|
+
});
|
|
335
|
+
return Promise.race([
|
|
336
|
+
drained,
|
|
337
|
+
timedOut
|
|
338
|
+
]).finally(()=>{
|
|
339
|
+
if (timeout) {
|
|
340
|
+
clearTimeout(timeout);
|
|
341
|
+
}
|
|
342
|
+
if (onDrain) {
|
|
343
|
+
this.pendingDrainedResolvers.delete(onDrain);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
notifyPendingDrained() {
|
|
348
|
+
if (this.pendingRequests.size > 0) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
for (const resolve of Array.from(this.pendingDrainedResolvers)){
|
|
352
|
+
resolve();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async cleanupFifo() {
|
|
356
|
+
if (this.fifoDir) {
|
|
357
|
+
await rm(this.fifoDir, {
|
|
358
|
+
recursive: true,
|
|
359
|
+
force: true
|
|
360
|
+
}).catch(()=>{});
|
|
361
|
+
} else if (this.fifoPath) {
|
|
362
|
+
await rm(this.fifoPath, {
|
|
363
|
+
force: true
|
|
364
|
+
}).catch(()=>{});
|
|
365
|
+
}
|
|
366
|
+
this.fifoDir = undefined;
|
|
367
|
+
this.fifoPath = '';
|
|
368
|
+
}
|
|
369
|
+
cleanupFifoSync() {
|
|
370
|
+
try {
|
|
371
|
+
if (this.fifoDir) {
|
|
372
|
+
rmSync(this.fifoDir, {
|
|
373
|
+
recursive: true,
|
|
374
|
+
force: true
|
|
375
|
+
});
|
|
376
|
+
} else if (this.fifoPath) {
|
|
377
|
+
rmSync(this.fifoPath, {
|
|
378
|
+
force: true
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
} catch {
|
|
382
|
+
/* ignore */ }
|
|
383
|
+
}
|
|
232
384
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bb-prover",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.9a89641",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -70,16 +70,16 @@
|
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@aztec/bb.js": "0.0
|
|
74
|
-
"@aztec/constants": "0.0.1-commit.
|
|
75
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
76
|
-
"@aztec/noir-noirc_abi": "0.0
|
|
77
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
78
|
-
"@aztec/noir-types": "0.0
|
|
79
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
82
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
73
|
+
"@aztec/bb.js": "6.0.0-nightly.20260807",
|
|
74
|
+
"@aztec/constants": "0.0.1-commit.9a89641",
|
|
75
|
+
"@aztec/foundation": "0.0.1-commit.9a89641",
|
|
76
|
+
"@aztec/noir-noirc_abi": "6.0.0-nightly.20260807",
|
|
77
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.9a89641",
|
|
78
|
+
"@aztec/noir-types": "6.0.0-nightly.20260807",
|
|
79
|
+
"@aztec/simulator": "0.0.1-commit.9a89641",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.9a89641",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.9a89641",
|
|
82
|
+
"@aztec/world-state": "0.0.1-commit.9a89641",
|
|
83
83
|
"commander": "^12.1.0",
|
|
84
84
|
"msgpackr": "^1.11.2",
|
|
85
85
|
"pako": "^2.1.0",
|
|
@@ -87,11 +87,11 @@
|
|
|
87
87
|
"tslib": "^2.4.0"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
91
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
92
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
93
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
94
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
90
|
+
"@aztec/ethereum": "0.0.1-commit.9a89641",
|
|
91
|
+
"@aztec/kv-store": "0.0.1-commit.9a89641",
|
|
92
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.9a89641",
|
|
93
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.9a89641",
|
|
94
|
+
"@aztec/protocol-contracts": "0.0.1-commit.9a89641",
|
|
95
95
|
"@jest/globals": "^30.0.0",
|
|
96
96
|
"@types/jest": "^30.0.0",
|
|
97
97
|
"@types/node": "^22.15.17",
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { AvmStat } from '@aztec/bb.js';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
4
|
import {
|
|
5
|
+
type MeasuredSimulatorFactory,
|
|
4
6
|
PublicTxSimulationTester,
|
|
5
7
|
SimpleContractDataSource,
|
|
6
8
|
type TestEnqueuedCall,
|
|
7
9
|
type TestExecutorMetrics,
|
|
8
10
|
type TestPrivateInsertions,
|
|
9
11
|
} from '@aztec/simulator/public/fixtures';
|
|
12
|
+
import { AvmSimulatorPool, MeasuredPublicTxSimulator } from '@aztec/simulator/server';
|
|
10
13
|
import type { PublicTxResult } from '@aztec/simulator/server';
|
|
11
14
|
import { AvmCircuitInputs, AvmCircuitPublicInputs, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
12
15
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -19,7 +22,7 @@ import path from 'path';
|
|
|
19
22
|
|
|
20
23
|
import { BBJsFactory } from '../bb/bb_js_backend.js';
|
|
21
24
|
|
|
22
|
-
const BB_PATH = path.resolve('../../
|
|
25
|
+
const BB_PATH = path.resolve('../../labs-aztec-toolchain/bin/bb-avm');
|
|
23
26
|
|
|
24
27
|
// Config with collectHints enabled for proving tests
|
|
25
28
|
const provingConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
|
|
@@ -32,7 +35,10 @@ const provingConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
|
|
|
32
35
|
});
|
|
33
36
|
|
|
34
37
|
export class AvmProvingTester extends PublicTxSimulationTester {
|
|
35
|
-
private readonly bbJsFactory = new BBJsFactory(BB_PATH
|
|
38
|
+
private readonly bbJsFactory = new BBJsFactory(BB_PATH, {
|
|
39
|
+
debugDir: process.env.BB_DEBUG_OUTPUT_DIR,
|
|
40
|
+
logger: createLogger('bb-prover:avm-proving-tester'),
|
|
41
|
+
});
|
|
36
42
|
|
|
37
43
|
constructor(
|
|
38
44
|
private checkCircuitOnly: boolean,
|
|
@@ -40,9 +46,9 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
40
46
|
merkleTrees: MerkleTreeWriteOperations,
|
|
41
47
|
globals?: GlobalVariables,
|
|
42
48
|
metrics?: TestExecutorMetrics,
|
|
49
|
+
simulatorFactory?: MeasuredSimulatorFactory,
|
|
43
50
|
) {
|
|
44
|
-
|
|
45
|
-
super(merkleTrees, contractDataSource, globals, metrics, /*simulatorFactory=*/ undefined, provingConfig);
|
|
51
|
+
super(merkleTrees, contractDataSource, globals, metrics, simulatorFactory, provingConfig);
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
static async new(
|
|
@@ -53,7 +59,29 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
53
59
|
) {
|
|
54
60
|
const contractDataSource = new SimpleContractDataSource();
|
|
55
61
|
const merkleTrees = await worldStateService.fork();
|
|
56
|
-
|
|
62
|
+
|
|
63
|
+
const avmSimulator = await AvmSimulatorPool.spawn({ wsdbIpcPath: worldStateService.getIpcPath() });
|
|
64
|
+
const simulatorFactory: MeasuredSimulatorFactory = (mt, cdb, g, m, c) =>
|
|
65
|
+
new MeasuredPublicTxSimulator(avmSimulator, g, cdb, mt.getRevision().forkId, m, c, undefined);
|
|
66
|
+
|
|
67
|
+
const tester = new AvmProvingTester(
|
|
68
|
+
checkCircuitOnly,
|
|
69
|
+
contractDataSource,
|
|
70
|
+
merkleTrees,
|
|
71
|
+
globals,
|
|
72
|
+
metrics,
|
|
73
|
+
simulatorFactory,
|
|
74
|
+
);
|
|
75
|
+
tester.avmSimulator = avmSimulator;
|
|
76
|
+
return tester;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public override async close(): Promise<void> {
|
|
80
|
+
const results = await Promise.allSettled([super.close(), this.bbJsFactory.destroy()]);
|
|
81
|
+
const errors = results.flatMap(result => (result.status === 'rejected' ? [result.reason] : []));
|
|
82
|
+
if (errors.length > 0) {
|
|
83
|
+
throw new AggregateError(errors, `Failed to close AVM proving tester`);
|
|
84
|
+
}
|
|
57
85
|
}
|
|
58
86
|
|
|
59
87
|
/**
|
|
@@ -192,7 +220,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
192
220
|
gasLimits?: Gas,
|
|
193
221
|
) {
|
|
194
222
|
await this.simProveVerify(
|
|
195
|
-
/*sender=*/ AztecAddress.
|
|
223
|
+
/*sender=*/ AztecAddress.fromNumberUnsafe(42),
|
|
196
224
|
/*setupCalls=*/ [],
|
|
197
225
|
[appCall],
|
|
198
226
|
undefined,
|
package/src/bb/bb_js_backend.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type AvmStat, type BackendOptions, BackendType, Barretenberg } from '@a
|
|
|
2
2
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
3
3
|
import { FifoMemoryQueue } from '@aztec/foundation/queue';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
+
import { ProvingError } from '@aztec/stdlib/errors';
|
|
5
6
|
|
|
6
7
|
import type { UltraHonkFlavor } from '../honk.js';
|
|
7
8
|
|
|
@@ -84,8 +85,13 @@ export class BBJsInstance implements BBJsApi {
|
|
|
84
85
|
if (threads !== undefined) {
|
|
85
86
|
options.threads = threads;
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
try {
|
|
89
|
+
return new BBJsInstance(await Barretenberg.new(options));
|
|
90
|
+
} catch (err) {
|
|
91
|
+
// bb startup failures are environmental (machine load, a wedged or dead bb process), never a
|
|
92
|
+
// property of the proof inputs, so the job is always safe to retry.
|
|
93
|
+
throw new ProvingError(`Failed to start bb process: ${err}`, err, /*retry*/ true);
|
|
94
|
+
}
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
/**
|