Skip to content

Commit 8cb3637

Browse files
author
Alex Gherghisan
committed
feat: proving benchmark
1 parent 980a62e commit 8cb3637

20 files changed

Lines changed: 299 additions & 114 deletions

File tree

yarn-project/Earthfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ deps:
55
LET packages = $(git ls-files "**/package*.json" package*.json)
66
LET tsconfigs = $(git ls-files "**/tsconfig*.json" tsconfig*.json)
77
FROM ../build-images+build
8-
# copy bb-js and noir-packages
8+
# copy bb, bb-js and noir-packages
9+
COPY ../barretenberg/cpp/+preset-release/bin /usr/src/barretenberg/cpp/build/
910
COPY ../barretenberg/ts/+build/build /usr/src/barretenberg/ts
1011
COPY ../noir/+packages/packages /usr/src/noir/packages
1112
WORKDIR /usr/src/yarn-project
@@ -100,7 +101,7 @@ end-to-end:
100101
RUN apt-get update && apt-get install -y wget gnupg \
101102
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
102103
&& echo "deb [arch=$(dpkg --print-architecture)] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
103-
&& apt update && apt install nodejs jq google-chrome-stable netcat-openbsd -y \
104+
&& apt update && apt install curl nodejs jq google-chrome-stable netcat-openbsd -y \
104105
&& rm -rf /var/lib/apt/lists/*
105106
ENV CHROME_BIN="/usr/bin/google-chrome-stable"
106107
ENV PATH=/opt/foundry/bin:$PATH

yarn-project/aztec-node/src/aztec-node/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type ArchiverConfig, getConfigEnvVars as getArchiverVars } from '@aztec/archiver';
22
import { type P2PConfig, getP2PConfigEnvVars } from '@aztec/p2p';
3-
import { type ProverConfig, getProverEnvVars } from '@aztec/prover-client';
3+
import { type ProverClientConfig, getProverEnvVars } from '@aztec/prover-client';
44
import { type SequencerClientConfig, getConfigEnvVars as getSequencerVars } from '@aztec/sequencer-client';
55
import { getConfigEnvVars as getWorldStateVars } from '@aztec/world-state';
66

@@ -9,7 +9,7 @@ import { getConfigEnvVars as getWorldStateVars } from '@aztec/world-state';
99
*/
1010
export type AztecNodeConfig = ArchiverConfig &
1111
SequencerClientConfig &
12-
ProverConfig &
12+
ProverClientConfig &
1313
P2PConfig & {
1414
/** Whether the sequencer is disabled for this node. */
1515
disableSequencer: boolean;

yarn-project/aztec-node/src/aztec-node/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
NullifierMembershipWitness,
1616
type ProcessOutput,
1717
type ProverClient,
18+
type ProverConfig,
1819
PublicDataWitness,
1920
type SequencerConfig,
2021
type SiblingPath,
@@ -688,9 +689,9 @@ export class AztecNodeService implements AztecNode {
688689
};
689690
}
690691

691-
public setConfig(config: Partial<SequencerConfig>): Promise<void> {
692+
public async setConfig(config: Partial<SequencerConfig & ProverConfig>): Promise<void> {
692693
this.sequencer?.updateSequencerConfig(config);
693-
return Promise.resolve();
694+
await this.prover.updateProverConfig(config);
694695
}
695696

696697
/**

yarn-project/aztec/src/cli/cmds/start_prover.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { type ProvingJobSource } from '@aztec/circuit-types';
22
import { ProverPool, createProvingJobSourceClient } from '@aztec/prover-client/prover-pool';
33

4+
import { tmpdir } from 'node:os';
5+
46
import { type ServiceStarter, parseModuleOptions } from '../util.js';
57

68
type ProverOptions = Partial<{
@@ -35,6 +37,8 @@ export const startProver: ServiceStarter = async (options, signalHandlers, logge
3537
{
3638
acvmBinaryPath: proverOptions.acvmBinaryPath,
3739
bbBinaryPath: proverOptions.bbBinaryPath,
40+
acvmWorkingDirectory: tmpdir(),
41+
bbWorkingDirectory: tmpdir(),
3842
},
3943
agentCount,
4044
);

yarn-project/circuit-types/src/interfaces/aztec-node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { type TxEffect } from '../tx_effect.js';
2626
import { type SequencerConfig } from './configs.js';
2727
import { type L2BlockNumber } from './l2_block_number.js';
2828
import { type NullifierMembershipWitness } from './nullifier_tree.js';
29+
import { type ProverConfig } from './prover-client.js';
2930
import { type PublicDataWitness } from './public_data_tree.js';
3031

3132
/**
@@ -288,7 +289,7 @@ export interface AztecNode {
288289
* Updates the configuration of this node.
289290
* @param config - Updated configuration to be merged with the current one.
290291
*/
291-
setConfig(config: Partial<SequencerConfig>): Promise<void>;
292+
setConfig(config: Partial<SequencerConfig & ProverConfig>): Promise<void>;
292293

293294
/**
294295
* Returns a registered contract class given its id.

yarn-project/circuit-types/src/interfaces/prover-client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { type BlockProver } from './block-prover.js';
22
import { type ProvingJobSource } from './proving-job.js';
33

4+
/**
5+
* The prover configuration.
6+
*/
7+
export type ProverConfig = {
8+
/** How many agents to run */
9+
proverAgents: number;
10+
};
11+
412
/**
513
* The interface to the prover client.
614
* Provides the ability to generate proofs and build rollups.
@@ -11,4 +19,6 @@ export interface ProverClient extends BlockProver {
1119
stop(): Promise<void>;
1220

1321
getProvingJobSource(): ProvingJobSource;
22+
23+
updateProverConfig(config: Partial<ProverConfig>): Promise<void>;
1424
}

yarn-project/end-to-end/Earthfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,11 @@ bench-tx-size:
100100
ARG COMMIT_HASH
101101
DO +E2E_COMPOSE_TEST --test=benchmarks/bench_tx_size_fees.test.ts --debug="aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees" --enable_gas=1 --compose_file=./scripts/docker-compose-no-sandbox.yml
102102
DO +UPLOAD_LOGS --e2e_mode=$e2e_mode --PULL_REQUEST=$PULL_REQUEST --BRANCH=$BRANCH --COMMIT_HASH=$COMMIT_HASH
103+
104+
bench-proving:
105+
ARG e2e_mode=local
106+
ARG PULL_REQUEST
107+
ARG BRANCH
108+
ARG COMMIT_HASH
109+
DO +E2E_COMPOSE_TEST --test=bench_proving --debug="aztec:benchmarks:*,aztec:prover*,aztec:bb*" --e2e_mode=$e2e_mode --enable_gas=1 --compose_file=./scripts/docker-compose-no-sandbox.yml
110+
DO +UPLOAD_LOGS --e2e_mode=$e2e_mode --PULL_REQUEST=$PULL_REQUEST --BRANCH=$BRANCH --COMMIT_HASH=$COMMIT_HASH
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { type AztecNodeService } from '@aztec/aztec-node';
2+
import { type AccountWallet, EthAddress, PublicFeePaymentMethod, TxStatus } from '@aztec/aztec.js';
3+
import { GasSettings } from '@aztec/circuits.js';
4+
import { FPCContract, GasTokenContract, TestContract, TokenContract } from '@aztec/noir-contracts.js';
5+
import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token';
6+
import { ProverPool } from '@aztec/prover-client/prover-pool';
7+
8+
import { jest } from '@jest/globals';
9+
10+
import { getACVMConfig } from '../fixtures/get_acvm_config.js';
11+
import { getBBConfig } from '../fixtures/get_bb_config.js';
12+
import { type EndToEndContext, publicDeployAccounts, setup } from '../fixtures/utils.js';
13+
14+
jest.setTimeout(600_000);
15+
16+
const txTimeoutSec = 600;
17+
18+
describe('benchmarks/proving', () => {
19+
let ctx: EndToEndContext;
20+
let wallet: AccountWallet;
21+
let testContract: TestContract;
22+
let tokenContract: TokenContract;
23+
let fpContract: FPCContract;
24+
let acvmCleanup: () => Promise<void>;
25+
let bbCleanup: () => Promise<void>;
26+
let proverPool: ProverPool;
27+
28+
// setup the environment quickly using fake proofs
29+
beforeAll(async () => {
30+
ctx = await setup(
31+
1,
32+
{
33+
// do setup with fake proofs
34+
realProofs: false,
35+
proverAgents: 4,
36+
proverAgentPollInterval: 10,
37+
minTxsPerBlock: 1,
38+
},
39+
{},
40+
true, // enable gas
41+
);
42+
43+
wallet = ctx.wallet;
44+
45+
await publicDeployAccounts(wallet, ctx.wallets);
46+
47+
testContract = await TestContract.deploy(wallet).send().deployed();
48+
tokenContract = await TokenContract.deploy(wallet, wallet.getAddress(), 'test', 't', 18).send().deployed();
49+
const gas = await GasTokenContract.at(
50+
getCanonicalGasTokenAddress(ctx.deployL1ContractsValues.l1ContractAddresses.gasPortalAddress),
51+
wallet,
52+
);
53+
fpContract = await FPCContract.deploy(wallet, tokenContract.address, gas.address).send().deployed();
54+
55+
await Promise.all([
56+
gas.methods.mint_public(fpContract.address, 1e12).send().wait(),
57+
tokenContract.methods.mint_public(wallet.getAddress(), 1e12).send().wait(),
58+
]);
59+
});
60+
61+
// remove the fake prover and setup the real one
62+
beforeAll(async () => {
63+
const [acvmConfig, bbConfig] = await Promise.all([getACVMConfig(ctx.logger), getBBConfig(ctx.logger)]);
64+
if (!acvmConfig || !bbConfig) {
65+
throw new Error('Missing ACVM or BB config');
66+
}
67+
68+
acvmCleanup = acvmConfig.cleanup;
69+
bbCleanup = bbConfig.cleanup;
70+
71+
proverPool = ProverPool.nativePool(
72+
{
73+
...acvmConfig,
74+
...bbConfig,
75+
},
76+
4,
77+
10,
78+
);
79+
80+
ctx.logger.info('Stopping fake provers');
81+
await ctx.aztecNode.setConfig({
82+
// stop the fake provers
83+
proverAgents: 0,
84+
// 4-tx blocks so that we have at least one merge level
85+
minTxsPerBlock: 4,
86+
});
87+
88+
ctx.logger.info('Starting real provers');
89+
await proverPool.start((ctx.aztecNode as AztecNodeService).getProver().getProvingJobSource());
90+
});
91+
92+
afterAll(async () => {
93+
await proverPool.stop();
94+
await ctx.teardown();
95+
await acvmCleanup();
96+
await bbCleanup();
97+
});
98+
99+
it('builds a full block', async () => {
100+
const txs = [
101+
// fully private tx
102+
testContract.methods.emit_nullifier(42).send(),
103+
// tx with setup, app, teardown
104+
testContract.methods.emit_unencrypted(43).send({
105+
fee: {
106+
gasSettings: GasSettings.default(),
107+
paymentMethod: new PublicFeePaymentMethod(tokenContract.address, fpContract.address, wallet),
108+
},
109+
}),
110+
// tx with messages
111+
testContract.methods.create_l2_to_l1_message_public(45, 46, EthAddress.random()).send(),
112+
// tx with private and public exec
113+
testContract.methods.set_tx_max_block_number(100, true).send({
114+
fee: {
115+
gasSettings: GasSettings.default(),
116+
paymentMethod: new PublicFeePaymentMethod(tokenContract.address, fpContract.address, wallet),
117+
},
118+
}),
119+
];
120+
121+
const receipts = await Promise.all(txs.map(tx => tx.wait({ timeout: txTimeoutSec })));
122+
expect(receipts.every(r => r.status === TxStatus.MINED)).toBe(true);
123+
});
124+
});

yarn-project/end-to-end/src/client_prover_integration/client_prover_test.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ import {
1515
import { TokenContract } from '@aztec/noir-contracts.js';
1616
import { BBNativeProofCreator, type PXEService } from '@aztec/pxe';
1717

18-
import * as fs from 'fs/promises';
19-
2018
import { waitRegisteredAccountSynced } from '../benchmarks/utils.js';
19+
import { getBBConfig } from '../fixtures/get_bb_config.js';
2120
import {
2221
type ISnapshotManager,
2322
type SubsystemsContext,
2423
addAccounts,
2524
createSnapshotManager,
2625
publicDeployAccounts,
2726
} from '../fixtures/snapshot_manager.js';
28-
import { getBBConfig, setupPXEService } from '../fixtures/utils.js';
27+
import { setupPXEService } from '../fixtures/utils.js';
2928
import { TokenSimulator } from '../simulators/token_simulator.js';
3029

3130
const { E2E_DATA_PATH: dataPath } = process.env;
@@ -55,7 +54,7 @@ export class ClientProverTest {
5554
fullProverPXE!: PXEService;
5655
provenAsset!: TokenContract;
5756
provenPXETeardown?: () => Promise<void>;
58-
private directoryToCleanup?: string;
57+
private bbConfigCleanup?: () => Promise<void>;
5958
proofCreator?: BBNativeProofCreator;
6059

6160
constructor(testName: string) {
@@ -121,21 +120,21 @@ export class ClientProverTest {
121120

122121
// Configure a full prover PXE
123122
const bbConfig = await getBBConfig(this.logger);
124-
this.directoryToCleanup = bbConfig?.directoryToCleanup;
123+
this.bbConfigCleanup = bbConfig?.cleanup;
125124

126-
if (!bbConfig?.bbWorkingDirectory || !bbConfig?.expectedBBPath) {
125+
if (!bbConfig?.bbWorkingDirectory || !bbConfig?.bbBinaryPath) {
127126
throw new Error(`Test must be run with BB native configuration`);
128127
}
129128

130-
this.proofCreator = new BBNativeProofCreator(bbConfig?.expectedBBPath, bbConfig?.bbWorkingDirectory);
129+
this.proofCreator = new BBNativeProofCreator(bbConfig.bbBinaryPath, bbConfig.bbWorkingDirectory);
131130

132131
this.logger.debug(`Main setup completed, initializing full prover PXE...`);
133132
({ pxe: this.fullProverPXE, teardown: this.provenPXETeardown } = await setupPXEService(
134133
0,
135134
this.aztecNode,
136135
{
137136
proverEnabled: false,
138-
bbBinaryPath: bbConfig?.expectedBBPath,
137+
bbBinaryPath: bbConfig?.bbBinaryPath,
139138
bbWorkingDirectory: bbConfig?.bbWorkingDirectory,
140139
},
141140
undefined,
@@ -180,9 +179,7 @@ export class ClientProverTest {
180179
// Cleanup related to the second 'full prover' PXE
181180
await this.provenPXETeardown?.();
182181

183-
if (this.directoryToCleanup) {
184-
await fs.rm(this.directoryToCleanup, { recursive: true, force: true });
185-
}
182+
await this.bbConfigCleanup?.();
186183
}
187184

188185
async addPendingShieldNoteToPXE(accountIndex: number, amount: bigint, secretHash: Fr, txHash: TxHash) {

yarn-project/end-to-end/src/fixtures/get_acvm_config.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ const {
1313
} = process.env;
1414

1515
// Determines if we have access to the acvm binary and a tmp folder for temp files
16-
export async function getACVMConfig(logger: DebugLogger) {
16+
export async function getACVMConfig(logger: DebugLogger): Promise<
17+
| {
18+
acvmWorkingDirectory: string;
19+
acvmBinaryPath: string;
20+
cleanup: () => Promise<void>;
21+
}
22+
| undefined
23+
> {
1724
try {
18-
const expectedAcvmPath = ACVM_BINARY_PATH ? ACVM_BINARY_PATH : `../../noir/${NOIR_RELEASE_DIR}/acvm`;
19-
await fs.access(expectedAcvmPath, fs.constants.R_OK);
25+
const acvmBinaryPath = ACVM_BINARY_PATH ? ACVM_BINARY_PATH : `../../noir/${NOIR_RELEASE_DIR}/acvm`;
26+
await fs.access(acvmBinaryPath, fs.constants.R_OK);
2027
const tempWorkingDirectory = `${TEMP_DIR}/${randomBytes(4).toString('hex')}`;
2128
const acvmWorkingDirectory = ACVM_WORKING_DIRECTORY ? ACVM_WORKING_DIRECTORY : `${tempWorkingDirectory}/acvm`;
2229
await fs.mkdir(acvmWorkingDirectory, { recursive: true });
23-
logger.verbose(`Using native ACVM binary at ${expectedAcvmPath} with working directory ${acvmWorkingDirectory}`);
30+
logger.verbose(`Using native ACVM binary at ${acvmBinaryPath} with working directory ${acvmWorkingDirectory}`);
2431

2532
const directoryToCleanup = ACVM_WORKING_DIRECTORY ? undefined : tempWorkingDirectory;
2633

@@ -33,7 +40,7 @@ export async function getACVMConfig(logger: DebugLogger) {
3340

3441
return {
3542
acvmWorkingDirectory,
36-
expectedAcvmPath,
43+
acvmBinaryPath,
3744
cleanup,
3845
};
3946
} catch (err) {

0 commit comments

Comments
 (0)