@aztec/bb-prover 0.0.0-test.1 → 0.0.1-commit.017a351

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 (130) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +21 -20
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +196 -87
  4. package/dest/bb/bb_js_backend.d.ts +196 -0
  5. package/dest/bb/bb_js_backend.d.ts.map +1 -0
  6. package/dest/bb/bb_js_backend.js +379 -0
  7. package/dest/bb/bb_js_debug.d.ts +52 -0
  8. package/dest/bb/bb_js_debug.d.ts.map +1 -0
  9. package/dest/bb/bb_js_debug.js +176 -0
  10. package/dest/bb/cli.d.ts +1 -1
  11. package/dest/bb/file_names.d.ts +4 -0
  12. package/dest/bb/file_names.d.ts.map +1 -0
  13. package/dest/bb/file_names.js +5 -0
  14. package/dest/bb/index.d.ts +1 -1
  15. package/dest/config.d.ts +19 -1
  16. package/dest/config.d.ts.map +1 -1
  17. package/dest/honk.d.ts +3 -3
  18. package/dest/honk.d.ts.map +1 -1
  19. package/dest/honk.js +3 -2
  20. package/dest/index.d.ts +4 -2
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +3 -1
  23. package/dest/instrumentation.d.ts +3 -3
  24. package/dest/instrumentation.d.ts.map +1 -1
  25. package/dest/instrumentation.js +22 -46
  26. package/dest/prover/client/bb_private_kernel_prover.d.ts +46 -0
  27. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
  28. package/dest/prover/client/bb_private_kernel_prover.js +177 -0
  29. package/dest/prover/client/bundle.d.ts +6 -0
  30. package/dest/prover/client/bundle.d.ts.map +1 -0
  31. package/dest/prover/client/bundle.js +7 -0
  32. package/dest/prover/client/lazy.d.ts +6 -0
  33. package/dest/prover/client/lazy.d.ts.map +1 -0
  34. package/dest/prover/client/lazy.js +7 -0
  35. package/dest/prover/index.d.ts +3 -4
  36. package/dest/prover/index.d.ts.map +1 -1
  37. package/dest/prover/index.js +2 -3
  38. package/dest/prover/proof_utils.d.ts +29 -0
  39. package/dest/prover/proof_utils.d.ts.map +1 -0
  40. package/dest/prover/proof_utils.js +95 -0
  41. package/dest/prover/server/bb_prover.d.ts +96 -0
  42. package/dest/prover/server/bb_prover.d.ts.map +1 -0
  43. package/dest/prover/server/bb_prover.js +841 -0
  44. package/dest/test/delay_values.d.ts +1 -1
  45. package/dest/test/delay_values.d.ts.map +1 -1
  46. package/dest/test/delay_values.js +37 -23
  47. package/dest/test/index.d.ts +2 -1
  48. package/dest/test/index.d.ts.map +1 -1
  49. package/dest/test/index.js +1 -0
  50. package/dest/test/test_circuit_prover.d.ts +27 -36
  51. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  52. package/dest/test/test_circuit_prover.js +517 -88
  53. package/dest/test/test_verifier.d.ts +6 -3
  54. package/dest/test/test_verifier.d.ts.map +1 -1
  55. package/dest/test/test_verifier.js +23 -1
  56. package/dest/verification_key/verification_key_data.d.ts +1 -2
  57. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  58. package/dest/verification_key/verification_key_data.js +9 -34
  59. package/dest/verifier/batch_chonk_verifier.d.ts +56 -0
  60. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  61. package/dest/verifier/batch_chonk_verifier.js +384 -0
  62. package/dest/verifier/bb_verifier.d.ts +9 -5
  63. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  64. package/dest/verifier/bb_verifier.js +156 -49
  65. package/dest/verifier/index.d.ts +3 -1
  66. package/dest/verifier/index.d.ts.map +1 -1
  67. package/dest/verifier/index.js +2 -0
  68. package/dest/verifier/queued_chonk_verifier.d.ts +14 -0
  69. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
  70. package/dest/verifier/queued_chonk_verifier.js +102 -0
  71. package/package.json +38 -34
  72. package/src/avm_proving_tests/avm_proving_tester.ts +163 -126
  73. package/src/bb/bb_js_backend.ts +435 -0
  74. package/src/bb/bb_js_debug.ts +227 -0
  75. package/src/bb/file_names.ts +6 -0
  76. package/src/config.ts +18 -0
  77. package/src/honk.ts +3 -2
  78. package/src/index.ts +3 -1
  79. package/src/instrumentation.ts +22 -47
  80. package/src/prover/client/bb_private_kernel_prover.ts +423 -0
  81. package/src/prover/client/bundle.ts +10 -0
  82. package/src/prover/client/lazy.ts +10 -0
  83. package/src/prover/index.ts +2 -3
  84. package/src/prover/proof_utils.ts +155 -0
  85. package/src/prover/server/bb_prover.ts +713 -0
  86. package/src/test/delay_values.ts +38 -22
  87. package/src/test/index.ts +1 -0
  88. package/src/test/test_circuit_prover.ts +264 -154
  89. package/src/test/test_verifier.ts +15 -3
  90. package/src/verification_key/verification_key_data.ts +11 -31
  91. package/src/verifier/batch_chonk_verifier.ts +415 -0
  92. package/src/verifier/bb_verifier.ts +93 -76
  93. package/src/verifier/index.ts +2 -0
  94. package/src/verifier/queued_chonk_verifier.ts +108 -0
  95. package/dest/bb/execute.d.ts +0 -140
  96. package/dest/bb/execute.d.ts.map +0 -1
  97. package/dest/bb/execute.js +0 -780
  98. package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
  99. package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
  100. package/dest/prover/bb_native_private_kernel_prover.js +0 -69
  101. package/dest/prover/bb_private_kernel_prover.d.ts +0 -32
  102. package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
  103. package/dest/prover/bb_private_kernel_prover.js +0 -109
  104. package/dest/prover/bb_prover.d.ts +0 -120
  105. package/dest/prover/bb_prover.d.ts.map +0 -1
  106. package/dest/prover/bb_prover.js +0 -423
  107. package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
  108. package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
  109. package/dest/prover/client_ivc_proof_utils.js +0 -43
  110. package/dest/stats.d.ts +0 -5
  111. package/dest/stats.d.ts.map +0 -1
  112. package/dest/stats.js +0 -62
  113. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
  114. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
  115. package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
  116. package/dest/wasm/bundle.d.ts +0 -6
  117. package/dest/wasm/bundle.d.ts.map +0 -1
  118. package/dest/wasm/bundle.js +0 -8
  119. package/dest/wasm/lazy.d.ts +0 -6
  120. package/dest/wasm/lazy.d.ts.map +0 -1
  121. package/dest/wasm/lazy.js +0 -8
  122. package/src/bb/execute.ts +0 -853
  123. package/src/prover/bb_native_private_kernel_prover.ts +0 -119
  124. package/src/prover/bb_private_kernel_prover.ts +0 -249
  125. package/src/prover/bb_prover.ts +0 -781
  126. package/src/prover/client_ivc_proof_utils.ts +0 -42
  127. package/src/stats.ts +0 -64
  128. package/src/wasm/bb_wasm_private_kernel_prover.ts +0 -55
  129. package/src/wasm/bundle.ts +0 -11
  130. package/src/wasm/lazy.ts +0 -11
@@ -0,0 +1,841 @@
1
+ function _ts_add_disposable_resource(env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() {
16
+ try {
17
+ inner.call(this);
18
+ } catch (e) {
19
+ return Promise.reject(e);
20
+ }
21
+ };
22
+ env.stack.push({
23
+ value: value,
24
+ dispose: dispose,
25
+ async: async
26
+ });
27
+ } else if (async) {
28
+ env.stack.push({
29
+ async: true
30
+ });
31
+ }
32
+ return value;
33
+ }
34
+ function _ts_dispose_resources(env) {
35
+ var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
36
+ var e = new Error(message);
37
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
38
+ };
39
+ return (_ts_dispose_resources = function _ts_dispose_resources(env) {
40
+ function fail(e) {
41
+ env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
42
+ env.hasError = true;
43
+ }
44
+ var r, s = 0;
45
+ function next() {
46
+ while(r = env.stack.pop()){
47
+ try {
48
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
49
+ if (r.dispose) {
50
+ var result = r.dispose.call(r.value);
51
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
52
+ fail(e);
53
+ return next();
54
+ });
55
+ } else s |= 1;
56
+ } catch (e) {
57
+ fail(e);
58
+ }
59
+ }
60
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
61
+ if (env.hasError) throw env.error;
62
+ }
63
+ return next();
64
+ })(env);
65
+ }
66
+ function applyDecs2203RFactory() {
67
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
68
+ return function addInitializer(initializer) {
69
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
70
+ assertCallable(initializer, "An initializer");
71
+ initializers.push(initializer);
72
+ };
73
+ }
74
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
75
+ var kindStr;
76
+ switch(kind){
77
+ case 1:
78
+ kindStr = "accessor";
79
+ break;
80
+ case 2:
81
+ kindStr = "method";
82
+ break;
83
+ case 3:
84
+ kindStr = "getter";
85
+ break;
86
+ case 4:
87
+ kindStr = "setter";
88
+ break;
89
+ default:
90
+ kindStr = "field";
91
+ }
92
+ var ctx = {
93
+ kind: kindStr,
94
+ name: isPrivate ? "#" + name : name,
95
+ static: isStatic,
96
+ private: isPrivate,
97
+ metadata: metadata
98
+ };
99
+ var decoratorFinishedRef = {
100
+ v: false
101
+ };
102
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
103
+ var get, set;
104
+ if (kind === 0) {
105
+ if (isPrivate) {
106
+ get = desc.get;
107
+ set = desc.set;
108
+ } else {
109
+ get = function() {
110
+ return this[name];
111
+ };
112
+ set = function(v) {
113
+ this[name] = v;
114
+ };
115
+ }
116
+ } else if (kind === 2) {
117
+ get = function() {
118
+ return desc.value;
119
+ };
120
+ } else {
121
+ if (kind === 1 || kind === 3) {
122
+ get = function() {
123
+ return desc.get.call(this);
124
+ };
125
+ }
126
+ if (kind === 1 || kind === 4) {
127
+ set = function(v) {
128
+ desc.set.call(this, v);
129
+ };
130
+ }
131
+ }
132
+ ctx.access = get && set ? {
133
+ get: get,
134
+ set: set
135
+ } : get ? {
136
+ get: get
137
+ } : {
138
+ set: set
139
+ };
140
+ try {
141
+ return dec(value, ctx);
142
+ } finally{
143
+ decoratorFinishedRef.v = true;
144
+ }
145
+ }
146
+ function assertNotFinished(decoratorFinishedRef, fnName) {
147
+ if (decoratorFinishedRef.v) {
148
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
149
+ }
150
+ }
151
+ function assertCallable(fn, hint) {
152
+ if (typeof fn !== "function") {
153
+ throw new TypeError(hint + " must be a function");
154
+ }
155
+ }
156
+ function assertValidReturnValue(kind, value) {
157
+ var type = typeof value;
158
+ if (kind === 1) {
159
+ if (type !== "object" || value === null) {
160
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
161
+ }
162
+ if (value.get !== undefined) {
163
+ assertCallable(value.get, "accessor.get");
164
+ }
165
+ if (value.set !== undefined) {
166
+ assertCallable(value.set, "accessor.set");
167
+ }
168
+ if (value.init !== undefined) {
169
+ assertCallable(value.init, "accessor.init");
170
+ }
171
+ } else if (type !== "function") {
172
+ var hint;
173
+ if (kind === 0) {
174
+ hint = "field";
175
+ } else if (kind === 10) {
176
+ hint = "class";
177
+ } else {
178
+ hint = "method";
179
+ }
180
+ throw new TypeError(hint + " decorators must return a function or void 0");
181
+ }
182
+ }
183
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
184
+ var decs = decInfo[0];
185
+ var desc, init, value;
186
+ if (isPrivate) {
187
+ if (kind === 0 || kind === 1) {
188
+ desc = {
189
+ get: decInfo[3],
190
+ set: decInfo[4]
191
+ };
192
+ } else if (kind === 3) {
193
+ desc = {
194
+ get: decInfo[3]
195
+ };
196
+ } else if (kind === 4) {
197
+ desc = {
198
+ set: decInfo[3]
199
+ };
200
+ } else {
201
+ desc = {
202
+ value: decInfo[3]
203
+ };
204
+ }
205
+ } else if (kind !== 0) {
206
+ desc = Object.getOwnPropertyDescriptor(base, name);
207
+ }
208
+ if (kind === 1) {
209
+ value = {
210
+ get: desc.get,
211
+ set: desc.set
212
+ };
213
+ } else if (kind === 2) {
214
+ value = desc.value;
215
+ } else if (kind === 3) {
216
+ value = desc.get;
217
+ } else if (kind === 4) {
218
+ value = desc.set;
219
+ }
220
+ var newValue, get, set;
221
+ if (typeof decs === "function") {
222
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
223
+ if (newValue !== void 0) {
224
+ assertValidReturnValue(kind, newValue);
225
+ if (kind === 0) {
226
+ init = newValue;
227
+ } else if (kind === 1) {
228
+ init = newValue.init;
229
+ get = newValue.get || value.get;
230
+ set = newValue.set || value.set;
231
+ value = {
232
+ get: get,
233
+ set: set
234
+ };
235
+ } else {
236
+ value = newValue;
237
+ }
238
+ }
239
+ } else {
240
+ for(var i = decs.length - 1; i >= 0; i--){
241
+ var dec = decs[i];
242
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
243
+ if (newValue !== void 0) {
244
+ assertValidReturnValue(kind, newValue);
245
+ var newInit;
246
+ if (kind === 0) {
247
+ newInit = newValue;
248
+ } else if (kind === 1) {
249
+ newInit = newValue.init;
250
+ get = newValue.get || value.get;
251
+ set = newValue.set || value.set;
252
+ value = {
253
+ get: get,
254
+ set: set
255
+ };
256
+ } else {
257
+ value = newValue;
258
+ }
259
+ if (newInit !== void 0) {
260
+ if (init === void 0) {
261
+ init = newInit;
262
+ } else if (typeof init === "function") {
263
+ init = [
264
+ init,
265
+ newInit
266
+ ];
267
+ } else {
268
+ init.push(newInit);
269
+ }
270
+ }
271
+ }
272
+ }
273
+ }
274
+ if (kind === 0 || kind === 1) {
275
+ if (init === void 0) {
276
+ init = function(instance, init) {
277
+ return init;
278
+ };
279
+ } else if (typeof init !== "function") {
280
+ var ownInitializers = init;
281
+ init = function(instance, init) {
282
+ var value = init;
283
+ for(var i = 0; i < ownInitializers.length; i++){
284
+ value = ownInitializers[i].call(instance, value);
285
+ }
286
+ return value;
287
+ };
288
+ } else {
289
+ var originalInitializer = init;
290
+ init = function(instance, init) {
291
+ return originalInitializer.call(instance, init);
292
+ };
293
+ }
294
+ ret.push(init);
295
+ }
296
+ if (kind !== 0) {
297
+ if (kind === 1) {
298
+ desc.get = value.get;
299
+ desc.set = value.set;
300
+ } else if (kind === 2) {
301
+ desc.value = value;
302
+ } else if (kind === 3) {
303
+ desc.get = value;
304
+ } else if (kind === 4) {
305
+ desc.set = value;
306
+ }
307
+ if (isPrivate) {
308
+ if (kind === 1) {
309
+ ret.push(function(instance, args) {
310
+ return value.get.call(instance, args);
311
+ });
312
+ ret.push(function(instance, args) {
313
+ return value.set.call(instance, args);
314
+ });
315
+ } else if (kind === 2) {
316
+ ret.push(value);
317
+ } else {
318
+ ret.push(function(instance, args) {
319
+ return value.call(instance, args);
320
+ });
321
+ }
322
+ } else {
323
+ Object.defineProperty(base, name, desc);
324
+ }
325
+ }
326
+ }
327
+ function applyMemberDecs(Class, decInfos, metadata) {
328
+ var ret = [];
329
+ var protoInitializers;
330
+ var staticInitializers;
331
+ var existingProtoNonFields = new Map();
332
+ var existingStaticNonFields = new Map();
333
+ for(var i = 0; i < decInfos.length; i++){
334
+ var decInfo = decInfos[i];
335
+ if (!Array.isArray(decInfo)) continue;
336
+ var kind = decInfo[1];
337
+ var name = decInfo[2];
338
+ var isPrivate = decInfo.length > 3;
339
+ var isStatic = kind >= 5;
340
+ var base;
341
+ var initializers;
342
+ if (isStatic) {
343
+ base = Class;
344
+ kind = kind - 5;
345
+ staticInitializers = staticInitializers || [];
346
+ initializers = staticInitializers;
347
+ } else {
348
+ base = Class.prototype;
349
+ protoInitializers = protoInitializers || [];
350
+ initializers = protoInitializers;
351
+ }
352
+ if (kind !== 0 && !isPrivate) {
353
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
354
+ var existingKind = existingNonFields.get(name) || 0;
355
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
356
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
357
+ } else if (!existingKind && kind > 2) {
358
+ existingNonFields.set(name, kind);
359
+ } else {
360
+ existingNonFields.set(name, true);
361
+ }
362
+ }
363
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
364
+ }
365
+ pushInitializers(ret, protoInitializers);
366
+ pushInitializers(ret, staticInitializers);
367
+ return ret;
368
+ }
369
+ function pushInitializers(ret, initializers) {
370
+ if (initializers) {
371
+ ret.push(function(instance) {
372
+ for(var i = 0; i < initializers.length; i++){
373
+ initializers[i].call(instance);
374
+ }
375
+ return instance;
376
+ });
377
+ }
378
+ }
379
+ function applyClassDecs(targetClass, classDecs, metadata) {
380
+ if (classDecs.length > 0) {
381
+ var initializers = [];
382
+ var newClass = targetClass;
383
+ var name = targetClass.name;
384
+ for(var i = classDecs.length - 1; i >= 0; i--){
385
+ var decoratorFinishedRef = {
386
+ v: false
387
+ };
388
+ try {
389
+ var nextNewClass = classDecs[i](newClass, {
390
+ kind: "class",
391
+ name: name,
392
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
393
+ metadata
394
+ });
395
+ } finally{
396
+ decoratorFinishedRef.v = true;
397
+ }
398
+ if (nextNewClass !== undefined) {
399
+ assertValidReturnValue(10, nextNewClass);
400
+ newClass = nextNewClass;
401
+ }
402
+ }
403
+ return [
404
+ defineMetadata(newClass, metadata),
405
+ function() {
406
+ for(var i = 0; i < initializers.length; i++){
407
+ initializers[i].call(newClass);
408
+ }
409
+ }
410
+ ];
411
+ }
412
+ }
413
+ function defineMetadata(Class, metadata) {
414
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
415
+ configurable: true,
416
+ enumerable: true,
417
+ value: metadata
418
+ });
419
+ }
420
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
421
+ if (parentClass !== void 0) {
422
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
423
+ }
424
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
425
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
426
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
427
+ return {
428
+ e: e,
429
+ get c () {
430
+ return applyClassDecs(targetClass, classDecs, metadata);
431
+ }
432
+ };
433
+ };
434
+ }
435
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
436
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
437
+ }
438
+ var _dec, _dec1, _dec2, _initProto;
439
+ import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, PAIRING_POINTS_SIZE, RECURSIVE_PROOF_LENGTH, ULTRA_KECCAK_PROOF_LENGTH } from '@aztec/constants';
440
+ import { Fr } from '@aztec/foundation/curves/bn254';
441
+ import { runInDirectory } from '@aztec/foundation/fs';
442
+ import { createLogger } from '@aztec/foundation/log';
443
+ import { convertBlockMergeRollupOutputsFromWitnessMap, convertBlockMergeRollupPrivateInputsToWitnessMap, convertBlockRootEmptyTxFirstRollupOutputsFromWitnessMap, convertBlockRootEmptyTxFirstRollupPrivateInputsToWitnessMap, convertBlockRootFirstRollupOutputsFromWitnessMap, convertBlockRootFirstRollupPrivateInputsToWitnessMap, convertBlockRootRollupOutputsFromWitnessMap, convertBlockRootRollupPrivateInputsToWitnessMap, convertBlockRootSingleTxFirstRollupOutputsFromWitnessMap, convertBlockRootSingleTxFirstRollupPrivateInputsToWitnessMap, convertBlockRootSingleTxRollupOutputsFromWitnessMap, convertBlockRootSingleTxRollupPrivateInputsToWitnessMap, convertCheckpointMergeRollupOutputsFromWitnessMap, convertCheckpointMergeRollupPrivateInputsToWitnessMap, convertCheckpointPaddingRollupOutputsFromWitnessMap, convertCheckpointPaddingRollupPrivateInputsToWitnessMap, convertCheckpointRootRollupOutputsFromWitnessMap, convertCheckpointRootRollupPrivateInputsToWitnessMap, convertCheckpointRootSingleBlockRollupOutputsFromWitnessMap, convertCheckpointRootSingleBlockRollupPrivateInputsToWitnessMap, convertParityBaseOutputsFromWitnessMap, convertParityBasePrivateInputsToWitnessMap, convertParityRootOutputsFromWitnessMap, convertParityRootPrivateInputsToWitnessMap, convertPrivateTxBaseRollupOutputsFromWitnessMap, convertPrivateTxBaseRollupPrivateInputsToWitnessMap, convertPublicChonkVerifierOutputsFromWitnessMap, convertPublicChonkVerifierPrivateInputsToWitnessMap, convertPublicTxBaseRollupOutputsFromWitnessMap, convertPublicTxBaseRollupPrivateInputsToWitnessMap, convertRootRollupOutputsFromWitnessMap, convertRootRollupPrivateInputsToWitnessMap, convertTxMergeRollupOutputsFromWitnessMap, convertTxMergeRollupPrivateInputsToWitnessMap, getServerCircuitArtifact } from '@aztec/noir-protocol-circuits-types/server';
444
+ import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
445
+ import { mapProtocolArtifactNameToCircuitName } from '@aztec/noir-protocol-circuits-types/types';
446
+ import { NativeACVMSimulator } from '@aztec/simulator/server';
447
+ import { ProvingError } from '@aztec/stdlib/errors';
448
+ import { makePublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
449
+ import { Proof, RecursiveProof, makeRecursiveProofFromBinary } from '@aztec/stdlib/proofs';
450
+ import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
451
+ import { promises as fs } from 'fs';
452
+ import { ungzip } from 'pako';
453
+ import * as path from 'path';
454
+ import { BBJsFactory } from '../../bb/bb_js_backend.js';
455
+ import { getUltraHonkFlavorForCircuit } from '../../honk.js';
456
+ import { ProverInstrumentation } from '../../instrumentation.js';
457
+ import { constructRecursiveProofFromBuffers } from '../proof_utils.js';
458
+ const logger = createLogger('bb-prover');
459
+ _dec = trackSpan('BBNativeRollupProver.getBaseParityProof', {
460
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-base'
461
+ }), _dec1 = trackSpan('BBNativeRollupProver.getRootParityProof', {
462
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-root'
463
+ }), _dec2 = trackSpan('BBNativeRollupProver.getAvmProof', (inputs)=>({
464
+ [Attributes.APP_CIRCUIT_NAME]: inputs.hints.tx.hash
465
+ }));
466
+ /**
467
+ * Prover implementation that uses barretenberg native proving
468
+ */ export class BBNativeRollupProver {
469
+ config;
470
+ static{
471
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
472
+ [
473
+ _dec,
474
+ 2,
475
+ "getBaseParityProof"
476
+ ],
477
+ [
478
+ _dec1,
479
+ 2,
480
+ "getRootParityProof"
481
+ ],
482
+ [
483
+ _dec2,
484
+ 2,
485
+ "getAvmProof"
486
+ ]
487
+ ], []));
488
+ }
489
+ instrumentation;
490
+ bbJsFactory;
491
+ constructor(config, telemetry){
492
+ this.config = config;
493
+ _initProto(this);
494
+ this.instrumentation = new ProverInstrumentation(telemetry, 'BBNativeRollupProver');
495
+ this.bbJsFactory = new BBJsFactory(config.bbBinaryPath, {
496
+ logger,
497
+ debugDir: config.bbDebugOutputDir
498
+ });
499
+ }
500
+ get tracer() {
501
+ return this.instrumentation.tracer;
502
+ }
503
+ static async new(config, telemetry = getTelemetryClient()) {
504
+ await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
505
+ await fs.mkdir(config.acvmWorkingDirectory, {
506
+ recursive: true
507
+ });
508
+ await fs.access(config.bbBinaryPath, fs.constants.R_OK);
509
+ await fs.mkdir(config.bbWorkingDirectory, {
510
+ recursive: true
511
+ });
512
+ logger.info(`Using bb.js API with binary at ${config.bbBinaryPath}`);
513
+ logger.info(`Using native ACVM at ${config.acvmBinaryPath} and working directory ${config.acvmWorkingDirectory}`);
514
+ return new BBNativeRollupProver(config, telemetry);
515
+ }
516
+ /**
517
+ * Simulates the base parity circuit from its inputs.
518
+ * @param inputs - Inputs to the circuit.
519
+ * @returns The public inputs of the parity circuit.
520
+ */ getBaseParityProof(inputs) {
521
+ return this.createRecursiveProofAndVerify(inputs, 'ParityBaseArtifact', RECURSIVE_PROOF_LENGTH, convertParityBasePrivateInputsToWitnessMap, convertParityBaseOutputsFromWitnessMap);
522
+ }
523
+ /**
524
+ * Simulates the root parity circuit from its inputs.
525
+ * @param inputs - Inputs to the circuit.
526
+ * @returns The public inputs of the parity circuit.
527
+ */ getRootParityProof(inputs) {
528
+ return this.createRecursiveProofAndVerify(inputs, 'ParityRootArtifact', NESTED_RECURSIVE_PROOF_LENGTH, convertParityRootPrivateInputsToWitnessMap, convertParityRootOutputsFromWitnessMap);
529
+ }
530
+ /**
531
+ * Creates an AVM proof and verifies it.
532
+ * @param inputs - The inputs to the AVM circuit.
533
+ * @returns The proof.
534
+ */ async getAvmProof(inputs) {
535
+ const proof = await this.createAvmProof(inputs);
536
+ await this.verifyAvmProof(proof.binaryProof, inputs.publicInputs);
537
+ return proof;
538
+ }
539
+ async getPublicChonkVerifierProof(inputs) {
540
+ const artifactName = 'PublicChonkVerifier';
541
+ const { circuitOutput, proof } = await this.createRecursiveProof(inputs, artifactName, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertPublicChonkVerifierPrivateInputsToWitnessMap, convertPublicChonkVerifierOutputsFromWitnessMap);
542
+ const verificationKey = this.getVerificationKeyDataForCircuit(artifactName);
543
+ await this.verifyProof(artifactName, proof.binaryProof);
544
+ return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
545
+ }
546
+ /**
547
+ * Simulates the base rollup circuit from its inputs.
548
+ * @param inputs - Inputs to the circuit.
549
+ * @returns The public inputs as outputs of the simulation.
550
+ */ getPrivateTxBaseRollupProof(inputs) {
551
+ return this.createRecursiveProofAndVerify(inputs, 'PrivateTxBaseRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertPrivateTxBaseRollupPrivateInputsToWitnessMap, convertPrivateTxBaseRollupOutputsFromWitnessMap);
552
+ }
553
+ /**
554
+ * Requests that the public kernel tail circuit be executed and the proof generated
555
+ * @param kernelRequest - The object encapsulating the request for a proof
556
+ * @returns The requested circuit's public inputs and proof
557
+ */ getPublicTxBaseRollupProof(inputs) {
558
+ return this.createRecursiveProofAndVerify(inputs, 'PublicTxBaseRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertPublicTxBaseRollupPrivateInputsToWitnessMap, convertPublicTxBaseRollupOutputsFromWitnessMap);
559
+ }
560
+ /**
561
+ * Simulates the merge rollup circuit from its inputs.
562
+ * @param input - Inputs to the circuit.
563
+ * @returns The public inputs as outputs of the simulation.
564
+ */ getTxMergeRollupProof(input) {
565
+ return this.createRecursiveProofAndVerify(input, 'TxMergeRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertTxMergeRollupPrivateInputsToWitnessMap, convertTxMergeRollupOutputsFromWitnessMap);
566
+ }
567
+ getBlockRootFirstRollupProof(input) {
568
+ return this.createRecursiveProofAndVerify(input, 'BlockRootFirstRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertBlockRootFirstRollupPrivateInputsToWitnessMap, convertBlockRootFirstRollupOutputsFromWitnessMap);
569
+ }
570
+ getBlockRootSingleTxFirstRollupProof(input) {
571
+ return this.createRecursiveProofAndVerify(input, 'BlockRootSingleTxFirstRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertBlockRootSingleTxFirstRollupPrivateInputsToWitnessMap, convertBlockRootSingleTxFirstRollupOutputsFromWitnessMap);
572
+ }
573
+ getBlockRootEmptyTxFirstRollupProof(input) {
574
+ return this.createRecursiveProofAndVerify(input, 'BlockRootEmptyTxFirstRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertBlockRootEmptyTxFirstRollupPrivateInputsToWitnessMap, convertBlockRootEmptyTxFirstRollupOutputsFromWitnessMap);
575
+ }
576
+ getBlockRootRollupProof(input) {
577
+ return this.createRecursiveProofAndVerify(input, 'BlockRootRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertBlockRootRollupPrivateInputsToWitnessMap, convertBlockRootRollupOutputsFromWitnessMap);
578
+ }
579
+ getBlockRootSingleTxRollupProof(input) {
580
+ return this.createRecursiveProofAndVerify(input, 'BlockRootSingleTxRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertBlockRootSingleTxRollupPrivateInputsToWitnessMap, convertBlockRootSingleTxRollupOutputsFromWitnessMap);
581
+ }
582
+ getBlockMergeRollupProof(input) {
583
+ return this.createRecursiveProofAndVerify(input, 'BlockMergeRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertBlockMergeRollupPrivateInputsToWitnessMap, convertBlockMergeRollupOutputsFromWitnessMap);
584
+ }
585
+ getCheckpointRootRollupProof(input) {
586
+ return this.createRecursiveProofAndVerify(input, 'CheckpointRootRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertCheckpointRootRollupPrivateInputsToWitnessMap, convertCheckpointRootRollupOutputsFromWitnessMap);
587
+ }
588
+ getCheckpointRootSingleBlockRollupProof(input) {
589
+ return this.createRecursiveProofAndVerify(input, 'CheckpointRootSingleBlockRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertCheckpointRootSingleBlockRollupPrivateInputsToWitnessMap, convertCheckpointRootSingleBlockRollupOutputsFromWitnessMap);
590
+ }
591
+ getCheckpointPaddingRollupProof(input) {
592
+ return this.createRecursiveProofAndVerify(input, 'CheckpointPaddingRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertCheckpointPaddingRollupPrivateInputsToWitnessMap, convertCheckpointPaddingRollupOutputsFromWitnessMap);
593
+ }
594
+ getCheckpointMergeRollupProof(input) {
595
+ return this.createRecursiveProofAndVerify(input, 'CheckpointMergeRollupArtifact', NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, convertCheckpointMergeRollupPrivateInputsToWitnessMap, convertCheckpointMergeRollupOutputsFromWitnessMap);
596
+ }
597
+ /**
598
+ * Simulates the root rollup circuit from its inputs.
599
+ * @param input - Inputs to the circuit.
600
+ * @returns The public inputs as outputs of the simulation.
601
+ */ async getRootRollupProof(input) {
602
+ const { proof, ...output } = await this.createRecursiveProofAndVerify(input, 'RootRollupArtifact', ULTRA_KECCAK_PROOF_LENGTH, convertRootRollupPrivateInputsToWitnessMap, convertRootRollupOutputsFromWitnessMap);
603
+ const recursiveProof = makeRecursiveProofFromBinary(proof.binaryProof, NESTED_RECURSIVE_PROOF_LENGTH);
604
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/13188): Remove this hack.
605
+ recursiveProof.binaryProof.numPublicInputs += PAIRING_POINTS_SIZE;
606
+ return {
607
+ ...output,
608
+ proof: recursiveProof
609
+ };
610
+ }
611
+ async createRecursiveProofAndVerify(input, artifactName, proofLength, convertInput, convertOutput) {
612
+ const { circuitOutput, proof } = await this.createRecursiveProof(input, artifactName, proofLength, convertInput, convertOutput);
613
+ await this.verifyProof(artifactName, proof.binaryProof);
614
+ const verificationKey = this.getVerificationKeyDataForCircuit(artifactName);
615
+ return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
616
+ }
617
+ async generateProofWithBB(input, circuitType, convertInput, convertOutput, workingDirectory) {
618
+ // Have the ACVM write the partial witness here (still needs a temp directory)
619
+ const outputWitnessFile = path.join(workingDirectory, 'partial-witness.gz');
620
+ // Generate the partial witness using the ACVM
621
+ const simulator = new NativeACVMSimulator(this.config.acvmWorkingDirectory, this.config.acvmBinaryPath, outputWitnessFile, logger);
622
+ const artifact = getServerCircuitArtifact(circuitType);
623
+ logger.debug(`Generating witness data for ${circuitType}`);
624
+ const inputWitness = convertInput(input);
625
+ const foreignCallHandler = undefined;
626
+ const witnessResult = await simulator.executeProtocolCircuit(inputWitness, artifact, foreignCallHandler);
627
+ const output = convertOutput(witnessResult.witness);
628
+ const circuitName = mapProtocolArtifactNameToCircuitName(circuitType);
629
+ this.instrumentation.recordDuration('witGenDuration', circuitName, witnessResult.duration);
630
+ this.instrumentation.recordSize('witGenInputSize', circuitName, input.toBuffer().length);
631
+ this.instrumentation.recordSize('witGenOutputSize', circuitName, output.toBuffer().length);
632
+ logger.info(`Generated witness`, {
633
+ circuitName,
634
+ duration: witnessResult.duration,
635
+ inputSize: input.toBuffer().length,
636
+ outputSize: output.toBuffer().length,
637
+ eventName: 'circuit-witness-generation'
638
+ });
639
+ // Read and decompress the witness for bb.js
640
+ const witnessGz = await fs.readFile(outputWitnessFile);
641
+ const witness = ungzip(witnessGz);
642
+ // Decompress bytecode for bb.js
643
+ const bytecode = ungzip(Buffer.from(artifact.bytecode, 'base64'));
644
+ // Prove the circuit via bb.js API
645
+ logger.debug(`Proving ${circuitType} via bb.js...`);
646
+ let proofResult;
647
+ try {
648
+ const env = {
649
+ stack: [],
650
+ error: void 0,
651
+ hasError: false
652
+ };
653
+ try {
654
+ const instance = _ts_add_disposable_resource(env, await this.bbJsFactory.getInstance(), true);
655
+ proofResult = await instance.generateProof(circuitType, bytecode, this.getVerificationKeyDataForCircuit(circuitType).keyAsBytes, witness, getUltraHonkFlavorForCircuit(circuitType));
656
+ } catch (e) {
657
+ env.error = e;
658
+ env.hasError = true;
659
+ } finally{
660
+ const result = _ts_dispose_resources(env);
661
+ if (result) await result;
662
+ }
663
+ } catch (error) {
664
+ throw new ProvingError(`Failed to generate proof for ${circuitType}: ${error}`);
665
+ }
666
+ return {
667
+ circuitOutput: output,
668
+ proofResult
669
+ };
670
+ }
671
+ async createAvmProof(input) {
672
+ const env = {
673
+ stack: [],
674
+ error: void 0,
675
+ hasError: false
676
+ };
677
+ try {
678
+ logger.info(`Proving avm-circuit for TX ${input.hints.tx.hash}...`);
679
+ const inputsBuffer = input.serializeWithMessagePack();
680
+ const instance = _ts_add_disposable_resource(env, await this.bbJsFactory.getInstance(), true);
681
+ const { proof: proofFieldArrays, durationMs } = await instance.generateAvmProof(inputsBuffer);
682
+ // Convert Uint8Array[] (32-byte field elements) to Fr[]
683
+ const proofFields = proofFieldArrays.map((f)=>Fr.fromBuffer(Buffer.from(f)));
684
+ // Pad to fixed size (during development the proof length may vary)
685
+ if (proofFields.length > AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED) {
686
+ throw new Error(`Proof has ${proofFields.length} fields, expected no more than ${AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED}.`);
687
+ }
688
+ const proofFieldsPadded = proofFields.concat(Array(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED - proofFields.length).fill(new Fr(0)));
689
+ // Build the binary proof from the raw field data
690
+ const rawProofBuffer = Buffer.concat(proofFieldArrays.map((f)=>Buffer.from(f)));
691
+ const binaryProof = new Proof(rawProofBuffer, /*numPublicInputs=*/ 0);
692
+ const avmProof = new RecursiveProof(proofFieldsPadded, binaryProof, true, AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED);
693
+ const circuitType = 'avm-circuit';
694
+ const appCircuitName = 'unknown';
695
+ this.instrumentation.recordAvmDuration('provingDuration', appCircuitName, durationMs);
696
+ this.instrumentation.recordAvmSize('proofSize', appCircuitName, avmProof.binaryProof.buffer.length);
697
+ logger.info(`Generated proof for ${circuitType}(${input.hints.tx.hash}) in ${Math.ceil(durationMs)} ms`, {
698
+ circuitName: circuitType,
699
+ appCircuitName: input.hints.tx.hash,
700
+ duration: durationMs,
701
+ proofSize: avmProof.binaryProof.buffer.length,
702
+ eventName: 'circuit-proving',
703
+ inputSize: inputsBuffer.length,
704
+ circuitSize: 1 << 21,
705
+ numPublicInputs: 0
706
+ });
707
+ return avmProof;
708
+ } catch (e) {
709
+ env.error = e;
710
+ env.hasError = true;
711
+ } finally{
712
+ const result = _ts_dispose_resources(env);
713
+ if (result) await result;
714
+ }
715
+ }
716
+ /**
717
+ * Executes a circuit and returns its outputs and corresponding proof with embedded aggregation object
718
+ * @param witnessMap - The input witness
719
+ * @param circuitType - The type of circuit to be executed
720
+ * @param proofLength - The length of the proof to be generated. This is a dummy parameter to aid in type checking
721
+ * @param convertInput - Function for mapping the input object to a witness map.
722
+ * @param convertOutput - Function for parsing the output witness to it's corresponding object
723
+ * @returns The circuits output object and it's proof
724
+ */ async createRecursiveProof(input, circuitType, proofLength, convertInput, convertOutput) {
725
+ // Still need runInDirectory for ACVM witness generation temp files
726
+ const operation = async (workingDirectory)=>{
727
+ const { proofResult, circuitOutput: output } = await this.generateProofWithBB(input, circuitType, convertInput, convertOutput, workingDirectory);
728
+ const vkData = this.getVerificationKeyDataForCircuit(circuitType);
729
+ // Construct proof from in-memory buffers (no file I/O needed)
730
+ const proof = constructRecursiveProofFromBuffers(proofResult.proofFields, proofResult.publicInputFields, vkData, proofLength);
731
+ const circuitName = mapProtocolArtifactNameToCircuitName(circuitType);
732
+ this.instrumentation.recordDuration('provingDuration', circuitName, proofResult.durationMs);
733
+ this.instrumentation.recordSize('proofSize', circuitName, proof.binaryProof.buffer.length);
734
+ this.instrumentation.recordSize('circuitPublicInputCount', circuitName, vkData.numPublicInputs);
735
+ this.instrumentation.recordSize('circuitSize', circuitName, vkData.circuitSize);
736
+ logger.info(`Generated proof for ${circuitType} in ${Math.ceil(proofResult.durationMs)} ms, size: ${proof.proof.length} fields`, {
737
+ circuitName,
738
+ circuitSize: vkData.circuitSize,
739
+ duration: proofResult.durationMs,
740
+ inputSize: output.toBuffer().length,
741
+ proofSize: proof.binaryProof.buffer.length,
742
+ eventName: 'circuit-proving',
743
+ numPublicInputs: vkData.numPublicInputs
744
+ });
745
+ return {
746
+ circuitOutput: output,
747
+ proof
748
+ };
749
+ };
750
+ return await this.runInDirectory(operation);
751
+ }
752
+ /**
753
+ * Verifies a proof via bb.js API (no temp files needed).
754
+ * @param circuitType - The type of circuit whose proof is to be verified
755
+ * @param proof - The proof to be verified
756
+ */ async verifyProof(circuitType, proof) {
757
+ const verificationKey = this.getVerificationKeyDataForCircuit(circuitType);
758
+ const flavor = getUltraHonkFlavorForCircuit(circuitType);
759
+ // Split proof buffer into public input fields and proof fields (32-byte each)
760
+ const publicInputFields = splitBufferToFieldArrays(proof.buffer.subarray(0, proof.numPublicInputs * 32));
761
+ const proofFields = splitBufferToFieldArrays(proof.buffer.subarray(proof.numPublicInputs * 32));
762
+ let verified;
763
+ let durationMs;
764
+ try {
765
+ const env = {
766
+ stack: [],
767
+ error: void 0,
768
+ hasError: false
769
+ };
770
+ try {
771
+ const instance = _ts_add_disposable_resource(env, await this.bbJsFactory.getInstance(), true);
772
+ ({ verified, durationMs } = await instance.verifyProof(proofFields, verificationKey.keyAsBytes, publicInputFields, flavor));
773
+ } catch (e) {
774
+ env.error = e;
775
+ env.hasError = true;
776
+ } finally{
777
+ const result = _ts_dispose_resources(env);
778
+ if (result) await result;
779
+ }
780
+ } catch (error) {
781
+ throw new ProvingError(`Failed to verify proof for ${circuitType}: ${error}`);
782
+ }
783
+ if (!verified) {
784
+ throw new ProvingError('Failed to verify proof from key!');
785
+ }
786
+ logger.info(`Successfully verified proof from key in ${durationMs} ms`);
787
+ }
788
+ /** Verify an AVM proof via bb.js API. */ async verifyAvmProof(proof, publicInputs) {
789
+ const env = {
790
+ stack: [],
791
+ error: void 0,
792
+ hasError: false
793
+ };
794
+ try {
795
+ // For AVM proofs, numPublicInputs is 0, so the full buffer is the proof.
796
+ const proofBuffer = proof.buffer.subarray(proof.numPublicInputs * 32);
797
+ // Split the raw proof buffer into 32-byte field element arrays
798
+ const proofFields = [];
799
+ for(let i = 0; i < proofBuffer.length; i += Fr.SIZE_IN_BYTES){
800
+ proofFields.push(new Uint8Array(proofBuffer.subarray(i, i + Fr.SIZE_IN_BYTES)));
801
+ }
802
+ const piBuffer = publicInputs.serializeWithMessagePack();
803
+ const instance = _ts_add_disposable_resource(env, await this.bbJsFactory.getInstance(), true);
804
+ const { verified, durationMs } = await instance.verifyAvmProof(proofFields, piBuffer);
805
+ if (!verified) {
806
+ throw new ProvingError('Failed to verify AVM proof!');
807
+ }
808
+ logger.info(`Successfully verified AVM proof in ${durationMs} ms`);
809
+ } catch (e) {
810
+ env.error = e;
811
+ env.hasError = true;
812
+ } finally{
813
+ const result = _ts_dispose_resources(env);
814
+ if (result) await result;
815
+ }
816
+ }
817
+ /**
818
+ * Returns the verification key data for a circuit.
819
+ * @param circuitType - The type of circuit for which the verification key is required
820
+ * @returns The verification key data
821
+ */ getVerificationKeyDataForCircuit(circuitType) {
822
+ const vk = ServerCircuitVks[circuitType];
823
+ if (vk === undefined) {
824
+ throw new Error('Could not find VK for server artifact ' + circuitType);
825
+ }
826
+ return vk;
827
+ }
828
+ runInDirectory(fn) {
829
+ return runInDirectory(this.config.bbWorkingDirectory, (dir)=>fn(dir).catch((err)=>{
830
+ logger.error(`Error running operation at ${dir}: ${err}`);
831
+ throw err;
832
+ }), this.config.bbSkipCleanup, logger);
833
+ }
834
+ }
835
+ /** Split a buffer into 32-byte Uint8Array field elements. */ function splitBufferToFieldArrays(buffer) {
836
+ const fields = [];
837
+ for(let i = 0; i < buffer.length; i += 32){
838
+ fields.push(new Uint8Array(buffer.subarray(i, i + 32)));
839
+ }
840
+ return fields;
841
+ }