@aztec/bb-prover 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9

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 (95) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +7 -6
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +38 -15
  4. package/dest/bb/cli.d.ts +1 -1
  5. package/dest/bb/execute.d.ts +9 -17
  6. package/dest/bb/execute.d.ts.map +1 -1
  7. package/dest/bb/execute.js +74 -165
  8. package/dest/bb/index.d.ts +1 -1
  9. package/dest/config.d.ts +1 -1
  10. package/dest/honk.d.ts +2 -2
  11. package/dest/honk.js +2 -2
  12. package/dest/index.d.ts +1 -1
  13. package/dest/instrumentation.d.ts +3 -3
  14. package/dest/instrumentation.d.ts.map +1 -1
  15. package/dest/instrumentation.js +21 -43
  16. package/dest/prover/client/bb_private_kernel_prover.d.ts +12 -6
  17. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  18. package/dest/prover/client/bb_private_kernel_prover.js +38 -7
  19. package/dest/prover/client/bundle.d.ts +6 -0
  20. package/dest/prover/client/bundle.d.ts.map +1 -0
  21. package/dest/prover/client/bundle.js +7 -0
  22. package/dest/prover/client/lazy.d.ts +6 -0
  23. package/dest/prover/client/lazy.d.ts.map +1 -0
  24. package/dest/prover/client/lazy.js +7 -0
  25. package/dest/prover/index.d.ts +1 -1
  26. package/dest/prover/proof_utils.d.ts +9 -9
  27. package/dest/prover/proof_utils.d.ts.map +1 -1
  28. package/dest/prover/proof_utils.js +42 -25
  29. package/dest/prover/server/bb_prover.d.ts +27 -50
  30. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  31. package/dest/prover/server/bb_prover.js +478 -182
  32. package/dest/test/delay_values.d.ts +1 -1
  33. package/dest/test/delay_values.d.ts.map +1 -1
  34. package/dest/test/delay_values.js +37 -25
  35. package/dest/test/index.d.ts +2 -1
  36. package/dest/test/index.d.ts.map +1 -1
  37. package/dest/test/index.js +1 -0
  38. package/dest/test/test_circuit_prover.d.ts +24 -34
  39. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  40. package/dest/test/test_circuit_prover.js +506 -85
  41. package/dest/test/test_verifier.d.ts +3 -1
  42. package/dest/test/test_verifier.d.ts.map +1 -1
  43. package/dest/test/test_verifier.js +15 -0
  44. package/dest/verification_key/verification_key_data.d.ts +1 -8
  45. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  46. package/dest/verification_key/verification_key_data.js +1 -20
  47. package/dest/verifier/bb_verifier.d.ts +3 -5
  48. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  49. package/dest/verifier/bb_verifier.js +23 -28
  50. package/dest/verifier/index.d.ts +2 -2
  51. package/dest/verifier/index.d.ts.map +1 -1
  52. package/dest/verifier/index.js +1 -1
  53. package/dest/verifier/queued_chonk_verifier.d.ts +15 -0
  54. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
  55. package/dest/verifier/{queued_ivc_verifier.js → queued_chonk_verifier.js} +10 -41
  56. package/package.json +23 -23
  57. package/src/avm_proving_tests/avm_proving_tester.ts +49 -35
  58. package/src/bb/execute.ts +50 -148
  59. package/src/honk.ts +1 -1
  60. package/src/instrumentation.ts +22 -45
  61. package/src/prover/client/bb_private_kernel_prover.ts +50 -10
  62. package/src/prover/client/bundle.ts +10 -0
  63. package/src/prover/client/lazy.ts +10 -0
  64. package/src/prover/proof_utils.ts +53 -31
  65. package/src/prover/server/bb_prover.ts +252 -324
  66. package/src/test/delay_values.ts +38 -24
  67. package/src/test/index.ts +1 -0
  68. package/src/test/test_circuit_prover.ts +229 -155
  69. package/src/test/test_verifier.ts +8 -0
  70. package/src/verification_key/verification_key_data.ts +1 -26
  71. package/src/verifier/bb_verifier.ts +33 -36
  72. package/src/verifier/index.ts +1 -1
  73. package/src/verifier/{queued_ivc_verifier.ts → queued_chonk_verifier.ts} +10 -41
  74. package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts +0 -23
  75. package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts.map +0 -1
  76. package/dest/prover/client/native/bb_native_private_kernel_prover.js +0 -66
  77. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts +0 -15
  78. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
  79. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.js +0 -48
  80. package/dest/prover/client/wasm/bundle.d.ts +0 -6
  81. package/dest/prover/client/wasm/bundle.d.ts.map +0 -1
  82. package/dest/prover/client/wasm/bundle.js +0 -8
  83. package/dest/prover/client/wasm/lazy.d.ts +0 -6
  84. package/dest/prover/client/wasm/lazy.d.ts.map +0 -1
  85. package/dest/prover/client/wasm/lazy.js +0 -8
  86. package/dest/stats.d.ts +0 -4
  87. package/dest/stats.d.ts.map +0 -1
  88. package/dest/stats.js +0 -45
  89. package/dest/verifier/queued_ivc_verifier.d.ts +0 -15
  90. package/dest/verifier/queued_ivc_verifier.d.ts.map +0 -1
  91. package/src/prover/client/native/bb_native_private_kernel_prover.ts +0 -105
  92. package/src/prover/client/wasm/bb_wasm_private_kernel_prover.ts +0 -60
  93. package/src/prover/client/wasm/bundle.ts +0 -11
  94. package/src/prover/client/wasm/lazy.ts +0 -11
  95. package/src/stats.ts +0 -47
@@ -1,41 +1,59 @@
1
1
  import {
2
+ CHONK_PROOF_LENGTH,
3
+ HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE,
2
4
  IPA_CLAIM_SIZE,
3
5
  NESTED_RECURSIVE_PROOF_LENGTH,
4
6
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
7
  PAIRING_POINTS_SIZE,
6
8
  ULTRA_KECCAK_PROOF_LENGTH,
7
9
  } from '@aztec/constants';
8
- import { Fr } from '@aztec/foundation/fields';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
9
11
  import type { Logger } from '@aztec/foundation/log';
10
- import { ClientIvcProof, Proof, RecursiveProof } from '@aztec/stdlib/proofs';
12
+ import { ChonkProofWithPublicInputs, Proof, RecursiveProof } from '@aztec/stdlib/proofs';
11
13
  import type { VerificationKeyData } from '@aztec/stdlib/vks';
12
14
 
13
15
  import assert from 'assert';
14
16
  import { promises as fs } from 'fs';
15
17
  import * as path from 'path';
16
18
 
17
- import { CLIENT_IVC_PROOF_FILE_NAME, PROOF_FILENAME, PUBLIC_INPUTS_FILENAME } from '../bb/execute.js';
19
+ import { PROOF_FILENAME, PUBLIC_INPUTS_FILENAME } from '../bb/execute.js';
18
20
 
19
21
  /**
20
- * Create a ClientIvcProof proof file.
22
+ * Create a ChonkProof proof file.
21
23
  *
22
24
  * @param directory the directory to read the proof from.
23
- * @returns the encapsulated client ivc proof
25
+ * @returns the encapsulated chonk proof
24
26
  */
25
- export async function readClientIVCProofFromOutputDirectory(directory: string) {
26
- const clientIvcProofBuffer = await fs.readFile(path.join(directory, CLIENT_IVC_PROOF_FILE_NAME));
27
- return new ClientIvcProof(clientIvcProofBuffer);
27
+ export async function readChonkProofFromOutputDirectory(directory: string) {
28
+ const proofFilename = path.join(directory, PROOF_FILENAME);
29
+ const binaryProof = await fs.readFile(proofFilename);
30
+ const proofFields = splitBufferIntoFields(binaryProof);
31
+ return new ChonkProofWithPublicInputs(proofFields);
28
32
  }
29
33
 
30
34
  /**
31
- * Serialize a ClientIvcProof to a proof file.
35
+ * Serialize a ChonkProof to a proof file.
32
36
  *
33
- * @param proof the ClientIvcProof from object
37
+ * @param proof the ChonkProof from object
34
38
  * @param directory the directory to write in
35
39
  */
36
- export async function writeClientIVCProofToOutputDirectory(clientIvcProof: ClientIvcProof, directory: string) {
37
- const { clientIvcProofBuffer } = clientIvcProof;
38
- await fs.writeFile(path.join(directory, CLIENT_IVC_PROOF_FILE_NAME), clientIvcProofBuffer);
40
+ export async function writeChonkProofToPath(chonkProof: ChonkProofWithPublicInputs, outputPath: string) {
41
+ // NB: Don't use chonkProof.toBuffer here because it will include the proof length.
42
+ const fieldsBuf = Buffer.concat(chonkProof.fieldsWithPublicInputs.map(field => field.toBuffer()));
43
+ await fs.writeFile(outputPath, fieldsBuf);
44
+ }
45
+
46
+ function getNumCustomPublicInputs(proofLength: number, vkData: VerificationKeyData) {
47
+ let numPublicInputs = vkData.numPublicInputs;
48
+ if (proofLength == CHONK_PROOF_LENGTH) {
49
+ numPublicInputs -= HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE;
50
+ } else {
51
+ numPublicInputs -= PAIRING_POINTS_SIZE;
52
+ if (proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH) {
53
+ numPublicInputs -= IPA_CLAIM_SIZE;
54
+ }
55
+ }
56
+ return numPublicInputs;
39
57
  }
40
58
 
41
59
  function splitBufferIntoFields(buffer: Buffer): Fr[] {
@@ -46,43 +64,47 @@ function splitBufferIntoFields(buffer: Buffer): Fr[] {
46
64
  return fields;
47
65
  }
48
66
 
49
- export async function readProofAsFields<PROOF_LENGTH extends number>(
50
- filePath: string,
67
+ export async function readProofsFromOutputDirectory<PROOF_LENGTH extends number>(
68
+ directory: string,
51
69
  vkData: VerificationKeyData,
52
70
  proofLength: PROOF_LENGTH,
53
71
  logger: Logger,
54
72
  ): Promise<RecursiveProof<PROOF_LENGTH>> {
55
- const publicInputsFilename = path.join(filePath, PUBLIC_INPUTS_FILENAME);
56
- const proofFilename = path.join(filePath, PROOF_FILENAME);
57
-
58
- const [binaryPublicInputs, binaryProof] = await Promise.all([
59
- fs.readFile(publicInputsFilename),
60
- fs.readFile(proofFilename),
61
- ]);
62
-
63
- const fieldsWithoutPublicInputs = splitBufferIntoFields(binaryProof);
64
-
65
- let numPublicInputs = vkData.numPublicInputs - PAIRING_POINTS_SIZE;
66
73
  assert(
67
- proofLength == NESTED_RECURSIVE_PROOF_LENGTH ||
74
+ proofLength == CHONK_PROOF_LENGTH ||
75
+ proofLength == NESTED_RECURSIVE_PROOF_LENGTH ||
68
76
  proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH ||
69
77
  proofLength == ULTRA_KECCAK_PROOF_LENGTH,
70
78
  `Proof length must be one of the expected proof lengths, received ${proofLength}`,
71
79
  );
72
- if (proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH) {
73
- numPublicInputs -= IPA_CLAIM_SIZE;
80
+
81
+ const publicInputsFilename = path.join(directory, PUBLIC_INPUTS_FILENAME);
82
+ const proofFilename = path.join(directory, PROOF_FILENAME);
83
+
84
+ // Handle CHONK separately because bb outputs the proof fields with public inputs for CHONK.
85
+ const isChonk = proofLength == CHONK_PROOF_LENGTH;
86
+
87
+ const [binaryPublicInputs, binaryProof] = await Promise.all([
88
+ isChonk ? Buffer.alloc(0) : fs.readFile(publicInputsFilename),
89
+ fs.readFile(proofFilename),
90
+ ]);
91
+
92
+ const numPublicInputs = getNumCustomPublicInputs(proofLength, vkData);
93
+ let fieldsWithoutPublicInputs = splitBufferIntoFields(binaryProof);
94
+ if (isChonk) {
95
+ fieldsWithoutPublicInputs = fieldsWithoutPublicInputs.slice(numPublicInputs);
74
96
  }
75
97
 
76
98
  assert(
77
99
  fieldsWithoutPublicInputs.length == proofLength,
78
- `Proof length mismatch: ${fieldsWithoutPublicInputs.length} != ${proofLength}`,
100
+ `Proof fields length mismatch: ${fieldsWithoutPublicInputs.length} != ${proofLength}`,
79
101
  );
80
102
 
81
103
  // Concat binary public inputs and binary proof
82
104
  // This buffer will have the form: [binary public inputs, binary proof]
83
105
  const binaryProofWithPublicInputs = Buffer.concat([binaryPublicInputs, binaryProof]);
84
106
  logger.debug(
85
- `Circuit path: ${filePath}, complete proof length: ${fieldsWithoutPublicInputs.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}`,
107
+ `Circuit path: ${directory}, proof fields length: ${fieldsWithoutPublicInputs.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}`,
86
108
  );
87
109
  return new RecursiveProof(
88
110
  fieldsWithoutPublicInputs,