@aztec/bb.js 0.0.1-alpha.7 → 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 -32
  2. package/package.json +56 -45
  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 +982 -415
  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 -1
  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 +96 -26
  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 +391 -168
  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/ignition_files_crs.d.ts +0 -37
  151. package/dest/crs/node/ignition_files_crs.d.ts.map +0 -1
  152. package/dest/crs/node/ignition_files_crs.js +0 -51
  153. package/dest/crs/node/index.d.ts +0 -21
  154. package/dest/crs/node/index.d.ts.map +0 -1
  155. package/dest/crs/node/index.js +0 -54
  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 -275
  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/ignition_files_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,311 +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 getJsonData(jsonPath: string) {
16
- const json = readFileSync(jsonPath, 'utf-8');
17
- const parsed = JSON.parse(json);
18
- return parsed;
19
- }
14
+ function getBytecode(bytecodePath: string): Uint8Array {
15
+ const extension = bytecodePath.substring(bytecodePath.lastIndexOf('.') + 1);
16
+
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
+ }
20
22
 
21
- function getBytecode(jsonPath: string) {
22
- const parsed = getJsonData(jsonPath);
23
- const buffer = Buffer.from(parsed.bytecode, 'base64');
24
- const decompressed = gunzipSync(buffer);
25
- return decompressed;
23
+ const encodedCircuit = readFileSync(bytecodePath);
24
+ const decompressed = gunzipSync(encodedCircuit);
25
+ return Uint8Array.from(decompressed);
26
26
  }
27
27
 
28
- async function getGates(jsonPath: string, api: BarretenbergApiAsync) {
29
- const parsed = getJsonData(jsonPath);
30
- if (parsed.gates) {
31
- return +parsed.gates;
32
- }
33
- const { total } = await computeCircuitSize(jsonPath, api);
34
- const jsonData = getJsonData(jsonPath);
35
- jsonData.gates = total;
36
- writeFileSync(jsonPath, JSON.stringify(jsonData));
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);
37
31
  return total;
38
32
  }
39
33
 
40
- function getWitness(witnessPath: string) {
34
+ function getWitness(witnessPath: string): Uint8Array {
41
35
  const data = readFileSync(witnessPath);
42
- return Buffer.concat([numToUInt32BE(data.length / 32), data]);
36
+ const decompressed = gunzipSync(data);
37
+ return Uint8Array.from(decompressed);
43
38
  }
44
39
 
45
- async function computeCircuitSize(jsonPath: string, api: BarretenbergApiAsync) {
46
- debug(`computing circuit size...`);
47
- const bytecode = getBytecode(jsonPath);
48
- const [exact, total, subgroup] = await api.acirGetCircuitSizes(new RawBuffer(bytecode));
49
- return { exact, total, subgroup };
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 };
50
45
  }
51
46
 
52
- async function init(jsonPath: string) {
53
- const api = await newBarretenbergApiAsync();
54
-
55
- const circuitSize = await getGates(jsonPath, api);
56
- const subgroupSize = Math.pow(2, Math.ceil(Math.log2(circuitSize)));
57
- if (subgroupSize > MAX_CIRCUIT_SIZE) {
58
- throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_CIRCUIT_SIZE}`);
59
- }
47
+ async function initUltraHonk(bytecodePath: string, crsPath: string) {
48
+ const api = await Barretenberg.new({
49
+ threads,
50
+ });
60
51
 
61
- debug(`circuit size: ${circuitSize}`);
62
- debug(`subgroup size: ${subgroupSize}`);
63
- debug('loading crs...');
64
- // Plus 1 needed! (Move +1 into Crs?)
65
- 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)));
66
58
 
67
- // Important to init slab allocator as first thing, to ensure maximum memory efficiency.
68
- 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);
69
61
 
70
62
  // Load CRS into wasm global CRS state.
71
- // 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.
72
64
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
73
-
74
- const acirComposer = await api.acirNewAcirComposer(subgroupSize);
75
- return { api, acirComposer, circuitSize: subgroupSize };
65
+ return { api, circuitSize, dyadicCircuitSize };
76
66
  }
77
67
 
78
- async function initLite() {
79
- const api = await newBarretenbergApiAsync(1);
68
+ async function initLite(crsPath: string) {
69
+ const api = await Barretenberg.new({ threads: 1 });
80
70
 
81
71
  // Plus 1 needed! (Move +1 into Crs?)
82
- const crs = await Crs.new(1);
72
+ const crs = await Crs.new(1, crsPath);
83
73
 
84
74
  // Load CRS into wasm global CRS state.
85
75
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
86
76
 
87
- const acirComposer = await api.acirNewAcirComposer(0);
88
- return { api, acirComposer };
77
+ return { api };
89
78
  }
90
79
 
91
- export async function proveAndVerify(jsonPath: string, witnessPath: string, isRecursive: boolean) {
92
- const { api, acirComposer } = await init(jsonPath);
80
+ export async function proveAndVerifyUltraHonk(bytecodePath: string, witnessPath: string, crsPath: string) {
81
+ /* eslint-disable camelcase */
82
+ const { api } = await initUltraHonk(bytecodePath, crsPath);
93
83
  try {
94
- debug(`creating proof...`);
95
- const bytecode = getBytecode(jsonPath);
84
+ const bytecode = getBytecode(bytecodePath);
96
85
  const witness = getWitness(witnessPath);
97
- const proof = await api.acirCreateProof(acirComposer, new RawBuffer(bytecode), new RawBuffer(witness), isRecursive);
98
86
 
99
- debug(`verifying...`);
100
- const verified = await api.acirVerifyProof(acirComposer, proof, isRecursive);
101
- console.log(`verified: ${verified}`);
87
+ const verified = await api.acirProveAndVerifyUltraHonk(bytecode, witness);
102
88
  return verified;
103
89
  } finally {
104
90
  await api.destroy();
105
91
  }
92
+ /* eslint-enable camelcase */
106
93
  }
107
94
 
108
- export async function prove(jsonPath: string, witnessPath: string, isRecursive: boolean, outputPath: string) {
109
- const { api, acirComposer } = await init(jsonPath);
95
+ export async function proveAndVerifyMegaHonk(bytecodePath: string, witnessPath: string, crsPath: string) {
96
+ /* eslint-disable camelcase */
97
+ const { api } = await initUltraHonk(bytecodePath, crsPath);
110
98
  try {
111
- debug(`creating proof...`);
112
- const bytecode = getBytecode(jsonPath);
99
+ const bytecode = getBytecode(bytecodePath);
113
100
  const witness = getWitness(witnessPath);
114
- const proof = await api.acirCreateProof(acirComposer, new RawBuffer(bytecode), new RawBuffer(witness), isRecursive);
115
- debug(`done.`);
116
101
 
117
- writeFileSync(outputPath, proof);
118
- console.log(`proof written to: ${outputPath}`);
102
+ const verified = await api.acirProveAndVerifyMegaHonk(bytecode, witness);
103
+ return verified;
119
104
  } finally {
120
105
  await api.destroy();
121
106
  }
107
+ /* eslint-enable camelcase */
122
108
  }
123
109
 
124
- export async function gateCount(jsonPath: string) {
125
- const api = await newBarretenbergApiAsync(1);
110
+ export async function gateCountUltra(bytecodePath: string, recursive: boolean, honkRecursion: boolean) {
111
+ const api = await Barretenberg.new({ threads: 1 });
126
112
  try {
127
- console.log(`gates: ${await getGates(jsonPath, api)}`);
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(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) {
162
- const { api, acirComposer } = await init(jsonPath);
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;
242
+ } finally {
243
+ await api.destroy();
244
+ }
245
+ }
246
+
247
+ export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: string, crsPath: string) {
248
+ const { api } = await initLite(crsPath);
249
+ try {
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
+ }
194
261
  } finally {
195
262
  await api.destroy();
196
263
  }
197
264
  }
198
265
 
199
- export async function vkAsFields(vkPath: string, vkeyOutputPath: string) {
200
- const { api, acirComposer } = await initLite();
266
+ export async function vkAsFieldsUltraHonk(vkPath: string, vkeyOutputPath: string, crsPath: string) {
267
+ const { api } = await initLite(crsPath);
201
268
 
202
269
  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.');
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
+ }
209
281
  } finally {
210
282
  await api.destroy();
211
283
  }
212
284
  }
213
285
 
214
- const program = new Command();
286
+ const program = new Command('bb');
215
287
 
216
288
  program.option('-v, --verbose', 'enable verbose logging', false);
289
+ program.option('-c, --crs-path <path>', 'set crs path', './crs');
217
290
 
218
291
  function handleGlobalOptions() {
219
- if (program.opts().verbose) {
220
- createDebug.enable('bb.js*');
221
- }
292
+ initLogger({ useStdErr: true, level: program.opts().verbose ? 'debug' : 'info' });
293
+ debug = createDebugLogger('bb');
294
+ return { crsPath: program.opts().crsPath };
222
295
  }
223
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
+
224
304
  program
225
305
  .command('prove_and_verify')
226
- .description('Generate a proof and verify it. Process exits with success or failure code.')
227
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
228
- .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.tr')
229
- .option('-r, --recursive', 'prove and verify using recursive prover and verifier', false)
230
- .action(async ({ jsonPath, witnessPath, recursive }) => {
231
- handleGlobalOptions();
232
- const result = await proveAndVerify(jsonPath, witnessPath, recursive);
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);
233
331
  process.exit(result ? 0 : 1);
234
332
  });
235
333
 
236
334
  program
237
335
  .command('prove')
238
- .description('Generate a proof and write it to a file.')
239
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
240
- .option('-w, --witness-path <path>', 'Specify the witness path', './target/witness.tr')
241
- .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')
242
340
  .option('-o, --output-path <path>', 'Specify the proof output path', './proofs/proof')
243
- .action(async ({ jsonPath, witnessPath, recursive, outputPath }) => {
244
- handleGlobalOptions();
245
- await prove(jsonPath, witnessPath, recursive, outputPath);
246
- });
341
+ .action(deprecatedCommandError());
247
342
 
248
343
  program
249
344
  .command('gates')
250
- .description('Print gate count to standard output.')
251
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
252
- .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 }) => {
253
350
  handleGlobalOptions();
254
- await gateCount(jsonPath);
351
+ await gateCountUltra(bytecodePath, recursive, honkRecursion);
255
352
  });
256
353
 
257
354
  program
258
355
  .command('verify')
259
- .description('Verify a proof. Process exists with success or failure code.')
356
+ .description('Verify a proof. Process exists with success or failure code. [DEPRECATED]')
260
357
  .requiredOption('-p, --proof-path <path>', 'Specify the path to the proof')
261
- .option('-r, --recursive', 'prove using recursive prover', false)
262
358
  .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
263
- .action(async ({ proofPath, recursive, vk }) => {
264
- handleGlobalOptions();
265
- const result = await verify(proofPath, recursive, vk);
266
- process.exit(result ? 0 : 1);
267
- });
359
+ .action(deprecatedCommandError());
268
360
 
269
361
  program
270
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')
271
371
  .description('Output solidity verification key contract.')
272
- .option('-j, --json-path <path>', 'Specify the JSON path', './target/main.json')
273
- .option('-o, --output-path <path>', 'Specify the path to write the contract', '-')
274
- .requiredOption('-k, --vk <path>', 'path to a verification key. avoids recomputation.')
275
- .action(async ({ outputPath, vk }) => {
276
- handleGlobalOptions();
277
- 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);
278
378
  });
279
379
 
280
380
  program
281
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')
282
452
  .description('Output verification key.')
283
- .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')
284
454
  .requiredOption('-o, --output-path <path>', 'Specify the path to write the key')
285
- .action(async ({ jsonPath, outputPath }) => {
286
- handleGlobalOptions();
287
- await writeVk(jsonPath, outputPath);
455
+ .action(async ({ bytecodePath, outputPath }) => {
456
+ const { crsPath } = handleGlobalOptions();
457
+ debug(`Writing verification key to ${outputPath}`);
458
+ await writeVkUltraHonk(bytecodePath, crsPath, outputPath);
288
459
  });
289
460
 
290
461
  program
291
- .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')
292
516
  .description('Return the proof as fields elements')
293
517
  .requiredOption('-p, --proof-path <path>', 'Specify the proof path')
294
- .requiredOption('-n, --num-public-inputs <number>', 'Specify the number of public inputs')
295
518
  .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the proof fields')
296
- .action(async ({ proofPath, numPublicInputs, outputPath }) => {
297
- handleGlobalOptions();
298
- await proofAsFields(proofPath, numPublicInputs, outputPath);
519
+ .action(async ({ proofPath, outputPath }) => {
520
+ const { crsPath } = handleGlobalOptions();
521
+ await proofAsFieldsUltraHonk(proofPath, outputPath, crsPath);
299
522
  });
300
523
 
301
524
  program
302
- .command('vk_as_fields')
303
- .description('Return the verifiation key represented as fields elements. Also return the verification key hash.')
304
- .requiredOption('-i, --input-path <path>', 'Specifies the vk path (output from write_vk)')
305
- .requiredOption('-o, --output-path <path>', 'Specify the JSON path to write the verification key fields and key hash')
306
- .action(async ({ inputPath, outputPath }) => {
307
- handleGlobalOptions();
308
- 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);
309
532
  });
310
533
 
311
534
  program.name('bb.js').parse(process.argv);