@aztec/bb-prover 0.39.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/cli.d.ts +9 -0
- package/dest/bb/cli.d.ts.map +1 -0
- package/dest/bb/cli.js +64 -0
- package/dest/bb/execute.d.ts +88 -0
- package/dest/bb/execute.d.ts.map +1 -0
- package/dest/bb/execute.js +288 -0
- package/dest/bb/index.d.ts +3 -0
- package/dest/bb/index.d.ts.map +1 -0
- package/dest/bb/index.js +18 -0
- package/dest/index.d.ts +3 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +3 -0
- package/dest/mappings/mappings.d.ts +12 -0
- package/dest/mappings/mappings.d.ts.map +1 -0
- package/dest/mappings/mappings.js +22 -0
- package/dest/prover/bb_native_proof_creator.d.ts +58 -0
- package/dest/prover/bb_native_proof_creator.d.ts.map +1 -0
- package/dest/prover/bb_native_proof_creator.js +238 -0
- package/dest/prover/bb_prover.d.ts +110 -0
- package/dest/prover/bb_prover.d.ts.map +1 -0
- package/dest/prover/bb_prover.js +321 -0
- package/dest/prover/index.d.ts +3 -0
- package/dest/prover/index.d.ts.map +1 -0
- package/dest/prover/index.js +3 -0
- package/dest/prover/verification_key_data.d.ts +16 -0
- package/dest/prover/verification_key_data.d.ts.map +1 -0
- package/dest/prover/verification_key_data.js +5 -0
- package/dest/stats.d.ts +9 -0
- package/dest/stats.d.ts.map +1 -0
- package/dest/stats.js +61 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +2 -0
- package/dest/test/test_circuit_prover.d.ts +48 -0
- package/dest/test/test_circuit_prover.d.ts.map +1 -0
- package/dest/test/test_circuit_prover.js +128 -0
- package/package.json +85 -0
- package/src/bb/cli.ts +92 -0
- package/src/bb/execute.ts +359 -0
- package/src/bb/index.ts +23 -0
- package/src/index.ts +2 -0
- package/src/mappings/mappings.ts +41 -0
- package/src/prover/bb_native_proof_creator.ts +382 -0
- package/src/prover/bb_prover.ts +557 -0
- package/src/prover/index.ts +2 -0
- package/src/prover/verification_key_data.ts +16 -0
- package/src/stats.ts +82 -0
- package/src/test/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +268 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PublicInputsAndProof,
|
|
3
|
+
type PublicKernelNonTailRequest,
|
|
4
|
+
type PublicKernelTailRequest,
|
|
5
|
+
PublicKernelType,
|
|
6
|
+
type ServerCircuitProver,
|
|
7
|
+
makePublicInputsAndProof,
|
|
8
|
+
} from '@aztec/circuit-types';
|
|
9
|
+
import {
|
|
10
|
+
type BaseOrMergeRollupPublicInputs,
|
|
11
|
+
type BaseParityInputs,
|
|
12
|
+
type BaseRollupInputs,
|
|
13
|
+
type KernelCircuitPublicInputs,
|
|
14
|
+
type MergeRollupInputs,
|
|
15
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
16
|
+
type Proof,
|
|
17
|
+
type PublicKernelCircuitPublicInputs,
|
|
18
|
+
RECURSIVE_PROOF_LENGTH,
|
|
19
|
+
RootParityInput,
|
|
20
|
+
type RootParityInputs,
|
|
21
|
+
type RootRollupInputs,
|
|
22
|
+
type RootRollupPublicInputs,
|
|
23
|
+
VerificationKeyAsFields,
|
|
24
|
+
makeEmptyProof,
|
|
25
|
+
makeRecursiveProof,
|
|
26
|
+
} from '@aztec/circuits.js';
|
|
27
|
+
import { createDebugLogger } from '@aztec/foundation/log';
|
|
28
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
29
|
+
import {
|
|
30
|
+
BaseParityArtifact,
|
|
31
|
+
MergeRollupArtifact,
|
|
32
|
+
RootParityArtifact,
|
|
33
|
+
RootRollupArtifact,
|
|
34
|
+
ServerCircuitArtifacts,
|
|
35
|
+
type ServerProtocolArtifact,
|
|
36
|
+
SimulatedBaseRollupArtifact,
|
|
37
|
+
convertBaseParityInputsToWitnessMap,
|
|
38
|
+
convertBaseParityOutputsFromWitnessMap,
|
|
39
|
+
convertMergeRollupInputsToWitnessMap,
|
|
40
|
+
convertMergeRollupOutputsFromWitnessMap,
|
|
41
|
+
convertPublicTailInputsToWitnessMap,
|
|
42
|
+
convertPublicTailOutputFromWitnessMap,
|
|
43
|
+
convertRootParityInputsToWitnessMap,
|
|
44
|
+
convertRootParityOutputsFromWitnessMap,
|
|
45
|
+
convertRootRollupInputsToWitnessMap,
|
|
46
|
+
convertRootRollupOutputsFromWitnessMap,
|
|
47
|
+
convertSimulatedBaseRollupInputsToWitnessMap,
|
|
48
|
+
convertSimulatedBaseRollupOutputsFromWitnessMap,
|
|
49
|
+
} from '@aztec/noir-protocol-circuits-types';
|
|
50
|
+
import { type SimulationProvider, WASMSimulator, emitCircuitSimulationStats } from '@aztec/simulator';
|
|
51
|
+
|
|
52
|
+
import { PublicKernelArtifactMapping } from '../mappings/mappings.js';
|
|
53
|
+
import { mapPublicKernelToCircuitName } from '../stats.js';
|
|
54
|
+
|
|
55
|
+
const VERIFICATION_KEYS: Record<ServerProtocolArtifact, VerificationKeyAsFields> = {
|
|
56
|
+
BaseParityArtifact: VerificationKeyAsFields.makeFake(),
|
|
57
|
+
RootParityArtifact: VerificationKeyAsFields.makeFake(),
|
|
58
|
+
PublicKernelAppLogicArtifact: VerificationKeyAsFields.makeFake(),
|
|
59
|
+
PublicKernelSetupArtifact: VerificationKeyAsFields.makeFake(),
|
|
60
|
+
PublicKernelTailArtifact: VerificationKeyAsFields.makeFake(),
|
|
61
|
+
PublicKernelTeardownArtifact: VerificationKeyAsFields.makeFake(),
|
|
62
|
+
BaseRollupArtifact: VerificationKeyAsFields.makeFake(),
|
|
63
|
+
MergeRollupArtifact: VerificationKeyAsFields.makeFake(),
|
|
64
|
+
RootRollupArtifact: VerificationKeyAsFields.makeFake(),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A class for use in testing situations (e2e, unit test etc)
|
|
69
|
+
* Simulates circuits using the most efficient method and performs no proving
|
|
70
|
+
*/
|
|
71
|
+
export class TestCircuitProver implements ServerCircuitProver {
|
|
72
|
+
private wasmSimulator = new WASMSimulator();
|
|
73
|
+
|
|
74
|
+
constructor(
|
|
75
|
+
private simulationProvider?: SimulationProvider,
|
|
76
|
+
private logger = createDebugLogger('aztec:test-prover'),
|
|
77
|
+
) {}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Simulates the base parity circuit from its inputs.
|
|
81
|
+
* @param inputs - Inputs to the circuit.
|
|
82
|
+
* @returns The public inputs of the parity circuit.
|
|
83
|
+
*/
|
|
84
|
+
public async getBaseParityProof(inputs: BaseParityInputs): Promise<RootParityInput<typeof RECURSIVE_PROOF_LENGTH>> {
|
|
85
|
+
const timer = new Timer();
|
|
86
|
+
const witnessMap = convertBaseParityInputsToWitnessMap(inputs);
|
|
87
|
+
|
|
88
|
+
// use WASM here as it is faster for small circuits
|
|
89
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, BaseParityArtifact);
|
|
90
|
+
const result = convertBaseParityOutputsFromWitnessMap(witness);
|
|
91
|
+
|
|
92
|
+
const rootParityInput = new RootParityInput<typeof RECURSIVE_PROOF_LENGTH>(
|
|
93
|
+
makeRecursiveProof<typeof RECURSIVE_PROOF_LENGTH>(RECURSIVE_PROOF_LENGTH),
|
|
94
|
+
VERIFICATION_KEYS['BaseParityArtifact'],
|
|
95
|
+
result,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
emitCircuitSimulationStats(
|
|
99
|
+
'base-parity',
|
|
100
|
+
timer.ms(),
|
|
101
|
+
inputs.toBuffer().length,
|
|
102
|
+
result.toBuffer().length,
|
|
103
|
+
this.logger,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return Promise.resolve(rootParityInput);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Simulates the root parity circuit from its inputs.
|
|
111
|
+
* @param inputs - Inputs to the circuit.
|
|
112
|
+
* @returns The public inputs of the parity circuit.
|
|
113
|
+
*/
|
|
114
|
+
public async getRootParityProof(
|
|
115
|
+
inputs: RootParityInputs,
|
|
116
|
+
): Promise<RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH>> {
|
|
117
|
+
const timer = new Timer();
|
|
118
|
+
const witnessMap = convertRootParityInputsToWitnessMap(inputs);
|
|
119
|
+
|
|
120
|
+
// use WASM here as it is faster for small circuits
|
|
121
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, RootParityArtifact);
|
|
122
|
+
|
|
123
|
+
const result = convertRootParityOutputsFromWitnessMap(witness);
|
|
124
|
+
|
|
125
|
+
const rootParityInput = new RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH>(
|
|
126
|
+
makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH),
|
|
127
|
+
VERIFICATION_KEYS['RootParityArtifact'],
|
|
128
|
+
result,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
emitCircuitSimulationStats(
|
|
132
|
+
'root-parity',
|
|
133
|
+
timer.ms(),
|
|
134
|
+
inputs.toBuffer().length,
|
|
135
|
+
result.toBuffer().length,
|
|
136
|
+
this.logger,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return Promise.resolve(rootParityInput);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Simulates the base rollup circuit from its inputs.
|
|
144
|
+
* @param input - Inputs to the circuit.
|
|
145
|
+
* @returns The public inputs as outputs of the simulation.
|
|
146
|
+
*/
|
|
147
|
+
public async getBaseRollupProof(
|
|
148
|
+
input: BaseRollupInputs,
|
|
149
|
+
): Promise<PublicInputsAndProof<BaseOrMergeRollupPublicInputs>> {
|
|
150
|
+
const timer = new Timer();
|
|
151
|
+
const witnessMap = convertSimulatedBaseRollupInputsToWitnessMap(input);
|
|
152
|
+
|
|
153
|
+
const simulationProvider = this.simulationProvider ?? this.wasmSimulator;
|
|
154
|
+
const witness = await simulationProvider.simulateCircuit(witnessMap, SimulatedBaseRollupArtifact);
|
|
155
|
+
|
|
156
|
+
const result = convertSimulatedBaseRollupOutputsFromWitnessMap(witness);
|
|
157
|
+
|
|
158
|
+
emitCircuitSimulationStats(
|
|
159
|
+
'base-rollup',
|
|
160
|
+
timer.ms(),
|
|
161
|
+
input.toBuffer().length,
|
|
162
|
+
result.toBuffer().length,
|
|
163
|
+
this.logger,
|
|
164
|
+
);
|
|
165
|
+
return makePublicInputsAndProof(result, makeEmptyProof());
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Simulates the merge rollup circuit from its inputs.
|
|
169
|
+
* @param input - Inputs to the circuit.
|
|
170
|
+
* @returns The public inputs as outputs of the simulation.
|
|
171
|
+
*/
|
|
172
|
+
public async getMergeRollupProof(
|
|
173
|
+
input: MergeRollupInputs,
|
|
174
|
+
): Promise<PublicInputsAndProof<BaseOrMergeRollupPublicInputs>> {
|
|
175
|
+
const timer = new Timer();
|
|
176
|
+
const witnessMap = convertMergeRollupInputsToWitnessMap(input);
|
|
177
|
+
|
|
178
|
+
// use WASM here as it is faster for small circuits
|
|
179
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, MergeRollupArtifact);
|
|
180
|
+
|
|
181
|
+
const result = convertMergeRollupOutputsFromWitnessMap(witness);
|
|
182
|
+
|
|
183
|
+
emitCircuitSimulationStats(
|
|
184
|
+
'merge-rollup',
|
|
185
|
+
timer.ms(),
|
|
186
|
+
input.toBuffer().length,
|
|
187
|
+
result.toBuffer().length,
|
|
188
|
+
this.logger,
|
|
189
|
+
);
|
|
190
|
+
return makePublicInputsAndProof(result, makeEmptyProof());
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Simulates the root rollup circuit from its inputs.
|
|
195
|
+
* @param input - Inputs to the circuit.
|
|
196
|
+
* @returns The public inputs as outputs of the simulation.
|
|
197
|
+
*/
|
|
198
|
+
public async getRootRollupProof(input: RootRollupInputs): Promise<PublicInputsAndProof<RootRollupPublicInputs>> {
|
|
199
|
+
const timer = new Timer();
|
|
200
|
+
const witnessMap = convertRootRollupInputsToWitnessMap(input);
|
|
201
|
+
|
|
202
|
+
// use WASM here as it is faster for small circuits
|
|
203
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, RootRollupArtifact);
|
|
204
|
+
|
|
205
|
+
const result = convertRootRollupOutputsFromWitnessMap(witness);
|
|
206
|
+
|
|
207
|
+
emitCircuitSimulationStats(
|
|
208
|
+
'root-rollup',
|
|
209
|
+
timer.ms(),
|
|
210
|
+
input.toBuffer().length,
|
|
211
|
+
result.toBuffer().length,
|
|
212
|
+
this.logger,
|
|
213
|
+
);
|
|
214
|
+
return makePublicInputsAndProof(result, makeEmptyProof());
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public async getPublicKernelProof(
|
|
218
|
+
kernelRequest: PublicKernelNonTailRequest,
|
|
219
|
+
): Promise<PublicInputsAndProof<PublicKernelCircuitPublicInputs>> {
|
|
220
|
+
const timer = new Timer();
|
|
221
|
+
const kernelOps = PublicKernelArtifactMapping[kernelRequest.type];
|
|
222
|
+
if (kernelOps === undefined) {
|
|
223
|
+
throw new Error(`Unable to prove for kernel type ${PublicKernelType[kernelRequest.type]}`);
|
|
224
|
+
}
|
|
225
|
+
const witnessMap = kernelOps.convertInputs(kernelRequest.inputs);
|
|
226
|
+
|
|
227
|
+
const witness = await this.wasmSimulator.simulateCircuit(witnessMap, ServerCircuitArtifacts[kernelOps.artifact]);
|
|
228
|
+
|
|
229
|
+
const result = kernelOps.convertOutputs(witness);
|
|
230
|
+
emitCircuitSimulationStats(
|
|
231
|
+
mapPublicKernelToCircuitName(kernelRequest.type),
|
|
232
|
+
timer.ms(),
|
|
233
|
+
kernelRequest.inputs.toBuffer().length,
|
|
234
|
+
result.toBuffer().length,
|
|
235
|
+
this.logger,
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
return makePublicInputsAndProof(result, makeEmptyProof());
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public async getPublicTailProof(
|
|
242
|
+
kernelRequest: PublicKernelTailRequest,
|
|
243
|
+
): Promise<PublicInputsAndProof<KernelCircuitPublicInputs>> {
|
|
244
|
+
const timer = new Timer();
|
|
245
|
+
const witnessMap = convertPublicTailInputsToWitnessMap(kernelRequest.inputs);
|
|
246
|
+
// use WASM here as it is faster for small circuits
|
|
247
|
+
const witness = await this.wasmSimulator.simulateCircuit(
|
|
248
|
+
witnessMap,
|
|
249
|
+
ServerCircuitArtifacts['PublicKernelTailArtifact'],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const result = convertPublicTailOutputFromWitnessMap(witness);
|
|
253
|
+
emitCircuitSimulationStats(
|
|
254
|
+
'public-kernel-tail',
|
|
255
|
+
timer.ms(),
|
|
256
|
+
kernelRequest.inputs.toBuffer().length,
|
|
257
|
+
result.toBuffer().length,
|
|
258
|
+
this.logger,
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
return makePublicInputsAndProof(result, makeEmptyProof());
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Not implemented for test circuits
|
|
265
|
+
public verifyProof(_1: ServerProtocolArtifact, _2: Proof): Promise<void> {
|
|
266
|
+
return Promise.reject(new Error('Method not implemented.'));
|
|
267
|
+
}
|
|
268
|
+
}
|