@aztec/bb-prover 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928

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 (62) 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 +153 -111
  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 +385 -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/prover/client/bb_private_kernel_prover.d.ts +12 -4
  19. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  20. package/dest/prover/client/bb_private_kernel_prover.js +46 -10
  21. package/dest/prover/proof_utils.d.ts +11 -1
  22. package/dest/prover/proof_utils.d.ts.map +1 -1
  23. package/dest/prover/proof_utils.js +24 -1
  24. package/dest/prover/server/bb_prover.d.ts +6 -7
  25. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  26. package/dest/prover/server/bb_prover.js +210 -79
  27. package/dest/test/test_circuit_prover.d.ts +3 -3
  28. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  29. package/dest/test/test_circuit_prover.js +2 -2
  30. package/dest/verification_key/verification_key_data.js +1 -1
  31. package/dest/verifier/batch_chonk_verifier.d.ts +46 -0
  32. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  33. package/dest/verifier/batch_chonk_verifier.js +237 -0
  34. package/dest/verifier/bb_verifier.d.ts +4 -1
  35. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  36. package/dest/verifier/bb_verifier.js +134 -45
  37. package/dest/verifier/index.d.ts +2 -1
  38. package/dest/verifier/index.d.ts.map +1 -1
  39. package/dest/verifier/index.js +1 -0
  40. package/dest/verifier/queued_chonk_verifier.d.ts +14 -3
  41. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  42. package/dest/verifier/queued_chonk_verifier.js +7 -6
  43. package/package.json +19 -17
  44. package/src/avm_proving_tests/avm_proving_tester.ts +54 -127
  45. package/src/bb/bb_js_backend.ts +441 -0
  46. package/src/bb/bb_js_debug.ts +227 -0
  47. package/src/bb/file_names.ts +6 -0
  48. package/src/config.ts +16 -0
  49. package/src/index.ts +2 -1
  50. package/src/prover/client/bb_private_kernel_prover.ts +133 -18
  51. package/src/prover/proof_utils.ts +41 -1
  52. package/src/prover/server/bb_prover.ts +130 -141
  53. package/src/test/test_circuit_prover.ts +3 -5
  54. package/src/verification_key/verification_key_data.ts +1 -1
  55. package/src/verifier/batch_chonk_verifier.ts +281 -0
  56. package/src/verifier/bb_verifier.ts +66 -76
  57. package/src/verifier/index.ts +1 -0
  58. package/src/verifier/queued_chonk_verifier.ts +8 -8
  59. package/dest/bb/execute.d.ts +0 -108
  60. package/dest/bb/execute.d.ts.map +0 -1
  61. package/dest/bb/execute.js +0 -652
  62. package/src/bb/execute.ts +0 -687
@@ -1,5 +1,5 @@
1
1
  import {
2
- AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
2
+ AVM_V2_PROOF_LENGTH_IN_FIELDS,
3
3
  NESTED_RECURSIVE_PROOF_LENGTH,
4
4
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
5
  PAIRING_POINTS_SIZE,
@@ -9,7 +9,6 @@ import {
9
9
  import { Fr } from '@aztec/foundation/curves/bn254';
10
10
  import { runInDirectory } from '@aztec/foundation/fs';
11
11
  import { createLogger } from '@aztec/foundation/log';
12
- import { BufferReader } from '@aztec/foundation/serialize';
13
12
  import {
14
13
  type ServerProtocolArtifact,
15
14
  convertBlockMergeRollupOutputsFromWitnessMap,
@@ -88,24 +87,14 @@ import { VerificationKeyData } from '@aztec/stdlib/vks';
88
87
  import { Attributes, type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
89
88
 
90
89
  import { promises as fs } from 'fs';
90
+ import { ungzip } from 'pako';
91
91
  import * as path from 'path';
92
92
 
93
- import {
94
- type BBFailure,
95
- type BBSuccess,
96
- BB_RESULT,
97
- PROOF_FILENAME,
98
- PUBLIC_INPUTS_FILENAME,
99
- VK_FILENAME,
100
- generateAvmProof,
101
- generateProof,
102
- verifyAvmProof,
103
- verifyProof,
104
- } from '../../bb/execute.js';
93
+ import { BBJsFactory, type BBJsProofResult } from '../../bb/bb_js_backend.js';
105
94
  import type { ACVMConfig, BBConfig } from '../../config.js';
106
95
  import { getUltraHonkFlavorForCircuit } from '../../honk.js';
107
96
  import { ProverInstrumentation } from '../../instrumentation.js';
108
- import { readProofsFromOutputDirectory } from '../proof_utils.js';
97
+ import { constructRecursiveProofFromBuffers } from '../proof_utils.js';
109
98
 
110
99
  const logger = createLogger('bb-prover');
111
100
 
@@ -119,12 +108,14 @@ export interface BBProverConfig extends BBConfig, ACVMConfig {
119
108
  */
120
109
  export class BBNativeRollupProver implements ServerCircuitProver {
121
110
  private instrumentation: ProverInstrumentation;
111
+ private bbJsFactory: BBJsFactory;
122
112
 
123
113
  constructor(
124
114
  private config: BBProverConfig,
125
115
  telemetry: TelemetryClient,
126
116
  ) {
127
117
  this.instrumentation = new ProverInstrumentation(telemetry, 'BBNativeRollupProver');
118
+ this.bbJsFactory = new BBJsFactory(config.bbBinaryPath, { logger, debugDir: config.bbDebugOutputDir });
128
119
  }
129
120
 
130
121
  get tracer() {
@@ -136,7 +127,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
136
127
  await fs.mkdir(config.acvmWorkingDirectory, { recursive: true });
137
128
  await fs.access(config.bbBinaryPath, fs.constants.R_OK);
138
129
  await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
139
- logger.info(`Using native BB at ${config.bbBinaryPath} and working directory ${config.bbWorkingDirectory}`);
130
+ logger.info(`Using bb.js API with binary at ${config.bbBinaryPath}`);
140
131
  logger.info(`Using native ACVM at ${config.acvmBinaryPath} and working directory ${config.acvmWorkingDirectory}`);
141
132
 
142
133
  return new BBNativeRollupProver(config, telemetry);
@@ -186,9 +177,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
186
177
  @trackSpan('BBNativeRollupProver.getAvmProof', inputs => ({
187
178
  [Attributes.APP_CIRCUIT_NAME]: inputs.hints.tx.hash,
188
179
  }))
189
- public async getAvmProof(
190
- inputs: AvmCircuitInputs,
191
- ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
180
+ public async getAvmProof(inputs: AvmCircuitInputs): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>> {
192
181
  const proof = await this.createAvmProof(inputs);
193
182
  await this.verifyAvmProof(proof.binaryProof, inputs.publicInputs);
194
183
  return proof;
@@ -453,12 +442,11 @@ export class BBNativeRollupProver implements ServerCircuitProver {
453
442
  convertInput: (input: Input) => WitnessMap,
454
443
  convertOutput: (outputWitness: WitnessMap) => Output,
455
444
  workingDirectory: string,
456
- ): Promise<{ circuitOutput: Output; provingResult: BBSuccess }> {
457
- // Have the ACVM write the partial witness here
445
+ ): Promise<{ circuitOutput: Output; proofResult: BBJsProofResult }> {
446
+ // Have the ACVM write the partial witness here (still needs a temp directory)
458
447
  const outputWitnessFile = path.join(workingDirectory, 'partial-witness.gz');
459
448
 
460
449
  // Generate the partial witness using the ACVM
461
- // A further temp directory will be created beneath ours and then cleaned up after the partial witness has been copied to our specified location
462
450
  const simulator = new NativeACVMSimulator(
463
451
  this.config.acvmWorkingDirectory,
464
452
  this.config.acvmBinaryPath,
@@ -471,7 +459,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
471
459
  logger.debug(`Generating witness data for ${circuitType}`);
472
460
 
473
461
  const inputWitness = convertInput(input);
474
- const foreignCallHandler = undefined; // We don't handle foreign calls in the native ACVM simulator
462
+ const foreignCallHandler = undefined;
475
463
  const witnessResult = await simulator.executeProtocolCircuit(inputWitness, artifact, foreignCallHandler);
476
464
  const output = convertOutput(witnessResult.witness);
477
465
 
@@ -488,75 +476,74 @@ export class BBNativeRollupProver implements ServerCircuitProver {
488
476
  eventName: 'circuit-witness-generation',
489
477
  } satisfies CircuitWitnessGenerationStats);
490
478
 
491
- // Now prove the circuit from the generated witness
492
- logger.debug(`Proving ${circuitType}...`);
479
+ // Read and decompress the witness for bb.js
480
+ const witnessGz = await fs.readFile(outputWitnessFile);
481
+ const witness = ungzip(witnessGz);
493
482
 
494
- const provingResult = await generateProof(
495
- this.config.bbBinaryPath,
496
- workingDirectory,
497
- circuitType,
498
- Buffer.from(artifact.bytecode, 'base64'),
499
- this.getVerificationKeyDataForCircuit(circuitType).keyAsBytes,
500
- outputWitnessFile,
501
- getUltraHonkFlavorForCircuit(circuitType),
502
- logger,
503
- );
483
+ // Decompress bytecode for bb.js
484
+ const bytecode = ungzip(Buffer.from(artifact.bytecode, 'base64'));
485
+
486
+ // Prove the circuit via bb.js API
487
+ logger.debug(`Proving ${circuitType} via bb.js...`);
504
488
 
505
- if (provingResult.status === BB_RESULT.FAILURE) {
506
- logger.error(`Failed to generate proof for ${circuitType}: ${provingResult.reason}`);
507
- throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
489
+ let proofResult: BBJsProofResult;
490
+ try {
491
+ await using instance = await this.bbJsFactory.getInstance();
492
+ proofResult = await instance.generateProof(
493
+ circuitType,
494
+ bytecode,
495
+ this.getVerificationKeyDataForCircuit(circuitType).keyAsBytes,
496
+ witness,
497
+ getUltraHonkFlavorForCircuit(circuitType),
498
+ );
499
+ } catch (error) {
500
+ // Preserve retryability of the underlying failure (e.g. a transient bb startup error).
501
+ const retry = error instanceof ProvingError && error.retry;
502
+ throw new ProvingError(`Failed to generate proof for ${circuitType}: ${error}`, error, retry);
508
503
  }
509
504
 
510
505
  return {
511
506
  circuitOutput: output,
512
- provingResult,
507
+ proofResult,
513
508
  };
514
509
  }
515
510
 
516
- private async generateAvmProofWithBB(input: AvmCircuitInputs, workingDirectory: string): Promise<BBSuccess> {
511
+ private async createAvmProof(input: AvmCircuitInputs): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>> {
517
512
  logger.info(`Proving avm-circuit for TX ${input.hints.tx.hash}...`);
518
513
 
519
- const provingResult = await generateAvmProof(this.config.bbBinaryPath, workingDirectory, input, logger);
514
+ const inputsBuffer = input.serializeWithMessagePack();
515
+ await using instance = await this.bbJsFactory.getInstance();
516
+ const { proof: proofFieldArrays, durationMs } = await instance.generateAvmProof(inputsBuffer);
520
517
 
521
- if (provingResult.status === BB_RESULT.FAILURE) {
522
- logger.error(`Failed to generate AVM proof for TX ${input.hints.tx.hash}: ${provingResult.reason}`);
523
- throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
524
- }
518
+ // Convert Uint8Array[] (32-byte field elements) to Fr[]
519
+ const proofFields = proofFieldArrays.map(f => Fr.fromBuffer(Buffer.from(f)));
525
520
 
526
- return provingResult;
527
- }
521
+ if (proofFields.length !== AVM_V2_PROOF_LENGTH_IN_FIELDS) {
522
+ throw new Error(`Proof has ${proofFields.length} fields, expected exactly ${AVM_V2_PROOF_LENGTH_IN_FIELDS}.`);
523
+ }
528
524
 
529
- private async createAvmProof(
530
- input: AvmCircuitInputs,
531
- ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
532
- const operation = async (bbWorkingDirectory: string) => {
533
- const provingResult = await this.generateAvmProofWithBB(input, bbWorkingDirectory);
525
+ // Build the binary proof from the raw field data
526
+ const rawProofBuffer = Buffer.concat(proofFieldArrays.map(f => Buffer.from(f)));
527
+ const binaryProof = new Proof(rawProofBuffer, /*numPublicInputs=*/ 0);
528
+ const avmProof = new RecursiveProof(proofFields, binaryProof, true, AVM_V2_PROOF_LENGTH_IN_FIELDS);
534
529
 
535
- const avmProof = await this.readAvmProofAsFields(provingResult.proofPath!);
530
+ const circuitType = 'avm-circuit' as const;
531
+ const appCircuitName = 'unknown' as const;
532
+ this.instrumentation.recordAvmDuration('provingDuration', appCircuitName, durationMs);
533
+ this.instrumentation.recordAvmSize('proofSize', appCircuitName, avmProof.binaryProof.buffer.length);
536
534
 
537
- const circuitType = 'avm-circuit' as const;
538
- const appCircuitName = 'unknown' as const;
539
- this.instrumentation.recordAvmDuration('provingDuration', appCircuitName, provingResult.durationMs);
540
- this.instrumentation.recordAvmSize('proofSize', appCircuitName, avmProof.binaryProof.buffer.length);
535
+ logger.info(`Generated proof for ${circuitType}(${input.hints.tx.hash}) in ${Math.ceil(durationMs)} ms`, {
536
+ circuitName: circuitType,
537
+ appCircuitName: input.hints.tx.hash,
538
+ duration: durationMs,
539
+ proofSize: avmProof.binaryProof.buffer.length,
540
+ eventName: 'circuit-proving',
541
+ inputSize: inputsBuffer.length,
542
+ circuitSize: 1 << 21,
543
+ numPublicInputs: 0,
544
+ } satisfies CircuitProvingStats);
541
545
 
542
- logger.info(
543
- `Generated proof for ${circuitType}(${input.hints.tx.hash}) in ${Math.ceil(provingResult.durationMs)} ms`,
544
- {
545
- circuitName: circuitType,
546
- appCircuitName: input.hints.tx.hash,
547
- // does not include reading the proof from disk
548
- duration: provingResult.durationMs,
549
- proofSize: avmProof.binaryProof.buffer.length,
550
- eventName: 'circuit-proving',
551
- inputSize: input.serializeWithMessagePack().length,
552
- circuitSize: 1 << 21,
553
- numPublicInputs: 0,
554
- } satisfies CircuitProvingStats,
555
- );
556
-
557
- return avmProof;
558
- };
559
- return await this.runInDirectory(operation);
546
+ return avmProof;
560
547
  }
561
548
 
562
549
  /**
@@ -579,33 +566,38 @@ export class BBNativeRollupProver implements ServerCircuitProver {
579
566
  convertInput: (input: CircuitInputType) => WitnessMap,
580
567
  convertOutput: (outputWitness: WitnessMap) => CircuitOutputType,
581
568
  ): Promise<{ circuitOutput: CircuitOutputType; proof: RecursiveProof<PROOF_LENGTH> }> {
582
- // this probably is gonna need to call chonk
583
- const operation = async (bbWorkingDirectory: string) => {
584
- const { provingResult, circuitOutput: output } = await this.generateProofWithBB(
569
+ // Still need runInDirectory for ACVM witness generation temp files
570
+ const operation = async (workingDirectory: string) => {
571
+ const { proofResult, circuitOutput: output } = await this.generateProofWithBB(
585
572
  input,
586
573
  circuitType,
587
574
  convertInput,
588
575
  convertOutput,
589
- bbWorkingDirectory,
576
+ workingDirectory,
590
577
  );
591
578
 
592
579
  const vkData = this.getVerificationKeyDataForCircuit(circuitType);
593
- // Read the proof as fields
594
- const proof = await readProofsFromOutputDirectory(provingResult.proofPath!, vkData, proofLength, logger);
580
+ // Construct proof from in-memory buffers (no file I/O needed)
581
+ const proof = constructRecursiveProofFromBuffers(
582
+ proofResult.proofFields,
583
+ proofResult.publicInputFields,
584
+ vkData,
585
+ proofLength,
586
+ );
595
587
 
596
588
  const circuitName = mapProtocolArtifactNameToCircuitName(circuitType);
597
- this.instrumentation.recordDuration('provingDuration', circuitName, provingResult.durationMs);
589
+ this.instrumentation.recordDuration('provingDuration', circuitName, proofResult.durationMs);
598
590
  this.instrumentation.recordSize('proofSize', circuitName, proof.binaryProof.buffer.length);
599
591
  this.instrumentation.recordSize('circuitPublicInputCount', circuitName, vkData.numPublicInputs);
600
592
  this.instrumentation.recordSize('circuitSize', circuitName, vkData.circuitSize);
601
593
  logger.info(
602
- `Generated proof for ${circuitType} in ${Math.ceil(provingResult.durationMs)} ms, size: ${
594
+ `Generated proof for ${circuitType} in ${Math.ceil(proofResult.durationMs)} ms, size: ${
603
595
  proof.proof.length
604
596
  } fields`,
605
597
  {
606
598
  circuitName,
607
599
  circuitSize: vkData.circuitSize,
608
- duration: provingResult.durationMs,
600
+ duration: proofResult.durationMs,
609
601
  inputSize: output.toBuffer().length,
610
602
  proofSize: proof.binaryProof.buffer.length,
611
603
  eventName: 'circuit-proving',
@@ -622,49 +614,60 @@ export class BBNativeRollupProver implements ServerCircuitProver {
622
614
  }
623
615
 
624
616
  /**
625
- * Verifies a proof, will generate the verification key if one is not cached internally
617
+ * Verifies a proof via bb.js API (no temp files needed).
626
618
  * @param circuitType - The type of circuit whose proof is to be verified
627
619
  * @param proof - The proof to be verified
628
620
  */
629
621
  public async verifyProof(circuitType: ServerProtocolArtifact, proof: Proof) {
630
622
  const verificationKey = this.getVerificationKeyDataForCircuit(circuitType);
631
- return await this.verifyInternal(proof, verificationKey, (proofPath, vkPath) =>
632
- verifyProof(this.config.bbBinaryPath, proofPath, vkPath, getUltraHonkFlavorForCircuit(circuitType), logger),
633
- );
623
+ const flavor = getUltraHonkFlavorForCircuit(circuitType);
624
+
625
+ // Split proof buffer into public input fields and proof fields (32-byte each)
626
+ const publicInputFields = splitBufferToFieldArrays(proof.buffer.subarray(0, proof.numPublicInputs * 32));
627
+ const proofFields = splitBufferToFieldArrays(proof.buffer.subarray(proof.numPublicInputs * 32));
628
+
629
+ let verified: boolean;
630
+ let durationMs: number;
631
+ try {
632
+ await using instance = await this.bbJsFactory.getInstance();
633
+ ({ verified, durationMs } = await instance.verifyProof(
634
+ proofFields,
635
+ verificationKey.keyAsBytes,
636
+ publicInputFields,
637
+ flavor,
638
+ ));
639
+ } catch (error) {
640
+ // Preserve retryability of the underlying failure (e.g. a transient bb startup error).
641
+ const retry = error instanceof ProvingError && error.retry;
642
+ throw new ProvingError(`Failed to verify proof for ${circuitType}: ${error}`, error, retry);
643
+ }
644
+
645
+ if (!verified) {
646
+ throw new ProvingError('Failed to verify proof from key!');
647
+ }
648
+
649
+ logger.info(`Successfully verified proof from key in ${durationMs} ms`);
634
650
  }
635
651
 
652
+ /** Verify an AVM proof via bb.js API. */
636
653
  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),
639
- );
640
- }
641
- private async verifyInternal(
642
- proof: Proof,
643
- verificationKey: { keyAsBytes: Buffer } | undefined,
644
- verificationFunction: (proofPath: string, vkPath: string) => Promise<BBFailure | BBSuccess>,
645
- ) {
646
- const operation = async (bbWorkingDirectory: string) => {
647
- const publicInputsFileName = path.join(bbWorkingDirectory, PUBLIC_INPUTS_FILENAME);
648
- const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
649
- const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
650
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/13189): Put this proof parsing logic in the proof class.
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
- }
656
-
657
- const result = await verificationFunction(proofFileName, verificationKeyPath);
658
-
659
- if (result.status === BB_RESULT.FAILURE) {
660
- const errorMessage = `Failed to verify proof from key!`;
661
- throw new ProvingError(errorMessage, result, result.retry);
662
- }
663
-
664
- logger.info(`Successfully verified proof from key in ${result.durationMs} ms`);
665
- };
654
+ // For AVM proofs, numPublicInputs is 0, so the full buffer is the proof.
655
+ const proofBuffer = proof.buffer.subarray(proof.numPublicInputs * 32);
656
+ // Split the raw proof buffer into 32-byte field element arrays
657
+ const proofFields: Uint8Array[] = [];
658
+ for (let i = 0; i < proofBuffer.length; i += Fr.SIZE_IN_BYTES) {
659
+ proofFields.push(new Uint8Array(proofBuffer.subarray(i, i + Fr.SIZE_IN_BYTES)));
660
+ }
661
+ const piBuffer = publicInputs.serializeWithMessagePack();
662
+
663
+ await using instance = await this.bbJsFactory.getInstance();
664
+ const { verified, durationMs } = await instance.verifyAvmProof(proofFields, piBuffer);
665
+
666
+ if (!verified) {
667
+ throw new ProvingError('Failed to verify AVM proof!');
668
+ }
666
669
 
667
- await this.runInDirectory(operation);
670
+ logger.info(`Successfully verified AVM proof in ${durationMs} ms`);
668
671
  }
669
672
 
670
673
  /**
@@ -680,29 +683,6 @@ export class BBNativeRollupProver implements ServerCircuitProver {
680
683
  return vk;
681
684
  }
682
685
 
683
- private async readAvmProofAsFields(
684
- proofFilename: string,
685
- ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
686
- const rawProofBuffer = await fs.readFile(proofFilename);
687
- const reader = BufferReader.asReader(rawProofBuffer);
688
- const proofFields = reader.readArray(rawProofBuffer.length / Fr.SIZE_IN_BYTES, Fr);
689
-
690
- // We extend to a fixed-size padded proof as during development any new AVM circuit column changes the
691
- // proof length and we do not have a mechanism to feedback a cpp constant to noir/TS.
692
- // TODO(#13390): Revive a non-padded AVM proof
693
- if (proofFields.length > AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED) {
694
- throw new Error(
695
- `Proof has ${proofFields.length} fields, expected no more than ${AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED}.`,
696
- );
697
- }
698
- const proofFieldsPadded = proofFields.concat(
699
- Array(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED - proofFields.length).fill(new Fr(0)),
700
- );
701
-
702
- const proof = new Proof(rawProofBuffer, /*numPublicInputs=*/ 0);
703
- return new RecursiveProof(proofFieldsPadded, proof, true, AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED);
704
- }
705
-
706
686
  private runInDirectory<T>(fn: (dir: string) => Promise<T>) {
707
687
  return runInDirectory(
708
688
  this.config.bbWorkingDirectory,
@@ -716,3 +696,12 @@ export class BBNativeRollupProver implements ServerCircuitProver {
716
696
  );
717
697
  }
718
698
  }
699
+
700
+ /** Split a buffer into 32-byte Uint8Array field elements. */
701
+ function splitBufferToFieldArrays(buffer: Buffer): Uint8Array[] {
702
+ const fields: Uint8Array[] = [];
703
+ for (let i = 0; i < buffer.length; i += 32) {
704
+ fields.push(new Uint8Array(buffer.subarray(i, i + 32)));
705
+ }
706
+ return fields;
707
+ }
@@ -1,5 +1,5 @@
1
1
  import {
2
- AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
2
+ AVM_V2_PROOF_LENGTH_IN_FIELDS,
3
3
  NESTED_RECURSIVE_PROOF_LENGTH,
4
4
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
5
  RECURSIVE_PROOF_LENGTH,
@@ -402,13 +402,11 @@ export class TestCircuitProver implements ServerCircuitProver {
402
402
  );
403
403
  }
404
404
 
405
- public getAvmProof(_inputs: AvmCircuitInputs): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
405
+ public getAvmProof(_inputs: AvmCircuitInputs): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>> {
406
406
  // We can't simulate the AVM because we don't have enough context to do so (e.g., DBs).
407
407
  // We just return an empty proof.
408
408
  this.logger.debug('Skipping AVM simulation in TestCircuitProver.');
409
- return this.applyDelay(ProvingRequestType.PUBLIC_VM, () =>
410
- makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED),
411
- );
409
+ return this.applyDelay(ProvingRequestType.PUBLIC_VM, () => makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS));
412
410
  }
413
411
 
414
412
  private async applyDelay<F extends () => any>(type: ProvingRequestType, fn: F): Promise<Awaited<ReturnType<F>>> {
@@ -5,7 +5,7 @@ import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks'
5
5
  import { promises as fs } from 'fs';
6
6
  import * as path from 'path';
7
7
 
8
- import { VK_FILENAME } from '../bb/execute.js';
8
+ import { VK_FILENAME } from '../bb/file_names.js';
9
9
 
10
10
  /**
11
11
  * Reads the verification key data stored at the specified location and parses into a VerificationKeyData