@aztec/bb-prover 0.0.1-commit.a5db02d → 0.0.1-commit.aa0c64f
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 +26 -4
- package/dest/prover/client/bb_private_kernel_prover.d.ts +11 -3
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/client/bb_private_kernel_prover.js +29 -3
- 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 +32 -4
- package/src/prover/client/bb_private_kernel_prover.ts +107 -2
- package/src/verifier/batch_chonk_verifier.ts +204 -65
|
@@ -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.aa0c64f",
|
|
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.1-commit.
|
|
74
|
-
"@aztec/constants": "0.0.1-commit.
|
|
75
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
76
|
-
"@aztec/noir-noirc_abi": "0.0.1-commit.
|
|
77
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
78
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
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": "0.0.1-commit.aa0c64f",
|
|
74
|
+
"@aztec/constants": "0.0.1-commit.aa0c64f",
|
|
75
|
+
"@aztec/foundation": "0.0.1-commit.aa0c64f",
|
|
76
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.aa0c64f",
|
|
77
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.aa0c64f",
|
|
78
|
+
"@aztec/noir-types": "0.0.1-commit.aa0c64f",
|
|
79
|
+
"@aztec/simulator": "0.0.1-commit.aa0c64f",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.aa0c64f",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.aa0c64f",
|
|
82
|
+
"@aztec/world-state": "0.0.1-commit.aa0c64f",
|
|
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.aa0c64f",
|
|
91
|
+
"@aztec/kv-store": "0.0.1-commit.aa0c64f",
|
|
92
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.aa0c64f",
|
|
93
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.aa0c64f",
|
|
94
|
+
"@aztec/protocol-contracts": "0.0.1-commit.aa0c64f",
|
|
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';
|
|
@@ -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
|
/**
|
|
@@ -9,12 +9,20 @@ import {
|
|
|
9
9
|
convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
|
|
10
10
|
convertPrivateKernelInit3InputsToWitnessMapWithAbi,
|
|
11
11
|
convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
|
|
12
|
+
convertPrivateKernelInit4InputsToWitnessMapWithAbi,
|
|
13
|
+
convertPrivateKernelInit4OutputsFromWitnessMapWithAbi,
|
|
14
|
+
convertPrivateKernelInit5InputsToWitnessMapWithAbi,
|
|
15
|
+
convertPrivateKernelInit5OutputsFromWitnessMapWithAbi,
|
|
12
16
|
convertPrivateKernelInitInputsToWitnessMapWithAbi,
|
|
13
17
|
convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
|
|
14
18
|
convertPrivateKernelInner2InputsToWitnessMapWithAbi,
|
|
15
19
|
convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
|
|
16
20
|
convertPrivateKernelInner3InputsToWitnessMapWithAbi,
|
|
17
21
|
convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
|
|
22
|
+
convertPrivateKernelInner4InputsToWitnessMapWithAbi,
|
|
23
|
+
convertPrivateKernelInner4OutputsFromWitnessMapWithAbi,
|
|
24
|
+
convertPrivateKernelInner5InputsToWitnessMapWithAbi,
|
|
25
|
+
convertPrivateKernelInner5OutputsFromWitnessMapWithAbi,
|
|
18
26
|
convertPrivateKernelInnerInputsToWitnessMapWithAbi,
|
|
19
27
|
convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
|
|
20
28
|
convertPrivateKernelResetInputsToWitnessMapWithAbi,
|
|
@@ -43,9 +51,13 @@ import type {
|
|
|
43
51
|
PrivateKernelCircuitPublicInputs,
|
|
44
52
|
PrivateKernelInit2CircuitPrivateInputs,
|
|
45
53
|
PrivateKernelInit3CircuitPrivateInputs,
|
|
54
|
+
PrivateKernelInit4CircuitPrivateInputs,
|
|
55
|
+
PrivateKernelInit5CircuitPrivateInputs,
|
|
46
56
|
PrivateKernelInitCircuitPrivateInputs,
|
|
47
57
|
PrivateKernelInner2CircuitPrivateInputs,
|
|
48
58
|
PrivateKernelInner3CircuitPrivateInputs,
|
|
59
|
+
PrivateKernelInner4CircuitPrivateInputs,
|
|
60
|
+
PrivateKernelInner5CircuitPrivateInputs,
|
|
49
61
|
PrivateKernelInnerCircuitPrivateInputs,
|
|
50
62
|
PrivateKernelResetCircuitPrivateInputs,
|
|
51
63
|
PrivateKernelResetTailCircuitPrivateInputs,
|
|
@@ -136,6 +148,50 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
136
148
|
);
|
|
137
149
|
}
|
|
138
150
|
|
|
151
|
+
public async generateInit4Output(
|
|
152
|
+
inputs: PrivateKernelInit4CircuitPrivateInputs,
|
|
153
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
154
|
+
return await this.generateCircuitOutput(
|
|
155
|
+
inputs,
|
|
156
|
+
'PrivateKernelInit4Artifact',
|
|
157
|
+
convertPrivateKernelInit4InputsToWitnessMapWithAbi,
|
|
158
|
+
convertPrivateKernelInit4OutputsFromWitnessMapWithAbi,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public async simulateInit4(
|
|
163
|
+
inputs: PrivateKernelInit4CircuitPrivateInputs,
|
|
164
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
165
|
+
return await this.simulateCircuitOutput(
|
|
166
|
+
inputs,
|
|
167
|
+
'PrivateKernelInit4Artifact',
|
|
168
|
+
convertPrivateKernelInit4InputsToWitnessMapWithAbi,
|
|
169
|
+
convertPrivateKernelInit4OutputsFromWitnessMapWithAbi,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public async generateInit5Output(
|
|
174
|
+
inputs: PrivateKernelInit5CircuitPrivateInputs,
|
|
175
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
176
|
+
return await this.generateCircuitOutput(
|
|
177
|
+
inputs,
|
|
178
|
+
'PrivateKernelInit5Artifact',
|
|
179
|
+
convertPrivateKernelInit5InputsToWitnessMapWithAbi,
|
|
180
|
+
convertPrivateKernelInit5OutputsFromWitnessMapWithAbi,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public async simulateInit5(
|
|
185
|
+
inputs: PrivateKernelInit5CircuitPrivateInputs,
|
|
186
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
187
|
+
return await this.simulateCircuitOutput(
|
|
188
|
+
inputs,
|
|
189
|
+
'PrivateKernelInit5Artifact',
|
|
190
|
+
convertPrivateKernelInit5InputsToWitnessMapWithAbi,
|
|
191
|
+
convertPrivateKernelInit5OutputsFromWitnessMapWithAbi,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
139
195
|
public async generateInnerOutput(
|
|
140
196
|
inputs: PrivateKernelInnerCircuitPrivateInputs,
|
|
141
197
|
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
@@ -202,6 +258,50 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
202
258
|
);
|
|
203
259
|
}
|
|
204
260
|
|
|
261
|
+
public async generateInner4Output(
|
|
262
|
+
inputs: PrivateKernelInner4CircuitPrivateInputs,
|
|
263
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
264
|
+
return await this.generateCircuitOutput(
|
|
265
|
+
inputs,
|
|
266
|
+
'PrivateKernelInner4Artifact',
|
|
267
|
+
convertPrivateKernelInner4InputsToWitnessMapWithAbi,
|
|
268
|
+
convertPrivateKernelInner4OutputsFromWitnessMapWithAbi,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public async simulateInner4(
|
|
273
|
+
inputs: PrivateKernelInner4CircuitPrivateInputs,
|
|
274
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
275
|
+
return await this.simulateCircuitOutput(
|
|
276
|
+
inputs,
|
|
277
|
+
'PrivateKernelInner4Artifact',
|
|
278
|
+
convertPrivateKernelInner4InputsToWitnessMapWithAbi,
|
|
279
|
+
convertPrivateKernelInner4OutputsFromWitnessMapWithAbi,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
public async generateInner5Output(
|
|
284
|
+
inputs: PrivateKernelInner5CircuitPrivateInputs,
|
|
285
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
286
|
+
return await this.generateCircuitOutput(
|
|
287
|
+
inputs,
|
|
288
|
+
'PrivateKernelInner5Artifact',
|
|
289
|
+
convertPrivateKernelInner5InputsToWitnessMapWithAbi,
|
|
290
|
+
convertPrivateKernelInner5OutputsFromWitnessMapWithAbi,
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
public async simulateInner5(
|
|
295
|
+
inputs: PrivateKernelInner5CircuitPrivateInputs,
|
|
296
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
297
|
+
return await this.simulateCircuitOutput(
|
|
298
|
+
inputs,
|
|
299
|
+
'PrivateKernelInner5Artifact',
|
|
300
|
+
convertPrivateKernelInner5InputsToWitnessMapWithAbi,
|
|
301
|
+
convertPrivateKernelInner5OutputsFromWitnessMapWithAbi,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
205
305
|
public async generateResetOutput(
|
|
206
306
|
inputs: PrivateKernelResetCircuitPrivateInputs,
|
|
207
307
|
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
@@ -387,6 +487,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
387
487
|
executionSteps.map(step => ungzip(step.bytecode)),
|
|
388
488
|
barretenberg,
|
|
389
489
|
executionSteps.map(step => step.functionName),
|
|
490
|
+
executionSteps.map(step => step.kind),
|
|
390
491
|
);
|
|
391
492
|
|
|
392
493
|
// Use compressed prove path to get both proof fields and compressed proof bytes
|
|
@@ -413,13 +514,17 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
413
514
|
return proofWithPubInputs;
|
|
414
515
|
}
|
|
415
516
|
|
|
416
|
-
public async computeGateCountForCircuit(
|
|
517
|
+
public async computeGateCountForCircuit(
|
|
518
|
+
_bytecode: Buffer,
|
|
519
|
+
_circuitName: string,
|
|
520
|
+
_circuitKind: PrivateExecutionStep['kind'],
|
|
521
|
+
): Promise<number> {
|
|
417
522
|
// Note we do not pass the vk to the backend. This is unneeded for gate counts.
|
|
418
523
|
const barretenberg = await Barretenberg.initSingleton({
|
|
419
524
|
...this.options,
|
|
420
525
|
logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
|
|
421
526
|
});
|
|
422
|
-
const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName]);
|
|
527
|
+
const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName], [_circuitKind]);
|
|
423
528
|
const gateCount = await backend.gates();
|
|
424
529
|
return gateCount[0];
|
|
425
530
|
}
|