@aztec/bb-prover 0.87.1 → 0.87.2-nightly.20250523

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
- AVM_PROOF_LENGTH_IN_FIELDS,
3
- AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS,
2
+ AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
3
+ AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED,
4
4
  NESTED_RECURSIVE_PROOF_LENGTH,
5
5
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
6
6
  RECURSIVE_PROOF_LENGTH,
@@ -302,14 +302,16 @@ export class TestCircuitProver implements ServerCircuitProver {
302
302
  );
303
303
  }
304
304
 
305
- public getAvmProof(_inputs: AvmCircuitInputs): Promise<ProofAndVerificationKey<typeof AVM_PROOF_LENGTH_IN_FIELDS>> {
305
+ public getAvmProof(
306
+ _inputs: AvmCircuitInputs,
307
+ ): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
306
308
  // We can't simulate the AVM because we don't have enough context to do so (e.g., DBs).
307
309
  // We just return an empty proof and VK data.
308
310
  this.logger.debug('Skipping AVM simulation in TestCircuitProver.');
309
311
  return this.applyDelay(ProvingRequestType.PUBLIC_VM, () =>
310
312
  makeProofAndVerificationKey(
311
- makeEmptyRecursiveProof(AVM_PROOF_LENGTH_IN_FIELDS),
312
- VerificationKeyData.makeFake(AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS),
313
+ makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED),
314
+ VerificationKeyData.makeFake(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED),
313
315
  ),
314
316
  );
315
317
  }
@@ -1,5 +1,6 @@
1
- import { AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS } from '@aztec/constants';
1
+ import { AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED } from '@aztec/constants';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
+ import { BufferReader } from '@aztec/foundation/serialize';
3
4
  import { hashVK } from '@aztec/stdlib/hash';
4
5
  import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks';
5
6
 
@@ -27,19 +28,25 @@ export async function extractVkData(vkDirectoryPath: string): Promise<Verificati
27
28
  return new VerificationKeyData(vkAsFields, rawBinary);
28
29
  }
29
30
 
30
- // TODO: This was adapted from the above function. A refactor might be needed.
31
+ /**
32
+ * Reads the verification key data stored in a binary file at the specified directory location and parses into a VerificationKeyData.
33
+ * We do not assume any JSON file available but only the binary version, contrary to the above extractVkData() method.
34
+ * @param vkDirectoryPath - The directory containing the verification key binary data file.
35
+ * @returns The verification key data
36
+ */
31
37
  export async function extractAvmVkData(vkDirectoryPath: string): Promise<VerificationKeyData> {
32
- const [rawFields, rawBinary] = await Promise.all([
33
- fs.readFile(path.join(vkDirectoryPath, VK_FIELDS_FILENAME), { encoding: 'utf-8' }),
34
- fs.readFile(path.join(vkDirectoryPath, VK_FILENAME)),
35
- ]);
36
- const fieldsJson = JSON.parse(rawFields);
37
- const fields = fieldsJson.map(Fr.fromHexString);
38
- // The first item is the hash, this is not part of the actual VK
39
- // TODO: is the above actually the case?
40
- const vkHash = fields[0];
41
- assert(fields.length === AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, 'Invalid AVM verification key length');
42
- const vkAsFields = new VerificationKeyAsFields(fields, vkHash);
38
+ const rawBinary = await fs.readFile(path.join(vkDirectoryPath, VK_FILENAME));
39
+
40
+ const numFields = rawBinary.length / Fr.SIZE_IN_BYTES;
41
+ assert(numFields <= AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED, 'Invalid AVM verification key length');
42
+ const reader = BufferReader.asReader(rawBinary);
43
+ const fieldsArray = reader.readArray(numFields, Fr);
44
+
45
+ const fieldsArrayPadded = fieldsArray.concat(
46
+ Array(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED - fieldsArray.length).fill(new Fr(0)),
47
+ );
48
+ // Currently, we do not need the vk hash for the AVM as we are not adding in the vk tree.
49
+ const vkAsFields = new VerificationKeyAsFields(fieldsArrayPadded, new Fr(0));
43
50
  const vk = new VerificationKeyData(vkAsFields, rawBinary);
44
51
  return vk;
45
52
  }