Skip to content

Commit

Permalink
feat: proving benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Apr 29, 2024
1 parent ed34227 commit b2a73e2
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 99 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,16 @@ jobs:
aztec_manifest_key: end-to-end
<<: *defaults_e2e_test

bench-proving:
steps:
- *checkout
- *setup_env
- run:
name: "Benchmark"
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose-no-sandbox.yml TEST=benchmarks/bench_proving.test.ts JOB_NAME="bench-proving" DEBUG=aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees,aztec:prover:*
aztec_manifest_key: end-to-end
<<: *defaults_e2e_test

build-docs:
machine:
image: default
Expand Down Expand Up @@ -799,11 +809,13 @@ workflows:
- bench-publish-rollup: *e2e_test
- bench-process-history: *e2e_test
- bench-tx-size: *e2e_test
- bench-proving: *e2e_test
- bench-summary:
requires:
- bench-publish-rollup
- bench-process-history
- bench-tx-size
- bench-proving
<<: *defaults

# Production releases.
Expand Down
1 change: 1 addition & 0 deletions build_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ end-to-end:
- noir-projects
- noir
- yarn-project
- barretenberg-x86_64-linux-clang
runDependencies:
- aztec

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
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"]
81 changes: 81 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,81 @@
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import { BatchCall, EthAddress, Fq, Fr, TxStatus, type Wallet } from '@aztec/aztec.js';
import { TestContract } from '@aztec/noir-contracts.js';
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, setupNoL2Deploy } from '../fixtures/utils.js';

jest.setTimeout(1_000_000);

// seconds!
const txTimeoutSec = 200;

describe('benchmarks/proving', () => {
let ctx: Omit<EndToEndContext, 'wallet'>;
let wallet: Wallet;
let testContract: TestContract;
let proverPool: ProverPool;
let acvmCleanup: () => Promise<void>;
let bbCleanup: () => Promise<void>;

// setup the environment
beforeAll(async () => {
ctx = await setupNoL2Deploy({
proverAgents: 0,
});

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(
{
acvmBinaryPath: acvmConfig.acvmBinaryPath,
acvmWorkingDirectory: acvmConfig.acvmWorkingDirectory,
bbBinaryPath: bbConfig.bbBinaryPath,
bbWorkingDirectory: bbConfig.bbWorkingDirectory,
},
4,
10,
);

await proverPool.start(ctx.prover!.getProvingJobSource());

wallet = await getSchnorrAccount(ctx.pxe, Fr.random(), Fq.random()).deploy().getWallet({
timeout: txTimeoutSec,
});
testContract = await TestContract.deploy(wallet).send().deployed({
timeout: txTimeoutSec,
});
});

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

await acvmCleanup();
await bbCleanup();
});

it('executes a batch call', async () => {
const call = new BatchCall(wallet, [
testContract.methods.emit_nullifier(42).request(),
testContract.methods.call_create_note(43, wallet.getAddress(), 44).request(),
testContract.methods.create_l2_to_l1_message_public(45, 46, EthAddress.random()).request(),
testContract.methods.emit_unencrypted(47).request(),
]);

const receipt = await call.send().wait({
timeout: txTimeoutSec,
});
expect(receipt.status).toBe(TxStatus.MINED);
});
});
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 b2a73e2

Please sign in to comment.