@aztec/bb-prover 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c

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 (47) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +1 -1
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +5 -2
  4. package/dest/bb/execute.d.ts +6 -6
  5. package/dest/bb/execute.d.ts.map +1 -1
  6. package/dest/bb/execute.js +46 -75
  7. package/dest/instrumentation.d.ts +1 -1
  8. package/dest/instrumentation.d.ts.map +1 -1
  9. package/dest/instrumentation.js +21 -43
  10. package/dest/prover/client/bb_private_kernel_prover.d.ts +9 -3
  11. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  12. package/dest/prover/client/bb_private_kernel_prover.js +16 -4
  13. package/dest/prover/client/bundle.d.ts +3 -3
  14. package/dest/prover/client/bundle.d.ts.map +1 -1
  15. package/dest/prover/client/bundle.js +2 -3
  16. package/dest/prover/client/lazy.d.ts +3 -3
  17. package/dest/prover/client/lazy.d.ts.map +1 -1
  18. package/dest/prover/client/lazy.js +2 -3
  19. package/dest/prover/server/bb_prover.d.ts +6 -9
  20. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  21. package/dest/prover/server/bb_prover.js +414 -38
  22. package/dest/test/delay_values.js +2 -2
  23. package/dest/test/test_circuit_prover.d.ts +4 -4
  24. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  25. package/dest/test/test_circuit_prover.js +462 -59
  26. package/dest/verification_key/verification_key_data.d.ts +1 -8
  27. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  28. package/dest/verification_key/verification_key_data.js +0 -19
  29. package/dest/verifier/bb_verifier.d.ts +1 -1
  30. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  31. package/dest/verifier/bb_verifier.js +1 -4
  32. package/dest/verifier/queued_chonk_verifier.d.ts +1 -1
  33. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  34. package/dest/verifier/queued_chonk_verifier.js +9 -40
  35. package/package.json +17 -17
  36. package/src/avm_proving_tests/avm_proving_tester.ts +6 -16
  37. package/src/bb/execute.ts +31 -59
  38. package/src/instrumentation.ts +20 -43
  39. package/src/prover/client/bb_private_kernel_prover.ts +20 -6
  40. package/src/prover/client/bundle.ts +3 -4
  41. package/src/prover/client/lazy.ts +3 -4
  42. package/src/prover/server/bb_prover.ts +22 -32
  43. package/src/test/delay_values.ts +2 -2
  44. package/src/test/test_circuit_prover.ts +10 -13
  45. package/src/verification_key/verification_key_data.ts +0 -25
  46. package/src/verifier/bb_verifier.ts +1 -5
  47. package/src/verifier/queued_chonk_verifier.ts +9 -40
@@ -55,10 +55,8 @@ import { NativeACVMSimulator } from '@aztec/simulator/server';
55
55
  import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
56
56
  import { ProvingError } from '@aztec/stdlib/errors';
57
57
  import {
58
- type ProofAndVerificationKey,
59
58
  type PublicInputsAndRecursiveProof,
60
59
  type ServerCircuitProver,
61
- makeProofAndVerificationKey,
62
60
  makePublicInputsAndRecursiveProof,
63
61
  } from '@aztec/stdlib/interfaces/server';
64
62
  import type { ParityBasePrivateInputs, ParityPublicInputs, ParityRootPrivateInputs } from '@aztec/stdlib/parity';
@@ -86,7 +84,7 @@ import {
86
84
  type TxRollupPublicInputs,
87
85
  } from '@aztec/stdlib/rollup';
88
86
  import type { CircuitProvingStats, CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
89
- import type { VerificationKeyData } from '@aztec/stdlib/vks';
87
+ import { VerificationKeyData } from '@aztec/stdlib/vks';
90
88
  import { Attributes, type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
91
89
 
92
90
  import { promises as fs } from 'fs';
@@ -105,9 +103,8 @@ import {
105
103
  verifyProof,
106
104
  } from '../../bb/execute.js';
107
105
  import type { ACVMConfig, BBConfig } from '../../config.js';
108
- import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../../honk.js';
106
+ import { getUltraHonkFlavorForCircuit } from '../../honk.js';
109
107
  import { ProverInstrumentation } from '../../instrumentation.js';
110
- import { extractAvmVkData } from '../../verification_key/verification_key_data.js';
111
108
  import { readProofsFromOutputDirectory } from '../proof_utils.js';
112
109
 
113
110
  const logger = createLogger('bb-prover');
@@ -191,10 +188,10 @@ export class BBNativeRollupProver implements ServerCircuitProver {
191
188
  }))
192
189
  public async getAvmProof(
193
190
  inputs: AvmCircuitInputs,
194
- ): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
195
- const proofAndVk = await this.createAvmProof(inputs);
196
- await this.verifyAvmProof(proofAndVk.proof.binaryProof, proofAndVk.verificationKey, inputs.publicInputs);
197
- return proofAndVk;
191
+ ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
192
+ const proof = await this.createAvmProof(inputs);
193
+ await this.verifyAvmProof(proof.binaryProof, inputs.publicInputs);
194
+ return proof;
198
195
  }
199
196
 
200
197
  public async getPublicChonkVerifierProof(
@@ -466,6 +463,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
466
463
  this.config.acvmWorkingDirectory,
467
464
  this.config.acvmBinaryPath,
468
465
  outputWitnessFile,
466
+ logger,
469
467
  );
470
468
 
471
469
  const artifact = getServerCircuitArtifact(circuitType);
@@ -530,11 +528,10 @@ export class BBNativeRollupProver implements ServerCircuitProver {
530
528
 
531
529
  private async createAvmProof(
532
530
  input: AvmCircuitInputs,
533
- ): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
531
+ ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
534
532
  const operation = async (bbWorkingDirectory: string) => {
535
533
  const provingResult = await this.generateAvmProofWithBB(input, bbWorkingDirectory);
536
534
 
537
- const avmVK = await extractAvmVkData(provingResult.vkDirectoryPath!);
538
535
  const avmProof = await this.readAvmProofAsFields(provingResult.proofPath!);
539
536
 
540
537
  const circuitType = 'avm-circuit' as const;
@@ -557,7 +554,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
557
554
  } satisfies CircuitProvingStats,
558
555
  );
559
556
 
560
- return makeProofAndVerificationKey(avmProof, avmVK);
557
+ return avmProof;
561
558
  };
562
559
  return await this.runInDirectory(operation);
563
560
  }
@@ -631,28 +628,19 @@ export class BBNativeRollupProver implements ServerCircuitProver {
631
628
  */
632
629
  public async verifyProof(circuitType: ServerProtocolArtifact, proof: Proof) {
633
630
  const verificationKey = this.getVerificationKeyDataForCircuit(circuitType);
634
- return await this.verifyWithKey(getUltraHonkFlavorForCircuit(circuitType), verificationKey, proof);
635
- }
636
-
637
- public async verifyAvmProof(
638
- proof: Proof,
639
- verificationKey: VerificationKeyData,
640
- publicInputs: AvmCircuitPublicInputs,
641
- ) {
642
- return await this.verifyWithKeyInternal(proof, verificationKey, (proofPath, vkPath) =>
643
- verifyAvmProof(this.config.bbBinaryPath, this.config.bbWorkingDirectory, proofPath, publicInputs, vkPath, logger),
631
+ return await this.verifyInternal(proof, verificationKey, (proofPath, vkPath) =>
632
+ verifyProof(this.config.bbBinaryPath, proofPath, vkPath, getUltraHonkFlavorForCircuit(circuitType), logger),
644
633
  );
645
634
  }
646
635
 
647
- public async verifyWithKey(flavor: UltraHonkFlavor, verificationKey: VerificationKeyData, proof: Proof) {
648
- return await this.verifyWithKeyInternal(proof, verificationKey, (proofPath, vkPath) =>
649
- verifyProof(this.config.bbBinaryPath, proofPath, vkPath, flavor, logger),
636
+ public async verifyAvmProof(proof: Proof, publicInputs: AvmCircuitPublicInputs) {
637
+ return await this.verifyInternal(proof, /*verificationKey=*/ undefined, (proofPath, /*unused*/ _vkPath) =>
638
+ verifyAvmProof(this.config.bbBinaryPath, this.config.bbWorkingDirectory, proofPath, publicInputs, logger),
650
639
  );
651
640
  }
652
-
653
- private async verifyWithKeyInternal(
641
+ private async verifyInternal(
654
642
  proof: Proof,
655
- verificationKey: { keyAsBytes: Buffer },
643
+ verificationKey: { keyAsBytes: Buffer } | undefined,
656
644
  verificationFunction: (proofPath: string, vkPath: string) => Promise<BBFailure | BBSuccess>,
657
645
  ) {
658
646
  const operation = async (bbWorkingDirectory: string) => {
@@ -660,11 +648,13 @@ export class BBNativeRollupProver implements ServerCircuitProver {
660
648
  const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
661
649
  const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
662
650
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/13189): Put this proof parsing logic in the proof class.
663
- await fs.writeFile(publicInputsFileName, proof.buffer.slice(0, proof.numPublicInputs * 32));
664
- await fs.writeFile(proofFileName, proof.buffer.slice(proof.numPublicInputs * 32));
665
- await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
651
+ await fs.writeFile(publicInputsFileName, proof.buffer.subarray(0, proof.numPublicInputs * 32));
652
+ await fs.writeFile(proofFileName, proof.buffer.subarray(proof.numPublicInputs * 32));
653
+ if (verificationKey !== undefined) {
654
+ await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
655
+ }
666
656
 
667
- const result = await verificationFunction(proofFileName, verificationKeyPath!);
657
+ const result = await verificationFunction(proofFileName, verificationKeyPath);
668
658
 
669
659
  if (result.status === BB_RESULT.FAILURE) {
670
660
  const errorMessage = `Failed to verify proof from key!`;
@@ -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,
@@ -43,5 +43,5 @@ export const PROOF_DELAY_MS: Record<ProvingRequestType, number> = {
43
43
  [ProvingRequestType.BLOCK_ROOT_SINGLE_TX_ROLLUP]: 15_000,
44
44
  [ProvingRequestType.CHECKPOINT_ROOT_ROLLUP]: 35_000,
45
45
  [ProvingRequestType.CHECKPOINT_PADDING_ROLLUP]: 0,
46
- [ProvingRequestType.PRIVATE_TX_BASE_ROLLUP]: 45_000, // Guess based on public
46
+ [ProvingRequestType.PRIVATE_TX_BASE_ROLLUP]: 22_000,
47
47
  };
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
3
- AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED,
4
3
  NESTED_RECURSIVE_PROOF_LENGTH,
5
4
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
6
5
  RECURSIVE_PROOF_LENGTH,
@@ -51,14 +50,18 @@ import type { WitnessMap } from '@aztec/noir-types';
51
50
  import { type CircuitSimulator, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator/server';
52
51
  import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
53
52
  import {
54
- type ProofAndVerificationKey,
55
53
  type PublicInputsAndRecursiveProof,
56
54
  type ServerCircuitProver,
57
- makeProofAndVerificationKey,
58
55
  makePublicInputsAndRecursiveProof,
59
56
  } from '@aztec/stdlib/interfaces/server';
60
57
  import type { ParityBasePrivateInputs, ParityPublicInputs, ParityRootPrivateInputs } from '@aztec/stdlib/parity';
61
- import { type Proof, ProvingRequestType, makeEmptyRecursiveProof, makeRecursiveProof } from '@aztec/stdlib/proofs';
58
+ import {
59
+ type Proof,
60
+ ProvingRequestType,
61
+ RecursiveProof,
62
+ makeEmptyRecursiveProof,
63
+ makeRecursiveProof,
64
+ } from '@aztec/stdlib/proofs';
62
65
  import {
63
66
  type BlockMergeRollupPrivateInputs,
64
67
  type BlockRollupPublicInputs,
@@ -81,7 +84,6 @@ import {
81
84
  type TxMergeRollupPrivateInputs,
82
85
  type TxRollupPublicInputs,
83
86
  } from '@aztec/stdlib/rollup';
84
- import { VerificationKeyData } from '@aztec/stdlib/vks';
85
87
  import { type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
86
88
 
87
89
  import { ProverInstrumentation } from '../instrumentation.js';
@@ -400,17 +402,12 @@ export class TestCircuitProver implements ServerCircuitProver {
400
402
  );
401
403
  }
402
404
 
403
- public getAvmProof(
404
- _inputs: AvmCircuitInputs,
405
- ): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
405
+ public getAvmProof(_inputs: AvmCircuitInputs): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
406
406
  // We can't simulate the AVM because we don't have enough context to do so (e.g., DBs).
407
- // We just return an empty proof and VK data.
407
+ // We just return an empty proof.
408
408
  this.logger.debug('Skipping AVM simulation in TestCircuitProver.');
409
409
  return this.applyDelay(ProvingRequestType.PUBLIC_VM, () =>
410
- makeProofAndVerificationKey(
411
- makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED),
412
- VerificationKeyData.makeFake(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED),
413
- ),
410
+ makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED),
414
411
  );
415
412
  }
416
413
 
@@ -1,9 +1,7 @@
1
- import { AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED } from '@aztec/constants';
2
1
  import { Fr } from '@aztec/foundation/curves/bn254';
3
2
  import { BufferReader } from '@aztec/foundation/serialize';
4
3
  import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks';
5
4
 
6
- import { strict as assert } from 'assert';
7
5
  import { promises as fs } from 'fs';
8
6
  import * as path from 'path';
9
7
 
@@ -25,26 +23,3 @@ export async function extractVkData(vkDirectoryPath: string): Promise<Verificati
25
23
  const vkAsFields = await VerificationKeyAsFields.fromKey(fields);
26
24
  return new VerificationKeyData(vkAsFields, rawBinary);
27
25
  }
28
-
29
- /**
30
- * Reads the verification key data stored in a binary file at the specified directory location and parses into a VerificationKeyData.
31
- * We do not assume any JSON file available but only the binary version, contrary to the above extractVkData() method.
32
- * @param vkDirectoryPath - The directory containing the verification key binary data file.
33
- * @returns The verification key data
34
- */
35
- export async function extractAvmVkData(vkDirectoryPath: string): Promise<VerificationKeyData> {
36
- const rawBinary = await fs.readFile(path.join(vkDirectoryPath, VK_FILENAME));
37
-
38
- const numFields = rawBinary.length / Fr.SIZE_IN_BYTES;
39
- assert(numFields <= AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED, 'Invalid AVM verification key length');
40
- const reader = BufferReader.asReader(rawBinary);
41
- const fieldsArray = reader.readArray(numFields, Fr);
42
-
43
- const fieldsArrayPadded = fieldsArray.concat(
44
- Array(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED - fieldsArray.length).fill(new Fr(0)),
45
- );
46
- const vkAsFields = await VerificationKeyAsFields.fromKey(fieldsArrayPadded);
47
- // TODO(#16644): We should have a different type for AVM verification keys since we don't have circuit size or num public inputs in AVM VKs.
48
- const vk = new VerificationKeyData(vkAsFields, rawBinary);
49
- return vk;
50
- }
@@ -102,10 +102,6 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
102
102
 
103
103
  // Block below is almost copy-pasted from verifyProofForCircuit
104
104
  const operation = async (bbWorkingDirectory: string) => {
105
- const logFunction = (message: string) => {
106
- this.logger.debug(`${proofType} BB out - ${message}`);
107
- };
108
-
109
105
  const proofPath = path.join(bbWorkingDirectory, PROOF_FILENAME);
110
106
  await writeChonkProofToPath(tx.chonkProof.attachPublicInputs(tx.data.publicInputs().toFields()), proofPath);
111
107
 
@@ -118,7 +114,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
118
114
  this.config.bbBinaryPath,
119
115
  proofPath,
120
116
  verificationKeyPath,
121
- logFunction,
117
+ this.logger,
122
118
  this.config.bbIVCConcurrency,
123
119
  );
124
120
  verificationDuration = timer.ms();
@@ -10,7 +10,7 @@ import {
10
10
  type ObservableGauge,
11
11
  type TelemetryClient,
12
12
  type UpDownCounter,
13
- ValueType,
13
+ createUpDownCounterWithDefault,
14
14
  getTelemetryClient,
15
15
  } from '@aztec/telemetry-client';
16
16
 
@@ -36,49 +36,18 @@ class IVCVerifierMetrics {
36
36
  constructor(client: TelemetryClient, name = 'QueuedIVCVerifier') {
37
37
  const meter = client.getMeter(name);
38
38
 
39
- this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME, {
40
- unit: 'ms',
41
- description: 'Duration to verify chonk proofs',
42
- valueType: ValueType.INT,
43
- });
39
+ this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME);
44
40
 
45
- this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME, {
46
- unit: 'ms',
47
- description: 'Total duration to verify chonk proofs, including serde',
48
- valueType: ValueType.INT,
49
- });
41
+ this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME);
50
42
 
51
- this.ivcFailureCount = meter.createUpDownCounter(Metrics.IVC_VERIFIER_FAILURE_COUNT, {
52
- description: 'Count of failed IVC proof verifications',
53
- valueType: ValueType.INT,
54
- });
43
+ this.ivcFailureCount = createUpDownCounterWithDefault(meter, Metrics.IVC_VERIFIER_FAILURE_COUNT);
55
44
 
56
45
  this.aggDurationMetrics = {
57
- avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG, {
58
- valueType: ValueType.DOUBLE,
59
- description: 'AVG ivc verification',
60
- unit: 'ms',
61
- }),
62
- max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX, {
63
- valueType: ValueType.DOUBLE,
64
- description: 'MAX ivc verification',
65
- unit: 'ms',
66
- }),
67
- min: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MIN, {
68
- valueType: ValueType.DOUBLE,
69
- description: 'MIN ivc verification',
70
- unit: 'ms',
71
- }),
72
- p50: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P50, {
73
- valueType: ValueType.DOUBLE,
74
- description: 'P50 ivc verification',
75
- unit: 'ms',
76
- }),
77
- p90: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P90, {
78
- valueType: ValueType.DOUBLE,
79
- description: 'P90 ivc verification',
80
- unit: 'ms',
81
- }),
46
+ avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG),
47
+ max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX),
48
+ min: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MIN),
49
+ p50: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P50),
50
+ p90: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P90),
82
51
  };
83
52
 
84
53
  meter.addBatchObservableCallback(this.aggregate, Object.values(this.aggDurationMetrics));