@aztec/bb-prover 0.69.1 → 0.70.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 +3 -0
- package/dest/bb/cli.d.ts.map +1 -1
- package/dest/bb/cli.js +7 -2
- package/dest/bb/execute.d.ts +14 -3
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +108 -10
- package/dest/honk.d.ts +8 -8
- package/dest/honk.d.ts.map +1 -1
- package/dest/honk.js +2 -7
- package/dest/prover/bb_native_private_kernel_prover.d.ts +25 -0
- package/dest/prover/bb_native_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/bb_native_private_kernel_prover.js +69 -0
- package/dest/prover/bb_private_kernel_prover.d.ts +26 -41
- package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/bb_private_kernel_prover.js +62 -118
- package/dest/prover/bb_prover.d.ts +4 -6
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +13 -34
- package/dest/prover/index.d.ts +1 -1
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/prover/index.js +2 -2
- package/dest/stats.d.ts +3 -3
- package/dest/stats.d.ts.map +1 -1
- package/dest/stats.js +4 -7
- package/dest/test/test_avm.d.ts +1 -1
- package/dest/test/test_avm.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.d.ts +5 -5
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +13 -11
- package/dest/verifier/bb_verifier.d.ts +6 -6
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +5 -8
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +16 -0
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +1 -0
- package/dest/wasm/bb_wasm_private_kernel_prover.js +31 -0
- package/dest/wasm/bundle.d.ts +6 -0
- package/dest/wasm/bundle.d.ts.map +1 -0
- package/dest/wasm/bundle.js +9 -0
- package/dest/wasm/lazy.d.ts +6 -0
- package/dest/wasm/lazy.d.ts.map +1 -0
- package/dest/wasm/lazy.js +9 -0
- package/package.json +11 -10
- package/src/bb/cli.ts +9 -1
- package/src/bb/execute.ts +134 -11
- package/src/honk.ts +16 -21
- package/src/prover/bb_native_private_kernel_prover.ts +118 -0
- package/src/prover/bb_private_kernel_prover.ts +141 -202
- package/src/prover/bb_prover.ts +29 -77
- package/src/prover/index.ts +1 -1
- package/src/stats.ts +6 -11
- package/src/test/test_avm.ts +1 -1
- package/src/test/test_circuit_prover.ts +26 -41
- package/src/verifier/bb_verifier.ts +12 -15
- package/src/wasm/bb_wasm_private_kernel_prover.ts +42 -0
- package/src/wasm/bundle.ts +11 -0
- package/src/wasm/lazy.ts +11 -0
- package/dest/wasm/index.d.ts +0 -19
- package/dest/wasm/index.d.ts.map +0 -1
- package/dest/wasm/index.js +0 -74
- package/src/wasm/index.ts +0 -155
package/src/test/test_avm.ts
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
} from '@aztec/circuits.js';
|
|
29
29
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
30
30
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
31
|
-
import { type PublicFunctionCallResult } from '@aztec/simulator';
|
|
31
|
+
import { type PublicFunctionCallResult } from '@aztec/simulator/server';
|
|
32
32
|
|
|
33
33
|
// TODO: pub somewhere more usable - copied from abstract phase manager
|
|
34
34
|
export function getPublicInputs(result: PublicFunctionCallResult): PublicCircuitPublicInputs {
|
|
@@ -10,13 +10,9 @@ import {
|
|
|
10
10
|
AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS,
|
|
11
11
|
type AvmCircuitInputs,
|
|
12
12
|
type BaseParityInputs,
|
|
13
|
-
EmptyNestedData,
|
|
14
13
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
15
14
|
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
16
15
|
type ParityPublicInputs,
|
|
17
|
-
type PrivateKernelEmptyInputData,
|
|
18
|
-
PrivateKernelEmptyInputs,
|
|
19
|
-
type PrivateToRollupKernelCircuitPublicInputs,
|
|
20
16
|
type Proof,
|
|
21
17
|
RECURSIVE_PROOF_LENGTH,
|
|
22
18
|
type RootParityInputs,
|
|
@@ -36,13 +32,13 @@ import {
|
|
|
36
32
|
type PublicBaseRollupInputs,
|
|
37
33
|
type RootRollupInputs,
|
|
38
34
|
type RootRollupPublicInputs,
|
|
35
|
+
type SingleTxBlockRootRollupInputs,
|
|
39
36
|
type TubeInputs,
|
|
40
37
|
} from '@aztec/circuits.js/rollup';
|
|
41
38
|
import { createLogger } from '@aztec/foundation/log';
|
|
42
39
|
import { sleep } from '@aztec/foundation/sleep';
|
|
43
40
|
import { Timer } from '@aztec/foundation/timer';
|
|
44
41
|
import {
|
|
45
|
-
ProtocolCircuitVks,
|
|
46
42
|
type ServerProtocolArtifact,
|
|
47
43
|
SimulatedServerCircuitArtifacts,
|
|
48
44
|
convertBaseParityInputsToWitnessMap,
|
|
@@ -53,7 +49,6 @@ import {
|
|
|
53
49
|
convertEmptyBlockRootRollupOutputsFromWitnessMap,
|
|
54
50
|
convertMergeRollupInputsToWitnessMap,
|
|
55
51
|
convertMergeRollupOutputsFromWitnessMap,
|
|
56
|
-
convertPrivateKernelEmptyInputsToWitnessMap,
|
|
57
52
|
convertRootParityInputsToWitnessMap,
|
|
58
53
|
convertRootParityOutputsFromWitnessMap,
|
|
59
54
|
convertRootRollupInputsToWitnessMap,
|
|
@@ -62,11 +57,13 @@ import {
|
|
|
62
57
|
convertSimulatedBlockRootRollupOutputsFromWitnessMap,
|
|
63
58
|
convertSimulatedPrivateBaseRollupInputsToWitnessMap,
|
|
64
59
|
convertSimulatedPrivateBaseRollupOutputsFromWitnessMap,
|
|
65
|
-
convertSimulatedPrivateKernelEmptyOutputsFromWitnessMap,
|
|
66
60
|
convertSimulatedPublicBaseRollupInputsToWitnessMap,
|
|
67
61
|
convertSimulatedPublicBaseRollupOutputsFromWitnessMap,
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
convertSimulatedSingleTxBlockRootRollupInputsToWitnessMap,
|
|
63
|
+
convertSimulatedSingleTxBlockRootRollupOutputsFromWitnessMap,
|
|
64
|
+
} from '@aztec/noir-protocol-circuits-types/server';
|
|
65
|
+
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
|
|
66
|
+
import { type SimulationProvider, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator/server';
|
|
70
67
|
import { type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
71
68
|
|
|
72
69
|
import { type WitnessMap } from '@noir-lang/types';
|
|
@@ -95,36 +92,6 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
95
92
|
return this.instrumentation.tracer;
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
public async getEmptyPrivateKernelProof(
|
|
99
|
-
inputs: PrivateKernelEmptyInputData,
|
|
100
|
-
): Promise<
|
|
101
|
-
PublicInputsAndRecursiveProof<
|
|
102
|
-
PrivateToRollupKernelCircuitPublicInputs,
|
|
103
|
-
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
104
|
-
>
|
|
105
|
-
> {
|
|
106
|
-
const emptyNested = new EmptyNestedData(
|
|
107
|
-
makeRecursiveProof(NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH),
|
|
108
|
-
ProtocolCircuitVks['EmptyNestedArtifact'].keyAsFields,
|
|
109
|
-
);
|
|
110
|
-
const kernelInputs = new PrivateKernelEmptyInputs(
|
|
111
|
-
emptyNested,
|
|
112
|
-
inputs.header,
|
|
113
|
-
inputs.chainId,
|
|
114
|
-
inputs.version,
|
|
115
|
-
inputs.vkTreeRoot,
|
|
116
|
-
inputs.protocolContractTreeRoot,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
return await this.simulate(
|
|
120
|
-
kernelInputs,
|
|
121
|
-
'PrivateKernelEmptyArtifact',
|
|
122
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
123
|
-
convertPrivateKernelEmptyInputsToWitnessMap,
|
|
124
|
-
convertSimulatedPrivateKernelEmptyOutputsFromWitnessMap,
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
95
|
/**
|
|
129
96
|
* Simulates the base parity circuit from its inputs.
|
|
130
97
|
* @param inputs - Inputs to the circuit.
|
|
@@ -239,6 +206,21 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
239
206
|
);
|
|
240
207
|
}
|
|
241
208
|
|
|
209
|
+
@trackSpan('TestCircuitProver.getSingleTxBlockRootRollupProof')
|
|
210
|
+
public async getSingleTxBlockRootRollupProof(
|
|
211
|
+
input: SingleTxBlockRootRollupInputs,
|
|
212
|
+
): Promise<
|
|
213
|
+
PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
214
|
+
> {
|
|
215
|
+
return await this.simulate(
|
|
216
|
+
input,
|
|
217
|
+
'SingleTxBlockRootRollupArtifact',
|
|
218
|
+
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
219
|
+
convertSimulatedSingleTxBlockRootRollupInputsToWitnessMap,
|
|
220
|
+
convertSimulatedSingleTxBlockRootRollupOutputsFromWitnessMap,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
242
224
|
/**
|
|
243
225
|
* Simulates the empty block root rollup circuit from its inputs.
|
|
244
226
|
* @param input - Inputs to the circuit.
|
|
@@ -337,12 +319,15 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
337
319
|
const circuitName = mapProtocolArtifactNameToCircuitName(artifactName);
|
|
338
320
|
|
|
339
321
|
let simulationProvider = this.simulationProvider ?? this.wasmSimulator;
|
|
340
|
-
if (
|
|
322
|
+
if (['BlockRootRollupArtifact', 'SingleTxBlockRootRollupArtifact'].includes(artifactName)) {
|
|
341
323
|
// TODO(#10323): temporarily force block root to use wasm while we simulate
|
|
342
324
|
// the blob operations with an oracle. Appears to be no way to provide nativeACVM with a foreign call hander.
|
|
343
325
|
simulationProvider = this.wasmSimulator;
|
|
344
326
|
}
|
|
345
|
-
const witness = await simulationProvider.
|
|
327
|
+
const witness = await simulationProvider.executeProtocolCircuit(
|
|
328
|
+
witnessMap,
|
|
329
|
+
SimulatedServerCircuitArtifacts[artifactName],
|
|
330
|
+
);
|
|
346
331
|
|
|
347
332
|
const result = convertOutput(witness);
|
|
348
333
|
|
|
@@ -3,11 +3,12 @@ import { type CircuitVerificationStats } from '@aztec/circuit-types/stats';
|
|
|
3
3
|
import { type Proof, type VerificationKeyData } from '@aztec/circuits.js';
|
|
4
4
|
import { runInDirectory } from '@aztec/foundation/fs';
|
|
5
5
|
import { type LogFn, type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { ServerCircuitArtifacts } from '@aztec/noir-protocol-circuits-types/server';
|
|
6
7
|
import {
|
|
7
8
|
type ClientProtocolArtifact,
|
|
8
9
|
type ProtocolArtifact,
|
|
9
|
-
|
|
10
|
-
} from '@aztec/noir-protocol-circuits-types';
|
|
10
|
+
type ServerProtocolArtifact,
|
|
11
|
+
} from '@aztec/noir-protocol-circuits-types/types';
|
|
11
12
|
|
|
12
13
|
import { promises as fs } from 'fs';
|
|
13
14
|
import * as path from 'path';
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
verifyProof,
|
|
23
24
|
} from '../bb/execute.js';
|
|
24
25
|
import { type BBConfig } from '../config.js';
|
|
25
|
-
import { type
|
|
26
|
+
import { type UltraKeccakHonkServerProtocolArtifact, getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
26
27
|
import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js';
|
|
27
28
|
import { isProtocolArtifactRecursive, mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
28
29
|
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
@@ -36,7 +37,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
36
37
|
|
|
37
38
|
public static async new(
|
|
38
39
|
config: BBConfig,
|
|
39
|
-
initialCircuits:
|
|
40
|
+
initialCircuits: ServerProtocolArtifact[] = [],
|
|
40
41
|
logger = createLogger('bb-prover:verifier'),
|
|
41
42
|
) {
|
|
42
43
|
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
@@ -54,7 +55,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
private static async generateVerificationKey(
|
|
57
|
-
circuit:
|
|
58
|
+
circuit: ServerProtocolArtifact,
|
|
58
59
|
bbPath: string,
|
|
59
60
|
workingDirectory: string,
|
|
60
61
|
logFn: LogFn,
|
|
@@ -63,7 +64,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
63
64
|
bbPath,
|
|
64
65
|
workingDirectory,
|
|
65
66
|
circuit,
|
|
66
|
-
|
|
67
|
+
ServerCircuitArtifacts[circuit],
|
|
67
68
|
isProtocolArtifactRecursive(circuit),
|
|
68
69
|
getUltraHonkFlavorForCircuit(circuit),
|
|
69
70
|
logFn,
|
|
@@ -76,7 +77,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
public async getVerificationKeyData(circuit:
|
|
80
|
+
public async getVerificationKeyData(circuit: ServerProtocolArtifact) {
|
|
80
81
|
let promise = this.verificationKeys.get(circuit);
|
|
81
82
|
if (!promise) {
|
|
82
83
|
promise = BBCircuitVerifier.generateVerificationKey(
|
|
@@ -91,7 +92,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
91
92
|
return vk.clone();
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
public async verifyProofForCircuit(circuit:
|
|
95
|
+
public async verifyProofForCircuit(circuit: ServerProtocolArtifact, proof: Proof) {
|
|
95
96
|
const operation = async (bbWorkingDirectory: string) => {
|
|
96
97
|
const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
|
|
97
98
|
const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
|
|
@@ -102,16 +103,12 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
102
103
|
await fs.writeFile(proofFileName, proof.buffer);
|
|
103
104
|
await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
|
|
104
105
|
|
|
105
|
-
const logFunction = (message: string) => {
|
|
106
|
-
this.logger.debug(`${circuit} BB out - ${message}`);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
106
|
const result = await verifyProof(
|
|
110
107
|
this.config.bbBinaryPath,
|
|
111
108
|
proofFileName,
|
|
112
109
|
verificationKeyPath!,
|
|
113
110
|
getUltraHonkFlavorForCircuit(circuit),
|
|
114
|
-
|
|
111
|
+
this.logger,
|
|
115
112
|
);
|
|
116
113
|
|
|
117
114
|
if (result.status === BB_RESULT.FAILURE) {
|
|
@@ -129,12 +126,12 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
129
126
|
await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup);
|
|
130
127
|
}
|
|
131
128
|
|
|
132
|
-
public async generateSolidityContract(circuit:
|
|
129
|
+
public async generateSolidityContract(circuit: UltraKeccakHonkServerProtocolArtifact, contractName: string) {
|
|
133
130
|
const result = await generateContractForCircuit(
|
|
134
131
|
this.config.bbBinaryPath,
|
|
135
132
|
this.config.bbWorkingDirectory,
|
|
136
133
|
circuit,
|
|
137
|
-
|
|
134
|
+
ServerCircuitArtifacts[circuit],
|
|
138
135
|
contractName,
|
|
139
136
|
this.logger.debug,
|
|
140
137
|
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AztecClientBackend } from '@aztec/bb.js';
|
|
2
|
+
import { ClientIvcProof } from '@aztec/circuits.js';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
+
import { type ArtifactProvider } from '@aztec/noir-protocol-circuits-types/types';
|
|
6
|
+
import { type SimulationProvider } from '@aztec/simulator/client';
|
|
7
|
+
|
|
8
|
+
import { serializeWitness } from '@noir-lang/noirc_abi';
|
|
9
|
+
import { type WitnessMap } from '@noir-lang/types';
|
|
10
|
+
import { ungzip } from 'pako';
|
|
11
|
+
|
|
12
|
+
import { BBPrivateKernelProver } from '../prover/bb_private_kernel_prover.js';
|
|
13
|
+
|
|
14
|
+
export abstract class BBWASMPrivateKernelProver extends BBPrivateKernelProver {
|
|
15
|
+
constructor(
|
|
16
|
+
protected override artifactProvider: ArtifactProvider,
|
|
17
|
+
protected override simulationProvider: SimulationProvider,
|
|
18
|
+
private threads: number = 1,
|
|
19
|
+
protected override log = createLogger('bb-prover:wasm'),
|
|
20
|
+
) {
|
|
21
|
+
super(artifactProvider, simulationProvider, log);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public override async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
|
|
25
|
+
const timer = new Timer();
|
|
26
|
+
this.log.info(`Generating ClientIVC proof...`);
|
|
27
|
+
const backend = new AztecClientBackend(
|
|
28
|
+
acirs.map(acir => ungzip(acir)),
|
|
29
|
+
{ threads: this.threads },
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => ungzip(serializeWitness(witnessMap))));
|
|
33
|
+
await backend.destroy();
|
|
34
|
+
this.log.info(`Generated ClientIVC proof`, {
|
|
35
|
+
eventName: 'client-ivc-proof-generation',
|
|
36
|
+
duration: timer.ms(),
|
|
37
|
+
proofSize: proof.length,
|
|
38
|
+
vkSize: vk.length,
|
|
39
|
+
});
|
|
40
|
+
return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
|
|
3
|
+
import { type SimulationProvider } from '@aztec/simulator/client';
|
|
4
|
+
|
|
5
|
+
import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
|
|
6
|
+
|
|
7
|
+
export class BBWASMBundlePrivateKernelProver extends BBWASMPrivateKernelProver {
|
|
8
|
+
constructor(simulationProvider: SimulationProvider, threads = 1, log = createLogger('bb-prover:wasm:bundle')) {
|
|
9
|
+
super(new BundleArtifactProvider(), simulationProvider, threads, log);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/wasm/lazy.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
|
|
3
|
+
import { type SimulationProvider } from '@aztec/simulator/client';
|
|
4
|
+
|
|
5
|
+
import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
|
|
6
|
+
|
|
7
|
+
export class BBWASMLazyPrivateKernelProver extends BBWASMPrivateKernelProver {
|
|
8
|
+
constructor(simulationProvider: SimulationProvider, threads = 1, log = createLogger('bb-prover:wasm:lazy')) {
|
|
9
|
+
super(new LazyArtifactProvider(), simulationProvider, threads, log);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/dest/wasm/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types';
|
|
4
|
-
import { ClientIvcProof, type PrivateKernelCircuitPublicInputs, type PrivateKernelInitCircuitPrivateInputs, type PrivateKernelInnerCircuitPrivateInputs, type PrivateKernelResetCircuitPrivateInputs, type PrivateKernelTailCircuitPrivateInputs, type PrivateKernelTailCircuitPublicInputs } from '@aztec/circuits.js';
|
|
5
|
-
import { type WitnessMap } from '@noir-lang/noir_js';
|
|
6
|
-
export declare class BBWasmPrivateKernelProver implements PrivateKernelProver {
|
|
7
|
-
private threads;
|
|
8
|
-
private log;
|
|
9
|
-
private simulator;
|
|
10
|
-
constructor(threads?: number, log?: import("@aztec/foundation/log").Logger);
|
|
11
|
-
simulateProofInit(inputs: PrivateKernelInitCircuitPrivateInputs): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>>;
|
|
12
|
-
simulateProofInner(inputs: PrivateKernelInnerCircuitPrivateInputs): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>>;
|
|
13
|
-
simulateProofReset(inputs: PrivateKernelResetCircuitPrivateInputs): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>>;
|
|
14
|
-
simulateProofTail(inputs: PrivateKernelTailCircuitPrivateInputs): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>>;
|
|
15
|
-
private simulate;
|
|
16
|
-
createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof>;
|
|
17
|
-
computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dest/wasm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wasm/index.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,EACL,cAAc,EACd,KAAK,gCAAgC,EACrC,KAAK,qCAAqC,EAC1C,KAAK,sCAAsC,EAC3C,KAAK,sCAAsC,EAC3C,KAAK,qCAAqC,EAC1C,KAAK,oCAAoC,EAC1C,MAAM,oBAAoB,CAAC;AAsB5B,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,qBAAa,yBAA0B,YAAW,mBAAmB;IAGvD,OAAO,CAAC,OAAO;IAAc,OAAO,CAAC,GAAG;IAFpD,OAAO,CAAC,SAAS,CAAuB;gBAEpB,OAAO,GAAE,MAAU,EAAU,GAAG,yCAAiC;IAExE,iBAAiB,CAC5B,MAAM,EAAE,qCAAqC,GAC5C,OAAO,CAAC,2BAA2B,CAAC,gCAAgC,CAAC,CAAC;IAS5D,kBAAkB,CAC7B,MAAM,EAAE,sCAAsC,GAC7C,OAAO,CAAC,2BAA2B,CAAC,gCAAgC,CAAC,CAAC;IAS5D,kBAAkB,CAC7B,MAAM,EAAE,sCAAsC,GAC7C,OAAO,CAAC,2BAA2B,CAAC,gCAAgC,CAAC,CAAC;IAW5D,iBAAiB,CAC5B,MAAM,EAAE,qCAAqC,GAC5C,OAAO,CAAC,2BAA2B,CAAC,oCAAoC,CAAC,CAAC;YAiB/D,QAAQ;IAqChB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAmBhG,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGrF"}
|
package/dest/wasm/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { AztecClientBackend } from '@aztec/bb.js';
|
|
2
|
-
import { ClientIvcProof, } from '@aztec/circuits.js';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
-
import { ClientCircuitArtifacts, ClientCircuitVks, convertPrivateKernelInitInputsToWitnessMap, convertPrivateKernelInitOutputsFromWitnessMap, convertPrivateKernelInnerInputsToWitnessMap, convertPrivateKernelInnerOutputsFromWitnessMap, convertPrivateKernelResetInputsToWitnessMap, convertPrivateKernelResetOutputsFromWitnessMap, convertPrivateKernelTailForPublicOutputsFromWitnessMap, convertPrivateKernelTailInputsToWitnessMap, convertPrivateKernelTailOutputsFromWitnessMap, convertPrivateKernelTailToPublicInputsToWitnessMap, getPrivateKernelResetArtifactName, } from '@aztec/noir-protocol-circuits-types/client';
|
|
6
|
-
import { WASMSimulator } from '@aztec/simulator/client';
|
|
7
|
-
import { serializeWitness } from '@noir-lang/noirc_abi';
|
|
8
|
-
import { ungzip } from 'pako';
|
|
9
|
-
export class BBWasmPrivateKernelProver {
|
|
10
|
-
constructor(threads = 1, log = createLogger('bb-prover:wasm')) {
|
|
11
|
-
this.threads = threads;
|
|
12
|
-
this.log = log;
|
|
13
|
-
this.simulator = new WASMSimulator();
|
|
14
|
-
}
|
|
15
|
-
async simulateProofInit(inputs) {
|
|
16
|
-
return await this.simulate(inputs, 'PrivateKernelInitArtifact', convertPrivateKernelInitInputsToWitnessMap, convertPrivateKernelInitOutputsFromWitnessMap);
|
|
17
|
-
}
|
|
18
|
-
async simulateProofInner(inputs) {
|
|
19
|
-
return await this.simulate(inputs, 'PrivateKernelInnerArtifact', convertPrivateKernelInnerInputsToWitnessMap, convertPrivateKernelInnerOutputsFromWitnessMap);
|
|
20
|
-
}
|
|
21
|
-
async simulateProofReset(inputs) {
|
|
22
|
-
const variantInputs = inputs.trimToSizes();
|
|
23
|
-
const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
|
|
24
|
-
return await this.simulate(variantInputs, artifactName, variantInputs => convertPrivateKernelResetInputsToWitnessMap(variantInputs, artifactName), output => convertPrivateKernelResetOutputsFromWitnessMap(output, artifactName));
|
|
25
|
-
}
|
|
26
|
-
async simulateProofTail(inputs) {
|
|
27
|
-
if (!inputs.isForPublic()) {
|
|
28
|
-
return await this.simulate(inputs, 'PrivateKernelTailArtifact', convertPrivateKernelTailInputsToWitnessMap, convertPrivateKernelTailOutputsFromWitnessMap);
|
|
29
|
-
}
|
|
30
|
-
return await this.simulate(inputs, 'PrivateKernelTailToPublicArtifact', convertPrivateKernelTailToPublicInputsToWitnessMap, convertPrivateKernelTailForPublicOutputsFromWitnessMap);
|
|
31
|
-
}
|
|
32
|
-
async simulate(inputs, circuitType, convertInputs, convertOutputs) {
|
|
33
|
-
this.log.debug(`Generating witness for ${circuitType}`);
|
|
34
|
-
const compiledCircuit = ClientCircuitArtifacts[circuitType];
|
|
35
|
-
const witnessMap = convertInputs(inputs);
|
|
36
|
-
const timer = new Timer();
|
|
37
|
-
const outputWitness = await this.simulator.simulateCircuit(witnessMap, compiledCircuit);
|
|
38
|
-
const output = convertOutputs(outputWitness);
|
|
39
|
-
this.log.debug(`Generated witness for ${circuitType}`, {
|
|
40
|
-
eventName: 'circuit-witness-generation',
|
|
41
|
-
circuitName: circuitType,
|
|
42
|
-
duration: timer.ms(),
|
|
43
|
-
inputSize: inputs.toBuffer().length,
|
|
44
|
-
outputSize: output.toBuffer().length,
|
|
45
|
-
});
|
|
46
|
-
const verificationKey = ClientCircuitVks[circuitType].keyAsFields;
|
|
47
|
-
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
48
|
-
const kernelOutput = {
|
|
49
|
-
publicInputs: output,
|
|
50
|
-
verificationKey,
|
|
51
|
-
outputWitness,
|
|
52
|
-
bytecode,
|
|
53
|
-
};
|
|
54
|
-
return kernelOutput;
|
|
55
|
-
}
|
|
56
|
-
async createClientIvcProof(acirs, witnessStack) {
|
|
57
|
-
const timer = new Timer();
|
|
58
|
-
this.log.info(`Generating ClientIVC proof...`);
|
|
59
|
-
const backend = new AztecClientBackend(acirs.map(acir => ungzip(acir)), { threads: this.threads });
|
|
60
|
-
const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => ungzip(serializeWitness(witnessMap))));
|
|
61
|
-
await backend.destroy();
|
|
62
|
-
this.log.info(`Generated ClientIVC proof`, {
|
|
63
|
-
eventName: 'client-ivc-proof-generation',
|
|
64
|
-
duration: timer.ms(),
|
|
65
|
-
proofSize: proof.length,
|
|
66
|
-
vkSize: vk.length,
|
|
67
|
-
});
|
|
68
|
-
return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk));
|
|
69
|
-
}
|
|
70
|
-
computeGateCountForCircuit(_bytecode, _circuitName) {
|
|
71
|
-
return Promise.resolve(0);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd2FzbS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFFbEQsT0FBTyxFQUNMLGNBQWMsR0FPZixNQUFNLG9CQUFvQixDQUFDO0FBQzVCLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNyRCxPQUFPLEVBQUUsS0FBSyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDaEQsT0FBTyxFQUNMLHNCQUFzQixFQUN0QixnQkFBZ0IsRUFFaEIsMENBQTBDLEVBQzFDLDZDQUE2QyxFQUM3QywyQ0FBMkMsRUFDM0MsOENBQThDLEVBQzlDLDJDQUEyQyxFQUMzQyw4Q0FBOEMsRUFDOUMsc0RBQXNELEVBQ3RELDBDQUEwQyxFQUMxQyw2Q0FBNkMsRUFDN0Msa0RBQWtELEVBQ2xELGlDQUFpQyxHQUNsQyxNQUFNLDRDQUE0QyxDQUFDO0FBQ3BELE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUl4RCxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxzQkFBc0IsQ0F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ssQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUFDLFVBQVUsQ0FBQyxFQUFFLENBQUMsTUFBTSxDQUFDLGdCQUFnQixDQUFDLFVBQVUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzlHLE1BQU0sT0FBTyxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ3hCLElBQUksQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLDJCQUEyQixFQUFFO1lBQ3pDLFNBQVMsRUFBRSw2QkFBNkI7WUFDeEMsUUFBUSxFQUFFLEtBQUssQ0FBQyxFQUFFLEVBQUU7WUFDcEIsU0FBUyxFQUFFLEtBQUssQ0FBQyxNQUFNO1lBQ3ZCLE1BQU0sRUFBRSxFQUFFLENBQUMsTUFBTTtTQUNsQixDQUFDLENBQUM7UUFDSCxPQUFPLElBQUksY0FBYyxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLEVBQUUsTUFBTSxDQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDO0lBQ2pFLENBQUM7SUFFRCwwQkFBMEIsQ0FBQyxTQUFpQixFQUFFLFlBQW9CO1FBQ2hFLE9BQU8sT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUM1QixDQUFDO0NBQ0YifQ==
|
package/src/wasm/index.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { AztecClientBackend } from '@aztec/bb.js';
|
|
2
|
-
import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types';
|
|
3
|
-
import {
|
|
4
|
-
ClientIvcProof,
|
|
5
|
-
type PrivateKernelCircuitPublicInputs,
|
|
6
|
-
type PrivateKernelInitCircuitPrivateInputs,
|
|
7
|
-
type PrivateKernelInnerCircuitPrivateInputs,
|
|
8
|
-
type PrivateKernelResetCircuitPrivateInputs,
|
|
9
|
-
type PrivateKernelTailCircuitPrivateInputs,
|
|
10
|
-
type PrivateKernelTailCircuitPublicInputs,
|
|
11
|
-
} from '@aztec/circuits.js';
|
|
12
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
13
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
14
|
-
import {
|
|
15
|
-
ClientCircuitArtifacts,
|
|
16
|
-
ClientCircuitVks,
|
|
17
|
-
type ClientProtocolArtifact,
|
|
18
|
-
convertPrivateKernelInitInputsToWitnessMap,
|
|
19
|
-
convertPrivateKernelInitOutputsFromWitnessMap,
|
|
20
|
-
convertPrivateKernelInnerInputsToWitnessMap,
|
|
21
|
-
convertPrivateKernelInnerOutputsFromWitnessMap,
|
|
22
|
-
convertPrivateKernelResetInputsToWitnessMap,
|
|
23
|
-
convertPrivateKernelResetOutputsFromWitnessMap,
|
|
24
|
-
convertPrivateKernelTailForPublicOutputsFromWitnessMap,
|
|
25
|
-
convertPrivateKernelTailInputsToWitnessMap,
|
|
26
|
-
convertPrivateKernelTailOutputsFromWitnessMap,
|
|
27
|
-
convertPrivateKernelTailToPublicInputsToWitnessMap,
|
|
28
|
-
getPrivateKernelResetArtifactName,
|
|
29
|
-
} from '@aztec/noir-protocol-circuits-types/client';
|
|
30
|
-
import { WASMSimulator } from '@aztec/simulator/client';
|
|
31
|
-
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
32
|
-
|
|
33
|
-
import { type WitnessMap } from '@noir-lang/noir_js';
|
|
34
|
-
import { serializeWitness } from '@noir-lang/noirc_abi';
|
|
35
|
-
import { ungzip } from 'pako';
|
|
36
|
-
|
|
37
|
-
export class BBWasmPrivateKernelProver implements PrivateKernelProver {
|
|
38
|
-
private simulator = new WASMSimulator();
|
|
39
|
-
|
|
40
|
-
constructor(private threads: number = 1, private log = createLogger('bb-prover:wasm')) {}
|
|
41
|
-
|
|
42
|
-
public async simulateProofInit(
|
|
43
|
-
inputs: PrivateKernelInitCircuitPrivateInputs,
|
|
44
|
-
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
45
|
-
return await this.simulate(
|
|
46
|
-
inputs,
|
|
47
|
-
'PrivateKernelInitArtifact',
|
|
48
|
-
convertPrivateKernelInitInputsToWitnessMap,
|
|
49
|
-
convertPrivateKernelInitOutputsFromWitnessMap,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async simulateProofInner(
|
|
54
|
-
inputs: PrivateKernelInnerCircuitPrivateInputs,
|
|
55
|
-
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
56
|
-
return await this.simulate(
|
|
57
|
-
inputs,
|
|
58
|
-
'PrivateKernelInnerArtifact',
|
|
59
|
-
convertPrivateKernelInnerInputsToWitnessMap,
|
|
60
|
-
convertPrivateKernelInnerOutputsFromWitnessMap,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public async simulateProofReset(
|
|
65
|
-
inputs: PrivateKernelResetCircuitPrivateInputs,
|
|
66
|
-
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
67
|
-
const variantInputs = inputs.trimToSizes();
|
|
68
|
-
const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
|
|
69
|
-
return await this.simulate(
|
|
70
|
-
variantInputs,
|
|
71
|
-
artifactName,
|
|
72
|
-
variantInputs => convertPrivateKernelResetInputsToWitnessMap(variantInputs, artifactName),
|
|
73
|
-
output => convertPrivateKernelResetOutputsFromWitnessMap(output, artifactName),
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public async simulateProofTail(
|
|
78
|
-
inputs: PrivateKernelTailCircuitPrivateInputs,
|
|
79
|
-
): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
80
|
-
if (!inputs.isForPublic()) {
|
|
81
|
-
return await this.simulate(
|
|
82
|
-
inputs,
|
|
83
|
-
'PrivateKernelTailArtifact',
|
|
84
|
-
convertPrivateKernelTailInputsToWitnessMap,
|
|
85
|
-
convertPrivateKernelTailOutputsFromWitnessMap,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return await this.simulate(
|
|
89
|
-
inputs,
|
|
90
|
-
'PrivateKernelTailToPublicArtifact',
|
|
91
|
-
convertPrivateKernelTailToPublicInputsToWitnessMap,
|
|
92
|
-
convertPrivateKernelTailForPublicOutputsFromWitnessMap,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private async simulate<
|
|
97
|
-
I extends { toBuffer: () => Buffer },
|
|
98
|
-
O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
|
|
99
|
-
>(
|
|
100
|
-
inputs: I,
|
|
101
|
-
circuitType: ClientProtocolArtifact,
|
|
102
|
-
convertInputs: (inputs: I) => WitnessMap,
|
|
103
|
-
convertOutputs: (outputs: WitnessMap) => O,
|
|
104
|
-
): Promise<PrivateKernelSimulateOutput<O>> {
|
|
105
|
-
this.log.debug(`Generating witness for ${circuitType}`);
|
|
106
|
-
const compiledCircuit: NoirCompiledCircuit = ClientCircuitArtifacts[circuitType];
|
|
107
|
-
|
|
108
|
-
const witnessMap = convertInputs(inputs);
|
|
109
|
-
const timer = new Timer();
|
|
110
|
-
const outputWitness = await this.simulator.simulateCircuit(witnessMap, compiledCircuit);
|
|
111
|
-
const output = convertOutputs(outputWitness);
|
|
112
|
-
|
|
113
|
-
this.log.debug(`Generated witness for ${circuitType}`, {
|
|
114
|
-
eventName: 'circuit-witness-generation',
|
|
115
|
-
circuitName: circuitType,
|
|
116
|
-
duration: timer.ms(),
|
|
117
|
-
inputSize: inputs.toBuffer().length,
|
|
118
|
-
outputSize: output.toBuffer().length,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const verificationKey = ClientCircuitVks[circuitType].keyAsFields;
|
|
122
|
-
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
123
|
-
|
|
124
|
-
const kernelOutput: PrivateKernelSimulateOutput<O> = {
|
|
125
|
-
publicInputs: output,
|
|
126
|
-
verificationKey,
|
|
127
|
-
outputWitness,
|
|
128
|
-
bytecode,
|
|
129
|
-
};
|
|
130
|
-
return kernelOutput;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
|
|
134
|
-
const timer = new Timer();
|
|
135
|
-
this.log.info(`Generating ClientIVC proof...`);
|
|
136
|
-
const backend = new AztecClientBackend(
|
|
137
|
-
acirs.map(acir => ungzip(acir)),
|
|
138
|
-
{ threads: this.threads },
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => ungzip(serializeWitness(witnessMap))));
|
|
142
|
-
await backend.destroy();
|
|
143
|
-
this.log.info(`Generated ClientIVC proof`, {
|
|
144
|
-
eventName: 'client-ivc-proof-generation',
|
|
145
|
-
duration: timer.ms(),
|
|
146
|
-
proofSize: proof.length,
|
|
147
|
-
vkSize: vk.length,
|
|
148
|
-
});
|
|
149
|
-
return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
|
|
153
|
-
return Promise.resolve(0);
|
|
154
|
-
}
|
|
155
|
-
}
|