@aztec/bb-prover 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (84) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +13 -8
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +152 -107
  4. package/dest/bb/bb_js_backend.d.ts +196 -0
  5. package/dest/bb/bb_js_backend.d.ts.map +1 -0
  6. package/dest/bb/bb_js_backend.js +379 -0
  7. package/dest/bb/bb_js_debug.d.ts +52 -0
  8. package/dest/bb/bb_js_debug.d.ts.map +1 -0
  9. package/dest/bb/bb_js_debug.js +176 -0
  10. package/dest/bb/file_names.d.ts +4 -0
  11. package/dest/bb/file_names.d.ts.map +1 -0
  12. package/dest/bb/file_names.js +5 -0
  13. package/dest/config.d.ts +17 -1
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/index.d.ts +3 -2
  16. package/dest/index.d.ts.map +1 -1
  17. package/dest/index.js +2 -1
  18. package/dest/instrumentation.d.ts +1 -1
  19. package/dest/instrumentation.d.ts.map +1 -1
  20. package/dest/instrumentation.js +21 -43
  21. package/dest/prover/client/bb_private_kernel_prover.d.ts +18 -4
  22. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  23. package/dest/prover/client/bb_private_kernel_prover.js +54 -8
  24. package/dest/prover/client/bundle.d.ts +3 -3
  25. package/dest/prover/client/bundle.d.ts.map +1 -1
  26. package/dest/prover/client/bundle.js +2 -3
  27. package/dest/prover/client/lazy.d.ts +3 -3
  28. package/dest/prover/client/lazy.d.ts.map +1 -1
  29. package/dest/prover/client/lazy.js +2 -3
  30. package/dest/prover/proof_utils.d.ts +11 -1
  31. package/dest/prover/proof_utils.d.ts.map +1 -1
  32. package/dest/prover/proof_utils.js +24 -1
  33. package/dest/prover/server/bb_prover.d.ts +8 -12
  34. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  35. package/dest/prover/server/bb_prover.js +612 -107
  36. package/dest/test/delay_values.d.ts +1 -1
  37. package/dest/test/delay_values.d.ts.map +1 -1
  38. package/dest/test/delay_values.js +27 -25
  39. package/dest/test/index.d.ts +2 -1
  40. package/dest/test/index.d.ts.map +1 -1
  41. package/dest/test/index.js +1 -0
  42. package/dest/test/test_circuit_prover.d.ts +4 -4
  43. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  44. package/dest/test/test_circuit_prover.js +462 -59
  45. package/dest/verification_key/verification_key_data.d.ts +1 -8
  46. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  47. package/dest/verification_key/verification_key_data.js +1 -20
  48. package/dest/verifier/batch_chonk_verifier.d.ts +45 -0
  49. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  50. package/dest/verifier/batch_chonk_verifier.js +232 -0
  51. package/dest/verifier/bb_verifier.d.ts +4 -1
  52. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  53. package/dest/verifier/bb_verifier.js +134 -48
  54. package/dest/verifier/index.d.ts +2 -1
  55. package/dest/verifier/index.d.ts.map +1 -1
  56. package/dest/verifier/index.js +1 -0
  57. package/dest/verifier/queued_chonk_verifier.d.ts +2 -3
  58. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  59. package/dest/verifier/queued_chonk_verifier.js +15 -45
  60. package/package.json +20 -18
  61. package/src/avm_proving_tests/avm_proving_tester.ts +53 -136
  62. package/src/bb/bb_js_backend.ts +435 -0
  63. package/src/bb/bb_js_debug.ts +227 -0
  64. package/src/bb/file_names.ts +6 -0
  65. package/src/config.ts +16 -0
  66. package/src/index.ts +2 -1
  67. package/src/instrumentation.ts +20 -43
  68. package/src/prover/client/bb_private_kernel_prover.ts +135 -9
  69. package/src/prover/client/bundle.ts +3 -4
  70. package/src/prover/client/lazy.ts +3 -4
  71. package/src/prover/proof_utils.ts +41 -1
  72. package/src/prover/server/bb_prover.ts +138 -153
  73. package/src/test/delay_values.ts +28 -24
  74. package/src/test/index.ts +1 -0
  75. package/src/test/test_circuit_prover.ts +10 -13
  76. package/src/verification_key/verification_key_data.ts +1 -26
  77. package/src/verifier/batch_chonk_verifier.ts +276 -0
  78. package/src/verifier/bb_verifier.ts +66 -80
  79. package/src/verifier/index.ts +1 -0
  80. package/src/verifier/queued_chonk_verifier.ts +15 -47
  81. package/dest/bb/execute.d.ts +0 -107
  82. package/dest/bb/execute.d.ts.map +0 -1
  83. package/dest/bb/execute.js +0 -676
  84. package/src/bb/execute.ts +0 -706
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/bb-prover",
3
- "version": "0.0.1-commit.03f7ef2",
3
+ "version": "0.0.1-commit.04d373f",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -9,7 +9,8 @@
9
9
  "./client": "./dest/prover/client/bb_private_kernel_prover.js",
10
10
  "./verifier": "./dest/verifier/index.js",
11
11
  "./test": "./dest/test/index.js",
12
- "./config": "./dest/config.js"
12
+ "./config": "./dest/config.js",
13
+ "./debug": "./dest/bb/bb_js_debug.js"
13
14
  },
14
15
  "bin": {
15
16
  "bb-cli": "./dest/bb/index.js"
@@ -69,32 +70,33 @@
69
70
  ]
70
71
  },
71
72
  "dependencies": {
72
- "@aztec/bb.js": "0.0.1-commit.03f7ef2",
73
- "@aztec/constants": "0.0.1-commit.03f7ef2",
74
- "@aztec/foundation": "0.0.1-commit.03f7ef2",
75
- "@aztec/noir-noirc_abi": "0.0.1-commit.03f7ef2",
76
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.03f7ef2",
77
- "@aztec/noir-types": "0.0.1-commit.03f7ef2",
78
- "@aztec/simulator": "0.0.1-commit.03f7ef2",
79
- "@aztec/stdlib": "0.0.1-commit.03f7ef2",
80
- "@aztec/telemetry-client": "0.0.1-commit.03f7ef2",
81
- "@aztec/world-state": "0.0.1-commit.03f7ef2",
73
+ "@aztec/bb.js": "0.0.1-commit.04d373f",
74
+ "@aztec/constants": "0.0.1-commit.04d373f",
75
+ "@aztec/foundation": "0.0.1-commit.04d373f",
76
+ "@aztec/noir-noirc_abi": "0.0.1-commit.04d373f",
77
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.04d373f",
78
+ "@aztec/noir-types": "0.0.1-commit.04d373f",
79
+ "@aztec/simulator": "0.0.1-commit.04d373f",
80
+ "@aztec/stdlib": "0.0.1-commit.04d373f",
81
+ "@aztec/telemetry-client": "0.0.1-commit.04d373f",
82
+ "@aztec/world-state": "0.0.1-commit.04d373f",
82
83
  "commander": "^12.1.0",
84
+ "msgpackr": "^1.11.2",
83
85
  "pako": "^2.1.0",
84
86
  "source-map-support": "^0.5.21",
85
87
  "tslib": "^2.4.0"
86
88
  },
87
89
  "devDependencies": {
88
- "@aztec/ethereum": "0.0.1-commit.03f7ef2",
89
- "@aztec/kv-store": "0.0.1-commit.03f7ef2",
90
- "@aztec/noir-contracts.js": "0.0.1-commit.03f7ef2",
91
- "@aztec/noir-test-contracts.js": "0.0.1-commit.03f7ef2",
92
- "@aztec/protocol-contracts": "0.0.1-commit.03f7ef2",
90
+ "@aztec/ethereum": "0.0.1-commit.04d373f",
91
+ "@aztec/kv-store": "0.0.1-commit.04d373f",
92
+ "@aztec/noir-contracts.js": "0.0.1-commit.04d373f",
93
+ "@aztec/noir-test-contracts.js": "0.0.1-commit.04d373f",
94
+ "@aztec/protocol-contracts": "0.0.1-commit.04d373f",
93
95
  "@jest/globals": "^30.0.0",
94
96
  "@types/jest": "^30.0.0",
95
97
  "@types/node": "^22.15.17",
96
98
  "@types/source-map-support": "^0.5.10",
97
- "@typescript/native-preview": "7.0.0-dev.20251126.1",
99
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
98
100
  "jest": "^30.0.0",
99
101
  "jest-mock-extended": "^4.0.0",
100
102
  "ts-node": "^10.9.1",
@@ -1,4 +1,4 @@
1
- import type { LogFn, LogLevel, Logger } from '@aztec/foundation/log';
1
+ import type { AvmStat } from '@aztec/bb.js';
2
2
  import { Timer } from '@aztec/foundation/timer';
3
3
  import {
4
4
  PublicTxSimulationTester,
@@ -10,84 +10,17 @@ 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';
16
17
 
17
- import fs from 'node:fs/promises';
18
- import { tmpdir } from 'node:os';
19
18
  import path from 'path';
20
19
 
21
- import {
22
- type BBResult,
23
- type BBSuccess,
24
- BB_RESULT,
25
- VK_FILENAME,
26
- generateAvmProof,
27
- verifyAvmProof,
28
- } from '../bb/execute.js';
20
+ import { BBJsFactory } from '../bb/bb_js_backend.js';
29
21
 
30
22
  const BB_PATH = path.resolve('../../barretenberg/cpp/build/bin/bb-avm');
31
23
 
32
- // An InterceptingLogger that records all log messages and forwards them to a wrapped logger.
33
- class InterceptingLogger implements Logger {
34
- public readonly logs: string[] = [];
35
- public level: LogLevel;
36
- public module: string;
37
-
38
- private logger: Logger;
39
-
40
- constructor(logger: Logger) {
41
- this.logger = logger;
42
- this.level = logger.level;
43
- this.module = logger.module;
44
- }
45
-
46
- isLevelEnabled(level: LogLevel): boolean {
47
- return this.logger.isLevelEnabled(level);
48
- }
49
-
50
- createChild(_childModule: string): Logger {
51
- throw new Error('Not implemented');
52
- }
53
-
54
- private intercept(level: LogLevel, msg: string, ...args: any[]) {
55
- this.logs.push(...msg.split('\n'));
56
- // Forward to the wrapped logger
57
- (this.logger[level] as LogFn)(msg, ...args);
58
- }
59
-
60
- // Log methods for each level
61
- silent(msg: string, ...args: any[]) {
62
- this.intercept('silent', msg, ...args);
63
- }
64
- fatal(msg: string, ...args: any[]) {
65
- this.intercept('fatal', msg, ...args);
66
- }
67
- warn(msg: string, ...args: any[]) {
68
- this.intercept('warn', msg, ...args);
69
- }
70
- info(msg: string, ...args: any[]) {
71
- this.intercept('info', msg, ...args);
72
- }
73
- verbose(msg: string, ...args: any[]) {
74
- this.intercept('verbose', msg, ...args);
75
- }
76
- debug(msg: string, ...args: any[]) {
77
- this.intercept('debug', msg, ...args);
78
- }
79
- trace(msg: string, ...args: any[]) {
80
- this.intercept('trace', msg, ...args);
81
- }
82
-
83
- // Error log function can be string or Error
84
- error(err: Error | string, ...args: any[]) {
85
- const msg = typeof err === 'string' ? err : err.message;
86
- this.logs.push(msg);
87
- this.logger.error(msg, err, ...args);
88
- }
89
- }
90
-
91
24
  // Config with collectHints enabled for proving tests
92
25
  const provingConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
93
26
  skipFeeEnforcement: false,
@@ -99,7 +32,7 @@ const provingConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
99
32
  });
100
33
 
101
34
  export class AvmProvingTester extends PublicTxSimulationTester {
102
- private bbWorkingDirectory: string = '';
35
+ private readonly bbJsFactory = new BBJsFactory(BB_PATH);
103
36
 
104
37
  constructor(
105
38
  private checkCircuitOnly: boolean,
@@ -123,53 +56,57 @@ export class AvmProvingTester extends PublicTxSimulationTester {
123
56
  return new AvmProvingTester(checkCircuitOnly, contractDataSource, merkleTrees, globals, metrics);
124
57
  }
125
58
 
126
- async prove(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx'): Promise<BBResult> {
127
- // We use a new working directory for each proof.
128
- this.bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
59
+ /**
60
+ * Generate an AVM proof (or run check-circuit if configured). Records per-stage timings in the test metrics.
61
+ * Returns the in-memory proof fields on success; throws via jest expect() on failure.
62
+ */
63
+ async prove(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx'): Promise<Uint8Array[]> {
64
+ const inputsBuffer = avmCircuitInputs.serializeWithMessagePack();
129
65
 
130
- const interceptingLogger = new InterceptingLogger(this.logger);
66
+ if (this.checkCircuitOnly) {
67
+ await using instance = await this.bbJsFactory.getInstance();
68
+ const { passed, stats } = await instance.checkAvmCircuit(inputsBuffer);
69
+ this.recordProverMetrics(stats, txLabel);
70
+ expect(passed).toBe(true);
71
+ return [];
72
+ }
131
73
 
132
- // Then we prove.
133
- const proofRes = await generateAvmProof(
134
- BB_PATH,
135
- this.bbWorkingDirectory,
136
- avmCircuitInputs,
137
- interceptingLogger,
138
- this.checkCircuitOnly,
139
- );
140
- if (proofRes.status === BB_RESULT.FAILURE) {
141
- this.logger.error(`Proof generation failed: ${proofRes.reason}`);
74
+ await using instance = await this.bbJsFactory.getInstance();
75
+ const { proof, stats } = await instance.generateAvmProof(inputsBuffer);
76
+ this.recordProverMetrics(stats, txLabel);
77
+ return proof;
78
+ }
79
+
80
+ async verify(proof: Uint8Array[], publicInputs: AvmCircuitPublicInputs): Promise<void> {
81
+ if (this.checkCircuitOnly) {
82
+ // Check-circuit did not generate a proof; nothing to verify.
83
+ return;
142
84
  }
143
- expect(proofRes.status).toEqual(BB_RESULT.SUCCESS);
85
+ const piBuffer = publicInputs.serializeWithMessagePack();
86
+ await using instance = await this.bbJsFactory.getInstance();
87
+ const { verified } = await instance.verifyAvmProof(proof, piBuffer);
88
+ expect(verified).toBe(true);
89
+ }
144
90
 
145
- // Parse the logs into a structured format.
146
- const logs = interceptingLogger.logs;
147
- // const traceSizes: { name: string; size: number }[] = [];
148
- // logs.forEach(log => {
149
- // const match = log.match(/\b(\w+): (\d+) \(~2/);
150
- // if (match) {
151
- // traceSizes.push({
152
- // name: match[1],
153
- // size: parseInt(match[2]),
154
- // });
155
- // }
156
- // });
157
- const times: { [key: string]: number } = {};
158
- logs.forEach(log => {
159
- const match = log.match(/\b([\w/]+)_ms: (\d+)/);
160
- if (match) {
161
- times[match[1]] = parseInt(match[2]);
162
- }
163
- });
91
+ public async proveVerify(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx') {
92
+ const proof = await this.prove(avmCircuitInputs, txLabel);
93
+ await this.verify(proof, avmCircuitInputs.publicInputs);
94
+ }
164
95
 
165
- // Throw if logs did not contain any times.
96
+ private recordProverMetrics(stats: AvmStat[], txLabel: string) {
97
+ // Build a lookup keyed on the stage name with the `_ms` suffix stripped, matching the legacy
98
+ // stdout-scraped shape. bb::avm2::Stats::time() stores keys with `_ms` appended.
99
+ const times: { [key: string]: number } = {};
100
+ for (const { name, valueMs } of stats) {
101
+ const key = name.endsWith('_ms') ? name.slice(0, -'_ms'.length) : name;
102
+ times[key] = valueMs;
103
+ }
166
104
  if (Object.keys(times).length === 0) {
167
- throw new Error('AVM stdout did not contain any proving times in the stats!');
105
+ throw new Error('AVM response did not contain any proving-stage timings!');
168
106
  }
169
-
170
107
  // Hack to make labels match.
171
108
  const txLabelWithCount = `${txLabel}/${this.txCount - 1}`;
172
- // I need to cast because TS doesnt realize metrics is protected not private.
109
+ // Cast because TS doesn't realize `metrics` is protected, not private on the parent class.
173
110
  (this as any).metrics?.recordProverMetrics(txLabelWithCount, {
174
111
  proverSimulationStepMs: times['simulation/all'],
175
112
  proverProvingStepMs: times['proving/all'],
@@ -182,33 +119,6 @@ export class AvmProvingTester extends PublicTxSimulationTester {
182
119
  provingLogDerivativeInverseCommitmentsMs: times['prove/log_derivative_inverse_commitments_round'],
183
120
  provingWireCommitmentsMs: times['prove/wire_commitments_round'],
184
121
  });
185
-
186
- return proofRes as BBSuccess;
187
- }
188
-
189
- async verify(proofRes: BBSuccess, publicInputs: AvmCircuitPublicInputs): Promise<BBResult> {
190
- if (this.checkCircuitOnly) {
191
- // Skip verification if we are only checking the circuit.
192
- // Check-circuit does not generate a proof to verify.
193
- return proofRes;
194
- }
195
-
196
- return await verifyAvmProof(
197
- BB_PATH,
198
- this.bbWorkingDirectory,
199
- proofRes.proofPath!,
200
- publicInputs,
201
- path.join(proofRes.vkDirectoryPath!, VK_FILENAME),
202
- this.logger,
203
- );
204
- }
205
-
206
- public async proveVerify(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx') {
207
- const provingRes = await this.prove(avmCircuitInputs, txLabel);
208
- expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
209
-
210
- const verificationRes = await this.verify(provingRes as BBSuccess, avmCircuitInputs.publicInputs);
211
- expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
212
122
  }
213
123
 
214
124
  public async simProveVerify(
@@ -221,6 +131,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
221
131
  privateInsertions?: TestPrivateInsertions,
222
132
  txLabel: string = 'unlabeledTx',
223
133
  disableRevertCheck: boolean = false,
134
+ gasLimits?: Gas,
224
135
  ): Promise<PublicTxResult> {
225
136
  const simTimer = new Timer();
226
137
  const simRes = await this.simulateTx(
@@ -231,6 +142,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
231
142
  feePayer,
232
143
  privateInsertions,
233
144
  txLabel,
145
+ gasLimits,
234
146
  );
235
147
  const simDuration = simTimer.ms();
236
148
  this.logger.info(`Simulation took ${simDuration} ms for tx ${txLabel}`);
@@ -257,6 +169,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
257
169
  teardownCall?: TestEnqueuedCall,
258
170
  feePayer?: AztecAddress,
259
171
  privateInsertions?: TestPrivateInsertions,
172
+ gasLimits?: Gas,
260
173
  ) {
261
174
  return await this.simProveVerify(
262
175
  sender,
@@ -268,6 +181,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
268
181
  privateInsertions,
269
182
  txLabel,
270
183
  true,
184
+ gasLimits,
271
185
  );
272
186
  }
273
187
 
@@ -275,6 +189,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
275
189
  appCall: TestEnqueuedCall,
276
190
  expectRevert?: boolean,
277
191
  txLabel: string = 'unlabeledTx',
192
+ gasLimits?: Gas,
278
193
  ) {
279
194
  await this.simProveVerify(
280
195
  /*sender=*/ AztecAddress.fromNumber(42),
@@ -285,6 +200,8 @@ export class AvmProvingTester extends PublicTxSimulationTester {
285
200
  /*feePayer=*/ undefined,
286
201
  /*privateInsertions=*/ undefined,
287
202
  txLabel,
203
+ /*disableRevertCheck=*/ false,
204
+ gasLimits,
288
205
  );
289
206
  }
290
207
  }