@aztec/bb.js 0.0.1-alpha.4 → 0.0.1-alpha.6

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.
@@ -12,47 +12,52 @@ export class BarretenbergApi {
12
12
  }
13
13
 
14
14
  async pedersenInit(): Promise<void> {
15
- const result = await this.binder.callWasmExport('pedersen_init', [], []);
15
+ const result = await this.binder.callWasmExport('pedersen___init', [], []);
16
16
  return;
17
17
  }
18
18
 
19
19
  async pedersenCompressFields(left: Fr, right: Fr): Promise<Fr> {
20
- const result = await this.binder.callWasmExport('pedersen_compress_fields', [left, right], [Fr]);
20
+ const result = await this.binder.callWasmExport('pedersen___compress_fields', [left, right], [Fr]);
21
21
  return result[0];
22
22
  }
23
23
 
24
24
  async pedersenPlookupCompressFields(left: Fr, right: Fr): Promise<Fr> {
25
- const result = await this.binder.callWasmExport('pedersen_plookup_compress_fields', [left, right], [Fr]);
25
+ const result = await this.binder.callWasmExport('pedersen___plookup_compress_fields', [left, right], [Fr]);
26
26
  return result[0];
27
27
  }
28
28
 
29
29
  async pedersenCompress(inputsBuffer: Fr[]): Promise<Fr> {
30
- const result = await this.binder.callWasmExport('pedersen_compress', [inputsBuffer], [Fr]);
30
+ const result = await this.binder.callWasmExport('pedersen___compress', [inputsBuffer], [Fr]);
31
31
  return result[0];
32
32
  }
33
33
 
34
34
  async pedersenPlookupCompress(inputsBuffer: Fr[]): Promise<Fr> {
35
- const result = await this.binder.callWasmExport('pedersen_plookup_compress', [inputsBuffer], [Fr]);
35
+ const result = await this.binder.callWasmExport('pedersen___plookup_compress', [inputsBuffer], [Fr]);
36
36
  return result[0];
37
37
  }
38
38
 
39
39
  async pedersenCompressWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
40
- const result = await this.binder.callWasmExport('pedersen_compress_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
40
+ const result = await this.binder.callWasmExport('pedersen___compress_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
41
41
  return result[0];
42
42
  }
43
43
 
44
44
  async pedersenCommit(inputsBuffer: Fr[]): Promise<Fr> {
45
- const result = await this.binder.callWasmExport('pedersen_commit', [inputsBuffer], [Fr]);
45
+ const result = await this.binder.callWasmExport('pedersen___commit', [inputsBuffer], [Fr]);
46
46
  return result[0];
47
47
  }
48
48
 
49
49
  async pedersenPlookupCommit(inputsBuffer: Fr[]): Promise<Fr> {
50
- const result = await this.binder.callWasmExport('pedersen_plookup_commit', [inputsBuffer], [Fr]);
50
+ const result = await this.binder.callWasmExport('pedersen___plookup_commit', [inputsBuffer], [Fr]);
51
+ return result[0];
52
+ }
53
+
54
+ async pedersenPlookupCommitWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
55
+ const result = await this.binder.callWasmExport('pedersen___plookup_commit_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
51
56
  return result[0];
52
57
  }
53
58
 
54
59
  async pedersenBufferToField(data: Uint8Array): Promise<Fr> {
55
- const result = await this.binder.callWasmExport('pedersen_buffer_to_field', [data], [Fr]);
60
+ const result = await this.binder.callWasmExport('pedersen___buffer_to_field', [data], [Fr]);
56
61
  return result[0];
57
62
  }
58
63
 
@@ -171,8 +176,8 @@ export class BarretenbergApi {
171
176
  return result as any;
172
177
  }
173
178
 
174
- async acirNewAcirComposer(): Promise<Ptr> {
175
- const result = await this.binder.callWasmExport('acir_new_acir_composer', [], [Ptr]);
179
+ async acirNewAcirComposer(sizeHint: number): Promise<Ptr> {
180
+ const result = await this.binder.callWasmExport('acir_new_acir_composer', [sizeHint], [Ptr]);
176
181
  return result[0];
177
182
  }
178
183
 
@@ -186,8 +191,8 @@ export class BarretenbergApi {
186
191
  return;
187
192
  }
188
193
 
189
- async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise<void> {
190
- const result = await this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf, sizeHint], []);
194
+ async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise<void> {
195
+ const result = await this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf], []);
191
196
  return;
192
197
  }
193
198
 
@@ -240,47 +245,52 @@ export class BarretenbergApiSync {
240
245
  }
241
246
 
242
247
  pedersenInit(): void {
243
- const result = this.binder.callWasmExport('pedersen_init', [], []);
248
+ const result = this.binder.callWasmExport('pedersen___init', [], []);
244
249
  return;
245
250
  }
246
251
 
247
252
  pedersenCompressFields(left: Fr, right: Fr): Fr {
248
- const result = this.binder.callWasmExport('pedersen_compress_fields', [left, right], [Fr]);
253
+ const result = this.binder.callWasmExport('pedersen___compress_fields', [left, right], [Fr]);
249
254
  return result[0];
250
255
  }
251
256
 
252
257
  pedersenPlookupCompressFields(left: Fr, right: Fr): Fr {
253
- const result = this.binder.callWasmExport('pedersen_plookup_compress_fields', [left, right], [Fr]);
258
+ const result = this.binder.callWasmExport('pedersen___plookup_compress_fields', [left, right], [Fr]);
254
259
  return result[0];
255
260
  }
256
261
 
257
262
  pedersenCompress(inputsBuffer: Fr[]): Fr {
258
- const result = this.binder.callWasmExport('pedersen_compress', [inputsBuffer], [Fr]);
263
+ const result = this.binder.callWasmExport('pedersen___compress', [inputsBuffer], [Fr]);
259
264
  return result[0];
260
265
  }
261
266
 
262
267
  pedersenPlookupCompress(inputsBuffer: Fr[]): Fr {
263
- const result = this.binder.callWasmExport('pedersen_plookup_compress', [inputsBuffer], [Fr]);
268
+ const result = this.binder.callWasmExport('pedersen___plookup_compress', [inputsBuffer], [Fr]);
264
269
  return result[0];
265
270
  }
266
271
 
267
272
  pedersenCompressWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Fr {
268
- const result = this.binder.callWasmExport('pedersen_compress_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
273
+ const result = this.binder.callWasmExport('pedersen___compress_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
269
274
  return result[0];
270
275
  }
271
276
 
272
277
  pedersenCommit(inputsBuffer: Fr[]): Fr {
273
- const result = this.binder.callWasmExport('pedersen_commit', [inputsBuffer], [Fr]);
278
+ const result = this.binder.callWasmExport('pedersen___commit', [inputsBuffer], [Fr]);
274
279
  return result[0];
275
280
  }
276
281
 
277
282
  pedersenPlookupCommit(inputsBuffer: Fr[]): Fr {
278
- const result = this.binder.callWasmExport('pedersen_plookup_commit', [inputsBuffer], [Fr]);
283
+ const result = this.binder.callWasmExport('pedersen___plookup_commit', [inputsBuffer], [Fr]);
284
+ return result[0];
285
+ }
286
+
287
+ pedersenPlookupCommitWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Fr {
288
+ const result = this.binder.callWasmExport('pedersen___plookup_commit_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
279
289
  return result[0];
280
290
  }
281
291
 
282
292
  pedersenBufferToField(data: Uint8Array): Fr {
283
- const result = this.binder.callWasmExport('pedersen_buffer_to_field', [data], [Fr]);
293
+ const result = this.binder.callWasmExport('pedersen___buffer_to_field', [data], [Fr]);
284
294
  return result[0];
285
295
  }
286
296
 
@@ -399,8 +409,8 @@ export class BarretenbergApiSync {
399
409
  return result as any;
400
410
  }
401
411
 
402
- acirNewAcirComposer(): Ptr {
403
- const result = this.binder.callWasmExport('acir_new_acir_composer', [], [Ptr]);
412
+ acirNewAcirComposer(sizeHint: number): Ptr {
413
+ const result = this.binder.callWasmExport('acir_new_acir_composer', [sizeHint], [Ptr]);
404
414
  return result[0];
405
415
  }
406
416
 
@@ -414,8 +424,8 @@ export class BarretenbergApiSync {
414
424
  return;
415
425
  }
416
426
 
417
- acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): void {
418
- const result = this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf, sizeHint], []);
427
+ acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): void {
428
+ const result = this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf], []);
419
429
  return;
420
430
  }
421
431
 
package/src/main.ts CHANGED
@@ -64,7 +64,7 @@ async function init(jsonPath: string, sizeHint?: number) {
64
64
  // TODO: Make RawBuffer be default behaviour, and have a specific Vector type for when wanting length prefixed.
65
65
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
66
66
 
67
- const acirComposer = await api.acirNewAcirComposer();
67
+ const acirComposer = await api.acirNewAcirComposer(subgroupSize);
68
68
  return { api, acirComposer, circuitSize: subgroupSize };
69
69
  }
70
70
 
@@ -77,24 +77,15 @@ async function initLite() {
77
77
  // Load CRS into wasm global CRS state.
78
78
  await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
79
79
 
80
- const acirComposer = await api.acirNewAcirComposer();
80
+ const acirComposer = await api.acirNewAcirComposer(0);
81
81
  return { api, acirComposer };
82
82
  }
83
83
 
84
84
  export async function proveAndVerify(jsonPath: string, witnessPath: string, isRecursive: boolean, sizeHint?: number) {
85
85
  const { api, acirComposer } = await init(jsonPath, sizeHint);
86
86
  try {
87
- // debug('initing proving key...');
88
- const bytecode = getBytecode(jsonPath);
89
- // await api.acirInitProvingKey(acirComposer, new RawBuffer(bytecode), circuitSize);
90
-
91
- // const circuitSize = await api.acirGetExactCircuitSize(acirComposer);
92
- // debug(`circuit size: ${circuitSize}`);
93
-
94
- // debug('initing verification key...');
95
- // await api.acirInitVerificationKey(acirComposer);
96
-
97
87
  debug(`creating proof...`);
88
+ const bytecode = getBytecode(jsonPath);
98
89
  const witness = getWitness(witnessPath);
99
90
  const proof = await api.acirCreateProof(acirComposer, new RawBuffer(bytecode), new RawBuffer(witness), isRecursive);
100
91
 
@@ -116,14 +107,8 @@ export async function prove(
116
107
  ) {
117
108
  const { api, acirComposer } = await init(jsonPath, sizeHint);
118
109
  try {
119
- // debug('initing proving key...');
120
- const bytecode = getBytecode(jsonPath);
121
- // await api.acirInitProvingKey(acirComposer, new RawBuffer(bytecode), circuitSize);
122
-
123
- // const circuitSize = await api.acirGetExactCircuitSize(acirComposer);
124
- // debug(`circuit size: ${circuitSize}`);
125
-
126
110
  debug(`creating proof...`);
111
+ const bytecode = getBytecode(jsonPath);
127
112
  const witness = getWitness(witnessPath);
128
113
  const proof = await api.acirCreateProof(acirComposer, new RawBuffer(bytecode), new RawBuffer(witness), isRecursive);
129
114
  debug(`done.`);
@@ -174,11 +159,11 @@ export async function contract(outputPath: string, vkPath: string) {
174
159
  }
175
160
 
176
161
  export async function writeVk(jsonPath: string, outputPath: string, sizeHint?: number) {
177
- const { api, acirComposer, circuitSize } = await init(jsonPath, sizeHint);
162
+ const { api, acirComposer } = await init(jsonPath, sizeHint);
178
163
  try {
179
164
  debug('initing proving key...');
180
165
  const bytecode = getBytecode(jsonPath);
181
- await api.acirInitProvingKey(acirComposer, new RawBuffer(bytecode), circuitSize);
166
+ await api.acirInitProvingKey(acirComposer, new RawBuffer(bytecode));
182
167
 
183
168
  debug('initing verification key...');
184
169
  const vk = await api.acirGetVerificationKey(acirComposer);