@aztec/bb-prover 0.55.1 → 0.57.0
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/bb/index.js +0 -0
- package/dest/honk.d.ts +5 -5
- package/dest/honk.d.ts.map +1 -1
- package/dest/honk.js +2 -2
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/prover/bb_private_kernel_prover.d.ts +2 -3
- package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/bb_private_kernel_prover.js +8 -10
- package/dest/prover/bb_prover.d.ts +18 -6
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +48 -27
- package/dest/stats.d.ts +0 -1
- package/dest/stats.d.ts.map +1 -1
- package/dest/stats.js +10 -21
- package/dest/test/index.d.ts +1 -0
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +2 -1
- package/dest/test/test_avm.d.ts +4 -0
- package/dest/test/test_avm.d.ts.map +1 -0
- package/dest/test/test_avm.js +33 -0
- package/dest/test/test_circuit_prover.d.ts +11 -4
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +55 -24
- package/dest/verifier/bb_verifier.d.ts +2 -1
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +1 -1
- package/package.json +11 -7
- package/src/honk.ts +7 -7
- package/src/index.ts +3 -0
- package/src/prover/bb_private_kernel_prover.ts +14 -19
- package/src/prover/bb_prover.ts +88 -37
- package/src/stats.ts +9 -21
- package/src/test/index.ts +1 -0
- package/src/test/test_avm.ts +85 -0
- package/src/test/test_circuit_prover.ts +98 -30
- package/src/verifier/bb_verifier.ts +2 -2
- package/dest/mappings/mappings.d.ts +0 -13
- package/dest/mappings/mappings.d.ts.map +0 -1
- package/dest/mappings/mappings.js +0 -41
- package/src/mappings/mappings.ts +0 -67
|
@@ -8,11 +8,10 @@ import {
|
|
|
8
8
|
AGGREGATION_OBJECT_LENGTH,
|
|
9
9
|
ClientIvcProof,
|
|
10
10
|
Fr,
|
|
11
|
-
type PrivateCircuitPublicInputs,
|
|
12
11
|
type PrivateKernelCircuitPublicInputs,
|
|
13
12
|
type PrivateKernelInitCircuitPrivateInputs,
|
|
14
13
|
type PrivateKernelInnerCircuitPrivateInputs,
|
|
15
|
-
type
|
|
14
|
+
type PrivateKernelResetCircuitPrivateInputs,
|
|
16
15
|
type PrivateKernelTailCircuitPrivateInputs,
|
|
17
16
|
type PrivateKernelTailCircuitPublicInputs,
|
|
18
17
|
Proof,
|
|
@@ -20,14 +19,13 @@ import {
|
|
|
20
19
|
type VerificationKeyAsFields,
|
|
21
20
|
type VerificationKeyData,
|
|
22
21
|
} from '@aztec/circuits.js';
|
|
23
|
-
import { siloNoteHash } from '@aztec/circuits.js/hash';
|
|
24
22
|
import { runInDirectory } from '@aztec/foundation/fs';
|
|
25
23
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
26
24
|
import { Timer } from '@aztec/foundation/timer';
|
|
27
25
|
import {
|
|
28
26
|
ClientCircuitArtifacts,
|
|
27
|
+
ClientCircuitVks,
|
|
29
28
|
type ClientProtocolArtifact,
|
|
30
|
-
PrivateResetTagToArtifactName,
|
|
31
29
|
ProtocolCircuitVks,
|
|
32
30
|
convertPrivateKernelInitInputsToWitnessMap,
|
|
33
31
|
convertPrivateKernelInitOutputsFromWitnessMap,
|
|
@@ -39,6 +37,7 @@ import {
|
|
|
39
37
|
convertPrivateKernelTailInputsToWitnessMap,
|
|
40
38
|
convertPrivateKernelTailOutputsFromWitnessMap,
|
|
41
39
|
convertPrivateKernelTailToPublicInputsToWitnessMap,
|
|
40
|
+
getPrivateKernelResetArtifactName,
|
|
42
41
|
} from '@aztec/noir-protocol-circuits-types';
|
|
43
42
|
import { WASMSimulator } from '@aztec/simulator';
|
|
44
43
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
@@ -130,12 +129,6 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
|
|
|
130
129
|
return await this.runInDirectory(operation);
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
public getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) {
|
|
134
|
-
const contractAddress = publicInputs.callContext.storageContractAddress;
|
|
135
|
-
|
|
136
|
-
return Promise.resolve(publicInputs.noteHashes.map(commitment => siloNoteHash(contractAddress, commitment.value)));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
132
|
public async simulateProofInit(
|
|
140
133
|
inputs: PrivateKernelInitCircuitPrivateInputs,
|
|
141
134
|
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
@@ -159,13 +152,15 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
|
|
|
159
152
|
}
|
|
160
153
|
|
|
161
154
|
public async simulateProofReset(
|
|
162
|
-
inputs:
|
|
155
|
+
inputs: PrivateKernelResetCircuitPrivateInputs,
|
|
163
156
|
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
157
|
+
const variantInputs = inputs.trimToSizes();
|
|
158
|
+
const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
|
|
164
159
|
return await this.simulate(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
convertPrivateKernelResetInputsToWitnessMap,
|
|
168
|
-
output => convertPrivateKernelResetOutputsFromWitnessMap(output,
|
|
160
|
+
variantInputs,
|
|
161
|
+
artifactName,
|
|
162
|
+
variantInputs => convertPrivateKernelResetInputsToWitnessMap(variantInputs, artifactName),
|
|
163
|
+
output => convertPrivateKernelResetOutputsFromWitnessMap(output, artifactName),
|
|
169
164
|
);
|
|
170
165
|
}
|
|
171
166
|
|
|
@@ -283,14 +278,14 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
|
|
|
283
278
|
outputSize: output.toBuffer().length,
|
|
284
279
|
} satisfies CircuitWitnessGenerationStats);
|
|
285
280
|
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
);
|
|
281
|
+
const verificationKey = ClientCircuitVks[circuitType].keyAsFields;
|
|
282
|
+
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
283
|
+
|
|
290
284
|
const kernelOutput: PrivateKernelSimulateOutput<O> = {
|
|
291
285
|
publicInputs: output,
|
|
292
286
|
verificationKey,
|
|
293
287
|
outputWitness,
|
|
288
|
+
bytecode,
|
|
294
289
|
};
|
|
295
290
|
return kernelOutput;
|
|
296
291
|
}
|
package/src/prover/bb_prover.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
import {
|
|
3
3
|
type AvmProofAndVerificationKey,
|
|
4
4
|
type PublicInputsAndRecursiveProof,
|
|
5
|
-
type PublicKernelNonTailRequest,
|
|
6
|
-
type PublicKernelTailRequest,
|
|
7
5
|
type ServerCircuitProver,
|
|
8
6
|
makePublicInputsAndRecursiveProof,
|
|
9
7
|
} from '@aztec/circuit-types';
|
|
@@ -18,6 +16,7 @@ import {
|
|
|
18
16
|
type BlockMergeRollupInputs,
|
|
19
17
|
type BlockRootOrBlockMergePublicInputs,
|
|
20
18
|
type BlockRootRollupInputs,
|
|
19
|
+
type EmptyBlockRootRollupInputs,
|
|
21
20
|
EmptyNestedCircuitInputs,
|
|
22
21
|
EmptyNestedData,
|
|
23
22
|
Fr,
|
|
@@ -27,7 +26,10 @@ import {
|
|
|
27
26
|
type PrivateKernelEmptyInputData,
|
|
28
27
|
PrivateKernelEmptyInputs,
|
|
29
28
|
Proof,
|
|
29
|
+
type PublicKernelCircuitPrivateInputs,
|
|
30
30
|
type PublicKernelCircuitPublicInputs,
|
|
31
|
+
type PublicKernelInnerCircuitPrivateInputs,
|
|
32
|
+
type PublicKernelTailCircuitPrivateInputs,
|
|
31
33
|
RECURSIVE_PROOF_LENGTH,
|
|
32
34
|
RecursiveProof,
|
|
33
35
|
RootParityInput,
|
|
@@ -36,6 +38,7 @@ import {
|
|
|
36
38
|
type RootRollupPublicInputs,
|
|
37
39
|
TUBE_PROOF_LENGTH,
|
|
38
40
|
type TubeInputs,
|
|
41
|
+
type VMCircuitPublicInputs,
|
|
39
42
|
type VerificationKeyAsFields,
|
|
40
43
|
type VerificationKeyData,
|
|
41
44
|
makeRecursiveProofFromBinary,
|
|
@@ -55,10 +58,16 @@ import {
|
|
|
55
58
|
convertBlockMergeRollupOutputsFromWitnessMap,
|
|
56
59
|
convertBlockRootRollupInputsToWitnessMap,
|
|
57
60
|
convertBlockRootRollupOutputsFromWitnessMap,
|
|
61
|
+
convertEmptyBlockRootRollupInputsToWitnessMap,
|
|
62
|
+
convertEmptyBlockRootRollupOutputsFromWitnessMap,
|
|
58
63
|
convertMergeRollupInputsToWitnessMap,
|
|
59
64
|
convertMergeRollupOutputsFromWitnessMap,
|
|
60
65
|
convertPrivateKernelEmptyInputsToWitnessMap,
|
|
61
66
|
convertPrivateKernelEmptyOutputsFromWitnessMap,
|
|
67
|
+
convertPublicInnerInputsToWitnessMap,
|
|
68
|
+
convertPublicInnerOutputFromWitnessMap,
|
|
69
|
+
convertPublicMergeInputsToWitnessMap,
|
|
70
|
+
convertPublicMergeOutputFromWitnessMap,
|
|
62
71
|
convertPublicTailInputsToWitnessMap,
|
|
63
72
|
convertPublicTailOutputFromWitnessMap,
|
|
64
73
|
convertRootParityInputsToWitnessMap,
|
|
@@ -94,7 +103,6 @@ import {
|
|
|
94
103
|
import type { ACVMConfig, BBConfig } from '../config.js';
|
|
95
104
|
import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
96
105
|
import { ProverInstrumentation } from '../instrumentation.js';
|
|
97
|
-
import { PublicKernelArtifactMapping } from '../mappings/mappings.js';
|
|
98
106
|
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
99
107
|
import { extractAvmVkData, extractVkData } from '../verification_key/verification_key_data.js';
|
|
100
108
|
|
|
@@ -206,47 +214,70 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
/**
|
|
209
|
-
* Requests that a public kernel circuit be executed and the proof generated
|
|
217
|
+
* Requests that a public kernel inner circuit be executed and the proof generated
|
|
210
218
|
* @param kernelRequest - The object encapsulating the request for a proof
|
|
211
219
|
* @returns The requested circuit's public inputs and proof
|
|
212
220
|
*/
|
|
213
|
-
@trackSpan('BBNativeRollupProver.
|
|
214
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
@trackSpan('BBNativeRollupProver.getPublicKernelInnerProof', {
|
|
222
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'public-kernel-inner',
|
|
223
|
+
})
|
|
224
|
+
public async getPublicKernelInnerProof(
|
|
225
|
+
inputs: PublicKernelInnerCircuitPrivateInputs,
|
|
226
|
+
): Promise<PublicInputsAndRecursiveProof<VMCircuitPublicInputs>> {
|
|
227
|
+
const artifact = 'PublicKernelInnerArtifact';
|
|
228
|
+
|
|
229
|
+
const { circuitOutput, proof } = await this.createRecursiveProof(
|
|
230
|
+
inputs,
|
|
231
|
+
artifact,
|
|
232
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
233
|
+
convertPublicInnerInputsToWitnessMap,
|
|
234
|
+
convertPublicInnerOutputFromWitnessMap,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const verificationKey = await this.getVerificationKeyDataForCircuit(artifact);
|
|
238
|
+
|
|
239
|
+
await this.verifyProof(artifact, proof.binaryProof);
|
|
240
|
+
|
|
241
|
+
return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Requests that a public kernel merge circuit be executed and the proof generated
|
|
246
|
+
* @param kernelRequest - The object encapsulating the request for a proof
|
|
247
|
+
* @returns The requested circuit's public inputs and proof
|
|
248
|
+
*/
|
|
249
|
+
@trackSpan('BBNativeRollupProver.getPublicKernelMergeProof', {
|
|
250
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'public-kernel-merge',
|
|
251
|
+
})
|
|
252
|
+
public async getPublicKernelMergeProof(
|
|
253
|
+
inputs: PublicKernelCircuitPrivateInputs,
|
|
220
254
|
): Promise<PublicInputsAndRecursiveProof<PublicKernelCircuitPublicInputs>> {
|
|
221
|
-
const
|
|
222
|
-
if (kernelOps === undefined) {
|
|
223
|
-
throw new Error(`Unable to prove kernel type ${kernelRequest.type}`);
|
|
224
|
-
}
|
|
255
|
+
const artifact = 'PublicKernelMergeArtifact';
|
|
225
256
|
|
|
226
257
|
// We may need to convert the recursive proof into fields format
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
258
|
+
inputs.previousKernel.proof = await this.ensureValidProof(
|
|
259
|
+
inputs.previousKernel.proof,
|
|
260
|
+
artifact,
|
|
261
|
+
inputs.previousKernel.vk,
|
|
231
262
|
);
|
|
232
263
|
|
|
233
264
|
await this.verifyWithKey(
|
|
234
|
-
getUltraHonkFlavorForCircuit(
|
|
235
|
-
|
|
236
|
-
|
|
265
|
+
getUltraHonkFlavorForCircuit(artifact),
|
|
266
|
+
inputs.previousKernel.vk,
|
|
267
|
+
inputs.previousKernel.proof.binaryProof,
|
|
237
268
|
);
|
|
238
269
|
|
|
239
270
|
const { circuitOutput, proof } = await this.createRecursiveProof(
|
|
240
|
-
|
|
241
|
-
|
|
271
|
+
inputs,
|
|
272
|
+
artifact,
|
|
242
273
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
243
|
-
|
|
244
|
-
|
|
274
|
+
convertPublicMergeInputsToWitnessMap,
|
|
275
|
+
convertPublicMergeOutputFromWitnessMap,
|
|
245
276
|
);
|
|
246
277
|
|
|
247
|
-
const verificationKey = await this.getVerificationKeyDataForCircuit(
|
|
278
|
+
const verificationKey = await this.getVerificationKeyDataForCircuit(artifact);
|
|
248
279
|
|
|
249
|
-
await this.verifyProof(
|
|
280
|
+
await this.verifyProof(artifact, proof.binaryProof);
|
|
250
281
|
|
|
251
282
|
return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
|
|
252
283
|
}
|
|
@@ -257,10 +288,10 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
257
288
|
* @returns The requested circuit's public inputs and proof
|
|
258
289
|
*/
|
|
259
290
|
public async getPublicTailProof(
|
|
260
|
-
|
|
291
|
+
inputs: PublicKernelTailCircuitPrivateInputs,
|
|
261
292
|
): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
|
|
262
293
|
const { circuitOutput, proof } = await this.createRecursiveProof(
|
|
263
|
-
|
|
294
|
+
inputs,
|
|
264
295
|
'PublicKernelTailArtifact',
|
|
265
296
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
266
297
|
convertPublicTailInputsToWitnessMap,
|
|
@@ -337,22 +368,42 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
337
368
|
public async getBlockRootRollupProof(
|
|
338
369
|
input: BlockRootRollupInputs,
|
|
339
370
|
): Promise<PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs>> {
|
|
340
|
-
|
|
341
|
-
// since we will no longer be verifying it directly on L1
|
|
342
|
-
const { circuitOutput, proof } = await this.createProof(
|
|
371
|
+
const { circuitOutput, proof } = await this.createRecursiveProof(
|
|
343
372
|
input,
|
|
344
373
|
'BlockRootRollupArtifact',
|
|
374
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
345
375
|
convertBlockRootRollupInputsToWitnessMap,
|
|
346
376
|
convertBlockRootRollupOutputsFromWitnessMap,
|
|
347
377
|
);
|
|
348
378
|
|
|
349
|
-
const recursiveProof = makeRecursiveProofFromBinary(proof, NESTED_RECURSIVE_PROOF_LENGTH);
|
|
350
|
-
|
|
351
379
|
const verificationKey = await this.getVerificationKeyDataForCircuit('BlockRootRollupArtifact');
|
|
352
380
|
|
|
353
|
-
await this.verifyProof('BlockRootRollupArtifact', proof);
|
|
381
|
+
await this.verifyProof('BlockRootRollupArtifact', proof.binaryProof);
|
|
354
382
|
|
|
355
|
-
return makePublicInputsAndRecursiveProof(circuitOutput,
|
|
383
|
+
return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Simulates the empty block root rollup circuit from its inputs.
|
|
388
|
+
* @param input - Inputs to the circuit.
|
|
389
|
+
* @returns The public inputs as outputs of the simulation.
|
|
390
|
+
*/
|
|
391
|
+
public async getEmptyBlockRootRollupProof(
|
|
392
|
+
input: EmptyBlockRootRollupInputs,
|
|
393
|
+
): Promise<PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs>> {
|
|
394
|
+
const { circuitOutput, proof } = await this.createRecursiveProof(
|
|
395
|
+
input,
|
|
396
|
+
'EmptyBlockRootRollupArtifact',
|
|
397
|
+
RECURSIVE_PROOF_LENGTH,
|
|
398
|
+
convertEmptyBlockRootRollupInputsToWitnessMap,
|
|
399
|
+
convertEmptyBlockRootRollupOutputsFromWitnessMap,
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
const verificationKey = await this.getVerificationKeyDataForCircuit('EmptyBlockRootRollupArtifact');
|
|
403
|
+
|
|
404
|
+
await this.verifyProof('EmptyBlockRootRollupArtifact', proof.binaryProof);
|
|
405
|
+
|
|
406
|
+
return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
|
|
356
407
|
}
|
|
357
408
|
|
|
358
409
|
/**
|
package/src/stats.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { CircuitName } from '@aztec/circuit-types/stats';
|
|
2
2
|
import { type ClientProtocolArtifact, type ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types';
|
|
3
3
|
|
|
4
|
-
export { mapPublicKernelToCircuitName } from '@aztec/circuit-types';
|
|
5
|
-
|
|
6
4
|
export function mapProtocolArtifactNameToCircuitName(
|
|
7
5
|
artifact: ServerProtocolArtifact | ClientProtocolArtifact,
|
|
8
6
|
): CircuitName {
|
|
@@ -17,16 +15,16 @@ export function mapProtocolArtifactNameToCircuitName(
|
|
|
17
15
|
return 'merge-rollup';
|
|
18
16
|
case 'BlockRootRollupArtifact':
|
|
19
17
|
return 'block-root-rollup';
|
|
18
|
+
case 'EmptyBlockRootRollupArtifact':
|
|
19
|
+
return 'empty-block-root-rollup';
|
|
20
20
|
case 'BlockMergeRollupArtifact':
|
|
21
21
|
return 'block-merge-rollup';
|
|
22
22
|
case 'RootRollupArtifact':
|
|
23
23
|
return 'root-rollup';
|
|
24
|
-
case '
|
|
25
|
-
return 'public-kernel-
|
|
26
|
-
case '
|
|
27
|
-
return 'public-kernel-
|
|
28
|
-
case 'PublicKernelTeardownArtifact':
|
|
29
|
-
return 'public-kernel-teardown';
|
|
24
|
+
case 'PublicKernelInnerArtifact':
|
|
25
|
+
return 'public-kernel-inner';
|
|
26
|
+
case 'PublicKernelMergeArtifact':
|
|
27
|
+
return 'public-kernel-merge';
|
|
30
28
|
case 'PublicKernelTailArtifact':
|
|
31
29
|
return 'public-kernel-tail';
|
|
32
30
|
case 'PrivateKernelInitArtifact':
|
|
@@ -37,24 +35,14 @@ export function mapProtocolArtifactNameToCircuitName(
|
|
|
37
35
|
return 'private-kernel-tail';
|
|
38
36
|
case 'PrivateKernelTailToPublicArtifact':
|
|
39
37
|
return 'private-kernel-tail-to-public';
|
|
40
|
-
case 'PrivateKernelResetFullArtifact':
|
|
41
|
-
return 'private-kernel-reset-full';
|
|
42
|
-
case 'PrivateKernelResetFullInnerArtifact':
|
|
43
|
-
return 'private-kernel-reset-full-inner';
|
|
44
|
-
case 'PrivateKernelResetBigArtifact':
|
|
45
|
-
return 'private-kernel-reset-big';
|
|
46
|
-
case 'PrivateKernelResetMediumArtifact':
|
|
47
|
-
return 'private-kernel-reset-medium';
|
|
48
|
-
case 'PrivateKernelResetSmallArtifact':
|
|
49
|
-
return 'private-kernel-reset-small';
|
|
50
|
-
case 'PrivateKernelResetTinyArtifact':
|
|
51
|
-
return 'private-kernel-reset-tiny';
|
|
52
38
|
case 'EmptyNestedArtifact':
|
|
53
39
|
return 'empty-nested';
|
|
54
40
|
case 'PrivateKernelEmptyArtifact':
|
|
55
41
|
return 'private-kernel-empty';
|
|
56
42
|
default: {
|
|
57
|
-
|
|
43
|
+
if (artifact.startsWith('PrivateKernelReset')) {
|
|
44
|
+
return 'private-kernel-reset';
|
|
45
|
+
}
|
|
58
46
|
throw new Error(`Unknown circuit type: ${artifact}`);
|
|
59
47
|
}
|
|
60
48
|
}
|
package/src/test/index.ts
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AztecAddress,
|
|
3
|
+
ContractStorageRead,
|
|
4
|
+
ContractStorageUpdateRequest,
|
|
5
|
+
Gas,
|
|
6
|
+
GlobalVariables,
|
|
7
|
+
Header,
|
|
8
|
+
L2ToL1Message,
|
|
9
|
+
LogHash,
|
|
10
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
11
|
+
MAX_L2_TO_L1_MSGS_PER_CALL,
|
|
12
|
+
MAX_NOTE_HASHES_PER_CALL,
|
|
13
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
14
|
+
MAX_NULLIFIERS_PER_CALL,
|
|
15
|
+
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
16
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
17
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
18
|
+
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
19
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
20
|
+
MAX_UNENCRYPTED_LOGS_PER_CALL,
|
|
21
|
+
NoteHash,
|
|
22
|
+
Nullifier,
|
|
23
|
+
PublicCircuitPublicInputs,
|
|
24
|
+
PublicInnerCallRequest,
|
|
25
|
+
ReadRequest,
|
|
26
|
+
RevertCode,
|
|
27
|
+
TreeLeafReadRequest,
|
|
28
|
+
} from '@aztec/circuits.js';
|
|
29
|
+
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
30
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
31
|
+
import { type PublicExecutionResult } from '@aztec/simulator';
|
|
32
|
+
|
|
33
|
+
// TODO: pub somewhere more usable - copied from abstract phase manager
|
|
34
|
+
export function getPublicInputs(result: PublicExecutionResult): PublicCircuitPublicInputs {
|
|
35
|
+
return PublicCircuitPublicInputs.from({
|
|
36
|
+
callContext: result.executionRequest.callContext,
|
|
37
|
+
proverAddress: AztecAddress.ZERO,
|
|
38
|
+
argsHash: computeVarArgsHash(result.executionRequest.args),
|
|
39
|
+
noteHashes: padArrayEnd(result.noteHashes, NoteHash.empty(), MAX_NOTE_HASHES_PER_CALL),
|
|
40
|
+
nullifiers: padArrayEnd(result.nullifiers, Nullifier.empty(), MAX_NULLIFIERS_PER_CALL),
|
|
41
|
+
l2ToL1Msgs: padArrayEnd(result.l2ToL1Messages, L2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_CALL),
|
|
42
|
+
startSideEffectCounter: result.startSideEffectCounter,
|
|
43
|
+
endSideEffectCounter: result.endSideEffectCounter,
|
|
44
|
+
returnsHash: computeVarArgsHash(result.returnValues),
|
|
45
|
+
noteHashReadRequests: padArrayEnd(
|
|
46
|
+
result.noteHashReadRequests,
|
|
47
|
+
TreeLeafReadRequest.empty(),
|
|
48
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
49
|
+
),
|
|
50
|
+
nullifierReadRequests: padArrayEnd(
|
|
51
|
+
result.nullifierReadRequests,
|
|
52
|
+
ReadRequest.empty(),
|
|
53
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
54
|
+
),
|
|
55
|
+
nullifierNonExistentReadRequests: padArrayEnd(
|
|
56
|
+
result.nullifierNonExistentReadRequests,
|
|
57
|
+
ReadRequest.empty(),
|
|
58
|
+
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
59
|
+
),
|
|
60
|
+
l1ToL2MsgReadRequests: padArrayEnd(
|
|
61
|
+
result.l1ToL2MsgReadRequests,
|
|
62
|
+
TreeLeafReadRequest.empty(),
|
|
63
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
64
|
+
),
|
|
65
|
+
contractStorageReads: padArrayEnd(
|
|
66
|
+
result.contractStorageReads,
|
|
67
|
+
ContractStorageRead.empty(),
|
|
68
|
+
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
69
|
+
),
|
|
70
|
+
contractStorageUpdateRequests: padArrayEnd(
|
|
71
|
+
result.contractStorageUpdateRequests,
|
|
72
|
+
ContractStorageUpdateRequest.empty(),
|
|
73
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
74
|
+
),
|
|
75
|
+
publicCallRequests: padArrayEnd([], PublicInnerCallRequest.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL),
|
|
76
|
+
unencryptedLogsHashes: padArrayEnd(result.unencryptedLogsHashes, LogHash.empty(), MAX_UNENCRYPTED_LOGS_PER_CALL),
|
|
77
|
+
historicalHeader: Header.empty(),
|
|
78
|
+
globalVariables: GlobalVariables.empty(),
|
|
79
|
+
startGasLeft: Gas.from(result.startGasLeft),
|
|
80
|
+
endGasLeft: Gas.from(result.endGasLeft),
|
|
81
|
+
transactionFee: result.transactionFee,
|
|
82
|
+
// TODO(@just-mitch): need better mapping from simulator to revert code.
|
|
83
|
+
revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AvmProofAndVerificationKey,
|
|
3
3
|
type PublicInputsAndRecursiveProof,
|
|
4
|
-
type PublicKernelNonTailRequest,
|
|
5
|
-
type PublicKernelTailRequest,
|
|
6
4
|
type ServerCircuitProver,
|
|
7
5
|
makePublicInputsAndRecursiveProof,
|
|
8
6
|
} from '@aztec/circuit-types';
|
|
@@ -15,6 +13,7 @@ import {
|
|
|
15
13
|
type BlockMergeRollupInputs,
|
|
16
14
|
type BlockRootOrBlockMergePublicInputs,
|
|
17
15
|
type BlockRootRollupInputs,
|
|
16
|
+
type EmptyBlockRootRollupInputs,
|
|
18
17
|
EmptyNestedData,
|
|
19
18
|
type KernelCircuitPublicInputs,
|
|
20
19
|
type MergeRollupInputs,
|
|
@@ -22,7 +21,10 @@ import {
|
|
|
22
21
|
type PrivateKernelEmptyInputData,
|
|
23
22
|
PrivateKernelEmptyInputs,
|
|
24
23
|
type Proof,
|
|
24
|
+
type PublicKernelCircuitPrivateInputs,
|
|
25
25
|
type PublicKernelCircuitPublicInputs,
|
|
26
|
+
type PublicKernelInnerCircuitPrivateInputs,
|
|
27
|
+
type PublicKernelTailCircuitPrivateInputs,
|
|
26
28
|
RECURSIVE_PROOF_LENGTH,
|
|
27
29
|
type RecursiveProof,
|
|
28
30
|
RootParityInput,
|
|
@@ -31,6 +33,7 @@ import {
|
|
|
31
33
|
type RootRollupPublicInputs,
|
|
32
34
|
TUBE_PROOF_LENGTH,
|
|
33
35
|
type TubeInputs,
|
|
36
|
+
type VMCircuitPublicInputs,
|
|
34
37
|
VerificationKeyData,
|
|
35
38
|
makeEmptyProof,
|
|
36
39
|
makeEmptyRecursiveProof,
|
|
@@ -50,6 +53,8 @@ import {
|
|
|
50
53
|
convertBlockMergeRollupOutputsFromWitnessMap,
|
|
51
54
|
convertBlockRootRollupInputsToWitnessMap,
|
|
52
55
|
convertBlockRootRollupOutputsFromWitnessMap,
|
|
56
|
+
convertEmptyBlockRootRollupInputsToWitnessMap,
|
|
57
|
+
convertEmptyBlockRootRollupOutputsFromWitnessMap,
|
|
53
58
|
convertMergeRollupInputsToWitnessMap,
|
|
54
59
|
convertMergeRollupOutputsFromWitnessMap,
|
|
55
60
|
convertPrivateKernelEmptyInputsToWitnessMap,
|
|
@@ -61,6 +66,10 @@ import {
|
|
|
61
66
|
convertSimulatedBaseRollupInputsToWitnessMap,
|
|
62
67
|
convertSimulatedBaseRollupOutputsFromWitnessMap,
|
|
63
68
|
convertSimulatedPrivateKernelEmptyOutputsFromWitnessMap,
|
|
69
|
+
convertSimulatedPublicInnerInputsToWitnessMap,
|
|
70
|
+
convertSimulatedPublicInnerOutputFromWitnessMap,
|
|
71
|
+
convertSimulatedPublicMergeInputsToWitnessMap,
|
|
72
|
+
convertSimulatedPublicMergeOutputFromWitnessMap,
|
|
64
73
|
convertSimulatedPublicTailInputsToWitnessMap,
|
|
65
74
|
convertSimulatedPublicTailOutputFromWitnessMap,
|
|
66
75
|
getVKSiblingPath,
|
|
@@ -69,8 +78,7 @@ import { type SimulationProvider, WASMSimulator, emitCircuitSimulationStats } fr
|
|
|
69
78
|
import { type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
70
79
|
|
|
71
80
|
import { ProverInstrumentation } from '../instrumentation.js';
|
|
72
|
-
import {
|
|
73
|
-
import { mapPublicKernelToCircuitName } from '../stats.js';
|
|
81
|
+
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
74
82
|
|
|
75
83
|
/**
|
|
76
84
|
* A class for use in testing situations (e2e, unit test, etc) and temporarily for assembling a block in the sequencer.
|
|
@@ -342,6 +350,41 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
342
350
|
);
|
|
343
351
|
}
|
|
344
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Simulates the empty block root rollup circuit from its inputs.
|
|
355
|
+
* @param input - Inputs to the circuit.
|
|
356
|
+
* @returns The public inputs as outputs of the simulation.
|
|
357
|
+
*/
|
|
358
|
+
@trackSpan('TestCircuitProver.getEmptyBlockRootRollupProof')
|
|
359
|
+
public async getEmptyBlockRootRollupProof(
|
|
360
|
+
input: EmptyBlockRootRollupInputs,
|
|
361
|
+
): Promise<PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs>> {
|
|
362
|
+
const timer = new Timer();
|
|
363
|
+
const witnessMap = convertEmptyBlockRootRollupInputsToWitnessMap(input);
|
|
364
|
+
|
|
365
|
+
// use WASM here as it is faster for small circuits
|
|
366
|
+
const witness = await this.wasmSimulator.simulateCircuit(
|
|
367
|
+
witnessMap,
|
|
368
|
+
SimulatedServerCircuitArtifacts.EmptyBlockRootRollupArtifact,
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
const result = convertEmptyBlockRootRollupOutputsFromWitnessMap(witness);
|
|
372
|
+
|
|
373
|
+
this.instrumentation.recordDuration('simulationDuration', 'empty-block-root-rollup', timer);
|
|
374
|
+
emitCircuitSimulationStats(
|
|
375
|
+
'empty-block-root-rollup',
|
|
376
|
+
timer.ms(),
|
|
377
|
+
input.toBuffer().length,
|
|
378
|
+
result.toBuffer().length,
|
|
379
|
+
this.logger,
|
|
380
|
+
);
|
|
381
|
+
return makePublicInputsAndRecursiveProof(
|
|
382
|
+
result,
|
|
383
|
+
makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
|
|
384
|
+
ProtocolCircuitVks['EmptyBlockRootRollupArtifact'],
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
345
388
|
/**
|
|
346
389
|
* Simulates the block merge rollup circuit from its inputs.
|
|
347
390
|
* @param input - Inputs to the circuit.
|
|
@@ -413,29 +456,53 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
413
456
|
);
|
|
414
457
|
}
|
|
415
458
|
|
|
416
|
-
@trackSpan('TestCircuitProver.
|
|
417
|
-
public async
|
|
418
|
-
|
|
419
|
-
): Promise<PublicInputsAndRecursiveProof<
|
|
459
|
+
@trackSpan('TestCircuitProver.getPublicKernelInnerProof')
|
|
460
|
+
public async getPublicKernelInnerProof(
|
|
461
|
+
inputs: PublicKernelInnerCircuitPrivateInputs,
|
|
462
|
+
): Promise<PublicInputsAndRecursiveProof<VMCircuitPublicInputs>> {
|
|
420
463
|
const timer = new Timer();
|
|
421
|
-
const kernelOps = SimulatedPublicKernelArtifactMapping[kernelRequest.type];
|
|
422
|
-
if (kernelOps === undefined) {
|
|
423
|
-
throw new Error(`Unable to prove for kernel type ${kernelRequest.type}`);
|
|
424
|
-
}
|
|
425
|
-
const witnessMap = kernelOps.convertInputs(kernelRequest.inputs);
|
|
426
464
|
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
465
|
+
const artifact = 'PublicKernelInnerArtifact';
|
|
466
|
+
const circuitName = mapProtocolArtifactNameToCircuitName(artifact);
|
|
467
|
+
|
|
468
|
+
const witnessMap = convertSimulatedPublicInnerInputsToWitnessMap(inputs);
|
|
469
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, SimulatedServerCircuitArtifacts[artifact]);
|
|
470
|
+
|
|
471
|
+
const result = convertSimulatedPublicInnerOutputFromWitnessMap(witness);
|
|
472
|
+
this.instrumentation.recordDuration('simulationDuration', circuitName, timer);
|
|
473
|
+
emitCircuitSimulationStats(
|
|
474
|
+
circuitName,
|
|
475
|
+
timer.ms(),
|
|
476
|
+
inputs.toBuffer().length,
|
|
477
|
+
result.toBuffer().length,
|
|
478
|
+
this.logger,
|
|
430
479
|
);
|
|
480
|
+
await this.delay();
|
|
481
|
+
return makePublicInputsAndRecursiveProof(
|
|
482
|
+
result,
|
|
483
|
+
makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
|
|
484
|
+
ProtocolCircuitVks[artifact],
|
|
485
|
+
);
|
|
486
|
+
}
|
|
431
487
|
|
|
432
|
-
|
|
433
|
-
|
|
488
|
+
@trackSpan('TestCircuitProver.getPublicKernelMergeProof')
|
|
489
|
+
public async getPublicKernelMergeProof(
|
|
490
|
+
inputs: PublicKernelCircuitPrivateInputs,
|
|
491
|
+
): Promise<PublicInputsAndRecursiveProof<PublicKernelCircuitPublicInputs>> {
|
|
492
|
+
const timer = new Timer();
|
|
493
|
+
|
|
494
|
+
const artifact = 'PublicKernelMergeArtifact';
|
|
495
|
+
const circuitName = mapProtocolArtifactNameToCircuitName(artifact);
|
|
496
|
+
|
|
497
|
+
const witnessMap = convertSimulatedPublicMergeInputsToWitnessMap(inputs);
|
|
498
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, SimulatedServerCircuitArtifacts[artifact]);
|
|
499
|
+
|
|
500
|
+
const result = convertSimulatedPublicMergeOutputFromWitnessMap(witness);
|
|
434
501
|
this.instrumentation.recordDuration('simulationDuration', circuitName, timer);
|
|
435
502
|
emitCircuitSimulationStats(
|
|
436
503
|
circuitName,
|
|
437
504
|
timer.ms(),
|
|
438
|
-
|
|
505
|
+
inputs.toBuffer().length,
|
|
439
506
|
result.toBuffer().length,
|
|
440
507
|
this.logger,
|
|
441
508
|
);
|
|
@@ -443,28 +510,29 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
443
510
|
return makePublicInputsAndRecursiveProof(
|
|
444
511
|
result,
|
|
445
512
|
makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
|
|
446
|
-
ProtocolCircuitVks[
|
|
513
|
+
ProtocolCircuitVks[artifact],
|
|
447
514
|
);
|
|
448
515
|
}
|
|
449
516
|
|
|
450
517
|
@trackSpan('TestCircuitProver.getPublicTailProof')
|
|
451
518
|
public async getPublicTailProof(
|
|
452
|
-
|
|
519
|
+
inputs: PublicKernelTailCircuitPrivateInputs,
|
|
453
520
|
): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
|
|
454
521
|
const timer = new Timer();
|
|
455
|
-
|
|
522
|
+
|
|
523
|
+
const artifact = 'PublicKernelTailArtifact';
|
|
524
|
+
const circuitName = mapProtocolArtifactNameToCircuitName(artifact);
|
|
525
|
+
|
|
526
|
+
const witnessMap = convertSimulatedPublicTailInputsToWitnessMap(inputs);
|
|
456
527
|
// use WASM here as it is faster for small circuits
|
|
457
|
-
const witness = await this.wasmSimulator.simulateCircuit(
|
|
458
|
-
witnessMap,
|
|
459
|
-
SimulatedServerCircuitArtifacts['PublicKernelTailArtifact'],
|
|
460
|
-
);
|
|
528
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, SimulatedServerCircuitArtifacts[artifact]);
|
|
461
529
|
|
|
462
530
|
const result = convertSimulatedPublicTailOutputFromWitnessMap(witness);
|
|
463
|
-
this.instrumentation.recordDuration('simulationDuration',
|
|
531
|
+
this.instrumentation.recordDuration('simulationDuration', circuitName, timer);
|
|
464
532
|
emitCircuitSimulationStats(
|
|
465
|
-
|
|
533
|
+
circuitName,
|
|
466
534
|
timer.ms(),
|
|
467
|
-
|
|
535
|
+
inputs.toBuffer().length,
|
|
468
536
|
result.toBuffer().length,
|
|
469
537
|
this.logger,
|
|
470
538
|
);
|
|
@@ -472,7 +540,7 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
472
540
|
return makePublicInputsAndRecursiveProof(
|
|
473
541
|
result,
|
|
474
542
|
makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
|
|
475
|
-
ProtocolCircuitVks[
|
|
543
|
+
ProtocolCircuitVks[artifact],
|
|
476
544
|
);
|
|
477
545
|
}
|
|
478
546
|
|