@aztec/bb.js 0.0.1-alpha.6 → 0.3.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 (39) hide show
  1. package/README.md +3 -4
  2. package/dest/barretenberg-threads.wasm +0 -0
  3. package/dest/barretenberg.wasm +0 -0
  4. package/dest/barretenberg_api/common.test.js +2 -2
  5. package/dest/barretenberg_api/index.d.ts.map +1 -1
  6. package/dest/barretenberg_api/index.js +2 -2
  7. package/dest/barretenberg_api/pedersen.test.js +1 -1
  8. package/dest/barretenberg_wasm/barretenberg_wasm.js +6 -6
  9. package/dest/barretenberg_wasm/barretenberg_wasm.test.js +6 -2
  10. package/dest/barretenberg_wasm/index.d.ts +1 -1
  11. package/dest/barretenberg_wasm/index.js +1 -1
  12. package/dest/barretenberg_wasm.js +1 -1
  13. package/dest/crs/browser/cached_net_crs.d.ts.map +1 -1
  14. package/dest/crs/browser/cached_net_crs.js +1 -1
  15. package/dest/crs/node/{file_crs.d.ts → ignition_files_crs.d.ts} +2 -2
  16. package/dest/crs/node/ignition_files_crs.d.ts.map +1 -0
  17. package/dest/crs/node/ignition_files_crs.js +51 -0
  18. package/dest/crs/node/index.d.ts +3 -13
  19. package/dest/crs/node/index.d.ts.map +1 -1
  20. package/dest/crs/node/index.js +29 -16
  21. package/dest/examples/simple.test.js +2 -2
  22. package/dest/main.d.ts +5 -5
  23. package/dest/main.d.ts.map +1 -1
  24. package/dest/main.js +46 -50
  25. package/dest/simple_test.js +1 -1
  26. package/package.json +7 -3
  27. package/src/barretenberg_api/common.test.ts +1 -1
  28. package/src/barretenberg_api/index.ts +220 -42
  29. package/src/barretenberg_api/pedersen.test.ts +1 -1
  30. package/src/barretenberg_wasm/barretenberg_wasm.test.ts +6 -1
  31. package/src/barretenberg_wasm/barretenberg_wasm.ts +5 -5
  32. package/src/barretenberg_wasm/index.ts +1 -1
  33. package/src/crs/browser/cached_net_crs.ts +0 -1
  34. package/src/crs/node/{file_crs.ts → ignition_files_crs.ts} +2 -2
  35. package/src/crs/node/index.ts +28 -20
  36. package/src/examples/simple.test.ts +2 -2
  37. package/src/main.ts +47 -53
  38. package/dest/crs/node/file_crs.d.ts.map +0 -1
  39. package/dest/crs/node/file_crs.js +0 -51
@@ -1,7 +1,13 @@
1
1
  // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT!
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
3
  import { BarretenbergBinder, BarretenbergBinderSync } from '../barretenberg_binder/index.js';
4
- import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer } from '../serialize/index.js';
4
+ import {
5
+ BufferDeserializer,
6
+ NumberDeserializer,
7
+ VectorDeserializer,
8
+ BoolDeserializer,
9
+ StringDeserializer,
10
+ } from '../serialize/index.js';
5
11
  import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js';
6
12
 
7
13
  export class BarretenbergApi {
@@ -37,7 +43,11 @@ export class BarretenbergApi {
37
43
  }
38
44
 
39
45
  async pedersenCompressWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
40
- const result = await this.binder.callWasmExport('pedersen___compress_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
46
+ const result = await this.binder.callWasmExport(
47
+ 'pedersen___compress_with_hash_index',
48
+ [inputsBuffer, hashIndex],
49
+ [Fr],
50
+ );
41
51
  return result[0];
42
52
  }
43
53
 
@@ -52,7 +62,11 @@ export class BarretenbergApi {
52
62
  }
53
63
 
54
64
  async pedersenPlookupCommitWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
55
- const result = await this.binder.callWasmExport('pedersen___plookup_commit_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
65
+ const result = await this.binder.callWasmExport(
66
+ 'pedersen___plookup_commit_with_hash_index',
67
+ [inputsBuffer, hashIndex],
68
+ [Fr],
69
+ );
56
70
  return result[0];
57
71
  }
58
72
 
@@ -77,7 +91,11 @@ export class BarretenbergApi {
77
91
  }
78
92
 
79
93
  async pedersenHashMultipleWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
80
- const result = await this.binder.callWasmExport('pedersen_hash_multiple_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
94
+ const result = await this.binder.callWasmExport(
95
+ 'pedersen_hash_multiple_with_hash_index',
96
+ [inputsBuffer, hashIndex],
97
+ [Fr],
98
+ );
81
99
  return result[0];
82
100
  }
83
101
 
@@ -107,37 +125,76 @@ export class BarretenbergApi {
107
125
  }
108
126
 
109
127
  async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> {
110
- const result = await this.binder.callWasmExport('schnorr_construct_signature', [message, privateKey], [Buffer32, Buffer32]);
128
+ const result = await this.binder.callWasmExport(
129
+ 'schnorr_construct_signature',
130
+ [message, privateKey],
131
+ [Buffer32, Buffer32],
132
+ );
111
133
  return result as any;
112
134
  }
113
135
 
114
136
  async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise<boolean> {
115
- const result = await this.binder.callWasmExport('schnorr_verify_signature', [message, pubKey, sigS, sigE], [BoolDeserializer()]);
137
+ const result = await this.binder.callWasmExport(
138
+ 'schnorr_verify_signature',
139
+ [message, pubKey, sigS, sigE],
140
+ [BoolDeserializer()],
141
+ );
116
142
  return result[0];
117
143
  }
118
144
 
119
145
  async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise<Buffer128> {
120
- const result = await this.binder.callWasmExport('schnorr_multisig_create_multisig_public_key', [privateKey], [Buffer128]);
146
+ const result = await this.binder.callWasmExport(
147
+ 'schnorr_multisig_create_multisig_public_key',
148
+ [privateKey],
149
+ [Buffer128],
150
+ );
121
151
  return result[0];
122
152
  }
123
153
 
124
154
  async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> {
125
- const result = await this.binder.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', [signerPubkeyBuf], [Point, BoolDeserializer()]);
155
+ const result = await this.binder.callWasmExport(
156
+ 'schnorr_multisig_validate_and_combine_signer_pubkeys',
157
+ [signerPubkeyBuf],
158
+ [Point, BoolDeserializer()],
159
+ );
126
160
  return result as any;
127
161
  }
128
162
 
129
163
  async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> {
130
- const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_1', [], [Buffer128, Buffer128]);
164
+ const result = await this.binder.callWasmExport(
165
+ 'schnorr_multisig_construct_signature_round_1',
166
+ [],
167
+ [Buffer128, Buffer128],
168
+ );
131
169
  return result as any;
132
170
  }
133
171
 
134
- async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fq, boolean]> {
135
- const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], [Fq, BoolDeserializer()]);
172
+ async schnorrMultisigConstructSignatureRound2(
173
+ message: Uint8Array,
174
+ privateKey: Fq,
175
+ signerRoundOnePrivateBuf: Buffer128,
176
+ signerPubkeysBuf: Buffer128[],
177
+ roundOnePublicBuf: Buffer128[],
178
+ ): Promise<[Fq, boolean]> {
179
+ const result = await this.binder.callWasmExport(
180
+ 'schnorr_multisig_construct_signature_round_2',
181
+ [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf],
182
+ [Fq, BoolDeserializer()],
183
+ );
136
184
  return result as any;
137
185
  }
138
186
 
139
- async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fr[]): Promise<[Buffer32, Buffer32, boolean]> {
140
- const result = await this.binder.callWasmExport('schnorr_multisig_combine_signatures', [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], [Buffer32, Buffer32, BoolDeserializer()]);
187
+ async schnorrMultisigCombineSignatures(
188
+ message: Uint8Array,
189
+ signerPubkeysBuf: Buffer128[],
190
+ roundOneBuf: Buffer128[],
191
+ roundTwoBuf: Fr[],
192
+ ): Promise<[Buffer32, Buffer32, boolean]> {
193
+ const result = await this.binder.callWasmExport(
194
+ 'schnorr_multisig_combine_signatures',
195
+ [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf],
196
+ [Buffer32, Buffer32, BoolDeserializer()],
197
+ );
141
198
  return result as any;
142
199
  }
143
200
 
@@ -147,7 +204,11 @@ export class BarretenbergApi {
147
204
  }
148
205
 
149
206
  async examplesSimpleCreateAndVerifyProof(): Promise<boolean> {
150
- const result = await this.binder.callWasmExport('examples_simple_create_and_verify_proof', [], [BoolDeserializer()]);
207
+ const result = await this.binder.callWasmExport(
208
+ 'examples_simple_create_and_verify_proof',
209
+ [],
210
+ [BoolDeserializer()],
211
+ );
151
212
  return result[0];
152
213
  }
153
214
 
@@ -172,7 +233,11 @@ export class BarretenbergApi {
172
233
  }
173
234
 
174
235
  async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> {
175
- const result = await this.binder.callWasmExport('acir_get_circuit_sizes', [constraintSystemBuf], [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]);
236
+ const result = await this.binder.callWasmExport(
237
+ 'acir_get_circuit_sizes',
238
+ [constraintSystemBuf],
239
+ [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()],
240
+ );
176
241
  return result as any;
177
242
  }
178
243
 
@@ -187,17 +252,34 @@ export class BarretenbergApi {
187
252
  }
188
253
 
189
254
  async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise<void> {
190
- const result = await this.binder.callWasmExport('acir_create_circuit', [acirComposerPtr, constraintSystemBuf, sizeHint], []);
255
+ const result = await this.binder.callWasmExport(
256
+ 'acir_create_circuit',
257
+ [acirComposerPtr, constraintSystemBuf, sizeHint],
258
+ [],
259
+ );
191
260
  return;
192
261
  }
193
262
 
194
263
  async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise<void> {
195
- const result = await this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf], []);
264
+ const result = await this.binder.callWasmExport(
265
+ 'acir_init_proving_key',
266
+ [acirComposerPtr, constraintSystemBuf],
267
+ [],
268
+ );
196
269
  return;
197
270
  }
198
271
 
199
- async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Promise<Uint8Array> {
200
- const result = await this.binder.callWasmExport('acir_create_proof', [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], [BufferDeserializer()]);
272
+ async acirCreateProof(
273
+ acirComposerPtr: Ptr,
274
+ constraintSystemBuf: Uint8Array,
275
+ witnessBuf: Uint8Array,
276
+ isRecursive: boolean,
277
+ ): Promise<Uint8Array> {
278
+ const result = await this.binder.callWasmExport(
279
+ 'acir_create_proof',
280
+ [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive],
281
+ [BufferDeserializer()],
282
+ );
201
283
  return result[0];
202
284
  }
203
285
 
@@ -212,27 +294,51 @@ export class BarretenbergApi {
212
294
  }
213
295
 
214
296
  async acirGetVerificationKey(acirComposerPtr: Ptr): Promise<Uint8Array> {
215
- const result = await this.binder.callWasmExport('acir_get_verification_key', [acirComposerPtr], [BufferDeserializer()]);
297
+ const result = await this.binder.callWasmExport(
298
+ 'acir_get_verification_key',
299
+ [acirComposerPtr],
300
+ [BufferDeserializer()],
301
+ );
216
302
  return result[0];
217
303
  }
218
304
 
219
305
  async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): Promise<boolean> {
220
- const result = await this.binder.callWasmExport('acir_verify_proof', [acirComposerPtr, proofBuf, isRecursive], [BoolDeserializer()]);
306
+ const result = await this.binder.callWasmExport(
307
+ 'acir_verify_proof',
308
+ [acirComposerPtr, proofBuf, isRecursive],
309
+ [BoolDeserializer()],
310
+ );
221
311
  return result[0];
222
312
  }
223
313
 
224
314
  async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise<string> {
225
- const result = await this.binder.callWasmExport('acir_get_solidity_verifier', [acirComposerPtr], [StringDeserializer()]);
315
+ const result = await this.binder.callWasmExport(
316
+ 'acir_get_solidity_verifier',
317
+ [acirComposerPtr],
318
+ [StringDeserializer()],
319
+ );
226
320
  return result[0];
227
321
  }
228
322
 
229
- async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise<Fr[]> {
230
- const result = await this.binder.callWasmExport('acir_serialize_proof_into_fields', [acirComposerPtr, proofBuf, numInnerPublicInputs], [VectorDeserializer(Fr)]);
323
+ async acirSerializeProofIntoFields(
324
+ acirComposerPtr: Ptr,
325
+ proofBuf: Uint8Array,
326
+ numInnerPublicInputs: number,
327
+ ): Promise<Fr[]> {
328
+ const result = await this.binder.callWasmExport(
329
+ 'acir_serialize_proof_into_fields',
330
+ [acirComposerPtr, proofBuf, numInnerPublicInputs],
331
+ [VectorDeserializer(Fr)],
332
+ );
231
333
  return result[0];
232
334
  }
233
335
 
234
336
  async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> {
235
- const result = await this.binder.callWasmExport('acir_serialize_verification_key_into_fields', [acirComposerPtr], [VectorDeserializer(Fr), Fr]);
337
+ const result = await this.binder.callWasmExport(
338
+ 'acir_serialize_verification_key_into_fields',
339
+ [acirComposerPtr],
340
+ [VectorDeserializer(Fr), Fr],
341
+ );
236
342
  return result as any;
237
343
  }
238
344
  }
@@ -285,7 +391,11 @@ export class BarretenbergApiSync {
285
391
  }
286
392
 
287
393
  pedersenPlookupCommitWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Fr {
288
- const result = this.binder.callWasmExport('pedersen___plookup_commit_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
394
+ const result = this.binder.callWasmExport(
395
+ 'pedersen___plookup_commit_with_hash_index',
396
+ [inputsBuffer, hashIndex],
397
+ [Fr],
398
+ );
289
399
  return result[0];
290
400
  }
291
401
 
@@ -310,7 +420,11 @@ export class BarretenbergApiSync {
310
420
  }
311
421
 
312
422
  pedersenHashMultipleWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Fr {
313
- const result = this.binder.callWasmExport('pedersen_hash_multiple_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
423
+ const result = this.binder.callWasmExport(
424
+ 'pedersen_hash_multiple_with_hash_index',
425
+ [inputsBuffer, hashIndex],
426
+ [Fr],
427
+ );
314
428
  return result[0];
315
429
  }
316
430
 
@@ -340,12 +454,20 @@ export class BarretenbergApiSync {
340
454
  }
341
455
 
342
456
  schnorrConstructSignature(message: Uint8Array, privateKey: Fr): [Buffer32, Buffer32] {
343
- const result = this.binder.callWasmExport('schnorr_construct_signature', [message, privateKey], [Buffer32, Buffer32]);
457
+ const result = this.binder.callWasmExport(
458
+ 'schnorr_construct_signature',
459
+ [message, privateKey],
460
+ [Buffer32, Buffer32],
461
+ );
344
462
  return result as any;
345
463
  }
346
464
 
347
465
  schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): boolean {
348
- const result = this.binder.callWasmExport('schnorr_verify_signature', [message, pubKey, sigS, sigE], [BoolDeserializer()]);
466
+ const result = this.binder.callWasmExport(
467
+ 'schnorr_verify_signature',
468
+ [message, pubKey, sigS, sigE],
469
+ [BoolDeserializer()],
470
+ );
349
471
  return result[0];
350
472
  }
351
473
 
@@ -355,22 +477,49 @@ export class BarretenbergApiSync {
355
477
  }
356
478
 
357
479
  schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): [Point, boolean] {
358
- const result = this.binder.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', [signerPubkeyBuf], [Point, BoolDeserializer()]);
480
+ const result = this.binder.callWasmExport(
481
+ 'schnorr_multisig_validate_and_combine_signer_pubkeys',
482
+ [signerPubkeyBuf],
483
+ [Point, BoolDeserializer()],
484
+ );
359
485
  return result as any;
360
486
  }
361
487
 
362
488
  schnorrMultisigConstructSignatureRound1(): [Buffer128, Buffer128] {
363
- const result = this.binder.callWasmExport('schnorr_multisig_construct_signature_round_1', [], [Buffer128, Buffer128]);
489
+ const result = this.binder.callWasmExport(
490
+ 'schnorr_multisig_construct_signature_round_1',
491
+ [],
492
+ [Buffer128, Buffer128],
493
+ );
364
494
  return result as any;
365
495
  }
366
496
 
367
- schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): [Fq, boolean] {
368
- const result = this.binder.callWasmExport('schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], [Fq, BoolDeserializer()]);
497
+ schnorrMultisigConstructSignatureRound2(
498
+ message: Uint8Array,
499
+ privateKey: Fq,
500
+ signerRoundOnePrivateBuf: Buffer128,
501
+ signerPubkeysBuf: Buffer128[],
502
+ roundOnePublicBuf: Buffer128[],
503
+ ): [Fq, boolean] {
504
+ const result = this.binder.callWasmExport(
505
+ 'schnorr_multisig_construct_signature_round_2',
506
+ [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf],
507
+ [Fq, BoolDeserializer()],
508
+ );
369
509
  return result as any;
370
510
  }
371
511
 
372
- schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fr[]): [Buffer32, Buffer32, boolean] {
373
- const result = this.binder.callWasmExport('schnorr_multisig_combine_signatures', [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], [Buffer32, Buffer32, BoolDeserializer()]);
512
+ schnorrMultisigCombineSignatures(
513
+ message: Uint8Array,
514
+ signerPubkeysBuf: Buffer128[],
515
+ roundOneBuf: Buffer128[],
516
+ roundTwoBuf: Fr[],
517
+ ): [Buffer32, Buffer32, boolean] {
518
+ const result = this.binder.callWasmExport(
519
+ 'schnorr_multisig_combine_signatures',
520
+ [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf],
521
+ [Buffer32, Buffer32, BoolDeserializer()],
522
+ );
374
523
  return result as any;
375
524
  }
376
525
 
@@ -405,7 +554,11 @@ export class BarretenbergApiSync {
405
554
  }
406
555
 
407
556
  acirGetCircuitSizes(constraintSystemBuf: Uint8Array): [number, number, number] {
408
- const result = this.binder.callWasmExport('acir_get_circuit_sizes', [constraintSystemBuf], [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]);
557
+ const result = this.binder.callWasmExport(
558
+ 'acir_get_circuit_sizes',
559
+ [constraintSystemBuf],
560
+ [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()],
561
+ );
409
562
  return result as any;
410
563
  }
411
564
 
@@ -420,7 +573,11 @@ export class BarretenbergApiSync {
420
573
  }
421
574
 
422
575
  acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): void {
423
- const result = this.binder.callWasmExport('acir_create_circuit', [acirComposerPtr, constraintSystemBuf, sizeHint], []);
576
+ const result = this.binder.callWasmExport(
577
+ 'acir_create_circuit',
578
+ [acirComposerPtr, constraintSystemBuf, sizeHint],
579
+ [],
580
+ );
424
581
  return;
425
582
  }
426
583
 
@@ -429,8 +586,17 @@ export class BarretenbergApiSync {
429
586
  return;
430
587
  }
431
588
 
432
- acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Uint8Array {
433
- const result = this.binder.callWasmExport('acir_create_proof', [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], [BufferDeserializer()]);
589
+ acirCreateProof(
590
+ acirComposerPtr: Ptr,
591
+ constraintSystemBuf: Uint8Array,
592
+ witnessBuf: Uint8Array,
593
+ isRecursive: boolean,
594
+ ): Uint8Array {
595
+ const result = this.binder.callWasmExport(
596
+ 'acir_create_proof',
597
+ [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive],
598
+ [BufferDeserializer()],
599
+ );
434
600
  return result[0];
435
601
  }
436
602
 
@@ -450,7 +616,11 @@ export class BarretenbergApiSync {
450
616
  }
451
617
 
452
618
  acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): boolean {
453
- const result = this.binder.callWasmExport('acir_verify_proof', [acirComposerPtr, proofBuf, isRecursive], [BoolDeserializer()]);
619
+ const result = this.binder.callWasmExport(
620
+ 'acir_verify_proof',
621
+ [acirComposerPtr, proofBuf, isRecursive],
622
+ [BoolDeserializer()],
623
+ );
454
624
  return result[0];
455
625
  }
456
626
 
@@ -460,12 +630,20 @@ export class BarretenbergApiSync {
460
630
  }
461
631
 
462
632
  acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Fr[] {
463
- const result = this.binder.callWasmExport('acir_serialize_proof_into_fields', [acirComposerPtr, proofBuf, numInnerPublicInputs], [VectorDeserializer(Fr)]);
633
+ const result = this.binder.callWasmExport(
634
+ 'acir_serialize_proof_into_fields',
635
+ [acirComposerPtr, proofBuf, numInnerPublicInputs],
636
+ [VectorDeserializer(Fr)],
637
+ );
464
638
  return result[0];
465
639
  }
466
640
 
467
641
  acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): [Fr[], Fr] {
468
- const result = this.binder.callWasmExport('acir_serialize_verification_key_into_fields', [acirComposerPtr], [VectorDeserializer(Fr), Fr]);
642
+ const result = this.binder.callWasmExport(
643
+ 'acir_serialize_verification_key_into_fields',
644
+ [acirComposerPtr],
645
+ [VectorDeserializer(Fr), Fr],
646
+ );
469
647
  return result as any;
470
648
  }
471
649
  }
@@ -36,7 +36,7 @@ describe('pedersen', () => {
36
36
 
37
37
  it('pedersenCompressWithHashIndex', () => {
38
38
  const result = api.pedersenCompressWithHashIndex([new Fr(4n), new Fr(8n)], 7);
39
- expect(result).toEqual(new Fr(12675961871866002745031098923411501942277744385859978302365013982702509949754n));
39
+ expect(result).toEqual(new Fr(11068631634751286805527305272746775861010877976108429785597565355072506728435n));
40
40
  });
41
41
 
42
42
  it('pedersenCommit', () => {
@@ -25,6 +25,11 @@ describe('barretenberg wasm', () => {
25
25
  it('test abort', () => {
26
26
  expect(() => wasm.call('test_abort')).toThrow();
27
27
  });
28
+
29
+ it('test c/c++ stdout/stderr', () => {
30
+ // We're checking we don't crash, but you can manually confirm you see log lines handled by logstr.
31
+ wasm.call('test_stdout_stderr');
32
+ });
28
33
  });
29
34
 
30
35
  describe('barretenberg wasm worker', () => {
@@ -33,7 +38,7 @@ describe('barretenberg wasm worker', () => {
33
38
 
34
39
  beforeAll(async () => {
35
40
  ({ wasm, worker } = await BarretenbergWasm.newWorker(2));
36
- });
41
+ }, 20000);
37
42
 
38
43
  afterAll(async () => {
39
44
  await wasm.destroy();
@@ -13,7 +13,7 @@ const debug = createDebug('bb.js:wasm');
13
13
  EventEmitter.defaultMaxListeners = 30;
14
14
 
15
15
  export class BarretenbergWasm {
16
- static MAX_THREADS = 16;
16
+ static MAX_THREADS = 32;
17
17
  private memStore: { [key: string]: Uint8Array } = {};
18
18
  private memory!: WebAssembly.Memory;
19
19
  private instance!: WebAssembly.Instance;
@@ -121,7 +121,7 @@ export class BarretenbergWasm {
121
121
  view.setBigUint64(out, ts, true);
122
122
  },
123
123
  proc_exit: () => {
124
- this.logger('HUNG: proc_exit was called. This is caused by unstable experimental wasi pthreads. Try again.');
124
+ this.logger('PANIC: proc_exit was called. This is maybe caused by "joining" with unstable wasi pthreads.');
125
125
  this.logger(new Error().stack!);
126
126
  killSelf();
127
127
  },
@@ -156,9 +156,9 @@ export class BarretenbergWasm {
156
156
  const m = this.getMemory();
157
157
  const str2 = `${str} (mem: ${(m.length / (1024 * 1024)).toFixed(2)}MiB)`;
158
158
  this.logger(str2);
159
- // if (str2.startsWith('WARNING:')) {
160
- // this.logger(new Error().stack!);
161
- // }
159
+ if (str2.startsWith('WARNING:')) {
160
+ this.logger(new Error().stack!);
161
+ }
162
162
  },
163
163
 
164
164
  get_data: (keyAddr: number, outBufAddr: number) => {
@@ -1 +1 @@
1
- export * from "./barretenberg_wasm.js";
1
+ export * from './barretenberg_wasm.js';
@@ -1,4 +1,3 @@
1
- import { concatenateUint8Arrays, numToUInt32BE } from '../../serialize/index.js';
2
1
  import { NetCrs } from '../net_crs.js';
3
2
  import { get, set } from 'idb-keyval';
4
3
 
@@ -11,7 +11,7 @@ export const SRS_DEV_PATH = dirname(fileURLToPath(import.meta.url)) + '/../../..
11
11
  /**
12
12
  * Downloader for CRS from a local file (for Node).
13
13
  */
14
- export class FileCrs {
14
+ export class IgnitionFilesCrs {
15
15
  private data!: Uint8Array;
16
16
  private g2Data!: Uint8Array;
17
17
 
@@ -20,7 +20,7 @@ export class FileCrs {
20
20
  * The number of circuit gates.
21
21
  */
22
22
  public readonly numPoints: number,
23
- private path = SRS_DEV_PATH
23
+ private path = SRS_DEV_PATH,
24
24
  ) {}
25
25
 
26
26
  static defaultExists() {
@@ -1,33 +1,41 @@
1
- import { concatenateUint8Arrays, numToUInt32BE } from '../../serialize/serialize.js';
2
1
  import { NetCrs } from '../net_crs.js';
3
- import { FileCrs } from './file_crs.js';
2
+ import { IgnitionFilesCrs } from './ignition_files_crs.js';
3
+ import { mkdirSync, readFileSync, writeFileSync } from 'fs';
4
+ import { readFile } from 'fs/promises';
5
+ import createDebug from 'debug';
6
+
7
+ const debug = createDebug('bb.js:crs');
4
8
 
5
9
  /**
6
10
  * Generic CRS finder utility class.
7
11
  */
8
12
  export class Crs {
9
- private crs: FileCrs | NetCrs;
10
-
11
- constructor(
12
- /**
13
- * The number of circuit gates.
14
- */
15
- public readonly numPoints: number,
16
- ) {
17
- this.crs = FileCrs.defaultExists() ? new FileCrs(numPoints) : new NetCrs(numPoints);
18
- }
13
+ constructor(public readonly numPoints: number, public readonly path: string) {}
19
14
 
20
- static async new(numPoints: number) {
21
- const crs = new Crs(numPoints);
15
+ static async new(numPoints: number, crsPath = './crs') {
16
+ const crs = new Crs(numPoints, crsPath);
22
17
  await crs.init();
23
18
  return crs;
24
19
  }
25
20
 
26
- /**
27
- * Read CRS from our chosen source.
28
- */
29
21
  async init() {
30
- await this.crs.init();
22
+ mkdirSync(this.path, { recursive: true });
23
+ const size = await readFile(this.path + '/size', 'ascii').catch(() => undefined);
24
+ if (size && +size >= this.numPoints) {
25
+ debug(`using cached crs of size: ${size}`);
26
+ return;
27
+ }
28
+
29
+ const crs = IgnitionFilesCrs.defaultExists() ? new IgnitionFilesCrs(this.numPoints) : new NetCrs(this.numPoints);
30
+ if (crs instanceof NetCrs) {
31
+ debug(`downloading crs of size: ${this.numPoints}`);
32
+ } else {
33
+ debug(`loading igntion file crs of size: ${this.numPoints}`);
34
+ }
35
+ await crs.init();
36
+ writeFileSync(this.path + '/size', this.numPoints.toString());
37
+ writeFileSync(this.path + '/g1.dat', crs.getG1Data());
38
+ writeFileSync(this.path + '/g2.dat', crs.getG2Data());
31
39
  }
32
40
 
33
41
  /**
@@ -35,7 +43,7 @@ export class Crs {
35
43
  * @returns The points data.
36
44
  */
37
45
  getG1Data(): Uint8Array {
38
- return this.crs.getG1Data();
46
+ return readFileSync(this.path + '/g1.dat');
39
47
  }
40
48
 
41
49
  /**
@@ -43,6 +51,6 @@ export class Crs {
43
51
  * @returns The points data.
44
52
  */
45
53
  getG2Data(): Uint8Array {
46
- return this.crs.getG2Data();
54
+ return readFileSync(this.path + '/g2.dat');
47
55
  }
48
56
  }
@@ -14,7 +14,7 @@ describe('simple', () => {
14
14
 
15
15
  const crs = await Crs.new(2 ** 19 + 1);
16
16
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
17
- }, 20000);
17
+ }, 30000);
18
18
 
19
19
  afterAll(async () => {
20
20
  await api.destroy();
@@ -23,5 +23,5 @@ describe('simple', () => {
23
23
  it('should construct 512k gate proof', async () => {
24
24
  const valid = await api.examplesSimpleCreateAndVerifyProof();
25
25
  expect(valid).toBe(true);
26
- }, 60000);
26
+ }, 90000);
27
27
  });