Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b981a7f
more tests, tentative trace
Thunkar Mar 27, 2025
0717740
Increase capacity to 17 kernels
codygunton Mar 27, 2025
789dd62
better test org
Thunkar Mar 27, 2025
50a1962
restored trace
Thunkar Mar 27, 2025
c2ab6b4
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 27, 2025
8e913f6
Merge branch 'cg/bump-translator' of github.com:AztecProtocol/aztec-p…
Thunkar Mar 27, 2025
462e622
magic trace
Thunkar Mar 28, 2025
aac2f41
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 28, 2025
9a4a279
monke
Thunkar Mar 28, 2025
7cfef13
Revert "Increase capacity to 17 kernels"
Thunkar Mar 28, 2025
084f0a1
bb so fast I had to batch logs in playground
Thunkar Mar 28, 2025
48987af
skip permutation relation when possible
Mar 28, 2025
0957ad2
allocate and deallocate full commitment key
Mar 28, 2025
dc21609
add worktodo and comments about constants
Mar 28, 2025
3e37928
Merge branch 'cg/bump-translator' of github.com:AztecProtocol/aztec-p…
Thunkar Mar 28, 2025
d7232f2
don't deallocate at then end
Mar 28, 2025
9e616fd
Merge branch 'cg/bump-translator' of github.com:AztecProtocol/aztec-p…
Thunkar Mar 28, 2025
672001d
benchmark parametrization
Thunkar Mar 28, 2025
f0046f3
wtf
Thunkar Mar 28, 2025
8d9c2a3
allow pointing bb.js node to any bb wasm
Thunkar Mar 28, 2025
6470771
Fix extra import
nventuro Mar 28, 2025
04a079d
use actual circuit content to size translator polynomials
ledwards2225 Mar 31, 2025
40a9af8
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 31, 2025
ba92312
Merge branch 'cg/bump-translator' of github.com:AztecProtocol/aztec-p…
Thunkar Mar 31, 2025
fef826a
Update barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp
Thunkar Mar 31, 2025
541aeb9
separated config
Thunkar Mar 31, 2025
e82166f
Merge branch 'gj/more_benchmarks' of github.com:AztecProtocol/aztec-p…
Thunkar Mar 31, 2025
b889e70
add comments
Thunkar Mar 31, 2025
1685c1f
Merge branch 'master' into gj/more_benchmarks
Thunkar Mar 31, 2025
34f566b
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 31, 2025
30625c9
reverted bb changes
Thunkar Mar 31, 2025
0dd7588
error from another branch
Thunkar Mar 31, 2025
c006784
removed unused var
Thunkar Mar 31, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function fetchCode(multithreaded: boolean, wasmPath?: string) {
: (await import(/* webpackIgnore: true */ './barretenberg.js')).default;
}
const res = await fetch(url);
// Default bb wasm is compressed, but user could point it to a non-compressed version
const maybeCompressedData = await res.arrayBuffer();
const buffer = new Uint8Array(maybeCompressedData);
const isGzip =
Expand Down
18 changes: 15 additions & 3 deletions barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ function getCurrentDir() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function fetchCode(multithreaded: boolean, wasmPath?: string) {
const path = wasmPath ?? getCurrentDir() + '/../../barretenberg-threads.wasm.gz';
const compressedData = await readFile(path);
const decompressedData = pako.ungzip(new Uint8Array(compressedData));
return decompressedData.buffer;
// Default bb wasm is compressed, but user could point it to a non-compressed version
const maybeCompressedData = await readFile(path);
const buffer = new Uint8Array(maybeCompressedData);
const isGzip =
// Check magic number
buffer[0] === 0x1f &&
buffer[1] === 0x8b &&
// Check compression method:
buffer[2] === 0x08;
if (isGzip) {
const decompressedData = pako.ungzip(buffer);
return decompressedData.buffer;
} else {
return buffer;
}
}
35 changes: 25 additions & 10 deletions playground/src/aztecEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import { NetworkDB, WalletDB } from './utils/storage';
import { type ContractFunctionInteractionTx } from './utils/txs';

const logLevel = ['silent', 'fatal', 'error', 'warn', 'info', 'verbose', 'debug', 'trace'] as const;
type LogLevel = (typeof logLevel)[number];

type Log = {
type: (typeof logLevel)[number];
id: string;
type: LogLevel;
timestamp: number;
prefix: string;
message: string;
Expand All @@ -30,10 +32,20 @@ export class WebLogger {
private static instance: WebLogger;
private logs: Log[] = [];

private constructor(private setLogs: (logs: Log[]) => void) {}
private static updateIntervalMs = 1000;
private static readonly MAX_LOGS_TO_KEEP = 200;

private constructor() {}

static create(setLogs: (logs: Log[]) => void) {
WebLogger.instance = new WebLogger(setLogs);
if (!WebLogger.instance) {
WebLogger.instance = new WebLogger();
setInterval(() => {
const instance = WebLogger.getInstance();
const newLogs = instance.logs.slice(0, WebLogger.MAX_LOGS_TO_KEEP).sort((a, b) => b.timestamp - a.timestamp);
setLogs(newLogs);
}, WebLogger.updateIntervalMs);
}
}

static getInstance() {
Expand All @@ -44,12 +56,11 @@ export class WebLogger {
return new Proxy(createLogger(prefix), {
get: (target, prop) => {
if (logLevel.includes(prop as (typeof logLevel)[number])) {
return function () {
// eslint-disable-next-line prefer-rest-params
const args = [prop, prefix, ...arguments] as Parameters<WebLogger['handleLog']>;
return function (this: Logger, ...data: Parameters<Logger[LogLevel]>) {
const loggingFn = prop as LogLevel;
const args = [loggingFn, prefix, ...data] as Parameters<WebLogger['handleLog']>;
WebLogger.getInstance().handleLog(...args);
// eslint-disable-next-line prefer-rest-params
target[prop].apply(this, arguments);
target[loggingFn].call(this, ...[data[0], data[1]]);
};
} else {
return target[prop];
Expand All @@ -65,8 +76,12 @@ export class WebLogger {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any,
) {
this.logs.unshift({ type, prefix, message, data, timestamp: Date.now() });
this.setLogs([...this.logs]);
this.logs.unshift({ id: this.randomId(), type, prefix, message, data, timestamp: Date.now() });
}

private randomId(): string {
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
return uint32.toString(16);
}
}

Expand Down
2 changes: 1 addition & 1 deletion playground/src/components/logPanel/logPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function LogPanel() {
</StyledBox>
<StyledBox sx={{ px: 0.5, height: '100%', overflow: 'auto' }}>
{logs.map((log, index) => (
<div key={`${log.timestamp}-${log.message}`} css={logContainer}>
<div key={log.id} css={logContainer}>
<div css={logPrefix}>
<Typography variant="subtitle2">{log.prefix}:&nbsp;</Typography>
</div>
Expand Down
152 changes: 91 additions & 61 deletions yarn-project/end-to-end/src/bench/client_flows/amm.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { AccountWallet, Fr, PrivateFeePaymentMethod, type SimulateMethodOptions } from '@aztec/aztec.js';
import { AccountWallet, Fr, type SimulateMethodOptions } from '@aztec/aztec.js';
import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants';
import type { AMMContract } from '@aztec/noir-contracts.js/AMM';
import type { FPCContract } from '@aztec/noir-contracts.js/FPC';
import type { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
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, ClientFlowsBenchmark } from './client_flows_benchmark.js';
import { type AccountType, type BenchmarkingFeePaymentMethod, ClientFlowsBenchmark } from './client_flows_benchmark.js';

jest.setTimeout(900_000);

const AMOUNT_PER_NOTE = 1_000_000;

const MINIMUM_NOTES_FOR_RECURSION_LEVEL = [0, 2, 10];

describe('Client flows benchmarking', () => {
describe('AMM benchmark', () => {
const t = new ClientFlowsBenchmark('amm');
// The admin that aids in the setup of the test
let adminWallet: AccountWallet;
Expand All @@ -30,22 +31,28 @@ describe('Client flows benchmarking', () => {
let amm: AMMContract;
// Liquidity contract for the AMM
let liquidityToken: TokenContract;
// Sponsored FPC contract
let sponsoredFPC: SponsoredFPCContract;
// Benchmarking configuration
const config = t.config.amm;

beforeAll(async () => {
await t.applyBaseSnapshots();
await t.applyDeployBananaTokenSnapshot();
await t.applyFPCSetupSnapshot();
await t.applyDeployCandyBarTokenSnapshot();
await t.applyDeployAmmSnapshot();
({ adminWallet, bananaFPC, bananaCoin, candyBarCoin, amm, liquidityToken } = await t.setup());
await t.applyDeploySponsoredFPCSnapshot();
({ adminWallet, bananaFPC, bananaCoin, candyBarCoin, amm, liquidityToken, sponsoredFPC } = await t.setup());
});

afterAll(async () => {
await t.teardown();
});

ammBenchmark('ecdsar1');
ammBenchmark('schnorr');
for (const accountType of config.accounts) {
ammBenchmark(accountType);
}

function ammBenchmark(accountType: AccountType) {
return describe(`AMM benchmark for ${accountType}`, () => {
Expand All @@ -68,68 +75,91 @@ describe('Client flows benchmarking', () => {
// Register the AMM and liquidity token on the user's Wallet so we can simulate and prove
await benchysWallet.registerContract(amm);
await benchysWallet.registerContract(liquidityToken);
// Register the sponsored FPC on the user's PXE so we can simulate and prove
await benchysWallet.registerContract(sponsoredFPC);
});

describe(`Add liquidity with ${notesToCreate} notes in both tokens using a ${accountType} account`, () => {
beforeEach(async () => {
// Mint some CandyBarCoins for the user, separated in different notes
await mintNotes(
adminWallet,
benchysWallet.getAddress(),
candyBarCoin,
Array(notesToCreate).fill(BigInt(AMOUNT_PER_NOTE)),
);
// Mint some BananaCoins for the user, separated in different notes
await mintNotes(
adminWallet,
benchysWallet.getAddress(),
bananaCoin,
Array(notesToCreate).fill(BigInt(AMOUNT_PER_NOTE)),
);
});

// Ensure we create a change note, by sending an amount that is not a multiple of the note amount
const amountToSend = MINIMUM_NOTES_FOR_RECURSION_LEVEL[1] * AMOUNT_PER_NOTE + 1;

it(`${accountType} contract adds liquidity to the AMM sending ${amountToSend} tokens using 1 recursions in both`, async () => {
const paymentMethod = new PrivateFeePaymentMethod(bananaFPC.address, benchysWallet);
const options: SimulateMethodOptions = { fee: { paymentMethod } };

const nonceForAuthwits = Fr.random();
const token0Authwit = await benchysWallet.createAuthWit({
caller: amm.address,
action: bananaCoin.methods.transfer_to_public(
function addLiquidityTest(benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) {
return describe(`Add liquidity with ${notesToCreate} notes in both tokens using a ${accountType} account`, () => {
beforeEach(async () => {
// Mint some CandyBarCoins for the user, separated in different notes
await mintNotes(
adminWallet,
benchysWallet.getAddress(),
amm.address,
amountToSend,
nonceForAuthwits,
),
});
const token1Authwit = await benchysWallet.createAuthWit({
caller: amm.address,
action: candyBarCoin.methods.transfer_to_public(
candyBarCoin,
Array(notesToCreate).fill(BigInt(AMOUNT_PER_NOTE)),
);
// Mint some BananaCoins for the user, separated in different notes
await mintNotes(
adminWallet,
benchysWallet.getAddress(),
amm.address,
amountToSend,
nonceForAuthwits,
),
bananaCoin,
Array(notesToCreate).fill(BigInt(AMOUNT_PER_NOTE)),
);
});

const addLiquidityInteraction = amm
.withWallet(benchysWallet)
.methods.add_liquidity(amountToSend, amountToSend, amountToSend, amountToSend, nonceForAuthwits)
.with({ authWitnesses: [token0Authwit, token1Authwit] });

await capturePrivateExecutionStepsIfEnvSet(
`${accountType}+amm_add_liquidity_1_recursions+pay_private_fpc`,
addLiquidityInteraction,
options,
);

const tx = await addLiquidityInteraction.send().wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);
// Ensure we create a change note, by sending an amount that is not a multiple of the note amount
const amountToSend = MINIMUM_NOTES_FOR_RECURSION_LEVEL[1] * AMOUNT_PER_NOTE + 1;

it(`${accountType} contract adds liquidity to the AMM sending ${amountToSend} tokens using 1 recursions in both and pays using ${benchmarkingPaymentMethod}`, async () => {
const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod];
const options: SimulateMethodOptions = {
fee: { paymentMethod: await paymentMethod.forWallet(benchysWallet) },
};

const nonceForAuthwits = Fr.random();
const token0Authwit = await benchysWallet.createAuthWit({
caller: amm.address,
action: bananaCoin.methods.transfer_to_public(
benchysWallet.getAddress(),
amm.address,
amountToSend,
nonceForAuthwits,
),
});
const token1Authwit = await benchysWallet.createAuthWit({
caller: amm.address,
action: candyBarCoin.methods.transfer_to_public(
benchysWallet.getAddress(),
amm.address,
amountToSend,
nonceForAuthwits,
),
});

const addLiquidityInteraction = amm
.withWallet(benchysWallet)
.methods.add_liquidity(amountToSend, amountToSend, amountToSend, amountToSend, nonceForAuthwits)
.with({ authWitnesses: [token0Authwit, token1Authwit] });

await capturePrivateExecutionStepsIfEnvSet(
`${accountType}+amm_add_liquidity_1_recursions+${benchmarkingPaymentMethod}`,
addLiquidityInteraction,
options,
1 + // Account entrypoint
1 + // Kernel init
paymentMethod.circuits + // Payment method circuits
2 + // AMM add_liquidity + kernel inner
2 + // Token transfer_to_public + kernel inner (token0)
2 + // Account verify_private_authwit + kernel inner
2 + // Token prepare_private_balance_increase + kernel inner (token0 refund)
2 + // Token transfer_to_public + kernel inner (token1)
2 + // Account verify_private_authwit + kernel inner
2 + // Token prepare_private_balance_increase + kernel inner (token1 refund)
2 + // Token prepare_private_balance_increase + kernel inner (liquidity token mint)
1 + // Kernel reset
1, // Kernel tail
);

const tx = await addLiquidityInteraction.send().wait();
expect(tx.transactionFee!).toBeGreaterThan(0n);
});
});
});
}

for (const paymentMethod of config.feePaymentMethods) {
addLiquidityTest(paymentMethod);
}
});
}
});
Loading