@aztec/bb.js 0.0.1-alpha.6 → 0.0.1-fake-ceab37513c

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 (227) hide show
  1. package/README.md +69 -33
  2. package/package.json +56 -41
  3. package/src/barretenberg/__snapshots__/pedersen.test.ts.snap +156 -0
  4. package/src/barretenberg/__snapshots__/poseidon.test.ts.snap +40 -0
  5. package/src/barretenberg/backend.ts +378 -0
  6. package/src/barretenberg/blake2s.test.ts +70 -0
  7. package/src/{barretenberg_api → barretenberg}/common.test.ts +7 -5
  8. package/src/barretenberg/index.ts +204 -0
  9. package/src/barretenberg/pedersen.test.ts +62 -0
  10. package/src/barretenberg/poseidon.test.ts +39 -0
  11. package/src/barretenberg_api/index.ts +1128 -383
  12. package/src/barretenberg_wasm/barretenberg_wasm_base/index.ts +138 -0
  13. package/src/barretenberg_wasm/barretenberg_wasm_main/factory/browser/index.ts +11 -0
  14. package/src/barretenberg_wasm/barretenberg_wasm_main/factory/browser/main.worker.ts +13 -0
  15. package/src/barretenberg_wasm/barretenberg_wasm_main/factory/node/index.ts +21 -0
  16. package/src/barretenberg_wasm/barretenberg_wasm_main/factory/node/main.worker.ts +19 -0
  17. package/src/{barretenberg_binder/heap_allocator_sync.ts → barretenberg_wasm/barretenberg_wasm_main/heap_allocator.ts} +20 -17
  18. package/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +167 -0
  19. package/src/barretenberg_wasm/barretenberg_wasm_thread/factory/browser/index.ts +11 -0
  20. package/src/barretenberg_wasm/barretenberg_wasm_thread/factory/browser/thread.worker.ts +13 -0
  21. package/src/barretenberg_wasm/barretenberg_wasm_thread/factory/node/index.ts +21 -0
  22. package/src/barretenberg_wasm/barretenberg_wasm_thread/factory/node/thread.worker.ts +19 -0
  23. package/src/barretenberg_wasm/barretenberg_wasm_thread/index.ts +47 -0
  24. package/src/barretenberg_wasm/fetch_code/browser/barretenberg-threads.ts +3 -0
  25. package/src/barretenberg_wasm/fetch_code/browser/barretenberg.ts +3 -0
  26. package/src/barretenberg_wasm/fetch_code/browser/index.ts +34 -0
  27. package/src/barretenberg_wasm/fetch_code/index.ts +1 -0
  28. package/src/barretenberg_wasm/fetch_code/node/index.ts +34 -0
  29. package/src/barretenberg_wasm/fetch_code/wasm-module.d.ts +4 -0
  30. package/src/barretenberg_wasm/helpers/browser/index.ts +47 -0
  31. package/src/barretenberg_wasm/helpers/index.ts +1 -0
  32. package/src/barretenberg_wasm/{node → helpers/node}/index.ts +24 -15
  33. package/src/barretenberg_wasm/index.test.ts +45 -0
  34. package/src/barretenberg_wasm/index.ts +22 -1
  35. package/src/benchmark/index.ts +26 -0
  36. package/src/benchmark/timer.ts +45 -0
  37. package/src/bigint-array/index.ts +39 -17
  38. package/src/bindgen/index.ts +2 -2
  39. package/src/bindgen/mappings.ts +3 -2
  40. package/src/bindgen/typescript.ts +50 -25
  41. package/src/cbind/README.md +1 -0
  42. package/src/cbind/generate.ts +89 -0
  43. package/src/cbind/schema_compiler.ts +833 -0
  44. package/src/crs/browser/cached_net_crs.ts +41 -2
  45. package/src/crs/browser/index.ts +1 -1
  46. package/src/crs/index.ts +1 -1
  47. package/src/crs/net_crs.ts +114 -19
  48. package/src/crs/node/index.ts +98 -20
  49. package/src/index.html +1 -1
  50. package/src/index.ts +13 -5
  51. package/src/log/browser/index.ts +35 -0
  52. package/src/log/index.ts +1 -0
  53. package/src/log/node/index.ts +52 -0
  54. package/src/log/types.ts +6 -0
  55. package/src/main.ts +395 -185
  56. package/src/proof/index.ts +94 -0
  57. package/src/random/browser/index.ts +1 -1
  58. package/src/retry/index.ts +50 -0
  59. package/src/serialize/buffer_reader.ts +4 -1
  60. package/src/types/fields.ts +46 -18
  61. package/src/types/point.ts +4 -1
  62. package/dest/async_map/index.d.ts +0 -10
  63. package/dest/async_map/index.d.ts.map +0 -1
  64. package/dest/async_map/index.js +0 -16
  65. package/dest/barretenberg-threads.wasm +0 -0
  66. package/dest/barretenberg.wasm +0 -0
  67. package/dest/barretenberg_api/blake2s.test.d.ts +0 -2
  68. package/dest/barretenberg_api/blake2s.test.d.ts.map +0 -1
  69. package/dest/barretenberg_api/blake2s.test.js +0 -30
  70. package/dest/barretenberg_api/common.test.d.ts +0 -2
  71. package/dest/barretenberg_api/common.test.d.ts.map +0 -1
  72. package/dest/barretenberg_api/common.test.js +0 -18
  73. package/dest/barretenberg_api/index.d.ts +0 -103
  74. package/dest/barretenberg_api/index.d.ts.map +0 -1
  75. package/dest/barretenberg_api/index.js +0 -379
  76. package/dest/barretenberg_api/pedersen.test.d.ts +0 -2
  77. package/dest/barretenberg_api/pedersen.test.d.ts.map +0 -1
  78. package/dest/barretenberg_api/pedersen.test.js +0 -69
  79. package/dest/barretenberg_api/schnorr.test.d.ts +0 -2
  80. package/dest/barretenberg_api/schnorr.test.d.ts.map +0 -1
  81. package/dest/barretenberg_api/schnorr.test.js +0 -113
  82. package/dest/barretenberg_binder/heap_allocator.d.ts +0 -22
  83. package/dest/barretenberg_binder/heap_allocator.d.ts.map +0 -1
  84. package/dest/barretenberg_binder/heap_allocator.js +0 -59
  85. package/dest/barretenberg_binder/heap_allocator_sync.d.ts +0 -22
  86. package/dest/barretenberg_binder/heap_allocator_sync.d.ts.map +0 -1
  87. package/dest/barretenberg_binder/heap_allocator_sync.js +0 -58
  88. package/dest/barretenberg_binder/index.d.ts +0 -32
  89. package/dest/barretenberg_binder/index.d.ts.map +0 -1
  90. package/dest/barretenberg_binder/index.js +0 -73
  91. package/dest/barretenberg_wasm/barretenberg_wasm.d.ts +0 -50
  92. package/dest/barretenberg_wasm/barretenberg_wasm.d.ts.map +0 -1
  93. package/dest/barretenberg_wasm/barretenberg_wasm.js +0 -212
  94. package/dest/barretenberg_wasm/barretenberg_wasm.test.d.ts +0 -2
  95. package/dest/barretenberg_wasm/barretenberg_wasm.test.d.ts.map +0 -1
  96. package/dest/barretenberg_wasm/barretenberg_wasm.test.js +0 -43
  97. package/dest/barretenberg_wasm/browser/index.d.ts +0 -8
  98. package/dest/barretenberg_wasm/browser/index.d.ts.map +0 -1
  99. package/dest/barretenberg_wasm/browser/index.js +0 -26
  100. package/dest/barretenberg_wasm/browser/worker.d.ts +0 -2
  101. package/dest/barretenberg_wasm/browser/worker.d.ts.map +0 -1
  102. package/dest/barretenberg_wasm/browser/worker.js +0 -11
  103. package/dest/barretenberg_wasm/index.d.ts +0 -2
  104. package/dest/barretenberg_wasm/index.d.ts.map +0 -1
  105. package/dest/barretenberg_wasm/index.js +0 -2
  106. package/dest/barretenberg_wasm/node/index.d.ts +0 -17
  107. package/dest/barretenberg_wasm/node/index.d.ts.map +0 -1
  108. package/dest/barretenberg_wasm/node/index.js +0 -40
  109. package/dest/barretenberg_wasm/node/node_endpoint.d.ts +0 -8
  110. package/dest/barretenberg_wasm/node/node_endpoint.d.ts.map +0 -1
  111. package/dest/barretenberg_wasm/node/node_endpoint.js +0 -28
  112. package/dest/barretenberg_wasm/node/worker.d.ts +0 -2
  113. package/dest/barretenberg_wasm/node/worker.d.ts.map +0 -1
  114. package/dest/barretenberg_wasm/node/worker.js +0 -9
  115. package/dest/barretenberg_wasm.js +0 -2
  116. package/dest/barretenberg_wasm.js.LICENSE.txt +0 -5
  117. package/dest/bigint-array/index.d.ts +0 -3
  118. package/dest/bigint-array/index.d.ts.map +0 -1
  119. package/dest/bigint-array/index.js +0 -21
  120. package/dest/bindgen/function_declaration.d.ts +0 -11
  121. package/dest/bindgen/function_declaration.d.ts.map +0 -1
  122. package/dest/bindgen/function_declaration.js +0 -2
  123. package/dest/bindgen/index.d.ts +0 -2
  124. package/dest/bindgen/index.d.ts.map +0 -1
  125. package/dest/bindgen/index.js +0 -15
  126. package/dest/bindgen/mappings.d.ts +0 -4
  127. package/dest/bindgen/mappings.d.ts.map +0 -1
  128. package/dest/bindgen/mappings.js +0 -63
  129. package/dest/bindgen/rust.d.ts +0 -2
  130. package/dest/bindgen/rust.d.ts.map +0 -1
  131. package/dest/bindgen/rust.js +0 -43
  132. package/dest/bindgen/to_camel_case.d.ts +0 -2
  133. package/dest/bindgen/to_camel_case.d.ts.map +0 -1
  134. package/dest/bindgen/to_camel_case.js +0 -11
  135. package/dest/bindgen/typescript.d.ts +0 -2
  136. package/dest/bindgen/typescript.d.ts.map +0 -1
  137. package/dest/bindgen/typescript.js +0 -80
  138. package/dest/crs/browser/cached_net_crs.d.ts +0 -25
  139. package/dest/crs/browser/cached_net_crs.d.ts.map +0 -1
  140. package/dest/crs/browser/cached_net_crs.js +0 -54
  141. package/dest/crs/browser/index.d.ts +0 -2
  142. package/dest/crs/browser/index.d.ts.map +0 -1
  143. package/dest/crs/browser/index.js +0 -2
  144. package/dest/crs/index.d.ts +0 -2
  145. package/dest/crs/index.d.ts.map +0 -1
  146. package/dest/crs/index.js +0 -2
  147. package/dest/crs/net_crs.d.ts +0 -36
  148. package/dest/crs/net_crs.d.ts.map +0 -1
  149. package/dest/crs/net_crs.js +0 -59
  150. package/dest/crs/node/file_crs.d.ts +0 -37
  151. package/dest/crs/node/file_crs.d.ts.map +0 -1
  152. package/dest/crs/node/file_crs.js +0 -51
  153. package/dest/crs/node/index.d.ts +0 -31
  154. package/dest/crs/node/index.d.ts.map +0 -1
  155. package/dest/crs/node/index.js +0 -41
  156. package/dest/examples/simple.rawtest.d.ts +0 -2
  157. package/dest/examples/simple.rawtest.d.ts.map +0 -1
  158. package/dest/examples/simple.rawtest.js +0 -29
  159. package/dest/examples/simple.test.d.ts +0 -2
  160. package/dest/examples/simple.test.d.ts.map +0 -1
  161. package/dest/examples/simple.test.js +0 -22
  162. package/dest/factory/index.d.ts +0 -21
  163. package/dest/factory/index.d.ts.map +0 -1
  164. package/dest/factory/index.js +0 -34
  165. package/dest/index.d.ts +0 -6
  166. package/dest/index.d.ts.map +0 -1
  167. package/dest/index.html +0 -1
  168. package/dest/index.js +0 -6
  169. package/dest/main.d.ts +0 -10
  170. package/dest/main.d.ts.map +0 -1
  171. package/dest/main.js +0 -280
  172. package/dest/random/browser/index.d.ts +0 -2
  173. package/dest/random/browser/index.d.ts.map +0 -1
  174. package/dest/random/browser/index.js +0 -31
  175. package/dest/random/index.d.ts +0 -2
  176. package/dest/random/index.d.ts.map +0 -1
  177. package/dest/random/index.js +0 -2
  178. package/dest/random/node/index.d.ts +0 -2
  179. package/dest/random/node/index.d.ts.map +0 -1
  180. package/dest/random/node/index.js +0 -5
  181. package/dest/serialize/buffer_reader.d.ts +0 -28
  182. package/dest/serialize/buffer_reader.d.ts.map +0 -1
  183. package/dest/serialize/buffer_reader.js +0 -66
  184. package/dest/serialize/index.d.ts +0 -4
  185. package/dest/serialize/index.d.ts.map +0 -1
  186. package/dest/serialize/index.js +0 -4
  187. package/dest/serialize/output_type.d.ts +0 -11
  188. package/dest/serialize/output_type.d.ts.map +0 -1
  189. package/dest/serialize/output_type.js +0 -44
  190. package/dest/serialize/serialize.d.ts +0 -53
  191. package/dest/serialize/serialize.d.ts.map +0 -1
  192. package/dest/serialize/serialize.js +0 -139
  193. package/dest/simple_test.js +0 -2
  194. package/dest/simple_test.js.LICENSE.txt +0 -14
  195. package/dest/types/fields.d.ts +0 -33
  196. package/dest/types/fields.d.ts.map +0 -1
  197. package/dest/types/fields.js +0 -86
  198. package/dest/types/fixed_size_buffer.d.ts +0 -26
  199. package/dest/types/fixed_size_buffer.d.ts.map +0 -1
  200. package/dest/types/fixed_size_buffer.js +0 -54
  201. package/dest/types/index.d.ts +0 -6
  202. package/dest/types/index.d.ts.map +0 -1
  203. package/dest/types/index.js +0 -6
  204. package/dest/types/point.d.ts +0 -17
  205. package/dest/types/point.d.ts.map +0 -1
  206. package/dest/types/point.js +0 -32
  207. package/dest/types/ptr.d.ts +0 -13
  208. package/dest/types/ptr.d.ts.map +0 -1
  209. package/dest/types/ptr.js +0 -20
  210. package/dest/types/raw_buffer.d.ts +0 -3
  211. package/dest/types/raw_buffer.d.ts.map +0 -1
  212. package/dest/types/raw_buffer.js +0 -5
  213. package/src/barretenberg_api/blake2s.test.ts +0 -39
  214. package/src/barretenberg_api/pedersen.test.ts +0 -84
  215. package/src/barretenberg_api/schnorr.test.ts +0 -169
  216. package/src/barretenberg_binder/heap_allocator.ts +0 -62
  217. package/src/barretenberg_binder/index.ts +0 -76
  218. package/src/barretenberg_wasm/barretenberg_wasm.test.ts +0 -52
  219. package/src/barretenberg_wasm/barretenberg_wasm.ts +0 -246
  220. package/src/barretenberg_wasm/browser/index.ts +0 -32
  221. package/src/barretenberg_wasm/browser/worker.ts +0 -13
  222. package/src/barretenberg_wasm/node/worker.ts +0 -10
  223. package/src/crs/node/file_crs.ts +0 -60
  224. package/src/examples/simple.rawtest.ts +0 -37
  225. package/src/examples/simple.test.ts +0 -27
  226. package/src/factory/index.ts +0 -36
  227. /package/src/barretenberg_wasm/{node → helpers/node}/node_endpoint.ts +0 -0
package/src/main.ts CHANGED
@@ -1,324 +1,534 @@
1
- #!/usr/bin/env -S node --no-warnings
2
- import { Crs, BarretenbergApiAsync, newBarretenbergApiAsync, RawBuffer } from './index.js';
3
- import createDebug from 'debug';
1
+ #!/usr/bin/env node
2
+ import 'source-map-support/register.js';
3
+ import { Crs, Barretenberg, RawBuffer } from './index.js';
4
+ import { createDebugLogger, initLogger } from './log/index.js';
4
5
  import { readFileSync, writeFileSync } from 'fs';
5
6
  import { gunzipSync } from 'zlib';
6
- import { numToUInt32BE } from './serialize/serialize.js';
7
7
  import { Command } from 'commander';
8
+ import { UltraHonkBackendOptions } from './barretenberg/backend.js';
8
9
 
9
- createDebug.log = console.error.bind(console);
10
- const debug = createDebug('bb.js');
10
+ let debug: (msg: string) => void;
11
11
 
12
- // Maximum we support.
13
- const MAX_CIRCUIT_SIZE = 2 ** 19;
12
+ const threads = +process.env.HARDWARE_CONCURRENCY! || undefined;
14
13
 
15
- function getBytecode(jsonPath: string) {
16
- const json = readFileSync(jsonPath, 'utf-8');
17
- const parsed = JSON.parse(json);
18
- const buffer = Buffer.from(parsed.bytecode, 'base64');
19
- const decompressed = gunzipSync(buffer);
20
- return decompressed;
21
- }
14
+ function getBytecode(bytecodePath: string): Uint8Array {
15
+ const extension = bytecodePath.substring(bytecodePath.lastIndexOf('.') + 1);
22
16
 
23
- function getWitness(witnessPath: string) {
24
- const data = readFileSync(witnessPath);
25
- return Buffer.concat([numToUInt32BE(data.length / 32), data]);
26
- }
17
+ if (extension == 'json') {
18
+ const encodedCircuit = JSON.parse(readFileSync(bytecodePath, 'utf8'));
19
+ const decompressed = gunzipSync(Buffer.from(encodedCircuit.bytecode, 'base64'));
20
+ return Uint8Array.from(decompressed);
21
+ }
27
22
 
28
- async function getCircuitSize(jsonPath: string, api: BarretenbergApiAsync) {
29
- const bytecode = getBytecode(jsonPath);
30
- const [exact, total, subgroup] = await api.acirGetCircuitSizes(new RawBuffer(bytecode));
31
- return { exact, total, subgroup };
23
+ const encodedCircuit = readFileSync(bytecodePath);
24
+ const decompressed = gunzipSync(encodedCircuit);
25
+ return Uint8Array.from(decompressed);
32
26
  }
33
27
 
34
- async function init(jsonPath: string, sizeHint?: number) {
35
- const api = await newBarretenbergApiAsync();
36
-
37
- const subgroupSize = await (async () => {
38
- if (sizeHint) {
39
- // Round to subgroup size.
40
- return Math.pow(2, Math.ceil(Math.log2(sizeHint)));
41
- }
28
+ // TODO(https://github.com/AztecProtocol/barretenberg/issues/1126): split this into separate Plonk and Honk functions as their gate count differs
29
+ async function getGatesUltra(bytecodePath: string, recursive: boolean, honkRecursion: boolean, api: Barretenberg) {
30
+ const { total } = await computeCircuitSize(bytecodePath, recursive, honkRecursion, api);
31
+ return total;
32
+ }
42
33
 
43
- // First compute circuit size.
44
- debug(`computing circuit size (use size hint to skip)...`);
45
- const circuitSizes = await getCircuitSize(jsonPath, api);
46
- debug(`circuit size: ${circuitSizes.total}`);
34
+ function getWitness(witnessPath: string): Uint8Array {
35
+ const data = readFileSync(witnessPath);
36
+ const decompressed = gunzipSync(data);
37
+ return Uint8Array.from(decompressed);
38
+ }
47
39
 
48
- if (circuitSizes.subgroup > MAX_CIRCUIT_SIZE) {
49
- throw new Error(`Circuit size of ${circuitSizes.subgroup} exceeds max supported of ${MAX_CIRCUIT_SIZE}`);
50
- }
40
+ async function computeCircuitSize(bytecodePath: string, recursive: boolean, honkRecursion: boolean, api: Barretenberg) {
41
+ debug(`Computing circuit size for ${bytecodePath}`);
42
+ const bytecode = getBytecode(bytecodePath);
43
+ const [total, subgroup] = await api.acirGetCircuitSizes(bytecode, recursive, honkRecursion);
44
+ return { total, subgroup };
45
+ }
51
46
 
52
- return circuitSizes.subgroup;
53
- })();
47
+ async function initUltraHonk(bytecodePath: string, crsPath: string) {
48
+ const api = await Barretenberg.new({
49
+ threads,
50
+ });
54
51
 
55
- debug(`subgroup size: ${subgroupSize}`);
56
- debug('loading crs...');
57
- // Plus 1 needed! (Move +1 into Crs?)
58
- const crs = await Crs.new(subgroupSize + 1);
52
+ // TODO(https://github.com/AztecProtocol/barretenberg/issues/1248): Get rid of this call to avoid building the circuit twice.
53
+ // TODO(https://github.com/AztecProtocol/barretenberg/issues/1126): use specific UltraHonk function
54
+ // recursive here is useless for UH, as it does not affect anything
55
+ const circuitSize = await getGatesUltra(bytecodePath, /*recursive=*/ false, /*honkRecursion=*/ true, api);
56
+ // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): remove subgroupSizeOverride hack for goblin
57
+ const dyadicCircuitSize = Math.pow(2, Math.ceil(Math.log2(circuitSize)));
59
58
 
60
- // Important to init slab allocator as first thing, to ensure maximum memory efficiency.
61
- await api.commonInitSlabAllocator(subgroupSize);
59
+ debug(`Loading CRS for UltraHonk with circuit-size=${circuitSize} dyadic-circuit-size=${dyadicCircuitSize}`);
60
+ const crs = await Crs.new(dyadicCircuitSize + 1, crsPath);
62
61
 
63
62
  // Load CRS into wasm global CRS state.
64
- // TODO: Make RawBuffer be default behaviour, and have a specific Vector type for when wanting length prefixed.
63
+ // TODO: Make RawBuffer be default behavior, and have a specific Vector type for when wanting length prefixed.
65
64
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
66
-
67
- const acirComposer = await api.acirNewAcirComposer(subgroupSize);
68
- return { api, acirComposer, circuitSize: subgroupSize };
65
+ return { api, circuitSize, dyadicCircuitSize };
69
66
  }
70
67
 
71
- async function initLite() {
72
- const api = await newBarretenbergApiAsync(1);
68
+ async function initLite(crsPath: string) {
69
+ const api = await Barretenberg.new({ threads: 1 });
73
70
 
74
71
  // Plus 1 needed! (Move +1 into Crs?)
75
- const crs = await Crs.new(1);
72
+ const crs = await Crs.new(1, crsPath);
76
73
 
77
74
  // Load CRS into wasm global CRS state.
78
75
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
79
76
 
80
- const acirComposer = await api.acirNewAcirComposer(0);
81
- return { api, acirComposer };
77
+ return { api };
82
78
  }
83
79
 
84
- export async function proveAndVerify(jsonPath: string, witnessPath: string, isRecursive: boolean, sizeHint?: number) {
85
- const { api, acirComposer } = await init(jsonPath, sizeHint);
80
+ export async function proveAndVerifyUltraHonk(bytecodePath: string, witnessPath: string, crsPath: string) {
81
+ /* eslint-disable camelcase */
82
+ const { api } = await initUltraHonk(bytecodePath, crsPath);
86
83
  try {
87
- debug(`creating proof...`);
88
- const bytecode = getBytecode(jsonPath);
84
+ const bytecode = getBytecode(bytecodePath);
89
85
  const witness = getWitness(witnessPath);
90
- const proof = await api.acirCreateProof(acirComposer, new RawBuffer(bytecode), new RawBuffer(witness), isRecursive);
91
86
 
92
- debug(`verifying...`);
93
- const verified = await api.acirVerifyProof(acirComposer, proof, isRecursive);
94
- console.log(`verified: ${verified}`);
87
+ const verified = await api.acirProveAndVerifyUltraHonk(bytecode, witness);
95
88
  return verified;
96
89
  } finally {
97
90
  await api.destroy();
98
91
  }
92
+ /* eslint-enable camelcase */
99
93
  }
100
94
 
101
- export async function prove(
102
- jsonPath: string,
103
- witnessPath: string,
104
- isRecursive: boolean,
105
- outputPath: string,
106
- sizeHint?: number,
107
- ) {
108
- const { api, acirComposer } = await init(jsonPath, sizeHint);
95
+ export async function proveAndVerifyMegaHonk(bytecodePath: string, witnessPath: string, crsPath: string) {
96
+ /* eslint-disable camelcase */
97
+ const { api } = await initUltraHonk(bytecodePath, crsPath);
109
98
  try {
110
- debug(`creating proof...`);
111
- const bytecode = getBytecode(jsonPath);
99
+ const bytecode = getBytecode(bytecodePath);
112
100
  const witness = getWitness(witnessPath);
113
- const proof = await api.acirCreateProof(acirComposer, new RawBuffer(bytecode), new RawBuffer(witness), isRecursive);
114
- debug(`done.`);
115
101
 
116
- writeFileSync(outputPath, proof);
117
- console.log(`proof written to: ${outputPath}`);
102
+ const verified = await api.acirProveAndVerifyMegaHonk(bytecode, witness);
103
+ return verified;
118
104
  } finally {
119
105
  await api.destroy();
120
106
  }
107
+ /* eslint-enable camelcase */
121
108
  }
122
109
 
123
- export async function gateCount(jsonPath: string) {
124
- const api = await newBarretenbergApiAsync(1);
110
+ export async function gateCountUltra(bytecodePath: string, recursive: boolean, honkRecursion: boolean) {
111
+ const api = await Barretenberg.new({ threads: 1 });
125
112
  try {
126
- const circuitSizes = await getCircuitSize(jsonPath, api);
127
- console.log(`${circuitSizes.exact}`);
113
+ const numberOfGates = await getGatesUltra(bytecodePath, recursive, honkRecursion, api);
114
+ debug(`Number of gates: ${numberOfGates}`);
115
+ // Create an 8-byte buffer and write the number into it.
116
+ // Writing number directly to stdout will result in a variable sized
117
+ // input depending on the size.
118
+ const buffer = Buffer.alloc(8);
119
+ buffer.writeBigInt64LE(BigInt(numberOfGates));
120
+
121
+ process.stdout.write(Uint8Array.from(buffer));
128
122
  } finally {
129
123
  await api.destroy();
130
124
  }
131
125
  }
132
126
 
133
- export async function verify(jsonPath: string, proofPath: string, isRecursive: boolean, vkPath: string) {
134
- const { api, acirComposer } = await initLite();
127
+ export async function contractUltraHonk(bytecodePath: string, vkPath: string, crsPath: string, outputPath: string) {
128
+ const { api } = await initUltraHonk(bytecodePath, crsPath);
135
129
  try {
136
- await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
137
- const verified = await api.acirVerifyProof(acirComposer, readFileSync(proofPath), isRecursive);
138
- console.log(`verified: ${verified}`);
139
- return verified;
130
+ debug(`Creating UltraHonk verifier contract bytecode=${bytecodePath} vk=${vkPath}`);
131
+ const bytecode = getBytecode(bytecodePath);
132
+ const vk = new RawBuffer(readFileSync(vkPath));
133
+ const contract = await api.acirHonkSolidityVerifier(bytecode, vk);
134
+
135
+ if (outputPath === '-') {
136
+ process.stdout.write(contract);
137
+ debug(`Solidity verifier contract written to stdout`);
138
+ } else {
139
+ writeFileSync(outputPath, contract);
140
+ debug(`Solidity verifier contract written to ${outputPath}`);
141
+ }
140
142
  } finally {
141
143
  await api.destroy();
142
144
  }
143
145
  }
144
146
 
145
- export async function contract(outputPath: string, vkPath: string) {
146
- const { api, acirComposer } = await initLite();
147
+ export async function proveUltraHonk(
148
+ bytecodePath: string,
149
+ witnessPath: string,
150
+ crsPath: string,
151
+ vkPath: string,
152
+ outputPath: string,
153
+ options?: UltraHonkBackendOptions,
154
+ ) {
155
+ const { api } = await initUltraHonk(bytecodePath, crsPath);
147
156
  try {
148
- await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
149
- const contract = await api.acirGetSolidityVerifier(acirComposer);
157
+ debug(`Creating UltraHonk proof bytecode=${bytecodePath}`);
158
+ const bytecode = getBytecode(bytecodePath);
159
+ const witness = getWitness(witnessPath);
160
+
161
+ const acirProveUltraHonk = options?.keccak
162
+ ? api.acirProveUltraKeccakHonk.bind(api)
163
+ : options?.keccakZK
164
+ ? api.acirProveUltraKeccakZkHonk.bind(api)
165
+ : options?.starknet
166
+ ? api.acirProveUltraStarknetHonk.bind(api)
167
+ : options?.starknetZK
168
+ ? api.acirProveUltraStarknetZkHonk.bind(api)
169
+ : api.acirProveUltraZKHonk.bind(api);
170
+ const proof = await acirProveUltraHonk(bytecode, witness, new RawBuffer(readFileSync(vkPath)));
171
+
150
172
  if (outputPath === '-') {
151
- console.log(contract);
173
+ process.stdout.write(proof);
174
+ debug(`Proof written to stdout`);
152
175
  } else {
153
- writeFileSync(outputPath, contract);
154
- console.log(`contract written to: ${outputPath}`);
176
+ writeFileSync(outputPath, proof);
177
+ debug(`Proof written to ${outputPath}`);
155
178
  }
156
179
  } finally {
157
180
  await api.destroy();
158
181
  }
159
182
  }
160
183
 
161
- export async function writeVk(jsonPath: string, outputPath: string, sizeHint?: number) {
162
- const { api, acirComposer } = await init(jsonPath, sizeHint);
184
+ export async function writeVkUltraHonk(
185
+ bytecodePath: string,
186
+ crsPath: string,
187
+ outputPath: string,
188
+ options?: UltraHonkBackendOptions,
189
+ ) {
190
+ const { api } = await initUltraHonk(bytecodePath, crsPath);
163
191
  try {
164
- debug('initing proving key...');
165
- const bytecode = getBytecode(jsonPath);
166
- await api.acirInitProvingKey(acirComposer, new RawBuffer(bytecode));
192
+ const bytecode = getBytecode(bytecodePath);
193
+ debug(`Initializing UltraHonk verification key bytecode=${bytecodePath}`);
194
+
195
+ const acirWriteVkUltraHonk = options?.keccak
196
+ ? api.acirWriteVkUltraKeccakHonk.bind(api)
197
+ : options?.keccakZK
198
+ ? api.acirWriteVkUltraKeccakZkHonk.bind(api)
199
+ : options?.starknet
200
+ ? api.acirWriteVkUltraStarknetHonk.bind(api)
201
+ : options?.starknetZK
202
+ ? api.acirWriteVkUltraStarknetZkHonk.bind(api)
203
+ : api.acirWriteVkUltraHonk.bind(api);
204
+ const vk = await acirWriteVkUltraHonk(bytecode);
167
205
 
168
- debug('initing verification key...');
169
- const vk = await api.acirGetVerificationKey(acirComposer);
170
206
  if (outputPath === '-') {
171
207
  process.stdout.write(vk);
208
+ debug(`Verification key written to stdout`);
172
209
  } else {
173
210
  writeFileSync(outputPath, vk);
174
- console.log(`vk written to: ${outputPath}`);
211
+ debug(`Verification key written to ${outputPath}`);
175
212
  }
176
213
  } finally {
177
214
  await api.destroy();
178
215
  }
179
216
  }
180
217
 
181
- export async function proofAsFields(proofPath: string, numInnerPublicInputs: number, outputPath: string) {
182
- const { api, acirComposer } = await initLite();
183
-
218
+ export async function verifyUltraHonk(
219
+ proofPath: string,
220
+ vkPath: string,
221
+ crsPath: string,
222
+ options?: UltraHonkBackendOptions,
223
+ ) {
224
+ const { api } = await initLite(crsPath);
184
225
  try {
185
- debug('serializing proof byte array into field elements');
186
- const proofAsFields = await api.acirSerializeProofIntoFields(
187
- acirComposer,
188
- readFileSync(proofPath),
189
- numInnerPublicInputs,
226
+ const acirVerifyUltraHonk = options?.keccak
227
+ ? api.acirVerifyUltraKeccakHonk.bind(api)
228
+ : options?.keccakZK
229
+ ? api.acirVerifyUltraKeccakZkHonk.bind(api)
230
+ : options?.starknet
231
+ ? api.acirVerifyUltraStarknetHonk.bind(api)
232
+ : options?.starknetZK
233
+ ? api.acirVerifyUltraStarknetZkHonk.bind(api)
234
+ : api.acirVerifyUltraZKHonk.bind(api);
235
+ const verified = await acirVerifyUltraHonk(
236
+ Uint8Array.from(readFileSync(proofPath)),
237
+ new RawBuffer(readFileSync(vkPath)),
190
238
  );
191
239
 
192
- writeFileSync(outputPath, JSON.stringify(proofAsFields.map(f => f.toString())));
193
- debug('done.');
240
+ debug(`Verification ${verified ? 'successful' : 'failed'}`);
241
+ return verified;
194
242
  } finally {
195
243
  await api.destroy();
196
244
  }
197
245
  }
198
246
 
199
- export async function vkAsFields(vkPath: string, vkeyOutputPath: string) {
200
- const { api, acirComposer } = await initLite();
201
-
247
+ export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: string, crsPath: string) {
248
+ const { api } = await initLite(crsPath);
202
249
  try {
203
- debug('serializing vk byte array into field elements');
204
- await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
205
- const [vkAsFields, vkHash] = await api.acirSerializeVerificationKeyIntoFields(acirComposer);
206
- const output = [vkHash, ...vkAsFields].map(f => f.toString());
207
- writeFileSync(vkeyOutputPath, JSON.stringify(output));
208
- debug('done.');
250
+ debug(`Outputting UltraHonk proof as vector of fields proof=${proofPath}`);
251
+ const proofAsFields = await api.acirProofAsFieldsUltraHonk(Uint8Array.from(readFileSync(proofPath)));
252
+ const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString()));
253
+
254
+ if (outputPath === '-') {
255
+ process.stdout.write(jsonProofAsFields);
256
+ debug(`Proof as fields written to stdout`);
257
+ } else {
258
+ writeFileSync(outputPath, jsonProofAsFields);
259
+ debug(`Proof as fields written to ${outputPath}`);
260
+ }
209
261
  } finally {
210
262
  await api.destroy();
211
263
  }
212
264
  }
213
265
 
214
- // nargo use bb.js: backend -> bb.js
215
- // backend prove --data-dir data --witness /foo/bar/witness.tr --json /foo/bar/main.json
216
- // backend verify ...
217
- // backend get_total_num_gates --data-dir data --json /foo/bar/main.json
218
- // backend get_sol_contract --data-dir data --json /foo/bar/main.json --output
219
- // backend get_features
220
- // OPTIONAL stateful backend:
221
- // backend start
222
- // backend stop
266
+ export async function vkAsFieldsUltraHonk(vkPath: string, vkeyOutputPath: string, crsPath: string) {
267
+ const { api } = await initLite(crsPath);
223
268
 
224
- const program = new Command();
269
+ try {
270
+ debug(`Serializing vk byte array into field elements vk=${vkPath}`);
271
+ const vkAsFields = await api.acirVkAsFieldsUltraHonk(new RawBuffer(readFileSync(vkPath)));
272
+ const jsonVKAsFields = JSON.stringify(vkAsFields.map(f => f.toString()));
273
+
274
+ if (vkeyOutputPath === '-') {
275
+ process.stdout.write(jsonVKAsFields);
276
+ debug(`Verification key as fields written to stdout`);
277
+ } else {
278
+ writeFileSync(vkeyOutputPath, jsonVKAsFields);
279
+ debug(`Verification key as fields written to ${vkeyOutputPath}`);
280
+ }
281
+ } finally {
282
+ await api.destroy();
283
+ }
284
+ }
285
+
286
+ const program = new Command('bb');
225
287
 
226
288
  program.option('-v, --verbose', 'enable verbose logging', false);
289
+ program.option('-c, --crs-path <path>', 'set crs path', './crs');
227
290
 
228
291
  function handleGlobalOptions() {
229
- if (program.opts().verbose) {
230
- createDebug.enable('bb.js*');
231
- }
292
+ initLogger({ useStdErr: true, level: program.opts().verbose ? 'debug' : 'info' });
293
+ debug = createDebugLogger('bb');
294
+ return { crsPath: program.opts().crsPath };
232
295
  }
233
296
 
297
+ const deprecatedCommandError = () => async () => {
298
+ console.error(
299
+ `Error: UltraPlonk is now deprecated (see https://github.com/AztecProtocol/barretenberg/issues/1377). Use UltraHonk!`,
300
+ );
301
+ process.exit(1);
302
+ };
303
+
234
304
  program
235
305
  .command('prove_and_verify')
236
- .description('Generate a proof and verify it. Process exits with success or failure code.')
237
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
238
- .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.tr')
239
- .option('-r, --recursive', 'prove and verify using recursive prover and verifier', false)
240
- .option('-s, --size-hint <gates>', 'provide a circuit size hint to skip calculation phase')
241
- .action(async ({ jsonPath, witnessPath, recursive, sizeHint }) => {
242
- handleGlobalOptions();
243
- const result = await proveAndVerify(jsonPath, witnessPath, recursive, sizeHint);
306
+ .description('Generate a proof and verify it. Process exits with success or failure code. [DEPRECATED]')
307
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
308
+ .option('-r, --recursive', 'Whether to use a SNARK friendly proof', false)
309
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
310
+ .action(deprecatedCommandError());
311
+
312
+ program
313
+ .command('prove_and_verify_ultra_honk')
314
+ .description('Generate an UltraHonk proof and verify it. Process exits with success or failure code.')
315
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
316
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
317
+ .action(async ({ bytecodePath, witnessPath }) => {
318
+ const { crsPath } = handleGlobalOptions();
319
+ const result = await proveAndVerifyUltraHonk(bytecodePath, witnessPath, crsPath);
320
+ process.exit(result ? 0 : 1);
321
+ });
322
+
323
+ program
324
+ .command('prove_and_verify_mega_honk')
325
+ .description('Generate a MegaHonk proof and verify it. Process exits with success or failure code.')
326
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
327
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
328
+ .action(async ({ bytecodePath, witnessPath }) => {
329
+ const { crsPath } = handleGlobalOptions();
330
+ const result = await proveAndVerifyMegaHonk(bytecodePath, witnessPath, crsPath);
244
331
  process.exit(result ? 0 : 1);
245
332
  });
246
333
 
247
334
  program
248
335
  .command('prove')
249
- .description('Generate a proof and write it to a file.')
250
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
251
- .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.tr')
252
- .option('-r, --recursive', 'prove using recursive prover', false)
336
+ .description('Generate a proof and write it to a file. [DEPRECATED]')
337
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
338
+ .option('-r, --recursive', 'Create a SNARK friendly proof', false)
339
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
253
340
  .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
254
- .option('-s, --size-hint <gates>', 'provide a circuit size hint to skip calculation phase')
255
- .action(async ({ jsonPath, witnessPath, recursive, outputPath, sizeHint }) => {
256
- handleGlobalOptions();
257
- await prove(jsonPath, witnessPath, recursive, outputPath, sizeHint);
258
- });
341
+ .action(deprecatedCommandError());
259
342
 
260
343
  program
261
344
  .command('gates')
262
- .description('Print gate count to standard output.')
263
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
264
- .action(async ({ jsonPath }) => {
345
+ .description('Print Ultra Builder gate count to standard output.')
346
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
347
+ .option('-r, --recursive', 'Create a SNARK friendly proof', false)
348
+ .option('-hr, --honk-recursion', 'Specify whether to use UltraHonk recursion', false)
349
+ .action(async ({ bytecodePath, recursive, honkRecursion: honkRecursion }) => {
265
350
  handleGlobalOptions();
266
- await gateCount(jsonPath);
351
+ await gateCountUltra(bytecodePath, recursive, honkRecursion);
267
352
  });
268
353
 
269
354
  program
270
355
  .command('verify')
271
- .description('Verify a proof. Process exists with success or failure code.')
272
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
356
+ .description('Verify a proof. Process exists with success or failure code. [DEPRECATED]')
273
357
  .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
274
- .option('-r, --recursive', 'prove using recursive prover', false)
275
358
  .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
276
- .action(async ({ jsonPath, proofPath, recursive, vk }) => {
277
- handleGlobalOptions();
278
- await verify(jsonPath, proofPath, recursive, vk);
279
- });
359
+ .action(deprecatedCommandError());
280
360
 
281
361
  program
282
362
  .command('contract')
363
+ .description('Output solidity verification key contract. [DEPRECATED]')
364
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
365
+ .option('-o, --output-path <path>', 'Specify the path to write the contract', './target/contract.sol')
366
+ .requiredOption('-k, --vk-path <path>', 'Path to a verification key. avoids recomputation.')
367
+ .action(deprecatedCommandError());
368
+
369
+ program
370
+ .command('contract_ultra_honk')
283
371
  .description('Output solidity verification key contract.')
284
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
285
- .option('-o, --output-path <path>', 'Specify the path to write the contract', '-')
286
- .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
287
- .action(async ({ outputPath, vk }) => {
288
- handleGlobalOptions();
289
- await contract(outputPath, vk);
372
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
373
+ .option('-o, --output-path <path>', 'Specify the path to write the contract', './target/contract.sol')
374
+ .requiredOption('-k, --vk-path <path>', 'Path to a verification key.')
375
+ .action(async ({ bytecodePath, outputPath, vkPath }) => {
376
+ const { crsPath } = handleGlobalOptions();
377
+ await contractUltraHonk(bytecodePath, vkPath, crsPath, outputPath);
290
378
  });
291
379
 
292
380
  program
293
381
  .command('write_vk')
382
+ .description('Output verification key. [DEPRECATED]')
383
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
384
+ .option('-r, --recursive', 'Create a SNARK friendly proof', false)
385
+ .option('-o, --output-path <path>', 'Specify the path to write the key')
386
+ .action(deprecatedCommandError());
387
+
388
+ program
389
+ .command('write_pk')
390
+ .description('Output proving key. [DEPRECATED]')
391
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
392
+ .option('-r, --recursive', 'Create a SNARK friendly proof', false)
393
+ .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
394
+ .action(deprecatedCommandError());
395
+
396
+ program
397
+ .command('proof_as_fields')
398
+ .description('Return the proof as fields elements. [DEPRECATED]')
399
+ .requiredOption('-p, --proof-path <path>', 'Specify the proof path')
400
+ .requiredOption('-k, --vk-path <path>', 'Path to verification key.')
401
+ .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the proof fields')
402
+ .action(deprecatedCommandError());
403
+
404
+ program
405
+ .command('vk_as_fields')
406
+ .description(
407
+ 'Return the verification key represented as fields elements. Also return the verification key hash. [DEPRECATED]',
408
+ )
409
+ .requiredOption('-k, --vk-path <path>', 'Path to verification key.')
410
+ .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the verification key fields and key hash')
411
+ .action(deprecatedCommandError());
412
+
413
+ program
414
+ .command('prove_ultra_honk')
415
+ .description('Generate a proof and write it to a file.')
416
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
417
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
418
+ .option('-k, --vk-path <path>', 'path to a verification key. avoids recomputation.')
419
+ .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
420
+ .action(async ({ bytecodePath, witnessPath, vkPath, outputPath }) => {
421
+ const { crsPath } = handleGlobalOptions();
422
+ debug(`Creating UltraHonk proof bytecodePath=${bytecodePath}, witnessPath=${witnessPath}, vkPath=${vkPath}`);
423
+ await proveUltraHonk(bytecodePath, witnessPath, crsPath, vkPath, outputPath);
424
+ });
425
+
426
+ program
427
+ .command('prove_ultra_keccak_honk')
428
+ .description('Generate a proof and write it to a file.')
429
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
430
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
431
+ .option('-k, --vk-path <path>', 'path to a verification key. avoids recomputation.')
432
+ .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
433
+ .action(async ({ bytecodePath, witnessPath, vkPath, outputPath }) => {
434
+ const { crsPath } = handleGlobalOptions();
435
+ await proveUltraHonk(bytecodePath, witnessPath, crsPath, vkPath, outputPath, { keccak: true });
436
+ });
437
+
438
+ program
439
+ .command('prove_ultra_starknet_honk')
440
+ .description('Generate a proof and write it to a file.')
441
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
442
+ .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.gz')
443
+ .option('-k, --vk-path <path>', 'path to a verification key. avoids recomputation.')
444
+ .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
445
+ .action(async ({ bytecodePath, witnessPath, vkPath, outputPath }) => {
446
+ const { crsPath } = handleGlobalOptions();
447
+ await proveUltraHonk(bytecodePath, witnessPath, crsPath, vkPath, outputPath, { starknet: true });
448
+ });
449
+
450
+ program
451
+ .command('write_vk_ultra_honk')
294
452
  .description('Output verification key.')
295
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
453
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
296
454
  .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
297
- .option('-s, --size-hint <gates>', 'provide a circuit size hint to skip calculation phase')
298
- .action(async ({ jsonPath, outputPath, sizeHint }) => {
299
- handleGlobalOptions();
300
- await writeVk(jsonPath, outputPath, sizeHint);
455
+ .action(async ({ bytecodePath, outputPath }) => {
456
+ const { crsPath } = handleGlobalOptions();
457
+ debug(`Writing verification key to ${outputPath}`);
458
+ await writeVkUltraHonk(bytecodePath, crsPath, outputPath);
301
459
  });
302
460
 
303
461
  program
304
- .command('proof_as_fields')
462
+ .command('write_vk_ultra_keccak_honk')
463
+ .description('Output verification key.')
464
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
465
+ .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
466
+ .action(async ({ bytecodePath, outputPath }) => {
467
+ const { crsPath } = handleGlobalOptions();
468
+ await writeVkUltraHonk(bytecodePath, crsPath, outputPath, { keccak: true });
469
+ });
470
+
471
+ program
472
+ .command('write_vk_ultra_starknet_honk')
473
+ .description('Output verification key.')
474
+ .option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
475
+ .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
476
+ .action(async ({ bytecodePath, outputPath }) => {
477
+ const { crsPath } = handleGlobalOptions();
478
+ await writeVkUltraHonk(bytecodePath, crsPath, outputPath, { starknet: true });
479
+ });
480
+
481
+ program
482
+ .command('verify_ultra_honk')
483
+ .description('Verify a proof. Process exists with success or failure code.')
484
+ .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
485
+ .requiredOption('-k, --vk-path <path>', 'path to a verification key. avoids recomputation.')
486
+ .action(async ({ proofPath, vkPath }) => {
487
+ const { crsPath } = handleGlobalOptions();
488
+ const result = await verifyUltraHonk(proofPath, vkPath, crsPath);
489
+ process.exit(result ? 0 : 1);
490
+ });
491
+
492
+ program
493
+ .command('verify_ultra_keccak_honk')
494
+ .description('Verify a proof. Process exists with success or failure code.')
495
+ .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
496
+ .requiredOption('-k, --vk-path <path>', 'path to a verification key. avoids recomputation.')
497
+ .action(async ({ proofPath, vkPath }) => {
498
+ const { crsPath } = handleGlobalOptions();
499
+ const result = await verifyUltraHonk(proofPath, vkPath, crsPath, { keccak: true });
500
+ process.exit(result ? 0 : 1);
501
+ });
502
+
503
+ program
504
+ .command('verify_ultra_starknet_honk')
505
+ .description('Verify a proof. Process exists with success or failure code.')
506
+ .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
507
+ .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
508
+ .action(async ({ proofPath, vk }) => {
509
+ const { crsPath } = handleGlobalOptions();
510
+ const result = await verifyUltraHonk(proofPath, vk, crsPath, { starknet: true });
511
+ process.exit(result ? 0 : 1);
512
+ });
513
+
514
+ program
515
+ .command('proof_as_fields_honk')
305
516
  .description('Return the proof as fields elements')
306
517
  .requiredOption('-p, --proof-path <path>', 'Specify the proof path')
307
- .requiredOption('-n, --num-public-inputs <number>', 'Specify the number of public inputs')
308
518
  .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the proof fields')
309
- .action(async ({ proofPath, numPublicInputs, outputPath }) => {
310
- handleGlobalOptions();
311
- await proofAsFields(proofPath, numPublicInputs, outputPath);
519
+ .action(async ({ proofPath, outputPath }) => {
520
+ const { crsPath } = handleGlobalOptions();
521
+ await proofAsFieldsUltraHonk(proofPath, outputPath, crsPath);
312
522
  });
313
523
 
314
524
  program
315
- .command('vk_as_fields')
316
- .description('Return the verifiation key represented as fields elements. Also return the verification key hash.')
317
- .requiredOption('-i, --input-path <path>', 'Specifies the vk path (output from write_vk)')
318
- .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the verification key fields and key hash')
319
- .action(async ({ inputPath, outputPath }) => {
320
- handleGlobalOptions();
321
- await vkAsFields(inputPath, outputPath);
525
+ .command('vk_as_fields_ultra_honk')
526
+ .description('Return the verification key represented as fields elements.')
527
+ .requiredOption('-k, --vk-path <path>', 'Path to verification key.')
528
+ .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the verification key fields.')
529
+ .action(async ({ vkPath, outputPath }) => {
530
+ const { crsPath } = handleGlobalOptions();
531
+ await vkAsFieldsUltraHonk(vkPath, outputPath, crsPath);
322
532
  });
323
533
 
324
534
  program.name('bb.js').parse(process.argv);