Skip to content

Commit

Permalink
feat: proving benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed May 2, 2024
1 parent 96ceebb commit d45e383
Show file tree
Hide file tree
Showing 20 changed files with 351 additions and 106 deletions.
1 change: 1 addition & 0 deletions build_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ end-to-end:
- noir-projects
- noir
- yarn-project
- barretenberg-x86_64-linux-clang
runDependencies:
- aztec

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-node/src/aztec-node/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ArchiverConfig, getConfigEnvVars as getArchiverVars } from '@aztec/archiver';
import { type P2PConfig, getP2PConfigEnvVars } from '@aztec/p2p';
import { type ProverConfig, getProverEnvVars } from '@aztec/prover-client';
import { type ProverClientConfig, getProverEnvVars } from '@aztec/prover-client';
import { type SequencerClientConfig, getConfigEnvVars as getSequencerVars } from '@aztec/sequencer-client';
import { getConfigEnvVars as getWorldStateVars } from '@aztec/world-state';

Expand All @@ -9,7 +9,7 @@ import { getConfigEnvVars as getWorldStateVars } from '@aztec/world-state';
*/
export type AztecNodeConfig = ArchiverConfig &
SequencerClientConfig &
ProverConfig &
ProverClientConfig &
P2PConfig & {
/** Whether the sequencer is disabled for this node. */
disableSequencer: boolean;
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
NullifierMembershipWitness,
type ProcessOutput,
type ProverClient,
type ProverConfig,
PublicDataWitness,
type SequencerConfig,
type SiblingPath,
Expand Down Expand Up @@ -688,8 +689,9 @@ export class AztecNodeService implements AztecNode {
};
}

public setConfig(config: Partial<SequencerConfig>): Promise<void> {
public setConfig(config: Partial<SequencerConfig | ProverConfig>): Promise<void> {
this.sequencer?.updateSequencerConfig(config);
this.prover.updateProverConfig(config);
return Promise.resolve();
}

Expand Down
4 changes: 4 additions & 0 deletions yarn-project/aztec/src/cli/cmds/start_prover.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type ProvingJobSource } from '@aztec/circuit-types';
import { ProverPool, createProvingJobSourceClient } from '@aztec/prover-client/prover-pool';

import { tmpdir } from 'node:os';

import { type ServiceStarter, parseModuleOptions } from '../util.js';

type ProverOptions = Partial<{
Expand Down Expand Up @@ -35,6 +37,8 @@ export const startProver: ServiceStarter = async (options, signalHandlers, logge
{
acvmBinaryPath: proverOptions.acvmBinaryPath,
bbBinaryPath: proverOptions.bbBinaryPath,
acvmWorkingDirectory: tmpdir(),
bbWorkingDirectory: tmpdir(),
},
agentCount,
);
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { type TxEffect } from '../tx_effect.js';
import { type SequencerConfig } from './configs.js';
import { type L2BlockNumber } from './l2_block_number.js';
import { type NullifierMembershipWitness } from './nullifier_tree.js';
import { type ProverConfig } from './prover-client.js';
import { type PublicDataWitness } from './public_data_tree.js';

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

/**
* Returns a registered contract class given its id.
Expand Down
22 changes: 22 additions & 0 deletions yarn-project/circuit-types/src/interfaces/prover-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { type BlockProver } from './block-prover.js';
import { type ProvingJobSource } from './proving-job.js';

/**
* The prover configuration.
*/
export type ProverConfig = {
/** The working directory to use for simulation/proving */
acvmWorkingDirectory: string;
/** The path to the ACVM binary */
acvmBinaryPath: string;
/** The working directory to for proving */
bbWorkingDirectory: string;
/** The path to the bb binary */
bbBinaryPath: string;
/** How many agents to start */
proverAgents: number;
/** Enable proving. If true, must set bb env vars */
realProofs: boolean;
/** The interval agents poll for jobs at */
proverAgentPollInterval: number;
};

/**
* The interface to the prover client.
* Provides the ability to generate proofs and build rollups.
Expand All @@ -11,4 +31,6 @@ export interface ProverClient extends BlockProver {
stop(): Promise<void>;

getProvingJobSource(): ProvingJobSource;

updateProverConfig(config: Partial<ProverConfig>): Promise<void>;
}
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM --platform=linux/amd64 aztecprotocol/bb.js as bb.js
FROM --platform=linux/amd64 aztecprotocol/noir-packages as noir-packages
FROM --platform=linux/amd64 aztecprotocol/l1-contracts as contracts
FROM --platform=linux/amd64 aztecprotocol/noir-projects as noir-projects
FROM --platform=linux/amd64 aztecprotocol/barretenberg-x86_64-linux-clang as bb
FROM aztecprotocol/noir as noir

FROM node:18.19.0 as builder
Expand All @@ -13,6 +14,7 @@ COPY --from=noir-packages /usr/src/noir/packages /usr/src/noir/packages
COPY --from=contracts /usr/src/l1-contracts /usr/src/l1-contracts
COPY --from=noir-projects /usr/src/noir-projects /usr/src/noir-projects
COPY --from=noir /usr/src/noir/noir-repo/target/release/acvm /usr/src/noir/noir-repo/target/release/acvm
COPY --from=bb /usr/src/barretenberg/cpp/build/bin/bb /usr/src/barretenberg/cpp/build/bin/bb

WORKDIR /usr/src/yarn-project
COPY . .
Expand Down Expand Up @@ -43,7 +45,7 @@ RUN /root/.foundry/bin/foundryup --version nightly-de33b6af53005037b463318d2628b

# Create minimal image.
FROM node:18.19.1-slim
RUN apt-get update && apt-get install jq gnupg wget netcat-openbsd -y && \
RUN apt-get update && apt-get install jq gnupg wget curl netcat-openbsd -y && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
Expand All @@ -52,4 +54,4 @@ RUN apt-get update && apt-get install jq gnupg wget netcat-openbsd -y && \
ENV CHROME_BIN="/usr/bin/google-chrome-stable"
COPY --from=builder /usr/src /usr/src
WORKDIR /usr/src/yarn-project/end-to-end
ENTRYPOINT ["yarn", "test"]
ENTRYPOINT ["yarn", "test"]
8 changes: 8 additions & 0 deletions yarn-project/end-to-end/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,11 @@ bench-tx-size:
ARG COMMIT_HASH
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
DO +UPLOAD_LOGS --e2e_mode=$e2e_mode --PULL_REQUEST=$PULL_REQUEST --BRANCH=$BRANCH --COMMIT_HASH=$COMMIT_HASH

bench-proving:
ARG e2e_mode=local
ARG PULL_REQUEST
ARG BRANCH
ARG COMMIT_HASH
DO +E2E_TEST --test=benchmarks/bench_tx_size_fees.test.ts --debug="aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees" --e2e_mode=$e2e_mode --enable_gas=0 --compose_file=./scripts/docker-compose-no-sandbox.yml
DO +UPLOAD_LOGS --e2e_mode=$e2e_mode --PULL_REQUEST=$PULL_REQUEST --BRANCH=$BRANCH --COMMIT_HASH=$COMMIT_HASH
124 changes: 124 additions & 0 deletions yarn-project/end-to-end/src/benchmarks/bench_proving.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { type AztecNodeService } from '@aztec/aztec-node';
import { type AccountWallet, EthAddress, PublicFeePaymentMethod, TxStatus } from '@aztec/aztec.js';
import { GasSettings } from '@aztec/circuits.js';
import { FPCContract, GasTokenContract, TestContract, TokenContract } from '@aztec/noir-contracts.js';
import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token';
import { ProverPool } from '@aztec/prover-client/prover-pool';

import { jest } from '@jest/globals';

import { getACVMConfig } from '../fixtures/get_acvm_config.js';
import { getBBConfig } from '../fixtures/get_bb_config.js';
import { type EndToEndContext, publicDeployAccounts, setup } from '../fixtures/utils.js';

jest.setTimeout(200_000);

const txTimeoutSec = 200;

describe('benchmarks/proving', () => {
let ctx: EndToEndContext;
let wallet: AccountWallet;
let testContract: TestContract;
let tokenContract: TokenContract;
let fpContract: FPCContract;
let acvmCleanup: () => Promise<void>;
let bbCleanup: () => Promise<void>;
let proverPool: ProverPool;

// setup the environment quickly using fake proofs
beforeAll(async () => {
ctx = await setup(
1,
{
// do setup with fake proofs
realProofs: false,
proverAgents: 4,
proverAgentPollInterval: 10,
minTxsPerBlock: 1,
},
{},
true, // enable gas
);

wallet = ctx.wallet;

await publicDeployAccounts(wallet, ctx.wallets);

testContract = await TestContract.deploy(wallet).send().deployed();
tokenContract = await TokenContract.deploy(wallet, wallet.getAddress(), 'test', 't', 18).send().deployed();
const gas = await GasTokenContract.at(
getCanonicalGasTokenAddress(ctx.deployL1ContractsValues.l1ContractAddresses.gasPortalAddress),
wallet,
);
fpContract = await FPCContract.deploy(wallet, tokenContract.address, gas.address).send().deployed();

await Promise.all([
gas.methods.mint_public(fpContract.address, 1e12).send().wait(),
tokenContract.methods.mint_public(wallet.getAddress(), 1e12).send().wait(),
]);
});

// remove the fake prover and setup the real one
beforeAll(async () => {
const [acvmConfig, bbConfig] = await Promise.all([getACVMConfig(ctx.logger), getBBConfig(ctx.logger)]);
if (!acvmConfig || !bbConfig) {
throw new Error('Missing ACVM or BB config');
}

acvmCleanup = acvmConfig.cleanup;
bbCleanup = bbConfig.cleanup;

proverPool = ProverPool.nativePool(
{
...acvmConfig,
...bbConfig,
},
4,
10,
);

ctx.logger.info('Stopping fake provers');
await ctx.aztecNode.setConfig({
// stop the fake provers
proverAgents: 0,
// 4-tx blocks so that we have at least one merge level
minTxsPerBlock: 4,
});

ctx.logger.info('Starting real provers');
await proverPool.start((ctx.aztecNode as AztecNodeService).getProver().getProvingJobSource());
});

afterAll(async () => {
await proverPool.stop();
await ctx.teardown();
await acvmCleanup();
await bbCleanup();
});

it('builds a full block', async () => {
const txs = [
// fully private tx
testContract.methods.emit_nullifier(42).send(),
// tx with setup, app, teardown
testContract.methods.emit_unencrypted(43).send({
fee: {
gasSettings: GasSettings.default(),
paymentMethod: new PublicFeePaymentMethod(tokenContract.address, fpContract.address, wallet),
},
}),
// tx with messages
testContract.methods.create_l2_to_l1_message_public(45, 46, EthAddress.random()).send(),
// tx with private and public exec
testContract.methods.set_tx_max_block_number(100, true).send({
fee: {
gasSettings: GasSettings.default(),
paymentMethod: new PublicFeePaymentMethod(tokenContract.address, fpContract.address, wallet),
},
}),
];

const receipts = await Promise.all(txs.map(tx => tx.wait({ timeout: txTimeoutSec })));
expect(receipts.every(r => r.status === TxStatus.MINED)).toBe(true);
});
});
17 changes: 12 additions & 5 deletions yarn-project/end-to-end/src/fixtures/get_acvm_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ const {
} = process.env;

// Determines if we have access to the acvm binary and a tmp folder for temp files
export async function getACVMConfig(logger: DebugLogger) {
export async function getACVMConfig(logger: DebugLogger): Promise<
| {
acvmWorkingDirectory: string;
acvmBinaryPath: string;
cleanup: () => Promise<void>;
}
| undefined
> {
try {
const expectedAcvmPath = ACVM_BINARY_PATH ? ACVM_BINARY_PATH : `../../noir/${NOIR_RELEASE_DIR}/acvm`;
await fs.access(expectedAcvmPath, fs.constants.R_OK);
const acvmBinaryPath = ACVM_BINARY_PATH ? ACVM_BINARY_PATH : `../../noir/${NOIR_RELEASE_DIR}/acvm`;
await fs.access(acvmBinaryPath, fs.constants.R_OK);
const tempWorkingDirectory = `${TEMP_DIR}/${randomBytes(4).toString('hex')}`;
const acvmWorkingDirectory = ACVM_WORKING_DIRECTORY ? ACVM_WORKING_DIRECTORY : `${tempWorkingDirectory}/acvm`;
await fs.mkdir(acvmWorkingDirectory, { recursive: true });
logger.verbose(`Using native ACVM binary at ${expectedAcvmPath} with working directory ${acvmWorkingDirectory}`);
logger.verbose(`Using native ACVM binary at ${acvmBinaryPath} with working directory ${acvmWorkingDirectory}`);

const directoryToCleanup = ACVM_WORKING_DIRECTORY ? undefined : tempWorkingDirectory;

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

return {
acvmWorkingDirectory,
expectedAcvmPath,
acvmBinaryPath,
cleanup,
};
} catch (err) {
Expand Down
46 changes: 46 additions & 0 deletions yarn-project/end-to-end/src/fixtures/get_bb_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { type DebugLogger, fileURLToPath } from '@aztec/aztec.js';

import fs from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'path';

const {
BB_RELEASE_DIR = 'barretenberg/cpp/build/bin',
BB_BINARY_PATH,
TEMP_DIR = tmpdir(),
BB_WORKING_DIRECTORY = '',
} = process.env;

export const getBBConfig = async (
logger: DebugLogger,
): Promise<{ bbBinaryPath: string; bbWorkingDirectory: string; cleanup: () => Promise<void> } | undefined> => {
try {
const bbBinaryPath =
BB_BINARY_PATH ??
path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../', BB_RELEASE_DIR, 'bb');
await fs.access(bbBinaryPath, fs.constants.R_OK);

let bbWorkingDirectory: string;
let directoryToCleanup: string | undefined;

if (BB_WORKING_DIRECTORY) {
bbWorkingDirectory = BB_WORKING_DIRECTORY;
} else {
bbWorkingDirectory = await fs.mkdtemp(path.join(TEMP_DIR, 'bb-'));
directoryToCleanup = bbWorkingDirectory;
}

await fs.mkdir(bbWorkingDirectory, { recursive: true });

const cleanup = async () => {
if (directoryToCleanup) {
await fs.rm(directoryToCleanup, { recursive: true, force: true });
}
};

return { bbBinaryPath, bbWorkingDirectory, cleanup };
} catch (err) {
logger.error(`Native BB not available, error: ${err}`);
return undefined;
}
};
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/fixtures/snapshot_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class SnapshotManager {
const acvmConfig = await getACVMConfig(this.logger);
if (acvmConfig) {
aztecNodeConfig.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
aztecNodeConfig.acvmBinaryPath = acvmConfig.expectedAcvmPath;
aztecNodeConfig.acvmBinaryPath = acvmConfig.acvmBinaryPath;
}

this.logger.verbose('Creating and synching an aztec node...');
Expand Down Expand Up @@ -254,7 +254,7 @@ export class SnapshotManager {
const acvmConfig = await getACVMConfig(this.logger);
if (acvmConfig) {
aztecNodeConfig.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
aztecNodeConfig.acvmBinaryPath = acvmConfig.expectedAcvmPath;
aztecNodeConfig.acvmBinaryPath = acvmConfig.acvmBinaryPath;
}

this.logger.verbose('Creating aztec node...');
Expand Down
Loading

0 comments on commit d45e383

Please sign in to comment.