@aztec/bb.js 0.0.0-devnet → 0.0.0-test.1

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 (189) hide show
  1. package/README.md +10 -2
  2. package/dest/browser/522.6386c00ebfb22619e11b.js +3 -0
  3. package/dest/browser/barretenberg/backend.d.ts +7 -2
  4. package/dest/browser/barretenberg/backend.d.ts.map +1 -1
  5. package/dest/browser/barretenberg/index.d.ts +6 -2
  6. package/dest/browser/barretenberg/index.d.ts.map +1 -1
  7. package/dest/browser/barretenberg-threads.js +32 -0
  8. package/dest/browser/barretenberg.js +32 -0
  9. package/dest/browser/barretenberg_api/index.d.ts +5 -2
  10. package/dest/browser/barretenberg_api/index.d.ts.map +1 -1
  11. package/dest/browser/barretenberg_wasm/barretenberg_wasm_base/index.d.ts.map +1 -1
  12. package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts +1 -1
  13. package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts.map +1 -1
  14. package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/index.d.ts +1 -1
  15. package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/index.d.ts.map +1 -1
  16. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
  17. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
  18. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
  19. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
  20. package/dest/browser/barretenberg_wasm/fetch_code/browser/index.d.ts +1 -1
  21. package/dest/browser/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
  22. package/dest/browser/barretenberg_wasm/fetch_code/node/index.d.ts +1 -1
  23. package/dest/browser/barretenberg_wasm/fetch_code/node/index.d.ts.map +1 -1
  24. package/dest/browser/barretenberg_wasm/index.d.ts +2 -2
  25. package/dest/browser/barretenberg_wasm/index.d.ts.map +1 -1
  26. package/dest/browser/bigint-array/index.d.ts +17 -2
  27. package/dest/browser/bigint-array/index.d.ts.map +1 -1
  28. package/dest/browser/crs/net_crs.d.ts.map +1 -1
  29. package/dest/browser/crs/node/index.d.ts +6 -4
  30. package/dest/browser/crs/node/index.d.ts.map +1 -1
  31. package/dest/browser/index.d.ts.map +1 -1
  32. package/dest/browser/index.js +10583 -16082
  33. package/dest/browser/index.js.LICENSE.txt +16 -0
  34. package/dest/browser/main.worker.worker.js.LICENSE.txt +5 -0
  35. package/dest/browser/proof/index.d.ts +10 -0
  36. package/dest/browser/proof/index.d.ts.map +1 -1
  37. package/dest/browser/retry/index.d.ts +26 -0
  38. package/dest/browser/retry/index.d.ts.map +1 -0
  39. package/dest/browser/thread.worker.worker.js.LICENSE.txt +5 -0
  40. package/dest/browser/thread.worker.worker.worker.js.LICENSE.txt +5 -0
  41. package/dest/browser/types/fields.d.ts +6 -5
  42. package/dest/browser/types/fields.d.ts.map +1 -1
  43. package/dest/node/barretenberg/__snapshots__/pedersen.test.js.snap +156 -0
  44. package/dest/node/barretenberg/__snapshots__/poseidon.test.js.snap +40 -0
  45. package/dest/node/barretenberg/backend.d.ts +7 -2
  46. package/dest/node/barretenberg/backend.d.ts.map +1 -1
  47. package/dest/node/barretenberg/backend.js +54 -4
  48. package/dest/node/barretenberg/blake2s.test.js +2 -2
  49. package/dest/node/barretenberg/index.d.ts +6 -2
  50. package/dest/node/barretenberg/index.d.ts.map +1 -1
  51. package/dest/node/barretenberg/index.js +15 -20
  52. package/dest/node/barretenberg/pedersen.test.js +2 -2
  53. package/dest/node/barretenberg/poseidon.test.js +2 -2
  54. package/dest/node/barretenberg_api/index.d.ts +5 -2
  55. package/dest/node/barretenberg_api/index.d.ts.map +1 -1
  56. package/dest/node/barretenberg_api/index.js +32 -2
  57. package/dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  58. package/dest/node/barretenberg_wasm/barretenberg_wasm_base/index.d.ts.map +1 -1
  59. package/dest/node/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -6
  60. package/dest/node/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts +1 -1
  61. package/dest/node/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts.map +1 -1
  62. package/dest/node/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.js +16 -11
  63. package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.d.ts +1 -1
  64. package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.d.ts.map +1 -1
  65. package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.js +7 -9
  66. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
  67. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
  68. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +3 -0
  69. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
  70. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
  71. package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.js +3 -0
  72. package/dest/node/barretenberg_wasm/fetch_code/browser/index.d.ts +1 -1
  73. package/dest/node/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
  74. package/dest/node/barretenberg_wasm/fetch_code/browser/index.js +31 -8
  75. package/dest/node/barretenberg_wasm/fetch_code/node/index.d.ts +1 -1
  76. package/dest/node/barretenberg_wasm/fetch_code/node/index.d.ts.map +1 -1
  77. package/dest/node/barretenberg_wasm/fetch_code/node/index.js +3 -3
  78. package/dest/node/barretenberg_wasm/index.d.ts +2 -2
  79. package/dest/node/barretenberg_wasm/index.d.ts.map +1 -1
  80. package/dest/node/barretenberg_wasm/index.js +12 -10
  81. package/dest/node/barretenberg_wasm/index.test.js +3 -3
  82. package/dest/node/bigint-array/index.d.ts +17 -2
  83. package/dest/node/bigint-array/index.d.ts.map +1 -1
  84. package/dest/node/bigint-array/index.js +34 -18
  85. package/dest/node/crs/net_crs.d.ts.map +1 -1
  86. package/dest/node/crs/net_crs.js +6 -5
  87. package/dest/node/crs/node/index.d.ts +6 -4
  88. package/dest/node/crs/node/index.d.ts.map +1 -1
  89. package/dest/node/crs/node/index.js +16 -13
  90. package/dest/node/examples/simple.test.js +2 -2
  91. package/dest/node/index.d.ts.map +1 -1
  92. package/dest/node/index.js +1 -1
  93. package/dest/node/main.d.ts.map +1 -1
  94. package/dest/node/main.js +57 -65
  95. package/dest/node/proof/index.d.ts +10 -0
  96. package/dest/node/proof/index.d.ts.map +1 -1
  97. package/dest/node/proof/index.js +1 -1
  98. package/dest/node/retry/index.d.ts +26 -0
  99. package/dest/node/retry/index.d.ts.map +1 -0
  100. package/dest/node/retry/index.js +50 -0
  101. package/dest/node/types/fields.d.ts +6 -5
  102. package/dest/node/types/fields.d.ts.map +1 -1
  103. package/dest/node/types/fields.js +15 -10
  104. package/dest/node-cjs/barretenberg/backend.d.ts +7 -2
  105. package/dest/node-cjs/barretenberg/backend.d.ts.map +1 -1
  106. package/dest/node-cjs/barretenberg/backend.js +56 -5
  107. package/dest/node-cjs/barretenberg/blake2s.test.js +2 -2
  108. package/dest/node-cjs/barretenberg/index.d.ts +6 -2
  109. package/dest/node-cjs/barretenberg/index.d.ts.map +1 -1
  110. package/dest/node-cjs/barretenberg/index.js +15 -19
  111. package/dest/node-cjs/barretenberg/pedersen.test.js +2 -2
  112. package/dest/node-cjs/barretenberg/poseidon.test.js +2 -2
  113. package/dest/node-cjs/barretenberg_api/index.d.ts +5 -2
  114. package/dest/node-cjs/barretenberg_api/index.d.ts.map +1 -1
  115. package/dest/node-cjs/barretenberg_api/index.js +32 -2
  116. package/dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  117. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_base/index.d.ts.map +1 -1
  118. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -6
  119. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts +1 -1
  120. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts.map +1 -1
  121. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.js +16 -11
  122. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.d.ts +1 -1
  123. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.d.ts.map +1 -1
  124. package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.js +7 -9
  125. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
  126. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
  127. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +6 -0
  128. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
  129. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
  130. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.js +6 -0
  131. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.d.ts +1 -1
  132. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
  133. package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.js +31 -8
  134. package/dest/node-cjs/barretenberg_wasm/fetch_code/node/index.d.ts +1 -1
  135. package/dest/node-cjs/barretenberg_wasm/fetch_code/node/index.d.ts.map +1 -1
  136. package/dest/node-cjs/barretenberg_wasm/fetch_code/node/index.js +3 -3
  137. package/dest/node-cjs/barretenberg_wasm/index.d.ts +2 -2
  138. package/dest/node-cjs/barretenberg_wasm/index.d.ts.map +1 -1
  139. package/dest/node-cjs/barretenberg_wasm/index.js +12 -10
  140. package/dest/node-cjs/barretenberg_wasm/index.test.js +3 -3
  141. package/dest/node-cjs/bigint-array/index.d.ts +17 -2
  142. package/dest/node-cjs/bigint-array/index.d.ts.map +1 -1
  143. package/dest/node-cjs/bigint-array/index.js +39 -21
  144. package/dest/node-cjs/crs/net_crs.d.ts.map +1 -1
  145. package/dest/node-cjs/crs/net_crs.js +6 -5
  146. package/dest/node-cjs/crs/node/index.d.ts +6 -4
  147. package/dest/node-cjs/crs/node/index.d.ts.map +1 -1
  148. package/dest/node-cjs/crs/node/index.js +16 -13
  149. package/dest/node-cjs/examples/simple.test.js +2 -2
  150. package/dest/node-cjs/index.d.ts.map +1 -1
  151. package/dest/node-cjs/index.js +1 -1
  152. package/dest/node-cjs/main.d.ts.map +1 -1
  153. package/dest/node-cjs/main.js +57 -65
  154. package/dest/node-cjs/proof/index.d.ts +10 -0
  155. package/dest/node-cjs/proof/index.d.ts.map +1 -1
  156. package/dest/node-cjs/proof/index.js +1 -1
  157. package/dest/node-cjs/retry/index.d.ts +26 -0
  158. package/dest/node-cjs/retry/index.d.ts.map +1 -0
  159. package/dest/node-cjs/retry/index.js +56 -0
  160. package/dest/node-cjs/types/fields.d.ts +6 -5
  161. package/dest/node-cjs/types/fields.d.ts.map +1 -1
  162. package/dest/node-cjs/types/fields.js +14 -9
  163. package/package.json +5 -5
  164. package/src/barretenberg/backend.ts +79 -3
  165. package/src/barretenberg/blake2s.test.ts +1 -1
  166. package/src/barretenberg/index.ts +27 -21
  167. package/src/barretenberg/pedersen.test.ts +1 -1
  168. package/src/barretenberg/poseidon.test.ts +1 -1
  169. package/src/barretenberg_api/index.ts +49 -2
  170. package/src/barretenberg_wasm/barretenberg_wasm_base/index.ts +4 -6
  171. package/src/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.ts +14 -10
  172. package/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +7 -10
  173. package/src/barretenberg_wasm/fetch_code/browser/barretenberg-threads.ts +3 -0
  174. package/src/barretenberg_wasm/fetch_code/browser/barretenberg.ts +3 -0
  175. package/src/barretenberg_wasm/fetch_code/browser/index.ts +28 -7
  176. package/src/barretenberg_wasm/fetch_code/node/index.ts +2 -2
  177. package/src/barretenberg_wasm/index.test.ts +2 -2
  178. package/src/barretenberg_wasm/index.ts +22 -11
  179. package/src/bigint-array/index.ts +39 -17
  180. package/src/crs/net_crs.ts +18 -9
  181. package/src/crs/node/index.ts +31 -15
  182. package/src/examples/simple.test.ts +1 -1
  183. package/src/index.ts +1 -0
  184. package/src/main.ts +61 -70
  185. package/src/proof/index.ts +11 -0
  186. package/src/retry/index.ts +50 -0
  187. package/src/types/fields.ts +24 -13
  188. package/dest/browser/522.index.js +0 -10
  189. /package/src/barretenberg_wasm/fetch_code/{browser/wasm-module.d.ts → wasm-module.d.ts} +0 -0
package/src/main.ts CHANGED
@@ -22,18 +22,18 @@ const debug = createDebug('bb.js');
22
22
  const MAX_ULTRAPLONK_CIRCUIT_SIZE_IN_WASM = 2 ** 19;
23
23
  const threads = +process.env.HARDWARE_CONCURRENCY! || undefined;
24
24
 
25
- function getBytecode(bytecodePath: string) {
25
+ function getBytecode(bytecodePath: string): Uint8Array {
26
26
  const extension = bytecodePath.substring(bytecodePath.lastIndexOf('.') + 1);
27
27
 
28
28
  if (extension == 'json') {
29
29
  const encodedCircuit = JSON.parse(readFileSync(bytecodePath, 'utf8'));
30
30
  const decompressed = gunzipSync(Buffer.from(encodedCircuit.bytecode, 'base64'));
31
- return decompressed;
31
+ return Uint8Array.from(decompressed);
32
32
  }
33
33
 
34
34
  const encodedCircuit = readFileSync(bytecodePath);
35
35
  const decompressed = gunzipSync(encodedCircuit);
36
- return decompressed;
36
+ return Uint8Array.from(decompressed);
37
37
  }
38
38
 
39
39
  function base64ToUint8Array(base64: string) {
@@ -62,14 +62,14 @@ async function getGatesUltra(bytecodePath: string, recursive: boolean, honkRecur
62
62
  return total;
63
63
  }
64
64
 
65
- function getWitness(witnessPath: string) {
65
+ function getWitness(witnessPath: string): Uint8Array {
66
66
  const data = readFileSync(witnessPath);
67
67
  const decompressed = gunzipSync(data);
68
- return decompressed;
68
+ return Uint8Array.from(decompressed);
69
69
  }
70
70
 
71
71
  async function computeCircuitSize(bytecodePath: string, recursive: boolean, honkRecursion: boolean, api: Barretenberg) {
72
- debug(`computing circuit size...`);
72
+ debug(`Computing circuit size for ${bytecodePath}`);
73
73
  const bytecode = getBytecode(bytecodePath);
74
74
  const [total, subgroup] = await api.acirGetCircuitSizes(bytecode, recursive, honkRecursion);
75
75
  return { total, subgroup };
@@ -84,6 +84,7 @@ async function initUltraPlonk(
84
84
  ) {
85
85
  const api = await Barretenberg.new({ threads });
86
86
 
87
+ // TODO(https://github.com/AztecProtocol/barretenberg/issues/1248): Get rid of this call to avoid building the circuit twice.
87
88
  // TODO(https://github.com/AztecProtocol/barretenberg/issues/1126): use specific UltraPlonk function
88
89
  const circuitSize = await getGatesUltra(bytecodePath, recursive, honkRecursion, api);
89
90
  // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): remove subgroupSizeOverride hack for goblin
@@ -92,9 +93,7 @@ async function initUltraPlonk(
92
93
  if (subgroupSize > MAX_ULTRAPLONK_CIRCUIT_SIZE_IN_WASM) {
93
94
  throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_ULTRAPLONK_CIRCUIT_SIZE_IN_WASM}`);
94
95
  }
95
- debug(`circuit size: ${circuitSize}`);
96
- debug(`subgroup size: ${subgroupSize}`);
97
- debug('loading crs...');
96
+ debug(`Loading CRS for UltraPlonk with circuit-size=${circuitSize} subgroup-size=${subgroupSize}`);
98
97
  // Plus 1 needed! (Move +1 into Crs?)
99
98
  const crs = await Crs.new(subgroupSize + 1, crsPath);
100
99
 
@@ -112,14 +111,13 @@ async function initUltraPlonk(
112
111
  async function initUltraHonk(bytecodePath: string, recursive: boolean, crsPath: string) {
113
112
  const api = await Barretenberg.new({ threads });
114
113
 
114
+ // TODO(https://github.com/AztecProtocol/barretenberg/issues/1248): Get rid of this call to avoid building the circuit twice.
115
115
  // TODO(https://github.com/AztecProtocol/barretenberg/issues/1126): use specific UltraHonk function
116
116
  const circuitSize = await getGatesUltra(bytecodePath, recursive, /*honkRecursion=*/ true, api);
117
117
  // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): remove subgroupSizeOverride hack for goblin
118
118
  const dyadicCircuitSize = Math.pow(2, Math.ceil(Math.log2(circuitSize)));
119
119
 
120
- debug(`circuit size: ${circuitSize}`);
121
- debug(`dyadic circuit size size: ${dyadicCircuitSize}`);
122
- debug('loading crs...');
120
+ debug(`Loading CRS for UltraHonk with circuit-size=${circuitSize} dyadic-circuit-size=${dyadicCircuitSize}`);
123
121
  const crs = await Crs.new(dyadicCircuitSize + 1, crsPath);
124
122
 
125
123
  // Load CRS into wasm global CRS state.
@@ -131,7 +129,7 @@ async function initUltraHonk(bytecodePath: string, recursive: boolean, crsPath:
131
129
  async function initClientIVC(crsPath: string) {
132
130
  const api = await Barretenberg.new({ threads });
133
131
 
134
- debug('loading BN254 and Grumpkin crs...');
132
+ debug('Loading CRS for ClientIVC');
135
133
  const crs = await Crs.new(2 ** 21 + 1, crsPath);
136
134
  const grumpkinCrs = await GrumpkinCrs.new(2 ** 16 + 1, crsPath);
137
135
 
@@ -161,7 +159,7 @@ export async function proveAndVerify(bytecodePath: string, recursive: boolean, w
161
159
 
162
160
  const { api, acirComposer, circuitSize, subgroupSize } = await initUltraPlonk(bytecodePath, recursive, crsPath);
163
161
  try {
164
- debug(`creating proof...`);
162
+ debug(`Creating proof bytecode=${bytecodePath} witness=${witnessPath} recursive=${recursive}`);
165
163
  const bytecode = getBytecode(bytecodePath);
166
164
  const witness = getWitness(witnessPath);
167
165
 
@@ -175,9 +173,9 @@ export async function proveAndVerify(bytecodePath: string, recursive: boolean, w
175
173
  const proof = await api.acirCreateProof(acirComposer, bytecode, recursive, witness);
176
174
  writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads });
177
175
 
178
- debug(`verifying...`);
176
+ debug(`Proof complete. Verifying.`);
179
177
  const verified = await api.acirVerifyProof(acirComposer, proof);
180
- debug(`verified: ${verified}`);
178
+ debug(`Verification ${verified ? 'successful' : 'failed'}`);
181
179
  return verified;
182
180
  } finally {
183
181
  await api.destroy();
@@ -233,7 +231,7 @@ export async function proveAndVerifyAztecClient(bytecodePath: string, witnessPat
233
231
  const witness = readStack(witnessPath);
234
232
 
235
233
  const verified = await api.acirProveAndVerifyAztecClient(bytecode, witness);
236
- console.log(`verified?: ${verified}`);
234
+ debug(`Verification ${verified ? 'successful' : 'failed'}`);
237
235
  return verified;
238
236
  } finally {
239
237
  await api.destroy();
@@ -254,7 +252,7 @@ export async function foldAndVerifyProgram(
254
252
  const witness = getWitness(witnessPath);
255
253
 
256
254
  const verified = await api.acirFoldAndVerifyProgramStack(bytecode, recursive, witness);
257
- debug(`verified: ${verified}`);
255
+ debug(`Verification ${verified ? 'successful' : 'failed'}`);
258
256
  return verified;
259
257
  } finally {
260
258
  await api.destroy();
@@ -271,18 +269,17 @@ export async function prove(
271
269
  ) {
272
270
  const { api, acirComposer } = await initUltraPlonk(bytecodePath, recursive, crsPath);
273
271
  try {
274
- debug(`creating proof...`);
272
+ debug(`Creating proof bytecode=${bytecodePath} witness=${witnessPath} recursive=${recursive}`);
275
273
  const bytecode = getBytecode(bytecodePath);
276
274
  const witness = getWitness(witnessPath);
277
275
  const proof = await api.acirCreateProof(acirComposer, bytecode, recursive, witness);
278
- debug(`done.`);
279
276
 
280
277
  if (outputPath === '-') {
281
278
  process.stdout.write(proof);
282
- debug(`proof written to stdout`);
279
+ debug(`Proof written to stdout`);
283
280
  } else {
284
281
  writeFileSync(outputPath, proof);
285
- debug(`proof written to: ${outputPath}`);
282
+ debug(`Proof written to ${outputPath}`);
286
283
  }
287
284
  } finally {
288
285
  await api.destroy();
@@ -293,14 +290,14 @@ export async function gateCountUltra(bytecodePath: string, recursive: boolean, h
293
290
  const api = await Barretenberg.new({ threads: 1 });
294
291
  try {
295
292
  const numberOfGates = await getGatesUltra(bytecodePath, recursive, honkRecursion, api);
296
- debug(`number of gates: : ${numberOfGates}`);
293
+ debug(`Number of gates: ${numberOfGates}`);
297
294
  // Create an 8-byte buffer and write the number into it.
298
295
  // Writing number directly to stdout will result in a variable sized
299
296
  // input depending on the size.
300
297
  const buffer = Buffer.alloc(8);
301
298
  buffer.writeBigInt64LE(BigInt(numberOfGates));
302
299
 
303
- process.stdout.write(buffer);
300
+ process.stdout.write(Uint8Array.from(buffer));
304
301
  } finally {
305
302
  await api.destroy();
306
303
  }
@@ -310,8 +307,8 @@ export async function verify(proofPath: string, vkPath: string, crsPath: string)
310
307
  const { api, acirComposer } = await initLite(crsPath);
311
308
  try {
312
309
  await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
313
- const verified = await api.acirVerifyProof(acirComposer, readFileSync(proofPath));
314
- debug(`verified: ${verified}`);
310
+ const verified = await api.acirVerifyProof(acirComposer, Uint8Array.from(readFileSync(proofPath)));
311
+ debug(`Verification ${verified ? 'successful' : 'failed'}`);
315
312
  return verified;
316
313
  } finally {
317
314
  await api.destroy();
@@ -321,15 +318,16 @@ export async function verify(proofPath: string, vkPath: string, crsPath: string)
321
318
  export async function contract(outputPath: string, vkPath: string, crsPath: string) {
322
319
  const { api, acirComposer } = await initLite(crsPath);
323
320
  try {
321
+ debug(`Creating verifier contract vk=${vkPath}`);
324
322
  await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
325
323
  const contract = await api.acirGetSolidityVerifier(acirComposer);
326
324
 
327
325
  if (outputPath === '-') {
328
326
  process.stdout.write(contract);
329
- debug(`contract written to stdout`);
327
+ debug(`Solidity verifier contract written to stdout`);
330
328
  } else {
331
329
  writeFileSync(outputPath, contract);
332
- debug(`contract written to: ${outputPath}`);
330
+ debug(`Solidity verifier contract written to ${outputPath}`);
333
331
  }
334
332
  } finally {
335
333
  await api.destroy();
@@ -339,18 +337,17 @@ export async function contract(outputPath: string, vkPath: string, crsPath: stri
339
337
  export async function contractUltraHonk(bytecodePath: string, vkPath: string, crsPath: string, outputPath: string) {
340
338
  const { api } = await initUltraHonk(bytecodePath, false, crsPath);
341
339
  try {
342
- console.log('bytecodePath', bytecodePath);
340
+ debug(`Creating UltraHonk verifier contract bytecode=${bytecodePath} vk=${vkPath}`);
343
341
  const bytecode = getBytecode(bytecodePath);
344
- console.log('vkPath', vkPath);
345
342
  const vk = new RawBuffer(readFileSync(vkPath));
346
343
  const contract = await api.acirHonkSolidityVerifier(bytecode, vk);
347
344
 
348
345
  if (outputPath === '-') {
349
346
  process.stdout.write(contract);
350
- debug(`contract written to stdout`);
347
+ debug(`Solidity verifier contract written to stdout`);
351
348
  } else {
352
349
  writeFileSync(outputPath, contract);
353
- debug(`contract written to: ${outputPath}`);
350
+ debug(`Solidity verifier contract written to ${outputPath}`);
354
351
  }
355
352
  } finally {
356
353
  await api.destroy();
@@ -360,19 +357,19 @@ export async function contractUltraHonk(bytecodePath: string, vkPath: string, cr
360
357
  export async function writeVk(bytecodePath: string, recursive: boolean, crsPath: string, outputPath: string) {
361
358
  const { api, acirComposer } = await initUltraPlonk(bytecodePath, recursive, crsPath);
362
359
  try {
363
- debug('initing proving key...');
360
+ debug(`Initializing proving key bytecode=${bytecodePath} recursive=${recursive}`);
364
361
  const bytecode = getBytecode(bytecodePath);
365
362
  await api.acirInitProvingKey(acirComposer, bytecode, recursive);
366
363
 
367
- debug('initing verification key...');
364
+ debug(`Initializing verification key`);
368
365
  const vk = await api.acirGetVerificationKey(acirComposer);
369
366
 
370
367
  if (outputPath === '-') {
371
368
  process.stdout.write(vk);
372
- debug(`vk written to stdout`);
369
+ debug(`Verification key written to stdout`);
373
370
  } else {
374
371
  writeFileSync(outputPath, vk);
375
- debug(`vk written to: ${outputPath}`);
372
+ debug(`Verification key written to ${outputPath}`);
376
373
  }
377
374
  } finally {
378
375
  await api.destroy();
@@ -382,16 +379,16 @@ export async function writeVk(bytecodePath: string, recursive: boolean, crsPath:
382
379
  export async function writePk(bytecodePath: string, recursive: boolean, crsPath: string, outputPath: string) {
383
380
  const { api, acirComposer } = await initUltraPlonk(bytecodePath, recursive, crsPath);
384
381
  try {
385
- debug('initing proving key...');
382
+ debug(`Initializing proving key bytecode=${bytecodePath} recursive=${recursive}`);
386
383
  const bytecode = getBytecode(bytecodePath);
387
384
  const pk = await api.acirGetProvingKey(acirComposer, bytecode, recursive);
388
385
 
389
386
  if (outputPath === '-') {
390
387
  process.stdout.write(pk);
391
- debug(`pk written to stdout`);
388
+ debug(`Proving key written to stdout`);
392
389
  } else {
393
390
  writeFileSync(outputPath, pk);
394
- debug(`pk written to: ${outputPath}`);
391
+ debug(`Proving key written to ${outputPath}`);
395
392
  }
396
393
  } finally {
397
394
  await api.destroy();
@@ -402,24 +399,22 @@ export async function proofAsFields(proofPath: string, vkPath: string, outputPat
402
399
  const { api, acirComposer } = await initLite(crsPath);
403
400
 
404
401
  try {
405
- debug('serializing proof byte array into field elements');
402
+ debug(`Serializing proof byte array into field elements proof=${proofPath} vk=${vkPath}`);
406
403
  const numPublicInputs = readFileSync(vkPath).readUint32BE(8);
407
404
  const proofAsFields = await api.acirSerializeProofIntoFields(
408
405
  acirComposer,
409
- readFileSync(proofPath),
406
+ Uint8Array.from(readFileSync(proofPath)),
410
407
  numPublicInputs,
411
408
  );
412
409
  const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString()));
413
410
 
414
411
  if (outputPath === '-') {
415
412
  process.stdout.write(jsonProofAsFields);
416
- debug(`proofAsFields written to stdout`);
413
+ debug(`Proof as fields written to stdout`);
417
414
  } else {
418
415
  writeFileSync(outputPath, jsonProofAsFields);
419
- debug(`proofAsFields written to: ${outputPath}`);
416
+ debug(`Proof as fields written to ${outputPath}`);
420
417
  }
421
-
422
- debug('done.');
423
418
  } finally {
424
419
  await api.destroy();
425
420
  }
@@ -429,7 +424,7 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string, crsPath
429
424
  const { api, acirComposer } = await initLite(crsPath);
430
425
 
431
426
  try {
432
- debug('serializing vk byte array into field elements');
427
+ debug(`Serializing vk byte array into field elements vk=${vkPath}`);
433
428
  await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
434
429
  const [vkAsFields, vkHash] = await api.acirSerializeVerificationKeyIntoFields(acirComposer);
435
430
  const output = [vkHash, ...vkAsFields].map(f => f.toString());
@@ -437,13 +432,11 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string, crsPath
437
432
 
438
433
  if (vkeyOutputPath === '-') {
439
434
  process.stdout.write(jsonVKAsFields);
440
- debug(`vkAsFields written to stdout`);
435
+ debug(`Verification key as fields written to stdout`);
441
436
  } else {
442
437
  writeFileSync(vkeyOutputPath, jsonVKAsFields);
443
- debug(`vkAsFields written to: ${vkeyOutputPath}`);
438
+ debug(`Verification key as fields written to ${vkeyOutputPath}`);
444
439
  }
445
-
446
- debug('done.');
447
440
  } finally {
448
441
  await api.destroy();
449
442
  }
@@ -459,7 +452,7 @@ export async function proveUltraHonk(
459
452
  ) {
460
453
  const { api } = await initUltraHonk(bytecodePath, recursive, crsPath);
461
454
  try {
462
- debug(`creating proof...`);
455
+ debug(`Creating UltraHonk proof bytecode=${bytecodePath} recursive=${recursive}`);
463
456
  const bytecode = getBytecode(bytecodePath);
464
457
  const witness = getWitness(witnessPath);
465
458
 
@@ -467,14 +460,13 @@ export async function proveUltraHonk(
467
460
  ? api.acirProveUltraKeccakHonk.bind(api)
468
461
  : api.acirProveUltraHonk.bind(api);
469
462
  const proof = await acirProveUltraHonk(bytecode, recursive, witness);
470
- debug(`done.`);
471
463
 
472
464
  if (outputPath === '-') {
473
465
  process.stdout.write(proof);
474
- debug(`proof written to stdout`);
466
+ debug(`Proof written to stdout`);
475
467
  } else {
476
468
  writeFileSync(outputPath, proof);
477
- debug(`proof written to: ${outputPath}`);
469
+ debug(`Proof written to ${outputPath}`);
478
470
  }
479
471
  } finally {
480
472
  await api.destroy();
@@ -491,7 +483,7 @@ export async function writeVkUltraHonk(
491
483
  const { api } = await initUltraHonk(bytecodePath, recursive, crsPath);
492
484
  try {
493
485
  const bytecode = getBytecode(bytecodePath);
494
- debug('initing verification key...');
486
+ debug(`Initializing UltraHonk verification key bytecode=${bytecodePath} recursive=${recursive}`);
495
487
 
496
488
  const acirWriteVkUltraHonk = options?.keccak
497
489
  ? api.acirWriteVkUltraKeccakHonk.bind(api)
@@ -500,10 +492,10 @@ export async function writeVkUltraHonk(
500
492
 
501
493
  if (outputPath === '-') {
502
494
  process.stdout.write(vk);
503
- debug(`vk written to stdout`);
495
+ debug(`Verification key written to stdout`);
504
496
  } else {
505
497
  writeFileSync(outputPath, vk);
506
- debug(`vk written to: ${outputPath}`);
498
+ debug(`Verification key written to ${outputPath}`);
507
499
  }
508
500
  } finally {
509
501
  await api.destroy();
@@ -521,9 +513,12 @@ export async function verifyUltraHonk(
521
513
  const acirVerifyUltraHonk = options?.keccak
522
514
  ? api.acirVerifyUltraKeccakHonk.bind(api)
523
515
  : api.acirVerifyUltraHonk.bind(api);
524
- const verified = await acirVerifyUltraHonk(readFileSync(proofPath), new RawBuffer(readFileSync(vkPath)));
516
+ const verified = await acirVerifyUltraHonk(
517
+ Uint8Array.from(readFileSync(proofPath)),
518
+ new RawBuffer(readFileSync(vkPath)),
519
+ );
525
520
 
526
- debug(`verified: ${verified}`);
521
+ debug(`Verification ${verified ? 'successful' : 'failed'}`);
527
522
  return verified;
528
523
  } finally {
529
524
  await api.destroy();
@@ -533,19 +528,17 @@ export async function verifyUltraHonk(
533
528
  export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: string, crsPath: string) {
534
529
  const { api } = await initLite(crsPath);
535
530
  try {
536
- debug('outputting proof as vector of fields');
537
- const proofAsFields = await api.acirProofAsFieldsUltraHonk(readFileSync(proofPath));
531
+ debug(`Outputting UltraHonk proof as vector of fields proof=${proofPath}`);
532
+ const proofAsFields = await api.acirProofAsFieldsUltraHonk(Uint8Array.from(readFileSync(proofPath)));
538
533
  const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString()));
539
534
 
540
535
  if (outputPath === '-') {
541
536
  process.stdout.write(jsonProofAsFields);
542
- debug(`proofAsFieldsUltraHonk written to stdout`);
537
+ debug(`Proof as fields written to stdout`);
543
538
  } else {
544
539
  writeFileSync(outputPath, jsonProofAsFields);
545
- debug(`proofAsFieldsUltraHonk written to: ${outputPath}`);
540
+ debug(`Proof as fields written to ${outputPath}`);
546
541
  }
547
-
548
- debug('done.');
549
542
  } finally {
550
543
  await api.destroy();
551
544
  }
@@ -555,19 +548,17 @@ export async function vkAsFieldsUltraHonk(vkPath: string, vkeyOutputPath: string
555
548
  const { api } = await initLite(crsPath);
556
549
 
557
550
  try {
558
- debug('serializing vk byte array into field elements');
551
+ debug(`Serializing vk byte array into field elements vk=${vkPath}`);
559
552
  const vkAsFields = await api.acirVkAsFieldsUltraHonk(new RawBuffer(readFileSync(vkPath)));
560
553
  const jsonVKAsFields = JSON.stringify(vkAsFields.map(f => f.toString()));
561
554
 
562
555
  if (vkeyOutputPath === '-') {
563
556
  process.stdout.write(jsonVKAsFields);
564
- debug(`vkAsFieldsUltraHonk written to stdout`);
557
+ debug(`Verification key as fields written to stdout`);
565
558
  } else {
566
559
  writeFileSync(vkeyOutputPath, jsonVKAsFields);
567
- debug(`vkAsFieldsUltraHonk written to: ${vkeyOutputPath}`);
560
+ debug(`Verification key as fields written to ${vkeyOutputPath}`);
568
561
  }
569
-
570
- debug('done.');
571
562
  } finally {
572
563
  await api.destroy();
573
564
  }
@@ -9,6 +9,17 @@ export type ProofData = {
9
9
  proof: Uint8Array;
10
10
  };
11
11
 
12
+ /**
13
+ * @description
14
+ * The representation of a proof
15
+ * */
16
+ export type ProofDataForRecursion = {
17
+ /** @description Public inputs of a proof */
18
+ publicInputs: string[];
19
+ /** @description An byte array representing the proof */
20
+ proof: string[];
21
+ };
22
+
12
23
  // Buffers are prepended with their size. The size takes 4 bytes.
13
24
  const serializedBufferSize = 4;
14
25
  const fieldByteSize = 32;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Generates a backoff sequence for retrying operations with an increasing delay.
3
+ * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
4
+ * This generator can be used in combination with the `retry` function to perform
5
+ * retries with exponential backoff and capped at 64 seconds between attempts.
6
+ *
7
+ * @returns A generator that yields the next backoff value in seconds as an integer.
8
+ */
9
+ export function* backoffGenerator() {
10
+ const v = [1, 1, 1, 2, 4, 8, 16, 32, 64];
11
+ let i = 0;
12
+ while (true) {
13
+ yield v[Math.min(i++, v.length - 1)];
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
19
+ * @param retries - Intervals to retry (in seconds).
20
+ * @returns A generator sequence.
21
+ */
22
+ export function* makeBackoff(retries: number[]) {
23
+ for (const retry of retries) {
24
+ yield retry;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
30
+ * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
31
+ *
32
+ * @param fn - The asynchronous function to be retried.
33
+ * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
34
+ * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
35
+ * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
36
+ */
37
+ export async function retry<Result>(fn: () => Promise<Result>, backoff = backoffGenerator()) {
38
+ while (true) {
39
+ try {
40
+ return await fn();
41
+ } catch (err: any) {
42
+ const s = backoff.next().value;
43
+ if (s === undefined) {
44
+ throw err;
45
+ }
46
+ await new Promise(resolve => setTimeout(resolve, s * 1000));
47
+ continue;
48
+ }
49
+ }
50
+ }
@@ -1,5 +1,10 @@
1
1
  import { randomBytes } from '../random/index.js';
2
- import { toBigIntBE, toBufferBE } from '../bigint-array/index.js';
2
+ import {
3
+ buffer32BytesToBigIntBE,
4
+ uint8ArrayToBigIntBE,
5
+ bigIntToBufferBE,
6
+ bigIntToUint8ArrayBE,
7
+ } from '../bigint-array/index.js';
3
8
  import { BufferReader, uint8ArrayToHexString } from '../serialize/index.js';
4
9
 
5
10
  // TODO(#4189): Replace with implementation in yarn-project/foundation/src/fields/fields.ts
@@ -15,30 +20,36 @@ export class Fr {
15
20
  static SIZE_IN_BYTES = 32;
16
21
  value: Uint8Array;
17
22
 
18
- constructor(value: Uint8Array | bigint) {
23
+ constructor(value: Uint8Array | Buffer | bigint) {
19
24
  // We convert buffer value to bigint to be able to check it fits within modulus
20
- const valueBigInt = typeof value === 'bigint' ? value : toBigIntBE(value);
25
+ const valueBigInt =
26
+ typeof value === 'bigint'
27
+ ? value
28
+ : value instanceof Buffer
29
+ ? buffer32BytesToBigIntBE(value)
30
+ : uint8ArrayToBigIntBE(value);
21
31
 
22
32
  if (valueBigInt > Fr.MAX_VALUE) {
23
33
  throw new Error(`Value 0x${valueBigInt.toString(16)} is greater or equal to field modulus.`);
24
34
  }
25
35
 
26
- this.value = typeof value === 'bigint' ? toBufferBE(value) : value;
36
+ this.value =
37
+ typeof value === 'bigint' ? bigIntToUint8ArrayBE(value) : value instanceof Buffer ? new Uint8Array(value) : value;
27
38
  }
28
39
 
29
40
  static random() {
30
- const r = toBigIntBE(randomBytes(64)) % Fr.MODULUS;
41
+ const r = uint8ArrayToBigIntBE(randomBytes(64)) % Fr.MODULUS;
31
42
  return new this(r);
32
43
  }
33
44
 
34
- static fromBuffer(buffer: Uint8Array | BufferReader) {
45
+ static fromBuffer(buffer: Uint8Array | Buffer | BufferReader) {
35
46
  const reader = BufferReader.asReader(buffer);
36
47
  return new this(reader.readBytes(this.SIZE_IN_BYTES));
37
48
  }
38
49
 
39
50
  static fromBufferReduce(buffer: Uint8Array | BufferReader) {
40
51
  const reader = BufferReader.asReader(buffer);
41
- return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
52
+ return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
42
53
  }
43
54
 
44
55
  static fromString(str: string) {
@@ -79,18 +90,18 @@ export class Fq {
79
90
  }
80
91
 
81
92
  static random() {
82
- const r = toBigIntBE(randomBytes(64)) % Fq.MODULUS;
93
+ const r = uint8ArrayToBigIntBE(randomBytes(64)) % Fq.MODULUS;
83
94
  return new this(r);
84
95
  }
85
96
 
86
- static fromBuffer(buffer: Uint8Array | BufferReader) {
97
+ static fromBuffer(buffer: Uint8Array | Buffer | BufferReader) {
87
98
  const reader = BufferReader.asReader(buffer);
88
- return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
99
+ return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
89
100
  }
90
101
 
91
- static fromBufferReduce(buffer: Uint8Array | BufferReader) {
102
+ static fromBufferReduce(buffer: Uint8Array | Buffer | BufferReader) {
92
103
  const reader = BufferReader.asReader(buffer);
93
- return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
104
+ return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
94
105
  }
95
106
 
96
107
  static fromString(str: string) {
@@ -98,7 +109,7 @@ export class Fq {
98
109
  }
99
110
 
100
111
  toBuffer() {
101
- return toBufferBE(this.value, Fq.SIZE_IN_BYTES);
112
+ return bigIntToBufferBE(this.value, Fq.SIZE_IN_BYTES);
102
113
  }
103
114
 
104
115
  toString() {
@@ -1,10 +0,0 @@
1
- (globalThis["webpackChunk_aztec_bb_js"] = globalThis["webpackChunk_aztec_bb_js"] || []).push([[522],{
2
-
3
- /***/ 522:
4
- /***/ (() => {
5
-
6
- /* (ignored) */
7
-
8
- /***/ })
9
-
10
- }])