@aztec/bb-prover 0.71.0 → 0.73.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/avm_proving_tests/avm_proving_tester.d.ts +24 -0
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -0
- package/dest/avm_proving_tests/avm_proving_tester.js +104 -0
- package/dest/bb/cli.d.ts.map +1 -1
- package/dest/bb/cli.js +1 -52
- package/dest/bb/execute.d.ts +0 -16
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +10 -99
- package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/bb_private_kernel_prover.js +10 -2
- package/dest/prover/bb_prover.d.ts +2 -15
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +25 -57
- package/dest/prover/client_ivc_proof_utils.d.ts +2 -0
- package/dest/prover/client_ivc_proof_utils.d.ts.map +1 -1
- package/dest/prover/client_ivc_proof_utils.js +6 -4
- package/dest/verification_key/verification_key_data.js +2 -2
- package/dest/verifier/bb_verifier.d.ts +2 -6
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +13 -37
- package/package.json +12 -10
- package/src/avm_proving_tests/avm_proving_tester.ts +175 -0
- package/src/bb/cli.ts +0 -76
- package/src/bb/execute.ts +9 -143
- package/src/prover/bb_private_kernel_prover.ts +9 -1
- package/src/prover/bb_prover.ts +36 -89
- package/src/prover/client_ivc_proof_utils.ts +6 -3
- package/src/verification_key/verification_key_data.ts +1 -1
- package/src/verifier/bb_verifier.ts +16 -94
- package/dest/test/test_avm.d.ts +0 -4
- package/dest/test/test_avm.d.ts.map +0 -1
- package/dest/test/test_avm.js +0 -33
- package/src/test/test_avm.ts +0 -85
|
@@ -1,51 +1,34 @@
|
|
|
1
1
|
import { Tx } from '@aztec/circuit-types';
|
|
2
2
|
import { runInDirectory } from '@aztec/foundation/fs';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
|
|
5
5
|
import { promises as fs } from 'fs';
|
|
6
6
|
import * as path from 'path';
|
|
7
|
-
import { BB_RESULT, PROOF_FILENAME, VK_FILENAME,
|
|
7
|
+
import { BB_RESULT, PROOF_FILENAME, VK_FILENAME, verifyClientIvcProof, verifyProof } from '../bb/execute.js';
|
|
8
8
|
import { getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
9
9
|
import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js';
|
|
10
|
-
import {
|
|
11
|
-
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
10
|
+
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
12
11
|
export class BBCircuitVerifier {
|
|
13
|
-
constructor(config,
|
|
12
|
+
constructor(config, logger) {
|
|
14
13
|
this.config = config;
|
|
15
|
-
this.verificationKeys = verificationKeys;
|
|
16
14
|
this.logger = logger;
|
|
17
15
|
}
|
|
18
|
-
static async new(config,
|
|
16
|
+
static async new(config, logger = createLogger('bb-prover:verifier')) {
|
|
19
17
|
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
20
|
-
|
|
21
|
-
for (const circuit of initialCircuits) {
|
|
22
|
-
const vkData = await this.generateVerificationKey(circuit, config.bbBinaryPath, config.bbWorkingDirectory, logger.debug);
|
|
23
|
-
keys.set(circuit, Promise.resolve(vkData));
|
|
24
|
-
}
|
|
25
|
-
return new BBCircuitVerifier(config, keys, logger);
|
|
26
|
-
}
|
|
27
|
-
static async generateVerificationKey(circuit, bbPath, workingDirectory, logFn) {
|
|
28
|
-
return await generateKeyForNoirCircuit(bbPath, workingDirectory, circuit, ServerCircuitArtifacts[circuit], isProtocolArtifactRecursive(circuit), getUltraHonkFlavorForCircuit(circuit), logFn).then(result => {
|
|
29
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
30
|
-
throw new Error(`Failed to created verification key for ${circuit}, ${result.reason}`);
|
|
31
|
-
}
|
|
32
|
-
return extractVkData(result.vkPath);
|
|
33
|
-
});
|
|
18
|
+
return new BBCircuitVerifier(config, logger);
|
|
34
19
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
20
|
+
getVerificationKeyData(circuitType) {
|
|
21
|
+
const vk = ServerCircuitVks[circuitType];
|
|
22
|
+
if (vk === undefined) {
|
|
23
|
+
throw new Error('Could not find VK for server artifact ' + circuitType);
|
|
39
24
|
}
|
|
40
|
-
|
|
41
|
-
const vk = await promise;
|
|
42
|
-
return vk.clone();
|
|
25
|
+
return vk;
|
|
43
26
|
}
|
|
44
27
|
async verifyProofForCircuit(circuit, proof) {
|
|
45
28
|
const operation = async (bbWorkingDirectory) => {
|
|
46
29
|
const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
|
|
47
30
|
const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
|
|
48
|
-
const verificationKey =
|
|
31
|
+
const verificationKey = this.getVerificationKeyData(circuit);
|
|
49
32
|
this.logger.debug(`${circuit} Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
|
|
50
33
|
await fs.writeFile(proofFileName, proof.buffer);
|
|
51
34
|
await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
|
|
@@ -63,13 +46,6 @@ export class BBCircuitVerifier {
|
|
|
63
46
|
};
|
|
64
47
|
await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup);
|
|
65
48
|
}
|
|
66
|
-
async generateSolidityContract(circuit, contractName) {
|
|
67
|
-
const result = await generateContractForCircuit(this.config.bbBinaryPath, this.config.bbWorkingDirectory, circuit, ServerCircuitArtifacts[circuit], contractName, this.logger.debug);
|
|
68
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
69
|
-
throw new Error(`Failed to create verifier contract for ${circuit}, ${result.reason}`);
|
|
70
|
-
}
|
|
71
|
-
return fs.readFile(result.contractPath, 'utf-8');
|
|
72
|
-
}
|
|
73
49
|
async verifyProof(tx) {
|
|
74
50
|
try {
|
|
75
51
|
// TODO(#7370) The verification keys should be supplied separately and based on the expectedCircuit
|
|
@@ -107,4 +83,4 @@ export class BBCircuitVerifier {
|
|
|
107
83
|
}
|
|
108
84
|
}
|
|
109
85
|
}
|
|
110
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
86
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmJfdmVyaWZpZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdmVyaWZpZXIvYmJfdmVyaWZpZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFzQyxFQUFFLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUc5RSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDdEQsT0FBTyxFQUFlLFlBQVksRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRWxFLE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHlDQUF5QyxDQUFDO0FBRTNFLE9BQU8sRUFBRSxRQUFRLElBQUksRUFBRSxFQUFFLE1BQU0sSUFBSSxDQUFDO0FBQ3BDLE9BQU8sS0FBSyxJQUFJLE1BQU0sTUFBTSxDQUFDO0FBRTdCLE9BQU8sRUFBRSxTQUFTLEVBQUUsY0FBYyxFQUFFLFdBQVcsRUFBRSxvQkFBb0IsRUFBRSxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUU3RyxPQUFPLEVBQUUsNEJBQTRCLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFDMUQsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDN0UsT0FBTyxFQUFFLG9DQUFvQyxFQUFFLE1BQU0sYUFBYSxDQU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HLG9CQUFvQixPQUFPLFNBQVMsQ0FBQztvQkFDMUQsTUFBTSxJQUFJLEtBQUssQ0FBQyxZQUFZLENBQUMsQ0FBQztnQkFDaEMsQ0FBQztnQkFFRCxJQUFJLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxHQUFHLE9BQU8sMEJBQTBCLEVBQUU7b0JBQ3RELFdBQVcsRUFBRSxvQ0FBb0MsQ0FBQyxlQUFlLENBQUM7b0JBQ2xFLFFBQVEsRUFBRSxNQUFNLENBQUMsVUFBVTtvQkFDM0IsU0FBUyxFQUFFLHNCQUFzQjtvQkFDakMsU0FBUyxFQUFFLFlBQVk7aUJBQ1csQ0FBQyxDQUFDO1lBQ3hDLENBQUMsQ0FBQztZQUNGLE1BQU0sY0FBYyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsa0JBQWtCLEVBQUUsU0FBUyxFQUFFLElBQUksQ0FBQyxNQUFNLENBQUMsYUFBYSxDQUFDLENBQUM7WUFDM0YsT0FBTyxJQUFJLENBQUM7UUFDZCxDQUFDO1FBQUMsT0FBTyxHQUFHLEVBQUUsQ0FBQztZQUNiLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLDJDQUEyQyxFQUFFLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxLQUFLLE1BQU0sQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLENBQUM7WUFDOUYsT0FBTyxLQUFLLENBQUM7UUFDZixDQUFDO0lBQ0gsQ0FBQztDQUNGIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bb-prover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.73.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/bb.js": "0.
|
|
71
|
-
"@aztec/circuit-types": "0.
|
|
72
|
-
"@aztec/circuits.js": "0.
|
|
73
|
-
"@aztec/foundation": "0.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
75
|
-
"@aztec/simulator": "0.
|
|
76
|
-
"@aztec/telemetry-client": "0.
|
|
77
|
-
"@aztec/world-state": "0.
|
|
70
|
+
"@aztec/bb.js": "0.73.0",
|
|
71
|
+
"@aztec/circuit-types": "0.73.0",
|
|
72
|
+
"@aztec/circuits.js": "0.73.0",
|
|
73
|
+
"@aztec/foundation": "0.73.0",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.73.0",
|
|
75
|
+
"@aztec/simulator": "0.73.0",
|
|
76
|
+
"@aztec/telemetry-client": "0.73.0",
|
|
77
|
+
"@aztec/world-state": "0.73.0",
|
|
78
78
|
"@msgpack/msgpack": "^3.0.0-beta2",
|
|
79
79
|
"@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
|
|
80
80
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
|
@@ -86,6 +86,8 @@
|
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@aztec/ethereum": "workspace:^",
|
|
88
88
|
"@aztec/kv-store": "workspace:^",
|
|
89
|
+
"@aztec/noir-contracts.js": "workspace:^",
|
|
90
|
+
"@aztec/protocol-contracts": "workspace:^",
|
|
89
91
|
"@aztec/types": "workspace:^",
|
|
90
92
|
"@jest/globals": "^29.5.0",
|
|
91
93
|
"@types/jest": "^29.5.0",
|
|
@@ -96,7 +98,7 @@
|
|
|
96
98
|
"jest-mock-extended": "^3.0.3",
|
|
97
99
|
"ts-node": "^10.9.1",
|
|
98
100
|
"typescript": "^5.0.4",
|
|
99
|
-
"viem": "
|
|
101
|
+
"viem": "2.22.8"
|
|
100
102
|
},
|
|
101
103
|
"files": [
|
|
102
104
|
"dest",
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { type MerkleTreeWriteOperations } from '@aztec/circuit-types';
|
|
2
|
+
import { type AvmCircuitInputs, AztecAddress, VerificationKeyData } from '@aztec/circuits.js';
|
|
3
|
+
import { openTmpStore } from '@aztec/kv-store/lmdb';
|
|
4
|
+
import { PublicTxSimulationTester, type TestEnqueuedCall } from '@aztec/simulator/public/fixtures';
|
|
5
|
+
import { MerkleTrees } from '@aztec/world-state';
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs/promises';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
|
|
11
|
+
import { SimpleContractDataSource } from '../../../simulator/src/avm/fixtures/simple_contract_data_source.js';
|
|
12
|
+
import {
|
|
13
|
+
type BBResult,
|
|
14
|
+
type BBSuccess,
|
|
15
|
+
BB_RESULT,
|
|
16
|
+
generateAvmProof,
|
|
17
|
+
generateAvmProofV2,
|
|
18
|
+
verifyAvmProof,
|
|
19
|
+
verifyAvmProofV2,
|
|
20
|
+
} from '../bb/execute.js';
|
|
21
|
+
import { extractAvmVkData } from '../verification_key/verification_key_data.js';
|
|
22
|
+
|
|
23
|
+
const BB_PATH = path.resolve('../../barretenberg/cpp/build/bin/bb');
|
|
24
|
+
|
|
25
|
+
export class AvmProvingTester extends PublicTxSimulationTester {
|
|
26
|
+
constructor(
|
|
27
|
+
private bbWorkingDirectory: string,
|
|
28
|
+
private checkCircuitOnly: boolean,
|
|
29
|
+
contractDataSource: SimpleContractDataSource,
|
|
30
|
+
merkleTrees: MerkleTreeWriteOperations,
|
|
31
|
+
skipContractDeployments: boolean,
|
|
32
|
+
) {
|
|
33
|
+
super(contractDataSource, merkleTrees, skipContractDeployments);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static override async create(checkCircuitOnly: boolean = false, skipContractDeployments: boolean = false) {
|
|
37
|
+
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
|
|
38
|
+
|
|
39
|
+
const contractDataSource = new SimpleContractDataSource();
|
|
40
|
+
const merkleTrees = await (await MerkleTrees.new(openTmpStore())).fork();
|
|
41
|
+
return new AvmProvingTester(
|
|
42
|
+
bbWorkingDirectory,
|
|
43
|
+
checkCircuitOnly,
|
|
44
|
+
contractDataSource,
|
|
45
|
+
merkleTrees,
|
|
46
|
+
skipContractDeployments,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async prove(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult> {
|
|
51
|
+
// Then we prove.
|
|
52
|
+
const proofRes = await generateAvmProof(
|
|
53
|
+
BB_PATH,
|
|
54
|
+
this.bbWorkingDirectory,
|
|
55
|
+
avmCircuitInputs,
|
|
56
|
+
this.logger,
|
|
57
|
+
this.checkCircuitOnly,
|
|
58
|
+
);
|
|
59
|
+
if (proofRes.status === BB_RESULT.FAILURE) {
|
|
60
|
+
this.logger.error(`Proof generation failed: ${proofRes.reason}`);
|
|
61
|
+
}
|
|
62
|
+
return proofRes;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async verify(proofRes: BBSuccess): Promise<BBResult> {
|
|
66
|
+
if (this.checkCircuitOnly) {
|
|
67
|
+
// Skip verification if we're only checking the circuit.
|
|
68
|
+
// Check-circuit doesn't generate a proof to verify.
|
|
69
|
+
return proofRes;
|
|
70
|
+
}
|
|
71
|
+
// Then we test VK extraction and serialization.
|
|
72
|
+
const succeededRes = proofRes as BBSuccess;
|
|
73
|
+
const vkData = await extractAvmVkData(succeededRes.vkPath!);
|
|
74
|
+
VerificationKeyData.fromBuffer(vkData.toBuffer());
|
|
75
|
+
|
|
76
|
+
// Then we verify.
|
|
77
|
+
const rawVkPath = path.join(succeededRes.vkPath!, 'vk');
|
|
78
|
+
return await verifyAvmProof(BB_PATH, succeededRes.proofPath!, rawVkPath, this.logger);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public async simProveVerify(
|
|
82
|
+
sender: AztecAddress,
|
|
83
|
+
setupCalls: TestEnqueuedCall[],
|
|
84
|
+
appCalls: TestEnqueuedCall[],
|
|
85
|
+
teardownCall: TestEnqueuedCall | undefined,
|
|
86
|
+
expectRevert: boolean | undefined,
|
|
87
|
+
feePayer?: AztecAddress,
|
|
88
|
+
) {
|
|
89
|
+
const simRes = await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer);
|
|
90
|
+
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
91
|
+
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
92
|
+
const provingRes = await this.prove(avmCircuitInputs);
|
|
93
|
+
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
94
|
+
const verificationRes = await this.verify(provingRes as BBSuccess);
|
|
95
|
+
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async simProveVerifyAppLogic(appCall: TestEnqueuedCall, expectRevert?: boolean) {
|
|
99
|
+
const simRes = await this.simulateTx(/*sender=*/ AztecAddress.fromNumber(42), /*setupCalls=*/ [], [appCall]);
|
|
100
|
+
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
101
|
+
|
|
102
|
+
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
103
|
+
const provingRes = await this.prove(avmCircuitInputs);
|
|
104
|
+
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
105
|
+
|
|
106
|
+
const verificationRes = await this.verify(provingRes as BBSuccess);
|
|
107
|
+
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class AvmProvingTesterV2 extends PublicTxSimulationTester {
|
|
112
|
+
constructor(
|
|
113
|
+
private bbWorkingDirectory: string,
|
|
114
|
+
contractDataSource: SimpleContractDataSource,
|
|
115
|
+
merkleTrees: MerkleTreeWriteOperations,
|
|
116
|
+
skipContractDeployments: boolean,
|
|
117
|
+
) {
|
|
118
|
+
super(contractDataSource, merkleTrees, skipContractDeployments);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static override async create(skipContractDeployments: boolean = false) {
|
|
122
|
+
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
|
|
123
|
+
|
|
124
|
+
const contractDataSource = new SimpleContractDataSource();
|
|
125
|
+
const merkleTrees = await (await MerkleTrees.new(openTmpStore())).fork();
|
|
126
|
+
return new AvmProvingTesterV2(bbWorkingDirectory, contractDataSource, merkleTrees, skipContractDeployments);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async proveV2(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult> {
|
|
130
|
+
// Then we prove.
|
|
131
|
+
const proofRes = await generateAvmProofV2(BB_PATH, this.bbWorkingDirectory, avmCircuitInputs, this.logger);
|
|
132
|
+
if (proofRes.status === BB_RESULT.FAILURE) {
|
|
133
|
+
this.logger.error(`Proof generation failed: ${proofRes.reason}`);
|
|
134
|
+
}
|
|
135
|
+
expect(proofRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
136
|
+
return proofRes as BBSuccess;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async verifyV2(proofRes: BBSuccess): Promise<BBResult> {
|
|
140
|
+
// Then we verify.
|
|
141
|
+
// Placeholder for now.
|
|
142
|
+
const publicInputs = {
|
|
143
|
+
dummy: [] as any[],
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const rawVkPath = path.join(proofRes.vkPath!, 'vk');
|
|
147
|
+
return await verifyAvmProofV2(
|
|
148
|
+
BB_PATH,
|
|
149
|
+
this.bbWorkingDirectory,
|
|
150
|
+
proofRes.proofPath!,
|
|
151
|
+
publicInputs,
|
|
152
|
+
rawVkPath,
|
|
153
|
+
this.logger,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public async simProveVerifyV2(
|
|
158
|
+
sender: AztecAddress,
|
|
159
|
+
setupCalls: TestEnqueuedCall[],
|
|
160
|
+
appCalls: TestEnqueuedCall[],
|
|
161
|
+
teardownCall: TestEnqueuedCall | undefined,
|
|
162
|
+
expectRevert: boolean | undefined,
|
|
163
|
+
feePayer?: AztecAddress,
|
|
164
|
+
) {
|
|
165
|
+
const simRes = await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer);
|
|
166
|
+
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
167
|
+
|
|
168
|
+
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
169
|
+
const provingRes = await this.proveV2(avmCircuitInputs);
|
|
170
|
+
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
171
|
+
|
|
172
|
+
const verificationRes = await this.verifyV2(provingRes as BBSuccess);
|
|
173
|
+
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
174
|
+
}
|
|
175
|
+
}
|
package/src/bb/cli.ts
CHANGED
|
@@ -5,11 +5,6 @@ import { type ProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types
|
|
|
5
5
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
6
6
|
|
|
7
7
|
import { Command } from 'commander';
|
|
8
|
-
import { promises as fs } from 'fs';
|
|
9
|
-
|
|
10
|
-
import { generateContractForCircuit, generateKeyForNoirCircuit } from './execute.js';
|
|
11
|
-
|
|
12
|
-
const { BB_WORKING_DIRECTORY, BB_BINARY_PATH } = process.env;
|
|
13
8
|
|
|
14
9
|
export const ProtocolCircuitArtifacts: Record<ProtocolArtifact, NoirCompiledCircuit> = {
|
|
15
10
|
...ClientCircuitArtifacts,
|
|
@@ -33,76 +28,5 @@ export function getProgram(log: LogFn): Command {
|
|
|
33
28
|
log(Object.keys(ProtocolCircuitArtifacts).reduce((prev: string, x: string) => prev.concat(`\n${x}`)));
|
|
34
29
|
});
|
|
35
30
|
|
|
36
|
-
program
|
|
37
|
-
.command('write-vk')
|
|
38
|
-
.description('Generates the verification key for the specified circuit')
|
|
39
|
-
.requiredOption(
|
|
40
|
-
'-w, --working-directory <string>',
|
|
41
|
-
'A directory to use for storing input/output files',
|
|
42
|
-
BB_WORKING_DIRECTORY,
|
|
43
|
-
)
|
|
44
|
-
.requiredOption('-b, --bb-path <string>', 'The path to the BB binary', BB_BINARY_PATH)
|
|
45
|
-
.requiredOption('-c, --circuit <string>', 'The name of a protocol circuit')
|
|
46
|
-
.requiredOption('-f, --flavor <string>', 'The name of the verification key flavor', 'ultra_honk')
|
|
47
|
-
.option('-r, --recursive', 'Whether a SNARK friendly key should be generated', false)
|
|
48
|
-
.action(async options => {
|
|
49
|
-
const compiledCircuit = ProtocolCircuitArtifacts[options.circuit as ProtocolArtifact];
|
|
50
|
-
if (!compiledCircuit) {
|
|
51
|
-
log(`Failed to find circuit ${options.circuit}`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
await fs.access(options.workingDirectory, fs.constants.W_OK);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
log(`Working directory does not exist`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
await generateKeyForNoirCircuit(
|
|
61
|
-
options.bbPath,
|
|
62
|
-
options.workingDirectory,
|
|
63
|
-
options.circuit,
|
|
64
|
-
compiledCircuit,
|
|
65
|
-
options.recursive,
|
|
66
|
-
options.flavor,
|
|
67
|
-
// (options.circuit as ServerProtocolArtifact) === 'RootRollupArtifact' ? 'ultra_keccak_honk' : 'ultra_honk',
|
|
68
|
-
log,
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
program
|
|
73
|
-
.command('write-contract')
|
|
74
|
-
.description('Generates the verification contract for the specified circuit')
|
|
75
|
-
.requiredOption(
|
|
76
|
-
'-w, --working-directory <string>',
|
|
77
|
-
'A directory to use for storing input/output files',
|
|
78
|
-
BB_WORKING_DIRECTORY,
|
|
79
|
-
)
|
|
80
|
-
.requiredOption('-b, --bb-path <string>', 'The path to the BB binary', BB_BINARY_PATH)
|
|
81
|
-
.requiredOption('-c, --circuit <string>', 'The name of a protocol circuit')
|
|
82
|
-
.requiredOption('-n --contract-name <string>', 'The name of the contract to generate', 'contract.sol')
|
|
83
|
-
.action(async options => {
|
|
84
|
-
const compiledCircuit = ProtocolCircuitArtifacts[options.circuit as ProtocolArtifact];
|
|
85
|
-
if (!compiledCircuit) {
|
|
86
|
-
log(`Failed to find circuit ${options.circuit}`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
await fs.access(options.workingDirectory, fs.constants.W_OK);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
log(`Working directory does not exist`);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
await generateContractForCircuit(
|
|
97
|
-
options.bbPath,
|
|
98
|
-
options.workingDirectory,
|
|
99
|
-
options.circuit,
|
|
100
|
-
compiledCircuit,
|
|
101
|
-
options.contractName,
|
|
102
|
-
log,
|
|
103
|
-
/*force= */ true,
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
31
|
return program;
|
|
108
32
|
}
|
package/src/bb/execute.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { type AvmCircuitInputs, serializeWithMessagePack } from '@aztec/circuits
|
|
|
2
2
|
import { sha256 } from '@aztec/foundation/crypto';
|
|
3
3
|
import { type LogFn, type Logger } from '@aztec/foundation/log';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
-
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
6
5
|
|
|
7
6
|
import * as proc from 'child_process';
|
|
8
7
|
import { promises as fs } from 'fs';
|
|
9
8
|
import { basename, dirname, join } from 'path';
|
|
10
9
|
|
|
11
10
|
import { type UltraHonkFlavor } from '../honk.js';
|
|
11
|
+
import { CLIENT_IVC_PROOF_FILE_NAME, CLIENT_IVC_VK_FILE_NAME } from '../prover/client_ivc_proof_utils.js';
|
|
12
12
|
|
|
13
13
|
export const VK_FILENAME = 'vk';
|
|
14
14
|
export const VK_FIELDS_FILENAME = 'vk_fields.json';
|
|
@@ -97,103 +97,6 @@ export function executeBB(
|
|
|
97
97
|
}).catch(_ => ({ status: BB_RESULT.FAILURE, exitCode: -1, signal: undefined }));
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
const bytecodeFilename = 'bytecode';
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Used for generating either a proving or verification key, will exit early if the key already exists
|
|
104
|
-
* It assumes the provided working directory is one where the caller wishes to maintain a permanent set of keys
|
|
105
|
-
* It is not considered a temporary directory
|
|
106
|
-
* @param pathToBB - The full path to the bb binary
|
|
107
|
-
* @param workingDirectory - The directory into which the key should be created
|
|
108
|
-
* @param circuitName - An identifier for the circuit
|
|
109
|
-
* @param compiledCircuit - The compiled circuit
|
|
110
|
-
* @param key - The type of key, either 'pk' or 'vk'
|
|
111
|
-
* @param log - A logging function
|
|
112
|
-
* @param force - Force the key to be regenerated even if it already exists
|
|
113
|
-
* @returns An instance of BBResult
|
|
114
|
-
*/
|
|
115
|
-
export async function generateKeyForNoirCircuit(
|
|
116
|
-
pathToBB: string,
|
|
117
|
-
workingDirectory: string,
|
|
118
|
-
circuitName: string,
|
|
119
|
-
compiledCircuit: NoirCompiledCircuit,
|
|
120
|
-
recursive: boolean,
|
|
121
|
-
flavor: UltraHonkFlavor,
|
|
122
|
-
log: LogFn,
|
|
123
|
-
force = false,
|
|
124
|
-
): Promise<BBSuccess | BBFailure> {
|
|
125
|
-
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
126
|
-
|
|
127
|
-
// The key generation is written to e.g. /workingDirectory/pk/BaseParityArtifact/pk
|
|
128
|
-
// The bytecode hash file is also written here as /workingDirectory/pk/BaseParityArtifact/bytecode-hash
|
|
129
|
-
// The bytecode is written to e.g. /workingDirectory/pk/BaseParityArtifact/bytecode
|
|
130
|
-
// The bytecode is removed after the key is generated, leaving just the hash file
|
|
131
|
-
const circuitOutputDirectory = `${workingDirectory}/vk/${circuitName}`;
|
|
132
|
-
const outputPath = `${circuitOutputDirectory}`;
|
|
133
|
-
const bytecodeHash = sha256(bytecode);
|
|
134
|
-
|
|
135
|
-
// ensure the directory exists
|
|
136
|
-
await fs.mkdir(circuitOutputDirectory, { recursive: true });
|
|
137
|
-
|
|
138
|
-
const res = await fsCache<BBSuccess | BBFailure>(circuitOutputDirectory, bytecodeHash, log, force, async () => {
|
|
139
|
-
const binaryPresent = await fs
|
|
140
|
-
.access(pathToBB, fs.constants.R_OK)
|
|
141
|
-
.then(_ => true)
|
|
142
|
-
.catch(_ => false);
|
|
143
|
-
if (!binaryPresent) {
|
|
144
|
-
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// We are now going to generate the key
|
|
148
|
-
try {
|
|
149
|
-
const bytecodePath = `${circuitOutputDirectory}/${bytecodeFilename}`;
|
|
150
|
-
// Write the bytecode to the working directory
|
|
151
|
-
await fs.writeFile(bytecodePath, bytecode);
|
|
152
|
-
|
|
153
|
-
// args are the output path and the input bytecode path
|
|
154
|
-
const args = ['-o', `${outputPath}/${VK_FILENAME}`, '-b', bytecodePath, recursive ? '--recursive' : ''];
|
|
155
|
-
const timer = new Timer();
|
|
156
|
-
let result = await executeBB(pathToBB, `write_vk_${flavor}`, args, log);
|
|
157
|
-
|
|
158
|
-
// If we succeeded and the type of key if verification, have bb write the 'fields' version too
|
|
159
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
160
|
-
const asFieldsArgs = ['-k', `${outputPath}/${VK_FILENAME}`, '-o', `${outputPath}/${VK_FIELDS_FILENAME}`, '-v'];
|
|
161
|
-
result = await executeBB(pathToBB, `vk_as_fields_${flavor}`, asFieldsArgs, log);
|
|
162
|
-
}
|
|
163
|
-
const duration = timer.ms();
|
|
164
|
-
|
|
165
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
166
|
-
return {
|
|
167
|
-
status: BB_RESULT.SUCCESS,
|
|
168
|
-
durationMs: duration,
|
|
169
|
-
pkPath: undefined,
|
|
170
|
-
vkPath: outputPath,
|
|
171
|
-
proofPath: undefined,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
175
|
-
return {
|
|
176
|
-
status: BB_RESULT.FAILURE,
|
|
177
|
-
reason: `Failed to generate key. Exit code: ${result.exitCode}. Signal ${result.signal}.`,
|
|
178
|
-
retry: !!result.signal,
|
|
179
|
-
};
|
|
180
|
-
} catch (error) {
|
|
181
|
-
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
if (!res) {
|
|
186
|
-
return {
|
|
187
|
-
status: BB_RESULT.ALREADY_PRESENT,
|
|
188
|
-
durationMs: 0,
|
|
189
|
-
pkPath: undefined,
|
|
190
|
-
vkPath: outputPath,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return res;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
100
|
// TODO(#7369) comment this etc (really just take inspiration from this and rewrite it all O:))
|
|
198
101
|
export async function executeBbClientIvcProof(
|
|
199
102
|
pathToBB: string,
|
|
@@ -443,8 +346,8 @@ export async function generateTubeProof(
|
|
|
443
346
|
}
|
|
444
347
|
|
|
445
348
|
// // Paths for the inputs
|
|
446
|
-
const vkPath = join(workingDirectory,
|
|
447
|
-
const proofPath = join(workingDirectory,
|
|
349
|
+
const vkPath = join(workingDirectory, CLIENT_IVC_VK_FILE_NAME);
|
|
350
|
+
const proofPath = join(workingDirectory, CLIENT_IVC_PROOF_FILE_NAME);
|
|
448
351
|
|
|
449
352
|
// The proof is written to e.g. /workingDirectory/proof
|
|
450
353
|
const outputPath = workingDirectory;
|
|
@@ -460,7 +363,7 @@ export async function generateTubeProof(
|
|
|
460
363
|
}
|
|
461
364
|
|
|
462
365
|
try {
|
|
463
|
-
if (!filePresent(vkPath) || !filePresent(proofPath)) {
|
|
366
|
+
if (!(await filePresent(vkPath)) || !(await filePresent(proofPath))) {
|
|
464
367
|
return { status: BB_RESULT.FAILURE, reason: `Client IVC input files not present in ${workingDirectory}` };
|
|
465
368
|
}
|
|
466
369
|
const args = ['-o', outputPath, '-v'];
|
|
@@ -534,7 +437,7 @@ export async function generateAvmProofV2(
|
|
|
534
437
|
// Write the inputs to the working directory.
|
|
535
438
|
const avmInputsPath = join(workingDirectory, 'avm_inputs.bin');
|
|
536
439
|
await fs.writeFile(avmInputsPath, inputsBuffer);
|
|
537
|
-
if (!filePresent(avmInputsPath)) {
|
|
440
|
+
if (!(await filePresent(avmInputsPath))) {
|
|
538
441
|
return { status: BB_RESULT.FAILURE, reason: `Could not write avm inputs to ${avmInputsPath}` };
|
|
539
442
|
}
|
|
540
443
|
|
|
@@ -616,13 +519,13 @@ export async function generateAvmProof(
|
|
|
616
519
|
try {
|
|
617
520
|
// Write the inputs to the working directory.
|
|
618
521
|
|
|
619
|
-
await fs.writeFile(publicInputsPath, input.
|
|
620
|
-
if (!filePresent(publicInputsPath)) {
|
|
522
|
+
await fs.writeFile(publicInputsPath, input.publicInputs.toBuffer());
|
|
523
|
+
if (!(await filePresent(publicInputsPath))) {
|
|
621
524
|
return { status: BB_RESULT.FAILURE, reason: `Could not write publicInputs at ${publicInputsPath}` };
|
|
622
525
|
}
|
|
623
526
|
|
|
624
527
|
await fs.writeFile(avmHintsPath, input.avmHints.toBuffer());
|
|
625
|
-
if (!filePresent(avmHintsPath)) {
|
|
528
|
+
if (!(await filePresent(avmHintsPath))) {
|
|
626
529
|
return { status: BB_RESULT.FAILURE, reason: `Could not write avmHints at ${avmHintsPath}` };
|
|
627
530
|
}
|
|
628
531
|
|
|
@@ -717,7 +620,7 @@ export async function verifyAvmProofV2(
|
|
|
717
620
|
.catch(_ => false);
|
|
718
621
|
const avmInputsPath = join(workingDirectory, 'avm_public_inputs.bin');
|
|
719
622
|
await fs.writeFile(avmInputsPath, inputsBuffer);
|
|
720
|
-
if (!filePresent(avmInputsPath)) {
|
|
623
|
+
if (!(await filePresent(avmInputsPath))) {
|
|
721
624
|
return { status: BB_RESULT.FAILURE, reason: `Could not write avm inputs to ${avmInputsPath}` };
|
|
722
625
|
}
|
|
723
626
|
|
|
@@ -960,43 +863,6 @@ export async function generateContractForVerificationKey(
|
|
|
960
863
|
return res;
|
|
961
864
|
}
|
|
962
865
|
|
|
963
|
-
export async function generateContractForCircuit(
|
|
964
|
-
pathToBB: string,
|
|
965
|
-
workingDirectory: string,
|
|
966
|
-
circuitName: string,
|
|
967
|
-
compiledCircuit: NoirCompiledCircuit,
|
|
968
|
-
contractName: string,
|
|
969
|
-
log: LogFn,
|
|
970
|
-
force = false,
|
|
971
|
-
) {
|
|
972
|
-
// Verifier contracts are never recursion friendly, because non-recursive proofs are generated using the keccak256 hash function.
|
|
973
|
-
// We need to use the same hash function during verification so proofs generated using keccak256 are cheap to verify on ethereum
|
|
974
|
-
// (where the verifier contract would be deployed) whereas if we want to verify the proof within a snark (for recursion) we want
|
|
975
|
-
// to use a snark-friendly hash function.
|
|
976
|
-
const recursive = false;
|
|
977
|
-
|
|
978
|
-
const vkResult = await generateKeyForNoirCircuit(
|
|
979
|
-
pathToBB,
|
|
980
|
-
workingDirectory,
|
|
981
|
-
circuitName,
|
|
982
|
-
compiledCircuit,
|
|
983
|
-
recursive,
|
|
984
|
-
'ultra_keccak_honk',
|
|
985
|
-
log,
|
|
986
|
-
force,
|
|
987
|
-
);
|
|
988
|
-
if (vkResult.status === BB_RESULT.FAILURE) {
|
|
989
|
-
return vkResult;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
return generateContractForVerificationKey(
|
|
993
|
-
pathToBB,
|
|
994
|
-
join(vkResult.vkPath!, VK_FILENAME),
|
|
995
|
-
join(workingDirectory, 'contract', circuitName, contractName),
|
|
996
|
-
log,
|
|
997
|
-
);
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
866
|
/**
|
|
1001
867
|
* Compute bb gate count for a given circuit
|
|
1002
868
|
* @param pathToBB - The full path to the bb binary
|
|
@@ -166,7 +166,15 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
166
166
|
const witnessMap = convertInputs(inputs, compiledCircuit.abi);
|
|
167
167
|
|
|
168
168
|
const timer = new Timer();
|
|
169
|
-
const outputWitness = await this.simulationProvider
|
|
169
|
+
const outputWitness = await this.simulationProvider
|
|
170
|
+
.executeProtocolCircuit(witnessMap, compiledCircuit)
|
|
171
|
+
.catch((err: Error) => {
|
|
172
|
+
this.log.debug(`Failed to simulate ${circuitType}`, {
|
|
173
|
+
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
174
|
+
error: err,
|
|
175
|
+
});
|
|
176
|
+
throw err;
|
|
177
|
+
});
|
|
170
178
|
const output = convertOutputs(outputWitness, compiledCircuit.abi);
|
|
171
179
|
|
|
172
180
|
this.log.debug(`Simulated ${circuitType}`, {
|