Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ function build_bench {
return
fi
parallel --line-buffer --tag --halt now,fail=1 'denoise "{}/bootstrap.sh build_bench"' ::: \
barretenberg/cpp \
yarn-project/end-to-end
barretenberg/cpp
}
export -f build_bench

Expand Down
2 changes: 2 additions & 0 deletions yarn-project/bb-prover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"@aztec/world-state": "workspace:^",
"commander": "^12.1.0",
"pako": "^2.1.0",
"pidusage": "^4.0.1",
"source-map-support": "^0.5.21",
"tslib": "^2.4.0"
},
Expand All @@ -90,6 +91,7 @@
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/node": "^22.15.17",
"@types/pidusage": "^2.0.5",
"@types/source-map-support": "^0.5.10",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.3",
Expand Down
17 changes: 15 additions & 2 deletions yarn-project/bb-prover/src/bb/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm
import * as proc from 'child_process';
import { promises as fs } from 'fs';
import { basename, dirname, join } from 'path';
import pidusage from 'pidusage';

import type { UltraHonkFlavor } from '../honk.js';

Expand Down Expand Up @@ -97,11 +98,23 @@ export function executeBB(

bb.stdout.on('data', data => {
const message = data.toString('utf-8').replace(/\n$/, '');
logger(message);
pidusage(bb.pid!, (err, stats) => {
if (err) {
logger(message);
} else {
logger(`${message} (mem: ${(stats.memory / 1024 / 1024).toFixed(2)}MiB)`);
}
});
});
bb.stderr.on('data', data => {
const message = data.toString('utf-8').replace(/\n$/, '');
logger(message);
pidusage(bb.pid!, (err, stats) => {
if (err) {
logger(message);
} else {
logger(`${message} (mem: ${(stats.memory / 1024 / 1024).toFixed(2)}MiB)`);
}
});
});
bb.on('close', (exitCode: number, signal?: string) => {
if (timeoutId) {
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/end-to-end/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ function test {

function bench_cmds {
echo "$hash:ISOLATE=1:NAME=bench_build_block BENCH_OUTPUT=bench-out/build-block.bench.json yarn-project/end-to-end/scripts/run_test.sh simple bench_build_block"
for dir in $bench_fixtures_dir/*; do
for runtime in native wasm; do
echo "$hash:CPUS=8 barretenberg/cpp/scripts/ci_benchmark_ivc_flows.sh $runtime ../../yarn-project/end-to-end/$dir"
done

for client_flow in client_flows/bridging client_flows/deployments client_flows/amm client_flows/account_deployments client_flows/transfers; do
echo "$hash:ISOLATE=1:CPUS=8:NAME=$client_flow REAL_PROOFS=1 BENCHMARK_CONFIG=key_flows LOG_LEVEL=error BENCH_OUTPUT=bench-out/ yarn-project/end-to-end/scripts/run_test.sh simple $client_flow"
done
}

Expand All @@ -82,6 +81,7 @@ function build_bench {
exit 1
fi
parallel --tag --line-buffer --halt now,fail=1 'docker_isolate "scripts/run_test.sh simple {}"' ::: \
client_flows/account_deployments \
client_flows/deployments \
client_flows/bridging \
client_flows/transfers \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EcdsaRAccountContractArtifact } from '@aztec/accounts/ecdsa';
import { AccountWallet, type DeployOptions, Fr, registerContractClass } from '@aztec/aztec.js';
import { AccountWallet, type DeployOptions, Fr, type PXE, registerContractClass } from '@aztec/aztec.js';
import type { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';

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

import { capturePrivateExecutionStepsIfEnvSet } from '../../shared/capture_private_execution_steps.js';
import { type AccountType, type BenchmarkingFeePaymentMethod, ClientFlowsBenchmark } from './client_flows_benchmark.js';
import { captureProfile } from './utils.js';

jest.setTimeout(300_000);

Expand All @@ -17,11 +17,13 @@ describe('Deployment benchmark', () => {
let sponsoredFPC: SponsoredFPCContract;
// Benchmarking configuration
const config = t.config.accountDeployments;
// Benchmarking user's PXE
let userPXE: PXE;

beforeAll(async () => {
await t.applyBaseSnapshots();
await t.applyDeploySponsoredFPCSnapshot();
({ adminWallet, sponsoredFPC } = await t.setup());
({ adminWallet, sponsoredFPC, userPXE } = await t.setup());
// Ensure the ECDSAR1 contract is already registered, to avoid benchmarking an extra call to the ContractClassRegisterer
// The typical interaction would be for a user to deploy an account contract that is already registered in the
// network.
Expand All @@ -41,7 +43,7 @@ describe('Deployment benchmark', () => {
return describe(`Deployment benchmark for ${accountType}`, () => {
function deploymentTest(benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) {
return it(`Deploys a ${accountType} account contract, pays using ${benchmarkingPaymentMethod}`, async () => {
const benchysAccountManager = await t.createBenchmarkingAccountManager(accountType);
const benchysAccountManager = await t.createBenchmarkingAccountManager(userPXE, accountType);
const benchysWallet = await benchysAccountManager.getWallet();

if (benchmarkingPaymentMethod === 'sponsored_fpc') {
Expand All @@ -66,7 +68,7 @@ describe('Deployment benchmark', () => {
contractAddressSalt: new Fr(benchysAccountManager.salt),
};

await capturePrivateExecutionStepsIfEnvSet(
await captureProfile(
`deploy_${accountType}+${benchmarkingPaymentMethod}`,
deploymentInteraction,
options,
Expand All @@ -81,9 +83,11 @@ describe('Deployment benchmark', () => {
1, // Kernel tail
);

// Ensure we paid a fee
const tx = await deploymentInteraction.send(options).wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);
if (process.env.SANITY_CHECKS) {
// Ensure we paid a fee
const tx = await deploymentInteraction.send(options).wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);
}
});
}

Expand Down
10 changes: 6 additions & 4 deletions yarn-project/end-to-end/src/bench/client_flows/amm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { jest } from '@jest/globals';

import { mintNotes } from '../../fixtures/token_utils.js';
import { capturePrivateExecutionStepsIfEnvSet } from '../../shared/capture_private_execution_steps.js';
import { type AccountType, type BenchmarkingFeePaymentMethod, ClientFlowsBenchmark } from './client_flows_benchmark.js';
import { captureProfile } from './utils.js';

jest.setTimeout(900_000);

Expand Down Expand Up @@ -132,7 +132,7 @@ describe('AMM benchmark', () => {
.methods.add_liquidity(amountToSend, amountToSend, amountToSend, amountToSend, nonceForAuthwits)
.with({ authWitnesses: [token0Authwit, token1Authwit] });

await capturePrivateExecutionStepsIfEnvSet(
await captureProfile(
`${accountType}+amm_add_liquidity_1_recursions+${benchmarkingPaymentMethod}`,
addLiquidityInteraction,
options,
Expand All @@ -151,8 +151,10 @@ describe('AMM benchmark', () => {
1, // Kernel tail
);

const tx = await addLiquidityInteraction.send().wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);
if (process.env.SANITY_CHECKS) {
const tx = await addLiquidityInteraction.send().wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);
}
});
});
}
Expand Down
18 changes: 10 additions & 8 deletions yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { TokenContract } from '@aztec/noir-contracts.js/Token';

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

import { capturePrivateExecutionStepsIfEnvSet } from '../../shared/capture_private_execution_steps.js';
import type { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js';
import { type AccountType, type BenchmarkingFeePaymentMethod, ClientFlowsBenchmark } from './client_flows_benchmark.js';
import { captureProfile } from './utils.js';

jest.setTimeout(300_000);

Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Bridging benchmark', () => {
messageLeafIndex,
);

await capturePrivateExecutionStepsIfEnvSet(
await captureProfile(
`${accountType}+token_bridge_claim_private+${benchmarkingPaymentMethod}`,
claimInteraction,
options,
Expand All @@ -104,14 +104,16 @@ describe('Bridging benchmark', () => {
1, // Kernel tail
);

// Ensure we paid a fee
const tx = await claimInteraction.send(options).wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);
if (process.env.SANITY_CHECKS) {
// Ensure we paid a fee
const tx = await claimInteraction.send(options).wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);

// 4. Check the balance
// 4. Check the balance

const balance = await crossChainTestHarness.getL2PrivateBalanceOf(benchysWallet.getAddress());
expect(balance).toBe(bridgeAmount);
const balance = await crossChainTestHarness.getL2PrivateBalanceOf(benchysWallet.getAddress());
expect(balance).toBe(bridgeAmount);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EcdsaRAccountContractArtifact, getEcdsaRAccount } from '@aztec/accounts
import { SchnorrAccountContractArtifact, getSchnorrAccount, getSchnorrWallet } from '@aztec/accounts/schnorr';
import {
type AccountWallet,
AccountWalletWithSecretKey,
AztecAddress,
type AztecNode,
FeeJuicePaymentMethod,
Expand Down Expand Up @@ -48,6 +49,7 @@ import {
type GasBridgingTestHarness,
} from '../../shared/gas_portal_test_harness.js';
import { type ClientFlowsConfig, FULL_FLOWS_CONFIG, KEY_FLOWS_CONFIG } from './config.js';
import { ProxyLogger } from './utils.js';

const { E2E_DATA_PATH: dataPath, BENCHMARK_CONFIG } = process.env;

Expand Down Expand Up @@ -91,6 +93,8 @@ export class ClientFlowsBenchmark {
// PXE used by the benchmarking user. It can be set up with client-side proving enabled
public userPXE!: PXE;

public realProofs = ['true', '1'].includes(process.env.REAL_PROOFS ?? '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

god i have javascript


public paymentMethods: Record<BenchmarkingFeePaymentMethod, { forWallet: FeePaymentMethodGetter; circuits: number }> =
{
// eslint-disable-next-line camelcase
Expand Down Expand Up @@ -121,6 +125,8 @@ export class ClientFlowsBenchmark {

public config: ClientFlowsConfig;

private proxyLogger: ProxyLogger;

constructor(testName?: string, setupOptions: Partial<SetupOptions & DeployL1ContractsArgs> = {}) {
this.logger = createLogger(`bench:client_flows${testName ? `:${testName}` : ''}`);
this.snapshotManager = createSnapshotManager(
Expand All @@ -130,6 +136,8 @@ export class ClientFlowsBenchmark {
{ ...setupOptions },
);
this.config = BENCHMARK_CONFIG === 'key_flows' ? KEY_FLOWS_CONFIG : FULL_FLOWS_CONFIG;
ProxyLogger.create();
this.proxyLogger = ProxyLogger.getInstance();
}

async setup() {
Expand Down Expand Up @@ -163,18 +171,18 @@ export class ClientFlowsBenchmark {
expect(balanceAfter).toEqual(balanceBefore + amount);
}

async createBenchmarkingAccountManager(type: 'ecdsar1' | 'schnorr') {
async createBenchmarkingAccountManager(pxe: PXE, type: 'ecdsar1' | 'schnorr') {
const benchysSecretKey = Fr.random();
const salt = Fr.random();

let benchysPrivateSigningKey;
let benchysAccountManager;
if (type === 'schnorr') {
benchysPrivateSigningKey = deriveSigningKey(benchysSecretKey);
benchysAccountManager = await getSchnorrAccount(this.userPXE, benchysSecretKey, benchysPrivateSigningKey, salt);
benchysAccountManager = await getSchnorrAccount(pxe, benchysSecretKey, benchysPrivateSigningKey, salt);
} else if (type === 'ecdsar1') {
benchysPrivateSigningKey = randomBytes(32);
benchysAccountManager = await getEcdsaRAccount(this.userPXE, benchysSecretKey, benchysPrivateSigningKey, salt);
benchysAccountManager = await getEcdsaRAccount(pxe, benchysSecretKey, benchysPrivateSigningKey, salt);
} else {
throw new Error(`Unknown account type: ${type}`);
}
Expand Down Expand Up @@ -212,11 +220,15 @@ export class ClientFlowsBenchmark {
const l1Contracts = await aztecNode.getL1ContractAddresses();
const userPXEConfigWithContracts = {
...userPXEConfig,
proverEnabled: ['true', '1'].includes(process.env.REAL_PROOFS ?? ''),
proverEnabled: this.realProofs,
l1Contracts,
} as PXEServiceConfig;

this.userPXE = await createPXEService(this.aztecNode, userPXEConfigWithContracts, 'pxe-user');
this.userPXE = await createPXEService(this.aztecNode, userPXEConfigWithContracts, {
loggers: {
prover: this.proxyLogger.createLogger('pxe:bb:wasm:bundle:proxied'),
},
});
},
);
}
Expand Down Expand Up @@ -337,7 +349,7 @@ export class ClientFlowsBenchmark {
}

public async createAndFundBenchmarkingWallet(accountType: AccountType) {
const benchysAccountManager = await this.createBenchmarkingAccountManager(accountType);
const benchysAccountManager = await this.createBenchmarkingAccountManager(this.pxe, accountType);
const benchysWallet = await benchysAccountManager.getWallet();
const benchysAddress = benchysAccountManager.getAddress();
const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(
Expand All @@ -346,13 +358,19 @@ export class ClientFlowsBenchmark {
);
const paymentMethod = new FeeJuicePaymentMethodWithClaim(benchysWallet, claim);
await benchysAccountManager.deploy({ fee: { paymentMethod } }).wait();
// Register benchy on admin's PXE so we can check its balances
await this.pxe.registerContract({
// Register benchy on the user's PXE, where we're going to be interacting from
await this.userPXE.registerContract({
instance: benchysAccountManager.getInstance(),
artifact: accountType === 'ecdsar1' ? EcdsaRAccountContractArtifact : SchnorrAccountContractArtifact,
});
await this.pxe.registerAccount(benchysWallet.getSecretKey(), benchysWallet.getCompleteAddress().partialAddress);
return benchysWallet;
await this.userPXE.registerAccount(benchysWallet.getSecretKey(), benchysWallet.getCompleteAddress().partialAddress);
const entrypoint = await benchysAccountManager.getAccount();
return new AccountWalletWithSecretKey(
this.userPXE,
entrypoint,
benchysWallet.getSecretKey(),
benchysAccountManager.salt,
);
}

public async applyDeployAmmSnapshot() {
Expand Down
Loading