@aztec/bb.js 0.67.1-devnet → 0.67.2-devnet

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aztec/bb.js",
3
- "packageManager": "yarn@1.22.22",
4
- "version": "0.67.1-devnet",
3
+ "packageManager": "yarn@4.5.2",
4
+ "version": "0.67.2-devnet",
5
5
  "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg/ts",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -31,23 +31,34 @@
31
31
  "formatting": "prettier --check ./src && eslint --max-warnings 0 ./src",
32
32
  "formatting:fix": "prettier -w ./src",
33
33
  "test": "NODE_OPTIONS='--loader ts-node/esm' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests",
34
- "test:debug": "NODE_OPTIONS='--loader ts-node/esm' NODE_NO_WARNINGS=1 node --inspect-brk=0.0.0.0 --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests --runInBand",
35
- "simple_test": "NODE_OPTIONS='--loader ts-node/esm' NODE_NO_WARNINGS=1 node ./src/examples/simple.rawtest.ts",
34
+ "test:debug": "NODE_NO_WARNINGS=1 node --inspect-brk=0.0.0.0 --experimental-vm-modules ./node_modules/.bin/jest --no-cache --passWithNoTests --runInBand",
35
+ "simple_test": "NODE_NO_WARNINGS=1 node ./src/examples/simple.rawtest.ts",
36
36
  "deploy": "npm publish --access public"
37
37
  },
38
38
  "jest": {
39
39
  "preset": "ts-jest/presets/default-esm",
40
40
  "transform": {
41
- "./src/.*\\.ts": [
42
- "ts-jest",
41
+ "^.+\\.tsx?$": [
42
+ "@swc/jest",
43
43
  {
44
- "useESM": true
44
+ "jsc": {
45
+ "parser": {
46
+ "syntax": "typescript",
47
+ "decorators": true
48
+ },
49
+ "transform": {
50
+ "decoratorVersion": "2022-03"
51
+ }
52
+ }
45
53
  }
46
54
  ]
47
55
  },
48
56
  "moduleNameMapper": {
49
57
  "^(\\.{1,2}/.*)\\.js$": "$1"
50
58
  },
59
+ "extensionsToTreatAsEsm": [
60
+ ".ts"
61
+ ],
51
62
  "testRegex": "./src/.*\\.test\\.ts$",
52
63
  "rootDir": "./src"
53
64
  },
@@ -62,6 +73,8 @@
62
73
  "devDependencies": {
63
74
  "@jest/globals": "^29.4.3",
64
75
  "@msgpack/msgpack": "^3.0.0-beta2",
76
+ "@swc/core": "^1.10.1",
77
+ "@swc/jest": "^0.2.37",
65
78
  "@types/debug": "^4.1.7",
66
79
  "@types/detect-node": "^2.0.0",
67
80
  "@types/jest": "^29.4.0",
@@ -79,6 +92,7 @@
79
92
  "jest": "^29.5.0",
80
93
  "prettier": "^2.8.4",
81
94
  "resolve-typescript-plugin": "^2.0.1",
95
+ "source-map-support": "^0.5.21",
82
96
  "ts-jest": "^29.1.0",
83
97
  "ts-loader": "^9.4.2",
84
98
  "ts-node": "^10.9.1",
@@ -1,6 +1,5 @@
1
1
  import createDebug from 'debug';
2
2
  import { randomBytes } from '../../random/index.js';
3
- import { killSelf } from '../helpers/index.js';
4
3
 
5
4
  const debug = createDebug('bb.js:wasm');
6
5
 
@@ -34,9 +33,8 @@ export class BarretenbergWasmBase {
34
33
  view.setBigUint64(out, ts, true);
35
34
  },
36
35
  proc_exit: () => {
37
- this.logger('PANIC: proc_exit was called. This is maybe caused by "joining" with unstable wasi pthreads.');
38
- this.logger(new Error().stack!);
39
- killSelf();
36
+ this.logger('PANIC: proc_exit was called.');
37
+ throw new Error();
40
38
  },
41
39
  },
42
40
 
@@ -1,5 +1,5 @@
1
1
  import { NetCrs, NetGrumpkinCrs } from '../net_crs.js';
2
- import { mkdirSync, readFileSync, writeFileSync } from 'fs';
2
+ import { closeSync, mkdirSync, openSync, readFileSync, readSync, writeFileSync } from 'fs';
3
3
  import { stat } from 'fs/promises';
4
4
  import createDebug from 'debug';
5
5
  import { homedir } from 'os';
@@ -45,7 +45,12 @@ export class Crs {
45
45
  * @returns The points data.
46
46
  */
47
47
  getG1Data(): Uint8Array {
48
- return readFileSync(this.path + '/bn254_g1.dat');
48
+ const length = this.numPoints * 64;
49
+ const fd = openSync(this.path + '/bn254_g1.dat', 'r');
50
+ const buffer = new Uint8Array(length);
51
+ readSync(fd, buffer, 0, length, 0);
52
+ closeSync(fd);
53
+ return buffer;
49
54
  }
50
55
 
51
56
  /**
package/src/main.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import 'source-map-support/register.js';
2
3
  import { Crs, GrumpkinCrs, Barretenberg, RawBuffer } from './index.js';
3
4
  import createDebug from 'debug';
4
5
  import { readFileSync, writeFileSync } from 'fs';
@@ -141,11 +142,11 @@ async function initClientIVC(crsPath: string) {
141
142
  return { api };
142
143
  }
143
144
 
144
- async function initLite() {
145
+ async function initLite(crsPath: string) {
145
146
  const api = await Barretenberg.new({ threads: 1 });
146
147
 
147
148
  // Plus 1 needed! (Move +1 into Crs?)
148
- const crs = await Crs.new(1);
149
+ const crs = await Crs.new(1, crsPath);
149
150
 
150
151
  // Load CRS into wasm global CRS state.
151
152
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
@@ -305,8 +306,8 @@ export async function gateCountUltra(bytecodePath: string, recursive: boolean, h
305
306
  }
306
307
  }
307
308
 
308
- export async function verify(proofPath: string, vkPath: string) {
309
- const { api, acirComposer } = await initLite();
309
+ export async function verify(proofPath: string, vkPath: string, crsPath: string) {
310
+ const { api, acirComposer } = await initLite(crsPath);
310
311
  try {
311
312
  await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
312
313
  const verified = await api.acirVerifyProof(acirComposer, readFileSync(proofPath));
@@ -317,8 +318,8 @@ export async function verify(proofPath: string, vkPath: string) {
317
318
  }
318
319
  }
319
320
 
320
- export async function contract(outputPath: string, vkPath: string) {
321
- const { api, acirComposer } = await initLite();
321
+ export async function contract(outputPath: string, vkPath: string, crsPath: string) {
322
+ const { api, acirComposer } = await initLite(crsPath);
322
323
  try {
323
324
  await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
324
325
  const contract = await api.acirGetSolidityVerifier(acirComposer);
@@ -397,8 +398,8 @@ export async function writePk(bytecodePath: string, recursive: boolean, crsPath:
397
398
  }
398
399
  }
399
400
 
400
- export async function proofAsFields(proofPath: string, vkPath: string, outputPath: string) {
401
- const { api, acirComposer } = await initLite();
401
+ export async function proofAsFields(proofPath: string, vkPath: string, outputPath: string, crsPath: string) {
402
+ const { api, acirComposer } = await initLite(crsPath);
402
403
 
403
404
  try {
404
405
  debug('serializing proof byte array into field elements');
@@ -424,8 +425,8 @@ export async function proofAsFields(proofPath: string, vkPath: string, outputPat
424
425
  }
425
426
  }
426
427
 
427
- export async function vkAsFields(vkPath: string, vkeyOutputPath: string) {
428
- const { api, acirComposer } = await initLite();
428
+ export async function vkAsFields(vkPath: string, vkeyOutputPath: string, crsPath: string) {
429
+ const { api, acirComposer } = await initLite(crsPath);
429
430
 
430
431
  try {
431
432
  debug('serializing vk byte array into field elements');
@@ -509,8 +510,13 @@ export async function writeVkUltraHonk(
509
510
  }
510
511
  }
511
512
 
512
- export async function verifyUltraHonk(proofPath: string, vkPath: string, options?: UltraHonkBackendOptions) {
513
- const { api } = await initLite();
513
+ export async function verifyUltraHonk(
514
+ proofPath: string,
515
+ vkPath: string,
516
+ crsPath: string,
517
+ options?: UltraHonkBackendOptions,
518
+ ) {
519
+ const { api } = await initLite(crsPath);
514
520
  try {
515
521
  const acirVerifyUltraHonk = options?.keccak
516
522
  ? api.acirVerifyUltraKeccakHonk.bind(api)
@@ -524,8 +530,8 @@ export async function verifyUltraHonk(proofPath: string, vkPath: string, options
524
530
  }
525
531
  }
526
532
 
527
- export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: string) {
528
- const { api } = await initLite();
533
+ export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: string, crsPath: string) {
534
+ const { api } = await initLite(crsPath);
529
535
  try {
530
536
  debug('outputting proof as vector of fields');
531
537
  const proofAsFields = await api.acirProofAsFieldsUltraHonk(readFileSync(proofPath));
@@ -545,8 +551,8 @@ export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: stri
545
551
  }
546
552
  }
547
553
 
548
- export async function vkAsFieldsUltraHonk(vkPath: string, vkeyOutputPath: string) {
549
- const { api } = await initLite();
554
+ export async function vkAsFieldsUltraHonk(vkPath: string, vkeyOutputPath: string, crsPath: string) {
555
+ const { api } = await initLite(crsPath);
550
556
 
551
557
  try {
552
558
  debug('serializing vk byte array into field elements');
@@ -576,6 +582,7 @@ function handleGlobalOptions() {
576
582
  if (program.opts().verbose) {
577
583
  createDebug.enable('bb.js*');
578
584
  }
585
+ return { crsPath: program.opts().crsPath };
579
586
  }
580
587
 
581
588
  program
@@ -584,8 +591,8 @@ program
584
591
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
585
592
  .option('-r, --recursive', 'Whether to use a SNARK friendly proof', false)
586
593
  .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
587
- .action(async ({ bytecodePath, recursive, witnessPath, crsPath }) => {
588
- handleGlobalOptions();
594
+ .action(async ({ bytecodePath, recursive, witnessPath }) => {
595
+ const { crsPath } = handleGlobalOptions();
589
596
  const result = await proveAndVerify(bytecodePath, recursive, witnessPath, crsPath);
590
597
  process.exit(result ? 0 : 1);
591
598
  });
@@ -596,8 +603,8 @@ program
596
603
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
597
604
  .option('-r, --recursive', 'Whether to use a SNARK friendly proof', false)
598
605
  .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
599
- .action(async ({ bytecodePath, recursive, witnessPath, crsPath }) => {
600
- handleGlobalOptions();
606
+ .action(async ({ bytecodePath, recursive, witnessPath }) => {
607
+ const { crsPath } = handleGlobalOptions();
601
608
  const result = await proveAndVerifyUltraHonk(bytecodePath, recursive, witnessPath, crsPath);
602
609
  process.exit(result ? 0 : 1);
603
610
  });
@@ -608,8 +615,8 @@ program
608
615
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
609
616
  .option('-r, --recursive', 'Whether to use a SNARK friendly proof', false)
610
617
  .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
611
- .action(async ({ bytecodePath, recursive, witnessPath, crsPath }) => {
612
- handleGlobalOptions();
618
+ .action(async ({ bytecodePath, recursive, witnessPath }) => {
619
+ const { crsPath } = handleGlobalOptions();
613
620
  const result = await proveAndVerifyMegaHonk(bytecodePath, recursive, witnessPath, crsPath);
614
621
  process.exit(result ? 0 : 1);
615
622
  });
@@ -619,8 +626,8 @@ program
619
626
  .description('Generate a ClientIVC proof.')
620
627
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/acir.msgpack.b64')
621
628
  .option('-w, --witness-path <path>', 'Specify the witness path', './target/witnesses.msgpack.b64')
622
- .action(async ({ bytecodePath, witnessPath, crsPath }) => {
623
- handleGlobalOptions();
629
+ .action(async ({ bytecodePath, witnessPath }) => {
630
+ const { crsPath } = handleGlobalOptions();
624
631
  const result = await proveAndVerifyAztecClient(bytecodePath, witnessPath, crsPath);
625
632
  process.exit(result ? 0 : 1);
626
633
  });
@@ -631,8 +638,8 @@ program
631
638
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
632
639
  .option('-r, --recursive', 'Create a SNARK friendly proof', false)
633
640
  .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
634
- .action(async ({ bytecodePath, recursive, witnessPath, crsPath }) => {
635
- handleGlobalOptions();
641
+ .action(async ({ bytecodePath, recursive, witnessPath }) => {
642
+ const { crsPath } = handleGlobalOptions();
636
643
  const result = await foldAndVerifyProgram(bytecodePath, recursive, witnessPath, crsPath);
637
644
  process.exit(result ? 0 : 1);
638
645
  });
@@ -644,8 +651,8 @@ program
644
651
  .option('-r, --recursive', 'Create a SNARK friendly proof', false)
645
652
  .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
646
653
  .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
647
- .action(async ({ bytecodePath, recursive, witnessPath, outputPath, crsPath }) => {
648
- handleGlobalOptions();
654
+ .action(async ({ bytecodePath, recursive, witnessPath, outputPath }) => {
655
+ const { crsPath } = handleGlobalOptions();
649
656
  await prove(bytecodePath, recursive, witnessPath, crsPath, outputPath);
650
657
  });
651
658
 
@@ -666,8 +673,8 @@ program
666
673
  .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
667
674
  .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
668
675
  .action(async ({ proofPath, vk }) => {
669
- handleGlobalOptions();
670
- const result = await verify(proofPath, vk);
676
+ const { crsPath } = handleGlobalOptions();
677
+ const result = await verify(proofPath, vk, crsPath);
671
678
  process.exit(result ? 0 : 1);
672
679
  });
673
680
 
@@ -678,8 +685,8 @@ program
678
685
  .option('-o, --output-path <path>', 'Specify the path to write the contract', './target/contract.sol')
679
686
  .requiredOption('-k, --vk-path <path>', 'Path to a verification key. avoids recomputation.')
680
687
  .action(async ({ outputPath, vkPath }) => {
681
- handleGlobalOptions();
682
- await contract(outputPath, vkPath);
688
+ const { crsPath } = handleGlobalOptions();
689
+ await contract(outputPath, vkPath, crsPath);
683
690
  });
684
691
 
685
692
  program
@@ -699,8 +706,8 @@ program
699
706
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
700
707
  .option('-r, --recursive', 'Create a SNARK friendly proof', false)
701
708
  .option('-o, --output-path <path>', 'Specify the path to write the key')
702
- .action(async ({ bytecodePath, recursive, outputPath, crsPath }) => {
703
- handleGlobalOptions();
709
+ .action(async ({ bytecodePath, recursive, outputPath }) => {
710
+ const { crsPath } = handleGlobalOptions();
704
711
  await writeVk(bytecodePath, recursive, crsPath, outputPath);
705
712
  });
706
713
 
@@ -710,8 +717,8 @@ program
710
717
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
711
718
  .option('-r, --recursive', 'Create a SNARK friendly proof', false)
712
719
  .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
713
- .action(async ({ bytecodePath, recursive, outputPath, crsPath }) => {
714
- handleGlobalOptions();
720
+ .action(async ({ bytecodePath, recursive, outputPath }) => {
721
+ const { crsPath } = handleGlobalOptions();
715
722
  await writePk(bytecodePath, recursive, crsPath, outputPath);
716
723
  });
717
724
 
@@ -722,8 +729,8 @@ program
722
729
  .requiredOption('-k, --vk-path <path>', 'Path to verification key.')
723
730
  .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the proof fields')
724
731
  .action(async ({ proofPath, vkPath, outputPath }) => {
725
- handleGlobalOptions();
726
- await proofAsFields(proofPath, vkPath, outputPath);
732
+ const { crsPath } = handleGlobalOptions();
733
+ await proofAsFields(proofPath, vkPath, outputPath, crsPath);
727
734
  });
728
735
 
729
736
  program
@@ -732,8 +739,8 @@ program
732
739
  .requiredOption('-k, --vk-path <path>', 'Path to verification key.')
733
740
  .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the verification key fields and key hash')
734
741
  .action(async ({ vkPath, outputPath }) => {
735
- handleGlobalOptions();
736
- await vkAsFields(vkPath, outputPath);
742
+ const { crsPath } = handleGlobalOptions();
743
+ await vkAsFields(vkPath, outputPath, crsPath);
737
744
  });
738
745
 
739
746
  program
@@ -743,8 +750,8 @@ program
743
750
  .option('-r, --recursive', 'Create a SNARK friendly proof', false)
744
751
  .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
745
752
  .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
746
- .action(async ({ bytecodePath, recursive, witnessPath, outputPath, crsPath }) => {
747
- handleGlobalOptions();
753
+ .action(async ({ bytecodePath, recursive, witnessPath, outputPath }) => {
754
+ const { crsPath } = handleGlobalOptions();
748
755
  await proveUltraHonk(bytecodePath, recursive, witnessPath, crsPath, outputPath);
749
756
  });
750
757
 
@@ -766,8 +773,8 @@ program
766
773
  .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
767
774
  .option('-r, --recursive', 'Create a SNARK friendly proof', false)
768
775
  .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
769
- .action(async ({ bytecodePath, recursive, outputPath, crsPath }) => {
770
- handleGlobalOptions();
776
+ .action(async ({ bytecodePath, recursive, outputPath }) => {
777
+ const { crsPath } = handleGlobalOptions();
771
778
  await writeVkUltraHonk(bytecodePath, recursive, crsPath, outputPath);
772
779
  });
773
780
 
@@ -788,8 +795,8 @@ program
788
795
  .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
789
796
  .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
790
797
  .action(async ({ proofPath, vk }) => {
791
- handleGlobalOptions();
792
- const result = await verifyUltraHonk(proofPath, vk);
798
+ const { crsPath } = handleGlobalOptions();
799
+ const result = await verifyUltraHonk(proofPath, vk, crsPath);
793
800
  process.exit(result ? 0 : 1);
794
801
  });
795
802
 
@@ -799,8 +806,8 @@ program
799
806
  .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
800
807
  .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
801
808
  .action(async ({ proofPath, vk }) => {
802
- handleGlobalOptions();
803
- const result = await verifyUltraHonk(proofPath, vk, { keccak: true });
809
+ const { crsPath } = handleGlobalOptions();
810
+ const result = await verifyUltraHonk(proofPath, vk, crsPath, { keccak: true });
804
811
  process.exit(result ? 0 : 1);
805
812
  });
806
813
 
@@ -810,8 +817,8 @@ program
810
817
  .requiredOption('-p, --proof-path <path>', 'Specify the proof path')
811
818
  .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the proof fields')
812
819
  .action(async ({ proofPath, outputPath }) => {
813
- handleGlobalOptions();
814
- await proofAsFieldsUltraHonk(proofPath, outputPath);
820
+ const { crsPath } = handleGlobalOptions();
821
+ await proofAsFieldsUltraHonk(proofPath, outputPath, crsPath);
815
822
  });
816
823
 
817
824
  program
@@ -820,8 +827,8 @@ program
820
827
  .requiredOption('-k, --vk-path <path>', 'Path to verification key.')
821
828
  .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the verification key fields.')
822
829
  .action(async ({ vkPath, outputPath }) => {
823
- handleGlobalOptions();
824
- await vkAsFieldsUltraHonk(vkPath, outputPath);
830
+ const { crsPath } = handleGlobalOptions();
831
+ await vkAsFieldsUltraHonk(vkPath, outputPath, crsPath);
825
832
  });
826
833
 
827
834
  program.name('bb.js').parse(process.argv);