@aztec/bb.js 0.65.2 → 0.67.0

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 (32) hide show
  1. package/dest/browser/barretenberg/backend.d.ts +15 -3
  2. package/dest/browser/barretenberg/backend.d.ts.map +1 -1
  3. package/dest/browser/barretenberg_api/index.d.ts +6 -1
  4. package/dest/browser/barretenberg_api/index.d.ts.map +1 -1
  5. package/dest/browser/index.js +68 -15
  6. package/dest/node/barretenberg/backend.d.ts +15 -3
  7. package/dest/node/barretenberg/backend.d.ts.map +1 -1
  8. package/dest/node/barretenberg/backend.js +26 -9
  9. package/dest/node/barretenberg/index.js +1 -1
  10. package/dest/node/barretenberg_api/index.d.ts +6 -1
  11. package/dest/node/barretenberg_api/index.d.ts.map +1 -1
  12. package/dest/node/barretenberg_api/index.js +39 -3
  13. package/dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  14. package/dest/node/main.d.ts +5 -3
  15. package/dest/node/main.d.ts.map +1 -1
  16. package/dest/node/main.js +78 -7
  17. package/dest/node-cjs/barretenberg/backend.d.ts +15 -3
  18. package/dest/node-cjs/barretenberg/backend.d.ts.map +1 -1
  19. package/dest/node-cjs/barretenberg/backend.js +26 -9
  20. package/dest/node-cjs/barretenberg/index.js +1 -1
  21. package/dest/node-cjs/barretenberg_api/index.d.ts +6 -1
  22. package/dest/node-cjs/barretenberg_api/index.d.ts.map +1 -1
  23. package/dest/node-cjs/barretenberg_api/index.js +39 -3
  24. package/dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  25. package/dest/node-cjs/main.d.ts +5 -3
  26. package/dest/node-cjs/main.d.ts.map +1 -1
  27. package/dest/node-cjs/main.js +80 -8
  28. package/package.json +1 -1
  29. package/src/barretenberg/backend.ts +43 -8
  30. package/src/barretenberg/index.ts +1 -1
  31. package/src/barretenberg_api/index.ts +63 -2
  32. package/src/main.ts +91 -5
package/src/main.ts CHANGED
@@ -8,6 +8,7 @@ import { Command } from 'commander';
8
8
  import { decode } from '@msgpack/msgpack';
9
9
  import { Timer, writeBenchmark } from './benchmark/index.js';
10
10
  import path from 'path';
11
+ import { UltraHonkBackendOptions } from './barretenberg/backend.js';
11
12
  createDebug.log = console.error.bind(console);
12
13
  const debug = createDebug('bb.js');
13
14
 
@@ -334,6 +335,27 @@ export async function contract(outputPath: string, vkPath: string) {
334
335
  }
335
336
  }
336
337
 
338
+ export async function contractUltraHonk(bytecodePath: string, vkPath: string, crsPath: string, outputPath: string) {
339
+ const { api } = await initUltraHonk(bytecodePath, false, crsPath);
340
+ try {
341
+ console.log('bytecodePath', bytecodePath);
342
+ const bytecode = getBytecode(bytecodePath);
343
+ console.log('vkPath', vkPath);
344
+ const vk = new RawBuffer(readFileSync(vkPath));
345
+ const contract = await api.acirHonkSolidityVerifier(bytecode, vk);
346
+
347
+ if (outputPath === '-') {
348
+ process.stdout.write(contract);
349
+ debug(`contract written to stdout`);
350
+ } else {
351
+ writeFileSync(outputPath, contract);
352
+ debug(`contract written to: ${outputPath}`);
353
+ }
354
+ } finally {
355
+ await api.destroy();
356
+ }
357
+ }
358
+
337
359
  export async function writeVk(bytecodePath: string, recursive: boolean, crsPath: string, outputPath: string) {
338
360
  const { api, acirComposer } = await initUltraPlonk(bytecodePath, recursive, crsPath);
339
361
  try {
@@ -432,13 +454,18 @@ export async function proveUltraHonk(
432
454
  witnessPath: string,
433
455
  crsPath: string,
434
456
  outputPath: string,
457
+ options?: UltraHonkBackendOptions,
435
458
  ) {
436
459
  const { api } = await initUltraHonk(bytecodePath, recursive, crsPath);
437
460
  try {
438
461
  debug(`creating proof...`);
439
462
  const bytecode = getBytecode(bytecodePath);
440
463
  const witness = getWitness(witnessPath);
441
- const proof = await api.acirProveUltraHonk(bytecode, recursive, witness);
464
+
465
+ const acirProveUltraHonk = options?.keccak
466
+ ? api.acirProveUltraKeccakHonk.bind(api)
467
+ : api.acirProveUltraHonk.bind(api);
468
+ const proof = await acirProveUltraHonk(bytecode, recursive, witness);
442
469
  debug(`done.`);
443
470
 
444
471
  if (outputPath === '-') {
@@ -453,12 +480,22 @@ export async function proveUltraHonk(
453
480
  }
454
481
  }
455
482
 
456
- export async function writeVkUltraHonk(bytecodePath: string, recursive: boolean, crsPath: string, outputPath: string) {
483
+ export async function writeVkUltraHonk(
484
+ bytecodePath: string,
485
+ recursive: boolean,
486
+ crsPath: string,
487
+ outputPath: string,
488
+ options?: UltraHonkBackendOptions,
489
+ ) {
457
490
  const { api } = await initUltraHonk(bytecodePath, recursive, crsPath);
458
491
  try {
459
492
  const bytecode = getBytecode(bytecodePath);
460
493
  debug('initing verification key...');
461
- const vk = await api.acirWriteVkUltraHonk(bytecode, recursive);
494
+
495
+ const acirWriteVkUltraHonk = options?.keccak
496
+ ? api.acirWriteVkUltraKeccakHonk.bind(api)
497
+ : api.acirWriteVkUltraHonk.bind(api);
498
+ const vk = await acirWriteVkUltraHonk(bytecode, recursive);
462
499
 
463
500
  if (outputPath === '-') {
464
501
  process.stdout.write(vk);
@@ -472,10 +509,14 @@ export async function writeVkUltraHonk(bytecodePath: string, recursive: boolean,
472
509
  }
473
510
  }
474
511
 
475
- export async function verifyUltraHonk(proofPath: string, vkPath: string) {
512
+ export async function verifyUltraHonk(proofPath: string, vkPath: string, options?: UltraHonkBackendOptions) {
476
513
  const { api } = await initLite();
477
514
  try {
478
- const verified = await api.acirVerifyUltraHonk(readFileSync(proofPath), new RawBuffer(readFileSync(vkPath)));
515
+ const acirVerifyUltraHonk = options?.keccak
516
+ ? api.acirVerifyUltraKeccakHonk.bind(api)
517
+ : api.acirVerifyUltraHonk.bind(api);
518
+ const verified = await acirVerifyUltraHonk(readFileSync(proofPath), new RawBuffer(readFileSync(vkPath)));
519
+
479
520
  debug(`verified: ${verified}`);
480
521
  return verified;
481
522
  } finally {
@@ -641,6 +682,17 @@ program
641
682
  await contract(outputPath, vkPath);
642
683
  });
643
684
 
685
+ program
686
+ .command('contract_ultra_honk')
687
+ .description('Output solidity verification key contract.')
688
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
689
+ .option('-o, --output-path <path>', 'Specify the path to write the contract', './target/contract.sol')
690
+ .requiredOption('-k, --vk-path <path>', 'Path to a verification key.')
691
+ .action(async ({ bytecodePath, outputPath, vkPath, crsPath }) => {
692
+ handleGlobalOptions();
693
+ await contractUltraHonk(bytecodePath, vkPath, crsPath, outputPath);
694
+ });
695
+
644
696
  program
645
697
  .command('write_vk')
646
698
  .description('Output verification key.')
@@ -696,6 +748,18 @@ program
696
748
  await proveUltraHonk(bytecodePath, recursive, witnessPath, crsPath, outputPath);
697
749
  });
698
750
 
751
+ program
752
+ .command('prove_ultra_keccak_honk')
753
+ .description('Generate a proof and write it to a file.')
754
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
755
+ .option('-r, --recursive', 'Create a SNARK friendly proof', false)
756
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
757
+ .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
758
+ .action(async ({ bytecodePath, recursive, witnessPath, outputPath, crsPath }) => {
759
+ handleGlobalOptions();
760
+ await proveUltraHonk(bytecodePath, recursive, witnessPath, crsPath, outputPath, { keccak: true });
761
+ });
762
+
699
763
  program
700
764
  .command('write_vk_ultra_honk')
701
765
  .description('Output verification key.')
@@ -707,6 +771,17 @@ program
707
771
  await writeVkUltraHonk(bytecodePath, recursive, crsPath, outputPath);
708
772
  });
709
773
 
774
+ program
775
+ .command('write_vk_ultra_keccak_honk')
776
+ .description('Output verification key.')
777
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
778
+ .option('-r, --recursive', 'Create a SNARK friendly proof', false)
779
+ .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
780
+ .action(async ({ bytecodePath, recursive, outputPath, crsPath }) => {
781
+ handleGlobalOptions();
782
+ await writeVkUltraHonk(bytecodePath, recursive, crsPath, outputPath, { keccak: true });
783
+ });
784
+
710
785
  program
711
786
  .command('verify_ultra_honk')
712
787
  .description('Verify a proof. Process exists with success or failure code.')
@@ -718,6 +793,17 @@ program
718
793
  process.exit(result ? 0 : 1);
719
794
  });
720
795
 
796
+ program
797
+ .command('verify_ultra_keccak_honk')
798
+ .description('Verify a proof. Process exists with success or failure code.')
799
+ .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
800
+ .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
801
+ .action(async ({ proofPath, vk }) => {
802
+ handleGlobalOptions();
803
+ const result = await verifyUltraHonk(proofPath, vk, { keccak: true });
804
+ process.exit(result ? 0 : 1);
805
+ });
806
+
721
807
  program
722
808
  .command('proof_as_fields_honk')
723
809
  .description('Return the proof as fields elements')