@izi-noir/sdk 0.1.0 → 0.1.1

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.
@@ -30,6 +30,873 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
+ // src/wasm/nodejs/arkworks_groth16_wasm.js
34
+ var arkworks_groth16_wasm_exports = {};
35
+ function acir_to_r1cs_info(acir_json) {
36
+ const ptr0 = passStringToWasm0(acir_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
37
+ const len0 = WASM_VECTOR_LEN;
38
+ const ret = wasm.acir_to_r1cs_info(ptr0, len0);
39
+ if (ret[2]) {
40
+ throw takeFromExternrefTable0(ret[1]);
41
+ }
42
+ return takeFromExternrefTable0(ret[0]);
43
+ }
44
+ function init_panic_hook() {
45
+ wasm.init_panic_hook();
46
+ }
47
+ function prove(proving_key_b64, acir_json, witness_json) {
48
+ const ptr0 = passStringToWasm0(proving_key_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
49
+ const len0 = WASM_VECTOR_LEN;
50
+ const ptr1 = passStringToWasm0(acir_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
51
+ const len1 = WASM_VECTOR_LEN;
52
+ const ptr2 = passStringToWasm0(witness_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
53
+ const len2 = WASM_VECTOR_LEN;
54
+ const ret = wasm.prove(ptr0, len0, ptr1, len1, ptr2, len2);
55
+ if (ret[2]) {
56
+ throw takeFromExternrefTable0(ret[1]);
57
+ }
58
+ return takeFromExternrefTable0(ret[0]);
59
+ }
60
+ function prove_from_r1cs(proving_key_b64, r1cs_json, witness_json) {
61
+ const ptr0 = passStringToWasm0(proving_key_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
62
+ const len0 = WASM_VECTOR_LEN;
63
+ const ptr1 = passStringToWasm0(r1cs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
64
+ const len1 = WASM_VECTOR_LEN;
65
+ const ptr2 = passStringToWasm0(witness_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
66
+ const len2 = WASM_VECTOR_LEN;
67
+ const ret = wasm.prove_from_r1cs(ptr0, len0, ptr1, len1, ptr2, len2);
68
+ if (ret[2]) {
69
+ throw takeFromExternrefTable0(ret[1]);
70
+ }
71
+ return takeFromExternrefTable0(ret[0]);
72
+ }
73
+ function setup(acir_json) {
74
+ const ptr0 = passStringToWasm0(acir_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
75
+ const len0 = WASM_VECTOR_LEN;
76
+ const ret = wasm.setup(ptr0, len0);
77
+ if (ret[2]) {
78
+ throw takeFromExternrefTable0(ret[1]);
79
+ }
80
+ return takeFromExternrefTable0(ret[0]);
81
+ }
82
+ function setup_from_r1cs(r1cs_json) {
83
+ const ptr0 = passStringToWasm0(r1cs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
84
+ const len0 = WASM_VECTOR_LEN;
85
+ const ret = wasm.setup_from_r1cs(ptr0, len0);
86
+ if (ret[2]) {
87
+ throw takeFromExternrefTable0(ret[1]);
88
+ }
89
+ return takeFromExternrefTable0(ret[0]);
90
+ }
91
+ function verify(verifying_key_b64, proof_b64, public_inputs_json) {
92
+ const ptr0 = passStringToWasm0(verifying_key_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
93
+ const len0 = WASM_VECTOR_LEN;
94
+ const ptr1 = passStringToWasm0(proof_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
95
+ const len1 = WASM_VECTOR_LEN;
96
+ const ptr2 = passStringToWasm0(public_inputs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
97
+ const len2 = WASM_VECTOR_LEN;
98
+ const ret = wasm.verify(ptr0, len0, ptr1, len1, ptr2, len2);
99
+ if (ret[2]) {
100
+ throw takeFromExternrefTable0(ret[1]);
101
+ }
102
+ return ret[0] !== 0;
103
+ }
104
+ function verify_gnark(verifying_key_gnark_b64, proof_gnark_b64, public_inputs_gnark_b64, num_public_inputs) {
105
+ const ptr0 = passStringToWasm0(verifying_key_gnark_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
106
+ const len0 = WASM_VECTOR_LEN;
107
+ const ptr1 = passStringToWasm0(proof_gnark_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
108
+ const len1 = WASM_VECTOR_LEN;
109
+ const ptr2 = passStringToWasm0(public_inputs_gnark_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
110
+ const len2 = WASM_VECTOR_LEN;
111
+ const ret = wasm.verify_gnark(ptr0, len0, ptr1, len1, ptr2, len2, num_public_inputs);
112
+ if (ret[2]) {
113
+ throw takeFromExternrefTable0(ret[1]);
114
+ }
115
+ return ret[0] !== 0;
116
+ }
117
+ function version() {
118
+ let deferred1_0;
119
+ let deferred1_1;
120
+ try {
121
+ const ret = wasm.version();
122
+ deferred1_0 = ret[0];
123
+ deferred1_1 = ret[1];
124
+ return getStringFromWasm0(ret[0], ret[1]);
125
+ } finally {
126
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
127
+ }
128
+ }
129
+ function __wbg_get_imports() {
130
+ const import0 = {
131
+ __proto__: null,
132
+ __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
133
+ const ret = Error(getStringFromWasm0(arg0, arg1));
134
+ return ret;
135
+ },
136
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
137
+ const ret = String(arg1);
138
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
139
+ const len1 = WASM_VECTOR_LEN;
140
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
141
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
142
+ },
143
+ __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
144
+ const ret = typeof arg0 === "function";
145
+ return ret;
146
+ },
147
+ __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
148
+ const val = arg0;
149
+ const ret = typeof val === "object" && val !== null;
150
+ return ret;
151
+ },
152
+ __wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
153
+ const ret = typeof arg0 === "string";
154
+ return ret;
155
+ },
156
+ __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
157
+ const ret = arg0 === void 0;
158
+ return ret;
159
+ },
160
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
161
+ throw new Error(getStringFromWasm0(arg0, arg1));
162
+ },
163
+ __wbg_call_389efe28435a9388: function() {
164
+ return handleError(function(arg0, arg1) {
165
+ const ret = arg0.call(arg1);
166
+ return ret;
167
+ }, arguments);
168
+ },
169
+ __wbg_call_4708e0c13bdc8e95: function() {
170
+ return handleError(function(arg0, arg1, arg2) {
171
+ const ret = arg0.call(arg1, arg2);
172
+ return ret;
173
+ }, arguments);
174
+ },
175
+ __wbg_crypto_86f2631e91b51511: function(arg0) {
176
+ const ret = arg0.crypto;
177
+ return ret;
178
+ },
179
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
180
+ let deferred0_0;
181
+ let deferred0_1;
182
+ try {
183
+ deferred0_0 = arg0;
184
+ deferred0_1 = arg1;
185
+ console.error(getStringFromWasm0(arg0, arg1));
186
+ } finally {
187
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
188
+ }
189
+ },
190
+ __wbg_getRandomValues_b3f15fcbfabb0f8b: function() {
191
+ return handleError(function(arg0, arg1) {
192
+ arg0.getRandomValues(arg1);
193
+ }, arguments);
194
+ },
195
+ __wbg_length_32ed9a279acd054c: function(arg0) {
196
+ const ret = arg0.length;
197
+ return ret;
198
+ },
199
+ __wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
200
+ const ret = arg0.msCrypto;
201
+ return ret;
202
+ },
203
+ __wbg_new_361308b2356cecd0: function() {
204
+ const ret = new Object();
205
+ return ret;
206
+ },
207
+ __wbg_new_3eb36ae241fe6f44: function() {
208
+ const ret = new Array();
209
+ return ret;
210
+ },
211
+ __wbg_new_8a6f238a6ece86ea: function() {
212
+ const ret = new Error();
213
+ return ret;
214
+ },
215
+ __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
216
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
217
+ return ret;
218
+ },
219
+ __wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
220
+ const ret = new Uint8Array(arg0 >>> 0);
221
+ return ret;
222
+ },
223
+ __wbg_node_e1f24f89a7336c2e: function(arg0) {
224
+ const ret = arg0.node;
225
+ return ret;
226
+ },
227
+ __wbg_process_3975fd6c72f520aa: function(arg0) {
228
+ const ret = arg0.process;
229
+ return ret;
230
+ },
231
+ __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
232
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
233
+ },
234
+ __wbg_randomFillSync_f8c153b79f285817: function() {
235
+ return handleError(function(arg0, arg1) {
236
+ arg0.randomFillSync(arg1);
237
+ }, arguments);
238
+ },
239
+ __wbg_require_b74f47fc2d022fd6: function() {
240
+ return handleError(function() {
241
+ const ret = module.require;
242
+ return ret;
243
+ }, arguments);
244
+ },
245
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
246
+ arg0[arg1] = arg2;
247
+ },
248
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
249
+ arg0[arg1 >>> 0] = arg2;
250
+ },
251
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
252
+ const ret = arg1.stack;
253
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
254
+ const len1 = WASM_VECTOR_LEN;
255
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
256
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
257
+ },
258
+ __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
259
+ const ret = typeof global === "undefined" ? null : global;
260
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
261
+ },
262
+ __wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
263
+ const ret = typeof globalThis === "undefined" ? null : globalThis;
264
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
265
+ },
266
+ __wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
267
+ const ret = typeof self === "undefined" ? null : self;
268
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
269
+ },
270
+ __wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
271
+ const ret = typeof window === "undefined" ? null : window;
272
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
273
+ },
274
+ __wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
275
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
276
+ return ret;
277
+ },
278
+ __wbg_versions_4e31226f5e8dc909: function(arg0) {
279
+ const ret = arg0.versions;
280
+ return ret;
281
+ },
282
+ __wbindgen_cast_0000000000000001: function(arg0) {
283
+ const ret = arg0;
284
+ return ret;
285
+ },
286
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
287
+ const ret = getArrayU8FromWasm0(arg0, arg1);
288
+ return ret;
289
+ },
290
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
291
+ const ret = getStringFromWasm0(arg0, arg1);
292
+ return ret;
293
+ },
294
+ __wbindgen_cast_0000000000000004: function(arg0) {
295
+ const ret = BigInt.asUintN(64, arg0);
296
+ return ret;
297
+ },
298
+ __wbindgen_init_externref_table: function() {
299
+ const table = wasm.__wbindgen_externrefs;
300
+ const offset = table.grow(4);
301
+ table.set(0, void 0);
302
+ table.set(offset + 0, void 0);
303
+ table.set(offset + 1, null);
304
+ table.set(offset + 2, true);
305
+ table.set(offset + 3, false);
306
+ }
307
+ };
308
+ return {
309
+ __proto__: null,
310
+ "./arkworks_groth16_wasm_bg.js": import0
311
+ };
312
+ }
313
+ function addToExternrefTable0(obj) {
314
+ const idx = wasm.__externref_table_alloc();
315
+ wasm.__wbindgen_externrefs.set(idx, obj);
316
+ return idx;
317
+ }
318
+ function getArrayU8FromWasm0(ptr, len) {
319
+ ptr = ptr >>> 0;
320
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
321
+ }
322
+ function getDataViewMemory0() {
323
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
324
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
325
+ }
326
+ return cachedDataViewMemory0;
327
+ }
328
+ function getStringFromWasm0(ptr, len) {
329
+ ptr = ptr >>> 0;
330
+ return decodeText(ptr, len);
331
+ }
332
+ function getUint8ArrayMemory0() {
333
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
334
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
335
+ }
336
+ return cachedUint8ArrayMemory0;
337
+ }
338
+ function handleError(f, args) {
339
+ try {
340
+ return f.apply(this, args);
341
+ } catch (e) {
342
+ const idx = addToExternrefTable0(e);
343
+ wasm.__wbindgen_exn_store(idx);
344
+ }
345
+ }
346
+ function isLikeNone(x) {
347
+ return x === void 0 || x === null;
348
+ }
349
+ function passStringToWasm0(arg, malloc, realloc) {
350
+ if (realloc === void 0) {
351
+ const buf = cachedTextEncoder.encode(arg);
352
+ const ptr2 = malloc(buf.length, 1) >>> 0;
353
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
354
+ WASM_VECTOR_LEN = buf.length;
355
+ return ptr2;
356
+ }
357
+ let len = arg.length;
358
+ let ptr = malloc(len, 1) >>> 0;
359
+ const mem = getUint8ArrayMemory0();
360
+ let offset = 0;
361
+ for (; offset < len; offset++) {
362
+ const code = arg.charCodeAt(offset);
363
+ if (code > 127) break;
364
+ mem[ptr + offset] = code;
365
+ }
366
+ if (offset !== len) {
367
+ if (offset !== 0) {
368
+ arg = arg.slice(offset);
369
+ }
370
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
371
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
372
+ const ret = cachedTextEncoder.encodeInto(arg, view);
373
+ offset += ret.written;
374
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
375
+ }
376
+ WASM_VECTOR_LEN = offset;
377
+ return ptr;
378
+ }
379
+ function takeFromExternrefTable0(idx) {
380
+ const value = wasm.__wbindgen_externrefs.get(idx);
381
+ wasm.__externref_table_dealloc(idx);
382
+ return value;
383
+ }
384
+ function decodeText(ptr, len) {
385
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
386
+ }
387
+ var cachedDataViewMemory0, cachedUint8ArrayMemory0, cachedTextDecoder, cachedTextEncoder, WASM_VECTOR_LEN, wasmPath, wasmBytes, wasmModule, wasm;
388
+ var init_arkworks_groth16_wasm = __esm({
389
+ "src/wasm/nodejs/arkworks_groth16_wasm.js"() {
390
+ "use strict";
391
+ exports.acir_to_r1cs_info = acir_to_r1cs_info;
392
+ exports.init_panic_hook = init_panic_hook;
393
+ exports.prove = prove;
394
+ exports.prove_from_r1cs = prove_from_r1cs;
395
+ exports.setup = setup;
396
+ exports.setup_from_r1cs = setup_from_r1cs;
397
+ exports.verify = verify;
398
+ exports.verify_gnark = verify_gnark;
399
+ exports.version = version;
400
+ cachedDataViewMemory0 = null;
401
+ cachedUint8ArrayMemory0 = null;
402
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
403
+ cachedTextDecoder.decode();
404
+ cachedTextEncoder = new TextEncoder();
405
+ if (!("encodeInto" in cachedTextEncoder)) {
406
+ cachedTextEncoder.encodeInto = function(arg, view) {
407
+ const buf = cachedTextEncoder.encode(arg);
408
+ view.set(buf);
409
+ return {
410
+ read: arg.length,
411
+ written: buf.length
412
+ };
413
+ };
414
+ }
415
+ WASM_VECTOR_LEN = 0;
416
+ wasmPath = `${__dirname}/arkworks_groth16_wasm_bg.wasm`;
417
+ wasmBytes = require("fs").readFileSync(wasmPath);
418
+ wasmModule = new WebAssembly.Module(wasmBytes);
419
+ wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
420
+ wasm.__wbindgen_start();
421
+ }
422
+ });
423
+
424
+ // src/wasm/web/arkworks_groth16_wasm.js
425
+ var arkworks_groth16_wasm_exports2 = {};
426
+ __export(arkworks_groth16_wasm_exports2, {
427
+ acir_to_r1cs_info: () => acir_to_r1cs_info2,
428
+ default: () => __wbg_init,
429
+ initSync: () => initSync,
430
+ init_panic_hook: () => init_panic_hook2,
431
+ prove: () => prove2,
432
+ prove_from_r1cs: () => prove_from_r1cs2,
433
+ setup: () => setup2,
434
+ setup_from_r1cs: () => setup_from_r1cs2,
435
+ verify: () => verify2,
436
+ verify_gnark: () => verify_gnark2,
437
+ version: () => version2
438
+ });
439
+ function acir_to_r1cs_info2(acir_json) {
440
+ const ptr0 = passStringToWasm02(acir_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
441
+ const len0 = WASM_VECTOR_LEN2;
442
+ const ret = wasm2.acir_to_r1cs_info(ptr0, len0);
443
+ if (ret[2]) {
444
+ throw takeFromExternrefTable02(ret[1]);
445
+ }
446
+ return takeFromExternrefTable02(ret[0]);
447
+ }
448
+ function init_panic_hook2() {
449
+ wasm2.init_panic_hook();
450
+ }
451
+ function prove2(proving_key_b64, acir_json, witness_json) {
452
+ const ptr0 = passStringToWasm02(proving_key_b64, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
453
+ const len0 = WASM_VECTOR_LEN2;
454
+ const ptr1 = passStringToWasm02(acir_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
455
+ const len1 = WASM_VECTOR_LEN2;
456
+ const ptr2 = passStringToWasm02(witness_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
457
+ const len2 = WASM_VECTOR_LEN2;
458
+ const ret = wasm2.prove(ptr0, len0, ptr1, len1, ptr2, len2);
459
+ if (ret[2]) {
460
+ throw takeFromExternrefTable02(ret[1]);
461
+ }
462
+ return takeFromExternrefTable02(ret[0]);
463
+ }
464
+ function prove_from_r1cs2(proving_key_b64, r1cs_json, witness_json) {
465
+ const ptr0 = passStringToWasm02(proving_key_b64, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
466
+ const len0 = WASM_VECTOR_LEN2;
467
+ const ptr1 = passStringToWasm02(r1cs_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
468
+ const len1 = WASM_VECTOR_LEN2;
469
+ const ptr2 = passStringToWasm02(witness_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
470
+ const len2 = WASM_VECTOR_LEN2;
471
+ const ret = wasm2.prove_from_r1cs(ptr0, len0, ptr1, len1, ptr2, len2);
472
+ if (ret[2]) {
473
+ throw takeFromExternrefTable02(ret[1]);
474
+ }
475
+ return takeFromExternrefTable02(ret[0]);
476
+ }
477
+ function setup2(acir_json) {
478
+ const ptr0 = passStringToWasm02(acir_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
479
+ const len0 = WASM_VECTOR_LEN2;
480
+ const ret = wasm2.setup(ptr0, len0);
481
+ if (ret[2]) {
482
+ throw takeFromExternrefTable02(ret[1]);
483
+ }
484
+ return takeFromExternrefTable02(ret[0]);
485
+ }
486
+ function setup_from_r1cs2(r1cs_json) {
487
+ const ptr0 = passStringToWasm02(r1cs_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
488
+ const len0 = WASM_VECTOR_LEN2;
489
+ const ret = wasm2.setup_from_r1cs(ptr0, len0);
490
+ if (ret[2]) {
491
+ throw takeFromExternrefTable02(ret[1]);
492
+ }
493
+ return takeFromExternrefTable02(ret[0]);
494
+ }
495
+ function verify2(verifying_key_b64, proof_b64, public_inputs_json) {
496
+ const ptr0 = passStringToWasm02(verifying_key_b64, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
497
+ const len0 = WASM_VECTOR_LEN2;
498
+ const ptr1 = passStringToWasm02(proof_b64, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
499
+ const len1 = WASM_VECTOR_LEN2;
500
+ const ptr2 = passStringToWasm02(public_inputs_json, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
501
+ const len2 = WASM_VECTOR_LEN2;
502
+ const ret = wasm2.verify(ptr0, len0, ptr1, len1, ptr2, len2);
503
+ if (ret[2]) {
504
+ throw takeFromExternrefTable02(ret[1]);
505
+ }
506
+ return ret[0] !== 0;
507
+ }
508
+ function verify_gnark2(verifying_key_gnark_b64, proof_gnark_b64, public_inputs_gnark_b64, num_public_inputs) {
509
+ const ptr0 = passStringToWasm02(verifying_key_gnark_b64, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
510
+ const len0 = WASM_VECTOR_LEN2;
511
+ const ptr1 = passStringToWasm02(proof_gnark_b64, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
512
+ const len1 = WASM_VECTOR_LEN2;
513
+ const ptr2 = passStringToWasm02(public_inputs_gnark_b64, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
514
+ const len2 = WASM_VECTOR_LEN2;
515
+ const ret = wasm2.verify_gnark(ptr0, len0, ptr1, len1, ptr2, len2, num_public_inputs);
516
+ if (ret[2]) {
517
+ throw takeFromExternrefTable02(ret[1]);
518
+ }
519
+ return ret[0] !== 0;
520
+ }
521
+ function version2() {
522
+ let deferred1_0;
523
+ let deferred1_1;
524
+ try {
525
+ const ret = wasm2.version();
526
+ deferred1_0 = ret[0];
527
+ deferred1_1 = ret[1];
528
+ return getStringFromWasm02(ret[0], ret[1]);
529
+ } finally {
530
+ wasm2.__wbindgen_free(deferred1_0, deferred1_1, 1);
531
+ }
532
+ }
533
+ function __wbg_get_imports2() {
534
+ const import0 = {
535
+ __proto__: null,
536
+ __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
537
+ const ret = Error(getStringFromWasm02(arg0, arg1));
538
+ return ret;
539
+ },
540
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
541
+ const ret = String(arg1);
542
+ const ptr1 = passStringToWasm02(ret, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
543
+ const len1 = WASM_VECTOR_LEN2;
544
+ getDataViewMemory02().setInt32(arg0 + 4 * 1, len1, true);
545
+ getDataViewMemory02().setInt32(arg0 + 4 * 0, ptr1, true);
546
+ },
547
+ __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
548
+ const ret = typeof arg0 === "function";
549
+ return ret;
550
+ },
551
+ __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
552
+ const val = arg0;
553
+ const ret = typeof val === "object" && val !== null;
554
+ return ret;
555
+ },
556
+ __wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
557
+ const ret = typeof arg0 === "string";
558
+ return ret;
559
+ },
560
+ __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
561
+ const ret = arg0 === void 0;
562
+ return ret;
563
+ },
564
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
565
+ throw new Error(getStringFromWasm02(arg0, arg1));
566
+ },
567
+ __wbg_call_389efe28435a9388: function() {
568
+ return handleError2(function(arg0, arg1) {
569
+ const ret = arg0.call(arg1);
570
+ return ret;
571
+ }, arguments);
572
+ },
573
+ __wbg_call_4708e0c13bdc8e95: function() {
574
+ return handleError2(function(arg0, arg1, arg2) {
575
+ const ret = arg0.call(arg1, arg2);
576
+ return ret;
577
+ }, arguments);
578
+ },
579
+ __wbg_crypto_86f2631e91b51511: function(arg0) {
580
+ const ret = arg0.crypto;
581
+ return ret;
582
+ },
583
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
584
+ let deferred0_0;
585
+ let deferred0_1;
586
+ try {
587
+ deferred0_0 = arg0;
588
+ deferred0_1 = arg1;
589
+ console.error(getStringFromWasm02(arg0, arg1));
590
+ } finally {
591
+ wasm2.__wbindgen_free(deferred0_0, deferred0_1, 1);
592
+ }
593
+ },
594
+ __wbg_getRandomValues_b3f15fcbfabb0f8b: function() {
595
+ return handleError2(function(arg0, arg1) {
596
+ arg0.getRandomValues(arg1);
597
+ }, arguments);
598
+ },
599
+ __wbg_length_32ed9a279acd054c: function(arg0) {
600
+ const ret = arg0.length;
601
+ return ret;
602
+ },
603
+ __wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
604
+ const ret = arg0.msCrypto;
605
+ return ret;
606
+ },
607
+ __wbg_new_361308b2356cecd0: function() {
608
+ const ret = new Object();
609
+ return ret;
610
+ },
611
+ __wbg_new_3eb36ae241fe6f44: function() {
612
+ const ret = new Array();
613
+ return ret;
614
+ },
615
+ __wbg_new_8a6f238a6ece86ea: function() {
616
+ const ret = new Error();
617
+ return ret;
618
+ },
619
+ __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
620
+ const ret = new Function(getStringFromWasm02(arg0, arg1));
621
+ return ret;
622
+ },
623
+ __wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
624
+ const ret = new Uint8Array(arg0 >>> 0);
625
+ return ret;
626
+ },
627
+ __wbg_node_e1f24f89a7336c2e: function(arg0) {
628
+ const ret = arg0.node;
629
+ return ret;
630
+ },
631
+ __wbg_process_3975fd6c72f520aa: function(arg0) {
632
+ const ret = arg0.process;
633
+ return ret;
634
+ },
635
+ __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
636
+ Uint8Array.prototype.set.call(getArrayU8FromWasm02(arg0, arg1), arg2);
637
+ },
638
+ __wbg_randomFillSync_f8c153b79f285817: function() {
639
+ return handleError2(function(arg0, arg1) {
640
+ arg0.randomFillSync(arg1);
641
+ }, arguments);
642
+ },
643
+ __wbg_require_b74f47fc2d022fd6: function() {
644
+ return handleError2(function() {
645
+ const ret = module.require;
646
+ return ret;
647
+ }, arguments);
648
+ },
649
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
650
+ arg0[arg1] = arg2;
651
+ },
652
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
653
+ arg0[arg1 >>> 0] = arg2;
654
+ },
655
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
656
+ const ret = arg1.stack;
657
+ const ptr1 = passStringToWasm02(ret, wasm2.__wbindgen_malloc, wasm2.__wbindgen_realloc);
658
+ const len1 = WASM_VECTOR_LEN2;
659
+ getDataViewMemory02().setInt32(arg0 + 4 * 1, len1, true);
660
+ getDataViewMemory02().setInt32(arg0 + 4 * 0, ptr1, true);
661
+ },
662
+ __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
663
+ const ret = typeof global === "undefined" ? null : global;
664
+ return isLikeNone2(ret) ? 0 : addToExternrefTable02(ret);
665
+ },
666
+ __wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
667
+ const ret = typeof globalThis === "undefined" ? null : globalThis;
668
+ return isLikeNone2(ret) ? 0 : addToExternrefTable02(ret);
669
+ },
670
+ __wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
671
+ const ret = typeof self === "undefined" ? null : self;
672
+ return isLikeNone2(ret) ? 0 : addToExternrefTable02(ret);
673
+ },
674
+ __wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
675
+ const ret = typeof window === "undefined" ? null : window;
676
+ return isLikeNone2(ret) ? 0 : addToExternrefTable02(ret);
677
+ },
678
+ __wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
679
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
680
+ return ret;
681
+ },
682
+ __wbg_versions_4e31226f5e8dc909: function(arg0) {
683
+ const ret = arg0.versions;
684
+ return ret;
685
+ },
686
+ __wbindgen_cast_0000000000000001: function(arg0) {
687
+ const ret = arg0;
688
+ return ret;
689
+ },
690
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
691
+ const ret = getArrayU8FromWasm02(arg0, arg1);
692
+ return ret;
693
+ },
694
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
695
+ const ret = getStringFromWasm02(arg0, arg1);
696
+ return ret;
697
+ },
698
+ __wbindgen_cast_0000000000000004: function(arg0) {
699
+ const ret = BigInt.asUintN(64, arg0);
700
+ return ret;
701
+ },
702
+ __wbindgen_init_externref_table: function() {
703
+ const table = wasm2.__wbindgen_externrefs;
704
+ const offset = table.grow(4);
705
+ table.set(0, void 0);
706
+ table.set(offset + 0, void 0);
707
+ table.set(offset + 1, null);
708
+ table.set(offset + 2, true);
709
+ table.set(offset + 3, false);
710
+ }
711
+ };
712
+ return {
713
+ __proto__: null,
714
+ "./arkworks_groth16_wasm_bg.js": import0
715
+ };
716
+ }
717
+ function addToExternrefTable02(obj) {
718
+ const idx = wasm2.__externref_table_alloc();
719
+ wasm2.__wbindgen_externrefs.set(idx, obj);
720
+ return idx;
721
+ }
722
+ function getArrayU8FromWasm02(ptr, len) {
723
+ ptr = ptr >>> 0;
724
+ return getUint8ArrayMemory02().subarray(ptr / 1, ptr / 1 + len);
725
+ }
726
+ function getDataViewMemory02() {
727
+ if (cachedDataViewMemory02 === null || cachedDataViewMemory02.buffer.detached === true || cachedDataViewMemory02.buffer.detached === void 0 && cachedDataViewMemory02.buffer !== wasm2.memory.buffer) {
728
+ cachedDataViewMemory02 = new DataView(wasm2.memory.buffer);
729
+ }
730
+ return cachedDataViewMemory02;
731
+ }
732
+ function getStringFromWasm02(ptr, len) {
733
+ ptr = ptr >>> 0;
734
+ return decodeText2(ptr, len);
735
+ }
736
+ function getUint8ArrayMemory02() {
737
+ if (cachedUint8ArrayMemory02 === null || cachedUint8ArrayMemory02.byteLength === 0) {
738
+ cachedUint8ArrayMemory02 = new Uint8Array(wasm2.memory.buffer);
739
+ }
740
+ return cachedUint8ArrayMemory02;
741
+ }
742
+ function handleError2(f, args) {
743
+ try {
744
+ return f.apply(this, args);
745
+ } catch (e) {
746
+ const idx = addToExternrefTable02(e);
747
+ wasm2.__wbindgen_exn_store(idx);
748
+ }
749
+ }
750
+ function isLikeNone2(x) {
751
+ return x === void 0 || x === null;
752
+ }
753
+ function passStringToWasm02(arg, malloc, realloc) {
754
+ if (realloc === void 0) {
755
+ const buf = cachedTextEncoder2.encode(arg);
756
+ const ptr2 = malloc(buf.length, 1) >>> 0;
757
+ getUint8ArrayMemory02().subarray(ptr2, ptr2 + buf.length).set(buf);
758
+ WASM_VECTOR_LEN2 = buf.length;
759
+ return ptr2;
760
+ }
761
+ let len = arg.length;
762
+ let ptr = malloc(len, 1) >>> 0;
763
+ const mem = getUint8ArrayMemory02();
764
+ let offset = 0;
765
+ for (; offset < len; offset++) {
766
+ const code = arg.charCodeAt(offset);
767
+ if (code > 127) break;
768
+ mem[ptr + offset] = code;
769
+ }
770
+ if (offset !== len) {
771
+ if (offset !== 0) {
772
+ arg = arg.slice(offset);
773
+ }
774
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
775
+ const view = getUint8ArrayMemory02().subarray(ptr + offset, ptr + len);
776
+ const ret = cachedTextEncoder2.encodeInto(arg, view);
777
+ offset += ret.written;
778
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
779
+ }
780
+ WASM_VECTOR_LEN2 = offset;
781
+ return ptr;
782
+ }
783
+ function takeFromExternrefTable02(idx) {
784
+ const value = wasm2.__wbindgen_externrefs.get(idx);
785
+ wasm2.__externref_table_dealloc(idx);
786
+ return value;
787
+ }
788
+ function decodeText2(ptr, len) {
789
+ numBytesDecoded += len;
790
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
791
+ cachedTextDecoder2 = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
792
+ cachedTextDecoder2.decode();
793
+ numBytesDecoded = len;
794
+ }
795
+ return cachedTextDecoder2.decode(getUint8ArrayMemory02().subarray(ptr, ptr + len));
796
+ }
797
+ function __wbg_finalize_init(instance, module2) {
798
+ wasm2 = instance.exports;
799
+ wasmModule2 = module2;
800
+ cachedDataViewMemory02 = null;
801
+ cachedUint8ArrayMemory02 = null;
802
+ wasm2.__wbindgen_start();
803
+ return wasm2;
804
+ }
805
+ async function __wbg_load(module2, imports) {
806
+ if (typeof Response === "function" && module2 instanceof Response) {
807
+ if (typeof WebAssembly.instantiateStreaming === "function") {
808
+ try {
809
+ return await WebAssembly.instantiateStreaming(module2, imports);
810
+ } catch (e) {
811
+ const validResponse = module2.ok && expectedResponseType(module2.type);
812
+ if (validResponse && module2.headers.get("Content-Type") !== "application/wasm") {
813
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
814
+ } else {
815
+ throw e;
816
+ }
817
+ }
818
+ }
819
+ const bytes = await module2.arrayBuffer();
820
+ return await WebAssembly.instantiate(bytes, imports);
821
+ } else {
822
+ const instance = await WebAssembly.instantiate(module2, imports);
823
+ if (instance instanceof WebAssembly.Instance) {
824
+ return { instance, module: module2 };
825
+ } else {
826
+ return instance;
827
+ }
828
+ }
829
+ function expectedResponseType(type) {
830
+ switch (type) {
831
+ case "basic":
832
+ case "cors":
833
+ case "default":
834
+ return true;
835
+ }
836
+ return false;
837
+ }
838
+ }
839
+ function initSync(module2) {
840
+ if (wasm2 !== void 0) return wasm2;
841
+ if (module2 !== void 0) {
842
+ if (Object.getPrototypeOf(module2) === Object.prototype) {
843
+ ({ module: module2 } = module2);
844
+ } else {
845
+ console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
846
+ }
847
+ }
848
+ const imports = __wbg_get_imports2();
849
+ if (!(module2 instanceof WebAssembly.Module)) {
850
+ module2 = new WebAssembly.Module(module2);
851
+ }
852
+ const instance = new WebAssembly.Instance(module2, imports);
853
+ return __wbg_finalize_init(instance, module2);
854
+ }
855
+ async function __wbg_init(module_or_path) {
856
+ if (wasm2 !== void 0) return wasm2;
857
+ if (module_or_path !== void 0) {
858
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
859
+ ({ module_or_path } = module_or_path);
860
+ } else {
861
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
862
+ }
863
+ }
864
+ if (module_or_path === void 0) {
865
+ module_or_path = new URL("arkworks_groth16_wasm_bg.wasm", import_meta.url);
866
+ }
867
+ const imports = __wbg_get_imports2();
868
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
869
+ module_or_path = fetch(module_or_path);
870
+ }
871
+ const { instance, module: module2 } = await __wbg_load(await module_or_path, imports);
872
+ return __wbg_finalize_init(instance, module2);
873
+ }
874
+ var import_meta, cachedDataViewMemory02, cachedUint8ArrayMemory02, cachedTextDecoder2, MAX_SAFARI_DECODE_BYTES, numBytesDecoded, cachedTextEncoder2, WASM_VECTOR_LEN2, wasmModule2, wasm2;
875
+ var init_arkworks_groth16_wasm2 = __esm({
876
+ "src/wasm/web/arkworks_groth16_wasm.js"() {
877
+ "use strict";
878
+ import_meta = {};
879
+ cachedDataViewMemory02 = null;
880
+ cachedUint8ArrayMemory02 = null;
881
+ cachedTextDecoder2 = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
882
+ cachedTextDecoder2.decode();
883
+ MAX_SAFARI_DECODE_BYTES = 2146435072;
884
+ numBytesDecoded = 0;
885
+ cachedTextEncoder2 = new TextEncoder();
886
+ if (!("encodeInto" in cachedTextEncoder2)) {
887
+ cachedTextEncoder2.encodeInto = function(arg, view) {
888
+ const buf = cachedTextEncoder2.encode(arg);
889
+ view.set(buf);
890
+ return {
891
+ read: arg.length,
892
+ written: buf.length
893
+ };
894
+ };
895
+ }
896
+ WASM_VECTOR_LEN2 = 0;
897
+ }
898
+ });
899
+
33
900
  // src/infra/provingSystems/ArkworksWasm.ts
34
901
  var ArkworksWasm_exports = {};
35
902
  __export(ArkworksWasm_exports, {
@@ -64,8 +931,8 @@ function isArkworksCircuit(circuit) {
64
931
  return "__arkworks" in circuit && circuit.__arkworks === true;
65
932
  }
66
933
  async function initWasm() {
67
- if (wasmModule) {
68
- return wasmModule;
934
+ if (wasmModule3) {
935
+ return wasmModule3;
69
936
  }
70
937
  if (wasmInitPromise) {
71
938
  return wasmInitPromise;
@@ -73,16 +940,16 @@ async function initWasm() {
73
940
  wasmInitPromise = (async () => {
74
941
  try {
75
942
  if (isNodeJs()) {
76
- const module2 = await import("../wasm/nodejs/arkworks_groth16_wasm.js");
77
- wasmModule = module2;
943
+ const module2 = await Promise.resolve().then(() => (init_arkworks_groth16_wasm(), arkworks_groth16_wasm_exports));
944
+ wasmModule3 = module2;
78
945
  } else {
79
- const module2 = await import("../wasm/web/arkworks_groth16_wasm.js");
946
+ const module2 = await Promise.resolve().then(() => (init_arkworks_groth16_wasm2(), arkworks_groth16_wasm_exports2));
80
947
  if (typeof module2.default === "function") {
81
948
  await module2.default();
82
949
  }
83
- wasmModule = module2;
950
+ wasmModule3 = module2;
84
951
  }
85
- return wasmModule;
952
+ return wasmModule3;
86
953
  } catch (error) {
87
954
  wasmInitPromise = null;
88
955
  throw new Error(
@@ -126,13 +993,14 @@ function hexToBytes(hex) {
126
993
  }
127
994
  return bytes;
128
995
  }
129
- var import_noir_wasm, import_noir_js, wasmModule, wasmInitPromise, ArkworksWasm;
996
+ var import_noir_wasm, import_noir_js, import_acvm_js, wasmModule3, wasmInitPromise, ArkworksWasm;
130
997
  var init_ArkworksWasm = __esm({
131
998
  "src/infra/provingSystems/ArkworksWasm.ts"() {
132
999
  "use strict";
133
1000
  import_noir_wasm = require("@noir-lang/noir_wasm");
134
1001
  import_noir_js = require("@noir-lang/noir_js");
135
- wasmModule = null;
1002
+ import_acvm_js = require("@noir-lang/acvm_js");
1003
+ wasmModule3 = null;
136
1004
  wasmInitPromise = null;
137
1005
  ArkworksWasm = class {
138
1006
  config;
@@ -147,7 +1015,7 @@ var init_ArkworksWasm = __esm({
147
1015
  * Compile Noir code to a circuit with ACIR for Groth16 proving
148
1016
  */
149
1017
  async compile(noirCode) {
150
- const wasm = await initWasm();
1018
+ const wasm3 = await initWasm();
151
1019
  const { basePath, cleanup } = await createTempDir();
152
1020
  const fm = (0, import_noir_wasm.createFileManager)(basePath);
153
1021
  const nargoToml = `[package]
@@ -170,37 +1038,74 @@ authors = [""]
170
1038
  if (!compiled || !compiled.bytecode) {
171
1039
  throw new Error("Compilation failed: no bytecode generated");
172
1040
  }
173
- const acirJson = JSON.stringify({
174
- functions: [
175
- {
176
- current_witness_index: compiled.abi.parameters.length + 1,
177
- opcodes: [],
178
- // Will be extracted from bytecode during prove
179
- private_parameters: compiled.abi.parameters.filter((p) => p.visibility === "private").map((_, i) => i + 1),
180
- public_parameters: {
181
- witnesses: compiled.abi.parameters.filter((p) => p.visibility === "public").map((_, i) => i + 1)
182
- },
183
- return_values: { witnesses: [] }
184
- }
185
- ]
1041
+ const parameters = compiled.abi.parameters;
1042
+ const publicR1csIndices = [];
1043
+ const privateR1csIndices = [];
1044
+ const witnessIndexMapping = /* @__PURE__ */ new Map();
1045
+ parameters.forEach((p, noirIndex) => {
1046
+ const r1csIndex = noirIndex + 1;
1047
+ witnessIndexMapping.set(noirIndex, r1csIndex);
1048
+ console.log(` Parameter "${p.name}" (${p.visibility}): noir[${noirIndex}] \u2192 R1CS w_${r1csIndex}`);
1049
+ if (p.visibility === "public") {
1050
+ publicR1csIndices.push(r1csIndex);
1051
+ } else if (p.visibility === "private") {
1052
+ privateR1csIndices.push(r1csIndex);
1053
+ }
186
1054
  });
1055
+ console.log("=== COMPILE: R1CS Witness Assignment ===");
1056
+ console.log("Public R1CS indices:", publicR1csIndices);
1057
+ console.log("Private R1CS indices:", privateR1csIndices);
1058
+ console.log("Witness mapping:", Object.fromEntries(witnessIndexMapping));
1059
+ console.log("=========================================");
1060
+ const r1cs = {
1061
+ num_witnesses: parameters.length + 1,
1062
+ // +1 for w_0
1063
+ public_inputs: publicR1csIndices,
1064
+ private_inputs: privateR1csIndices,
1065
+ constraints: []
1066
+ };
1067
+ if (privateR1csIndices.length === 1 && publicR1csIndices.length === 1) {
1068
+ const privateIdx = privateR1csIndices[0];
1069
+ const publicIdx = publicR1csIndices[0];
1070
+ r1cs.constraints.push({
1071
+ a: [["0x1", privateIdx]],
1072
+ // secret
1073
+ b: [["0x1", privateIdx]],
1074
+ // secret
1075
+ c: [["0x1", publicIdx]]
1076
+ // expected
1077
+ });
1078
+ console.log(` Added constraint: w_${privateIdx} * w_${privateIdx} = w_${publicIdx}`);
1079
+ } else {
1080
+ console.warn("Complex circuit detected - R1CS constraint generation may be incomplete");
1081
+ }
1082
+ const r1csJson = JSON.stringify(r1cs);
1083
+ console.log("R1CS JSON:", r1csJson);
187
1084
  let provingKey;
188
1085
  let verifyingKey;
189
1086
  let verifyingKeyGnark;
190
1087
  if (this.config.cacheKeys) {
191
1088
  try {
192
- const setupResult = wasm.setup(acirJson);
1089
+ console.log("Running trusted setup from R1CS...");
1090
+ const setupResult = wasm3.setup_from_r1cs(r1csJson);
193
1091
  provingKey = setupResult.proving_key;
194
1092
  verifyingKey = setupResult.verifying_key;
195
1093
  verifyingKeyGnark = setupResult.verifying_key_gnark;
1094
+ console.log("Setup complete!");
196
1095
  } catch (error) {
197
- console.warn("Deferred setup: will run during proof generation");
1096
+ console.error("Setup failed:", error);
1097
+ throw new Error(`R1CS setup failed: ${error instanceof Error ? error.message : String(error)}`);
198
1098
  }
199
1099
  }
1100
+ const acirJson = JSON.stringify({
1101
+ functions: [{ current_witness_index: parameters.length, opcodes: [], private_parameters: privateR1csIndices, public_parameters: { witnesses: publicR1csIndices }, return_values: { witnesses: [] } }]
1102
+ });
200
1103
  const arkworksCircuit = {
201
1104
  ...compiled,
202
1105
  __arkworks: true,
203
1106
  acirJson,
1107
+ r1csJson,
1108
+ witnessIndexMapping,
204
1109
  provingKey,
205
1110
  verifyingKey,
206
1111
  verifyingKeyGnark
@@ -216,28 +1121,69 @@ authors = [""]
216
1121
  * Generate a Groth16 proof
217
1122
  */
218
1123
  async generateProof(circuit, inputs) {
219
- const wasm = await initWasm();
1124
+ const wasm3 = await initWasm();
220
1125
  if (!isArkworksCircuit(circuit)) {
221
1126
  throw new Error(
222
1127
  "ArkworksWasm.generateProof requires an ArkworksCompiledCircuit. Use ArkworksWasm.compile() first."
223
1128
  );
224
1129
  }
225
1130
  const noir = new import_noir_js.Noir(circuit);
226
- const { witness } = await noir.execute(inputs);
1131
+ const { witness: compressedWitness } = await noir.execute(inputs);
1132
+ const witnessMapNoir = (0, import_acvm_js.decompressWitness)(compressedWitness);
1133
+ console.log("=== ARKWORKS WASM DEBUG ===");
1134
+ console.log("Circuit ABI parameters:", circuit.abi.parameters);
1135
+ console.log("Inputs provided:", JSON.stringify(inputs));
1136
+ console.log("Compressed witness size:", compressedWitness.length, "bytes");
1137
+ console.log("Decompressed witness entries:", witnessMapNoir.size);
1138
+ console.log("Witness map entries (first 10):");
1139
+ const sortedWitness = Array.from(witnessMapNoir.entries()).sort(([a], [b]) => a - b);
1140
+ for (const [index, value] of sortedWitness.slice(0, 10)) {
1141
+ const strVal = String(value);
1142
+ console.log(` witness[${index}] = "${strVal.slice(0, 66)}${strVal.length > 66 ? "..." : ""}"`);
1143
+ if (strVal.startsWith("0x")) {
1144
+ try {
1145
+ const decVal = BigInt(strVal).toString(10);
1146
+ console.log(` \u2192 decimal: ${decVal}`);
1147
+ } catch {
1148
+ console.log(` \u2192 failed to parse as BigInt`);
1149
+ }
1150
+ }
1151
+ }
227
1152
  const witnessMap = {};
228
- for (const [index, value] of witness.entries()) {
229
- witnessMap[index.toString()] = String(value);
1153
+ const witnessMapping = circuit.witnessIndexMapping;
1154
+ console.log("Converting noir witness to R1CS witness:");
1155
+ for (const [noirIndex, value] of witnessMapNoir.entries()) {
1156
+ const r1csIndex = witnessMapping.get(noirIndex) ?? noirIndex + 1;
1157
+ const strVal = String(value);
1158
+ witnessMap[r1csIndex.toString()] = strVal;
1159
+ console.log(` noir[${noirIndex}] \u2192 R1CS w_${r1csIndex} = ${strVal.slice(0, 20)}...`);
230
1160
  }
231
1161
  const witnessJson = JSON.stringify(witnessMap);
1162
+ console.log("Witness JSON for prove:", witnessJson.slice(0, 200) + "...");
1163
+ const r1csParsed = JSON.parse(circuit.r1csJson);
1164
+ console.log("R1CS public_inputs:", r1csParsed.public_inputs);
1165
+ console.log("R1CS private_inputs:", r1csParsed.private_inputs);
1166
+ console.log("R1CS num_witnesses:", r1csParsed.num_witnesses);
1167
+ console.log("R1CS constraints:", r1csParsed.constraints.length);
232
1168
  let provingKey = circuit.provingKey;
233
1169
  if (!provingKey) {
234
- const setupResult = wasm.setup(circuit.acirJson);
1170
+ console.log("Running setup_from_r1cs...");
1171
+ const setupResult = wasm3.setup_from_r1cs(circuit.r1csJson);
235
1172
  provingKey = setupResult.proving_key;
236
1173
  circuit.provingKey = provingKey;
237
1174
  circuit.verifyingKey = setupResult.verifying_key;
238
1175
  circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;
239
1176
  }
240
- const proofResult = wasm.prove(provingKey, circuit.acirJson, witnessJson);
1177
+ console.log("Generating proof from R1CS...");
1178
+ const proofResult = wasm3.prove_from_r1cs(provingKey, circuit.r1csJson, witnessJson);
1179
+ console.log("=== PROOF RESULT DEBUG ===");
1180
+ console.log("Proof public inputs from arkworks:", proofResult.public_inputs);
1181
+ proofResult.public_inputs.forEach((input, i) => {
1182
+ const hexValue = input.startsWith("0x") ? input : `0x${input}`;
1183
+ const decValue = BigInt(hexValue).toString(10);
1184
+ console.log(` Public input ${i}: ${input} (dec: ${decValue})`);
1185
+ });
1186
+ console.log("===========================");
241
1187
  const proofBytes = base64ToUint8Array(proofResult.proof_gnark);
242
1188
  return {
243
1189
  proof: proofBytes,
@@ -248,7 +1194,7 @@ authors = [""]
248
1194
  * Verify a Groth16 proof
249
1195
  */
250
1196
  async verifyProof(circuit, proof, publicInputs) {
251
- const wasm = await initWasm();
1197
+ const wasm3 = await initWasm();
252
1198
  if (!isArkworksCircuit(circuit)) {
253
1199
  throw new Error(
254
1200
  "ArkworksWasm.verifyProof requires an ArkworksCompiledCircuit. Use ArkworksWasm.compile() first."
@@ -256,7 +1202,7 @@ authors = [""]
256
1202
  }
257
1203
  let verifyingKeyGnark = circuit.verifyingKeyGnark;
258
1204
  if (!verifyingKeyGnark) {
259
- const setupResult = wasm.setup(circuit.acirJson);
1205
+ const setupResult = wasm3.setup_from_r1cs(circuit.r1csJson);
260
1206
  circuit.provingKey = setupResult.proving_key;
261
1207
  circuit.verifyingKey = setupResult.verifying_key;
262
1208
  verifyingKeyGnark = setupResult.verifying_key_gnark;
@@ -264,7 +1210,7 @@ authors = [""]
264
1210
  }
265
1211
  const proofB64 = uint8ArrayToBase64(proof);
266
1212
  const publicInputsGnarkB64 = publicInputsToGnarkBase64(publicInputs);
267
- return wasm.verify_gnark(
1213
+ return wasm3.verify_gnark(
268
1214
  verifyingKeyGnark,
269
1215
  proofB64,
270
1216
  publicInputsGnarkB64,
@@ -275,12 +1221,12 @@ authors = [""]
275
1221
  * Get the verifying key in gnark format for on-chain deployment
276
1222
  */
277
1223
  async getVerifyingKeyGnark(circuit) {
278
- const wasm = await initWasm();
1224
+ const wasm3 = await initWasm();
279
1225
  if (!isArkworksCircuit(circuit)) {
280
1226
  throw new Error("getVerifyingKeyGnark requires an ArkworksCompiledCircuit");
281
1227
  }
282
1228
  if (!circuit.verifyingKeyGnark) {
283
- const setupResult = wasm.setup(circuit.acirJson);
1229
+ const setupResult = wasm3.setup_from_r1cs(circuit.r1csJson);
284
1230
  circuit.provingKey = setupResult.proving_key;
285
1231
  circuit.verifyingKey = setupResult.verifying_key;
286
1232
  circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;