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