From b981a7fe3fdd04205b14623c06dd75ac979f5a3a Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 27 Mar 2025 15:30:51 +0000 Subject: [PATCH 01/23] more tests, tentative trace --- .../execution_trace/mega_execution_trace.hpp | 20 +-- .../src/bench/client_flows/amm.test.ts | 43 +++-- .../src/bench/client_flows/bridging.test.ts | 37 ++-- .../client_flows/client_flows_benchmark.ts | 63 ++++++- .../src/bench/client_flows/data_extractor.ts | 3 +- .../bench/client_flows/deployments.test.ts | 158 ++++++++---------- .../src/bench/client_flows/transfers.test.ts | 60 +++---- 7 files changed, 225 insertions(+), 159 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp index 4f02d9dc3c27..851a2a7fe7f8 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp @@ -330,16 +330,16 @@ static constexpr TraceStructure EXAMPLE_20{ .ecc_op = 1 << 11, /** * @brief Structuring tailored to the full e2e TS test (TO BE UPDATED ACCORDINGLY) */ -static constexpr TraceStructure E2E_FULL_TEST_STRUCTURE{ .ecc_op = 1 << 10, - .busread = 6000, - .lookup = 200000, - .pub_inputs = 4000, - .arithmetic = 200000, - .delta_range = 25000, - .elliptic = 80000, - .aux = 100000, - .poseidon2_external = 45192, - .poseidon2_internal = 258000, +static constexpr TraceStructure E2E_FULL_TEST_STRUCTURE{ .ecc_op = 756, + .busread = 4119, + .lookup = 14482, + .pub_inputs = 1814, + .arithmetic = 55274, + .delta_range = 17186, + .elliptic = 5870, + .aux = 25370, + .poseidon2_external = 16082, + .poseidon2_internal = 91658, .overflow = 0 }; template diff --git a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts index 04727dcce21e..6ab05ec22cb0 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts @@ -2,13 +2,14 @@ import { AccountWallet, Fr, PrivateFeePaymentMethod, type SimulateMethodOptions 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); @@ -16,7 +17,7 @@ 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; @@ -30,6 +31,8 @@ describe('Client flows benchmarking', () => { let amm: AMMContract; // Liquidity contract for the AMM let liquidityToken: TokenContract; + // Sponsored FPC contract + let sponsoredFPC: SponsoredFPCContract; beforeAll(async () => { await t.applyBaseSnapshots(); @@ -37,17 +40,20 @@ describe('Client flows benchmarking', () => { 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'); + ammBenchmark('ecdsar1', 'private_fpc'); + ammBenchmark('schnorr', 'private_fpc'); + ammBenchmark('ecdsar1', 'sponsored_fpc'); + ammBenchmark('schnorr', 'sponsored_fpc'); - function ammBenchmark(accountType: AccountType) { + function ammBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { return describe(`AMM benchmark for ${accountType}`, () => { // Our benchmarking user let benchysWallet: AccountWallet; @@ -68,6 +74,8 @@ 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`, () => { @@ -91,9 +99,11 @@ describe('Client flows benchmarking', () => { // 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 } }; + 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({ @@ -121,9 +131,22 @@ describe('Client flows benchmarking', () => { .with({ authWitnesses: [token0Authwit, token1Authwit] }); await capturePrivateExecutionStepsIfEnvSet( - `${accountType}+amm_add_liquidity_1_recursions+pay_private_fpc`, + `${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(); diff --git a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts index cb562da47cc1..d98c86df1e55 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts @@ -1,17 +1,18 @@ -import { AccountWallet, PrivateFeePaymentMethod, type SimulateMethodOptions } from '@aztec/aztec.js'; +import { AccountWallet, type SimulateMethodOptions } from '@aztec/aztec.js'; import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; 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 { capturePrivateExecutionStepsIfEnvSet } from '../../shared/capture_private_execution_steps.js'; import type { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js'; -import { type AccountType, ClientFlowsBenchmark } from './client_flows_benchmark.js'; +import { type AccountType, type BenchmarkingFeePaymentMethod, ClientFlowsBenchmark } from './client_flows_benchmark.js'; jest.setTimeout(300_000); -describe('Client flows benchmarking', () => { +describe('Bridging benchmark', () => { const t = new ClientFlowsBenchmark('bridging'); // The admin that aids in the setup of the test let adminWallet: AccountWallet; @@ -19,22 +20,27 @@ describe('Client flows benchmarking', () => { let bananaFPC: FPCContract; // BananaCoin Token contract, which we want to use to pay for the bridging let bananaCoin: TokenContract; + // Sponsored FPC contract + let sponsoredFPC: SponsoredFPCContract; beforeAll(async () => { await t.applyBaseSnapshots(); await t.applyDeployBananaTokenSnapshot(); await t.applyFPCSetupSnapshot(); - ({ bananaFPC, bananaCoin, adminWallet } = await t.setup()); + await t.applyDeploySponsoredFPCSnapshot(); + ({ bananaFPC, bananaCoin, adminWallet, sponsoredFPC } = await t.setup()); }); afterAll(async () => { await t.teardown(); }); - bridgingBenchmark('ecdsar1'); - bridgingBenchmark('schnorr'); + bridgingBenchmark('ecdsar1', 'private_fpc'); + bridgingBenchmark('schnorr', 'private_fpc'); + bridgingBenchmark('ecdsar1', 'sponsored_fpc'); + bridgingBenchmark('schnorr', 'sponsored_fpc'); - function bridgingBenchmark(accountType: AccountType) { + function bridgingBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { return describe(`Bridging benchmark for ${accountType}`, () => { // Our benchmarking user let benchysWallet: AccountWallet; @@ -53,9 +59,11 @@ describe('Client flows benchmarking', () => { // Register both FPC and BananCoin on the user's PXE so we can simulate and prove await benchysWallet.registerContract(bananaFPC); await benchysWallet.registerContract(bananaCoin); + // Register the sponsored FPC on the user's PXE so we can simulate and prove + await benchysWallet.registerContract(sponsoredFPC); }); - it(`${accountType} contract bridges tokens from L1 claiming privately, pays using private FPC`, async () => { + it(`${accountType} contract bridges tokens from L1 claiming privately, pays using ${benchmarkingPaymentMethod}`, async () => { // Generate a claim secret using pedersen const l1TokenBalance = 1000000n; const bridgeAmount = 100n; @@ -67,9 +75,9 @@ describe('Client flows benchmarking', () => { const claim = await crossChainTestHarness.sendTokensToPortalPrivate(bridgeAmount); await crossChainTestHarness.makeMessageConsumable(claim.messageHash); - // 3. Consume L1 -> L2 message and mint private tokens on L2, paying via FPC - const paymentMethod = new PrivateFeePaymentMethod(bananaFPC.address, benchysWallet); - const options: SimulateMethodOptions = { fee: { paymentMethod } }; + // 3. Consume L1 -> L2 message and mint private tokens on L2 + const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod]; + const options: SimulateMethodOptions = { fee: { paymentMethod: await paymentMethod.forWallet(benchysWallet) } }; const { recipient, claimAmount, claimSecret: secretForL2MessageConsumption, messageLeafIndex } = claim; const claimInteraction = crossChainTestHarness.l2Bridge.methods.claim_private( @@ -80,15 +88,12 @@ describe('Client flows benchmarking', () => { ); await capturePrivateExecutionStepsIfEnvSet( - `${accountType}+token_bridge_claim_private+pay_private_fpc`, + `${accountType}+token_bridge_claim_private+${benchmarkingPaymentMethod}`, claimInteraction, options, 1 + // Account entrypoint 1 + // Kernel init - 2 + // FPC entrypoint + kernel inner - 2 + // BananaCoin transfer_to_public + kernel inner - 2 + // Account verify_private_authwit + kernel inner - 2 + // BananaCoin prepare_private_balance_increase + kernel inner + paymentMethod.circuits + // Payment method circuits 2 + // TokenBridge claim_private + kernel inner 2 + // BridgedAsset mint_to_private + kernel inner 1 + // Kernel reset diff --git a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts index fa73c202fb86..bc32a7ff830f 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts @@ -5,12 +5,16 @@ import { AztecAddress, type AztecNode, FeeJuicePaymentMethodWithClaim, + type FeePaymentMethod, type Logger, type PXE, + PrivateFeePaymentMethod, + SponsoredFeePaymentMethod, + type Wallet, createLogger, } from '@aztec/aztec.js'; import { CheatCodes } from '@aztec/aztec.js/testing'; -import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; +import { FEE_FUNDING_FOR_TESTER_ACCOUNT, SPONSORED_FPC_SALT } from '@aztec/constants'; import { type DeployL1ContractsArgs, RollupContract, createL1Clients, deployL1Contract } from '@aztec/ethereum'; import { ChainMonitor } from '@aztec/ethereum/test'; import { randomBytes } from '@aztec/foundation/crypto'; @@ -21,6 +25,7 @@ import { TestERC20Bytecode } from '@aztec/l1-artifacts/TestERC20Bytecode'; import { AMMContract } from '@aztec/noir-contracts.js/AMM'; import { FPCContract } from '@aztec/noir-contracts.js/FPC'; import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice'; +import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC'; import { TokenContract as BananaCoin, TokenContract } from '@aztec/noir-contracts.js/Token'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice'; @@ -35,7 +40,7 @@ import { deployAccounts, } from '../../fixtures/snapshot_manager.js'; import { mintTokensToPrivate } from '../../fixtures/token_utils.js'; -import { type SetupOptions, setupCanonicalFeeJuice } from '../../fixtures/utils.js'; +import { type SetupOptions, setupCanonicalFeeJuice, setupSponsoredFPC } from '../../fixtures/utils.js'; import { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js'; import { FeeJuicePortalTestingHarnessFactory, @@ -45,6 +50,8 @@ import { const { E2E_DATA_PATH: dataPath } = process.env; export type AccountType = 'ecdsar1' | 'schnorr'; +export type FeePaymentMethodGetter = (wallet: Wallet) => Promise; +export type BenchmarkingFeePaymentMethod = 'bridged_fee_juice' | 'private_fpc' | 'sponsored_fpc'; export class ClientFlowsBenchmark { private snapshotManager: ISnapshotManager; @@ -76,10 +83,32 @@ export class ClientFlowsBenchmark { public amm!: AMMContract; // Liquidity token for AMM public liquidityToken!: TokenContract; + // Sponsored FPC contract + public sponsoredFPC!: SponsoredFPCContract; // PXE used by the benchmarking user. It can be set up with client-side proving enabled public userPXE!: PXE; + public paymentMethods: Record = + { + bridged_fee_juice: { + forWallet: this.getBridgedFeeJuicePaymentMethodForWallet.bind(this), + circuits: 2, // FeeJuice claim + kernel inner + }, + private_fpc: { + forWallet: this.getPrivateFPCPaymentMethodForWallet.bind(this), + circuits: + 2 + // FPC entrypoint + kernel inner + 2 + // BananaCoin transfer_to_public + kernel inner + 2 + // Account verify_private_authwit + kernel inner + 2, // BananaCoin prepare_private_balance_increase + kernel inner + }, + sponsored_fpc: { + forWallet: this.getSponsoredFPCPaymentMethodForWallet.bind(this), + circuits: 2, // Sponsored FPC sponsor_unconditionally + kernel inner + }, + }; + constructor(testName?: string, setupOptions: Partial = {}) { this.logger = createLogger(`bench:client_flows${testName ? `:${testName}` : ''}`); this.snapshotManager = createSnapshotManager( @@ -259,6 +288,20 @@ export class ClientFlowsBenchmark { ); } + async applyDeploySponsoredFPCSnapshot() { + await this.snapshotManager.snapshot( + 'deploy_sponsored_fpc', + async () => { + const sponsoredFPC = await setupSponsoredFPC(this.pxe); + this.logger.info(`SponsoredFPC deployed at ${sponsoredFPC.address}`); + return { sponsoredFPCAddress: sponsoredFPC.address }; + }, + async ({ sponsoredFPCAddress }) => { + this.sponsoredFPC = await SponsoredFPCContract.at(sponsoredFPCAddress, this.adminWallet); + }, + ); + } + public async createCrossChainTestHarness(owner: AccountWallet) { const { publicClient, walletClient } = createL1Clients(this.context.aztecNodeConfig.l1RpcUrls, MNEMONIC); @@ -328,4 +371,20 @@ export class ClientFlowsBenchmark { }, ); } + + public async getBridgedFeeJuicePaymentMethodForWallet(wallet: Wallet) { + const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1( + FEE_FUNDING_FOR_TESTER_ACCOUNT, + wallet.getAddress(), + ); + return new FeeJuicePaymentMethodWithClaim(wallet, claim); + } + + public async getPrivateFPCPaymentMethodForWallet(wallet: Wallet) { + return new PrivateFeePaymentMethod(this.bananaFPC.address, wallet); + } + + public async getSponsoredFPCPaymentMethodForWallet(wallet: Wallet) { + return new SponsoredFeePaymentMethod(this.sponsoredFPC.address); + } } diff --git a/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts b/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts index 2d0a47f47a06..d174cbcf48dc 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts @@ -179,10 +179,11 @@ async function main() { await writeFile(join(ivcFolder, flow, 'logs.json'), JSON.stringify(currentLogs, null, 2)); if (!error) { - minimumTrace = getMinimumTrace(currentLogs, proverType); stats = currentLogs[0].data as { duration: number; eventName: string; proofSize: number }; } + minimumTrace = getMinimumTrace(currentLogs, proverType); + const steps = executionSteps.reduce((acc, step, i) => { const previousAccGateCount = i === 0 ? 0 : acc[i - 1].accGateCount!; return [ diff --git a/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts b/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts index 7eedf7a5a812..630067e123fc 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts @@ -1,114 +1,88 @@ import { EcdsaRAccountContractArtifact } from '@aztec/accounts/ecdsa'; -import { - AccountWallet, - type DeployOptions, - FeeJuicePaymentMethodWithClaim, - Fr, - registerContractClass, -} from '@aztec/aztec.js'; -import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; +import { AccountWallet, type DeployOptions, Fr, 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 { ClientFlowsBenchmark } from './client_flows_benchmark.js'; +import { type AccountType, type BenchmarkingFeePaymentMethod, ClientFlowsBenchmark } from './client_flows_benchmark.js'; jest.setTimeout(300_000); -describe('Client flows benchmarking', () => { +describe('Deployment benchmark', () => { const t = new ClientFlowsBenchmark('deployments'); // The admin that aids in the setup of the test let adminWallet: AccountWallet; + // Sponsored FPC contract + let sponsoredFPC: SponsoredFPCContract; beforeAll(async () => { await t.applyBaseSnapshots(); - ({ adminWallet } = await t.setup()); + await t.applyDeploySponsoredFPCSnapshot(); + ({ adminWallet, sponsoredFPC } = await t.setup()); + // Ensure the ECDSAK1 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. + const registerContractClassInteraction = await registerContractClass(adminWallet, EcdsaRAccountContractArtifact); + await registerContractClassInteraction.send().wait(); }); afterAll(async () => { await t.teardown(); }); - describe('Deployments', () => { - it('Deploy ECDSA R1 account contract, pay using bridged fee juice', async () => { - // Ensure the 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. - const registerContractClassInteraction = await registerContractClass(adminWallet, EcdsaRAccountContractArtifact); - await registerContractClassInteraction.send().wait(); - - const benchysAccountManager = await t.createBenchmarkingAccountManager('ecdsar1'); - const benchysWallet = await benchysAccountManager.getWallet(); - const benchysAddress = benchysWallet.getAddress(); - - const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(FEE_FUNDING_FOR_TESTER_ACCOUNT, benchysAddress); - const paymentMethod = new FeeJuicePaymentMethodWithClaim(benchysWallet, claim); - - const deploymentInteraction = await benchysAccountManager.getDeployMethod(); - const wrappedPaymentMethod = await benchysAccountManager.getSelfPaymentMethod(paymentMethod); - const fee = { paymentMethod: wrappedPaymentMethod }; - // Publicly deploy the contract, but skip the class registration as that is the - // "typical" use case - const options: DeployOptions = { - fee, - universalDeploy: true, - skipClassRegistration: true, - skipPublicDeployment: false, - skipInitialization: false, - contractAddressSalt: new Fr(benchysAccountManager.salt), - }; - - await capturePrivateExecutionStepsIfEnvSet( - 'deploy_r1+claim_fee_juice+pay_fee_juice', - deploymentInteraction, - options, - ); - - // Ensure we paid a fee - const tx = await deploymentInteraction.send(options).wait(); - expect(tx.transactionFee!).toBeGreaterThan(0n); - }); - - it('Deploy Schnorr Account contract, pay using bridged fee juice', async () => { - const benchysAccountManager = await t.createBenchmarkingAccountManager('schnorr'); - const benchysWallet = await benchysAccountManager.getWallet(); - const benchysAddress = benchysWallet.getAddress(); - - const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(FEE_FUNDING_FOR_TESTER_ACCOUNT, benchysAddress); - const paymentMethod = new FeeJuicePaymentMethodWithClaim(benchysWallet, claim); - - const deploymentInteraction = await benchysAccountManager.getDeployMethod(); - const wrappedPaymentMethod = await benchysAccountManager.getSelfPaymentMethod(paymentMethod); - const fee = { paymentMethod: wrappedPaymentMethod }; - // Publicly deploy the contract, but skip the class registration as that is the - // "typical" use case - const options: DeployOptions = { - fee, - universalDeploy: true, - skipClassRegistration: true, - skipPublicDeployment: false, - skipInitialization: false, - contractAddressSalt: new Fr(benchysAccountManager.salt), - }; - - await capturePrivateExecutionStepsIfEnvSet( - 'deploy_schnorr+claim_fee_juice+pay_fee_juice', - deploymentInteraction, - options, - 1 + // Multicall entrypoint - 1 + // Kernel init - 2 + // ContractInstanceDeployer deploy + kernel inner - 2 + // ContractClassRegisterer assert_class_id_is_registered + kernel inner - 2 + // Account constructor + kernel inner - 2 + // Account entrypoint (wrapped fee payload) + kernel inner - 2 + // FeeJuice claim + kernel inner - 1 + // Kernel reset - 1, // Kernel tail - ); - - // Ensure we paid a fee - const tx = await deploymentInteraction.send(options).wait(); - expect(tx.transactionFee!).toBeGreaterThan(0n); + deploymentBenchmark('ecdsar1', 'bridged_fee_juice'); + deploymentBenchmark('schnorr', 'bridged_fee_juice'); + deploymentBenchmark('ecdsar1', 'sponsored_fpc'); + deploymentBenchmark('schnorr', 'sponsored_fpc'); + + function deploymentBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { + return describe(`Deployment benchmark for ${accountType}`, () => { + it(`Deploys a ${accountType} account contract, pays using ${benchmarkingPaymentMethod}`, async () => { + const benchysAccountManager = await t.createBenchmarkingAccountManager(accountType); + const benchysWallet = await benchysAccountManager.getWallet(); + + if (benchmarkingPaymentMethod === 'sponsored_fpc') { + await benchysWallet.registerContract(sponsoredFPC); + } + + const deploymentInteraction = await benchysAccountManager.getDeployMethod(); + + const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod]; + const wrappedPaymentMethod = await benchysAccountManager.getSelfPaymentMethod( + await paymentMethod.forWallet(benchysWallet), + ); + const fee = { paymentMethod: wrappedPaymentMethod }; + // Publicly deploy the contract, but skip the class registration as that is the + // "typical" use case + const options: DeployOptions = { + fee, + universalDeploy: true, + skipClassRegistration: true, + skipPublicDeployment: false, + skipInitialization: false, + contractAddressSalt: new Fr(benchysAccountManager.salt), + }; + + await capturePrivateExecutionStepsIfEnvSet( + `deploy_${accountType}+${benchmarkingPaymentMethod}`, + deploymentInteraction, + options, + 1 + // Multicall entrypoint + 1 + // Kernel init + 2 + // ContractInstanceDeployer deploy + kernel inner + 2 + // ContractClassRegisterer assert_class_id_is_registered + kernel inner + 2 + // Account constructor + kernel inner + 2 + // Account entrypoint (wrapped fee payload) + kernel inner + paymentMethod.circuits + // Payment method circuits + 1 + // Kernel reset + 1, // Kernel tail + ); + + // Ensure we paid a fee + const tx = await deploymentInteraction.send(options).wait(); + expect(tx.transactionFee!).toBeGreaterThan(0n); + }); }); - }); + } }); diff --git a/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts b/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts index ab76e06a6a27..2681c1b56ebc 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts @@ -1,27 +1,22 @@ -import { - AccountWallet, - type AztecNode, - Fr, - PrivateFeePaymentMethod, - type SimulateMethodOptions, -} from '@aztec/aztec.js'; +import { AccountWallet, type AztecNode, Fr, type SimulateMethodOptions } from '@aztec/aztec.js'; import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; 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); +jest.setTimeout(1_600_000); const AMOUNT_PER_NOTE = 1_000_000; const MINIMUM_NOTES_FOR_RECURSION_LEVEL = [0, 2, 10]; -describe('Client flows benchmarking', () => { +describe('Transfer benchmark', () => { const t = new ClientFlowsBenchmark('transfers'); // The admin that aids in the setup of the test let adminWallet: AccountWallet; @@ -33,23 +28,29 @@ describe('Client flows benchmarking', () => { let candyBarCoin: TokenContract; // Aztec node to answer queries let node: AztecNode; + // Sponsored FPC contract + let sponsoredFPC: SponsoredFPCContract; beforeAll(async () => { await t.applyBaseSnapshots(); await t.applyDeployBananaTokenSnapshot(); await t.applyFPCSetupSnapshot(); await t.applyDeployCandyBarTokenSnapshot(); - ({ adminWallet, bananaFPC, bananaCoin, candyBarCoin, aztecNode: node } = await t.setup()); + await t.applyDeploySponsoredFPCSnapshot(); + + ({ adminWallet, bananaFPC, bananaCoin, candyBarCoin, aztecNode: node, sponsoredFPC } = await t.setup()); }); afterAll(async () => { await t.teardown(); }); - transferBenchmark('ecdsar1'); - transferBenchmark('schnorr'); + transferBenchmark('ecdsar1', 'private_fpc'); + transferBenchmark('ecdsar1', 'sponsored_fpc'); + transferBenchmark('schnorr', 'private_fpc'); + transferBenchmark('schnorr', 'sponsored_fpc'); - function transferBenchmark(accountType: AccountType) { + function transferBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { return describe(`Transfer benchmark for ${accountType}`, () => { // Our benchmarking user let benchysWallet: AccountWallet; @@ -65,6 +66,8 @@ describe('Client flows benchmarking', () => { await benchysWallet.registerContract(bananaCoin); // Register the CandyBarCoin on the user's Wallet so we can simulate and prove await benchysWallet.registerContract(candyBarCoin); + // Register the sponsored FPC on the user's PXE so we can simulate and prove + await benchysWallet.registerContract(sponsoredFPC); }); function recursionTest(recursions: number, notesToCreate: number) { @@ -98,30 +101,29 @@ describe('Client flows benchmarking', () => { caller: adminWallet.getAddress(), action: interaction, }); - await interaction.send({ authWitnesses: [witness] }).wait(); + await interaction.send({ authWitnesses: [witness] }).wait({ timeout: 120 }); }); // 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[recursions] * AMOUNT_PER_NOTE + 1; - it(`${accountType} contract transfers ${amountToSend} tokens using ${recursions} recursions`, async () => { - const paymentMethod = new PrivateFeePaymentMethod(bananaFPC.address, benchysWallet); - const options: SimulateMethodOptions = { fee: { paymentMethod } }; + it(`${accountType} contract transfers ${amountToSend} tokens using ${recursions} recursions, pays using ${benchmarkingPaymentMethod}`, async () => { + const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod]; + const options: SimulateMethodOptions = { + fee: { paymentMethod: await paymentMethod.forWallet(benchysWallet) }, + }; const asset = await TokenContract.at(candyBarCoin.address, benchysWallet); const transferInteraction = asset.methods.transfer(adminWallet.getAddress(), amountToSend); await capturePrivateExecutionStepsIfEnvSet( - `${accountType}+transfer_${recursions}_recursions+pay_private_fpc`, + `${accountType}+transfer_${recursions}_recursions+${benchmarkingPaymentMethod}`, transferInteraction, options, 1 + // Account entrypoint 1 + // Kernel init - 2 + // FPC entrypoint + kernel inner - 2 + // BananaCoin transfer_to_public + kernel inner - 2 + // Account verify_private_authwit + kernel inner - 2 + // BananaCoin prepare_private_balance_increase + kernel inner + paymentMethod.circuits + // Payment method circuits 2 + // CandyBarCoin transfer + kernel inner recursions * 2 + // (CandyBarCoin _recurse_subtract_balance + kernel inner) * recursions 1 + // Kernel reset @@ -138,17 +140,19 @@ describe('Client flows benchmarking', () => { /* * We should have created the following nullifiers: * - One per created note - * - One for the fee note * - One for the transaction + * - One for the fee note if we're using private fpc */ - expect(txEffects!.data.nullifiers.length).toBe(notesToCreate + 2); + expect(txEffects!.data.nullifiers.length).toBe( + notesToCreate + 1 + (benchmarkingPaymentMethod === 'private_fpc' ? 1 : 0), + ); /** We should have created 4 new notes, * - One for the recipient * - One for the sender (with the change) - * - One for the fee - * - One for the fee refund + * - One for the fee if we're using private fpc + * - One for the fee refund if we're using private fpc */ - expect(txEffects!.data.noteHashes.length).toBe(4); + expect(txEffects!.data.noteHashes.length).toBe(2 + (benchmarkingPaymentMethod === 'private_fpc' ? 2 : 0)); expectedChange = totalAmount - BigInt(amountToSend); From 0717740433008550a86449f20c5b6d84b84eadb0 Mon Sep 17 00:00:00 2001 From: cody Date: Thu, 27 Mar 2025 18:48:50 +0000 Subject: [PATCH 02/23] Increase capacity to 17 kernels --- .../client_ivc/client_ivc.test.cpp | 30 +++++++++++++++++++ .../src/barretenberg/eccvm/eccvm_flavor.hpp | 3 +- .../cpp/src/barretenberg/goblin/goblin.hpp | 2 ++ .../translator_vm/translator_flavor.hpp | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index e60f986dd769..f3c94e8fea4f 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -10,6 +10,8 @@ using namespace bb; +static constexpr size_t MAX_NUM_KERNELS = 17; + class ClientIVCTests : public ::testing::Test { protected: static void SetUpTestSuite() @@ -438,6 +440,34 @@ TEST(ClientIVCBenchValidation, Full6MockedVKs) ASSERT_NO_FATAL_FAILURE(run_test()); } +TEST(ClientIVCKernelCapacity, MaxCapacityPassing) +{ + bb::srs::init_crs_factory(bb::srs::get_ignition_crs_path()); + bb::srs::init_grumpkin_crs_factory(bb::srs::get_grumpkin_crs_path()); + + ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; + const size_t total_num_circuits{ 2 * MAX_NUM_KERNELS }; + PrivateFunctionExecutionMockCircuitProducer circuit_producer; + auto precomputed_vkeys = circuit_producer.precompute_verification_keys(total_num_circuits, ivc.trace_settings); + perform_ivc_accumulation_rounds(total_num_circuits, ivc, precomputed_vkeys); + auto proof = ivc.prove(); + bool verified = verify_ivc(proof, ivc); + EXPECT_TRUE(verified); +} + +TEST(ClientIVCKernelCapacity, MaxCapacityFailing) +{ + bb::srs::init_crs_factory(bb::srs::get_ignition_crs_path()); + bb::srs::init_grumpkin_crs_factory(bb::srs::get_grumpkin_crs_path()); + + ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; + const size_t total_num_circuits{ 2 * (MAX_NUM_KERNELS + 1) }; + PrivateFunctionExecutionMockCircuitProducer circuit_producer; + auto precomputed_vkeys = circuit_producer.precompute_verification_keys(total_num_circuits, ivc.trace_settings); + perform_ivc_accumulation_rounds(total_num_circuits, ivc, precomputed_vkeys); + EXPECT_ANY_THROW(ivc.prove()); +} + /** * @brief Test use of structured trace overflow block mechanism * @details Accumulate 4 circuits which have progressively more arithmetic gates. The final two overflow the prescribed diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index bb702b6675a4..6b13a2a13e38 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -527,8 +527,7 @@ class ECCVMFlavor { size_t dyadic_num_rows = 1UL << (log_num_rows + (1UL << log_num_rows == num_rows ? 0 : 1)); if ((fixed_size) && (ECCVM_FIXED_SIZE < dyadic_num_rows)) { - info("The ECCVM circuit size has exceeded the fixed upper bound"); - ASSERT(false); + throw_or_abort("The ECCVM circuit size has exceeded the fixed upper bound"); } dyadic_num_rows = fixed_size ? ECCVM_FIXED_SIZE : dyadic_num_rows; diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 582d64e1e301..323e09d99b79 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -149,6 +149,8 @@ class GoblinProver { PROFILE_THIS_NAME("Goblin::prove"); + info("Constructing a Goblin proof with num ultra ops = ", op_queue->get_ultra_ops_table_num_rows()); + goblin_proof.merge_proof = merge_proof_in.empty() ? std::move(merge_proof) : std::move(merge_proof_in); { PROFILE_THIS_NAME("prove_eccvm"); diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 0cf41a07c186..530237a12b6b 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -44,7 +44,7 @@ class TranslatorFlavor { // A minicircuit of such size allows for 10 rounds of folding (i.e. 20 circuits). // Lowest possible size for the translator circuit (this sets the mini_circuit_size) static constexpr size_t MINIMUM_MINI_CIRCUIT_SIZE = 2048; - static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 8192; + static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 16384; static_assert(TRANSLATOR_VM_FIXED_SIZE >= MINIMUM_MINI_CIRCUIT_SIZE); // The size of the circuit which is filled with non-zero values for most polynomials. Most relations (everything From 789dd6226434afb82d409820debf8ad64dfad3b8 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 27 Mar 2025 20:23:15 +0000 Subject: [PATCH 03/23] better test org --- .../src/bench/client_flows/amm.test.ts | 153 +++++++++--------- .../src/bench/client_flows/bridging.test.ts | 107 ++++++------ .../bench/client_flows/deployments.test.ts | 93 +++++------ .../src/bench/client_flows/transfers.test.ts | 17 +- 4 files changed, 192 insertions(+), 178 deletions(-) diff --git a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts index 6ab05ec22cb0..75114b0513d1 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts @@ -48,12 +48,10 @@ describe('AMM benchmark', () => { await t.teardown(); }); - ammBenchmark('ecdsar1', 'private_fpc'); - ammBenchmark('schnorr', 'private_fpc'); - ammBenchmark('ecdsar1', 'sponsored_fpc'); - ammBenchmark('schnorr', 'sponsored_fpc'); + ammBenchmark('ecdsar1'); + ammBenchmark('schnorr'); - function ammBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { + function ammBenchmark(accountType: AccountType) { return describe(`AMM benchmark for ${accountType}`, () => { // Our benchmarking user let benchysWallet: AccountWallet; @@ -78,81 +76,86 @@ describe('AMM benchmark', () => { 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 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( + 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+${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); + // 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); + }); }); - }); + } + + addLiquidityTest('private_fpc'); + addLiquidityTest('sponsored_fpc'); }); } }); diff --git a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts index d98c86df1e55..075bfb58552f 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts @@ -35,12 +35,10 @@ describe('Bridging benchmark', () => { await t.teardown(); }); - bridgingBenchmark('ecdsar1', 'private_fpc'); - bridgingBenchmark('schnorr', 'private_fpc'); - bridgingBenchmark('ecdsar1', 'sponsored_fpc'); - bridgingBenchmark('schnorr', 'sponsored_fpc'); + bridgingBenchmark('ecdsar1'); + bridgingBenchmark('schnorr'); - function bridgingBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { + function bridgingBenchmark(accountType: AccountType) { return describe(`Bridging benchmark for ${accountType}`, () => { // Our benchmarking user let benchysWallet: AccountWallet; @@ -63,52 +61,59 @@ describe('Bridging benchmark', () => { await benchysWallet.registerContract(sponsoredFPC); }); - it(`${accountType} contract bridges tokens from L1 claiming privately, pays using ${benchmarkingPaymentMethod}`, async () => { - // Generate a claim secret using pedersen - const l1TokenBalance = 1000000n; - const bridgeAmount = 100n; - - // 1. Mint tokens on L1 - await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); - - // 2. Deposit tokens to the TokenPortal - const claim = await crossChainTestHarness.sendTokensToPortalPrivate(bridgeAmount); - await crossChainTestHarness.makeMessageConsumable(claim.messageHash); - - // 3. Consume L1 -> L2 message and mint private tokens on L2 - const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod]; - const options: SimulateMethodOptions = { fee: { paymentMethod: await paymentMethod.forWallet(benchysWallet) } }; - - const { recipient, claimAmount, claimSecret: secretForL2MessageConsumption, messageLeafIndex } = claim; - const claimInteraction = crossChainTestHarness.l2Bridge.methods.claim_private( - recipient, - claimAmount, - secretForL2MessageConsumption, - messageLeafIndex, - ); - - await capturePrivateExecutionStepsIfEnvSet( - `${accountType}+token_bridge_claim_private+${benchmarkingPaymentMethod}`, - claimInteraction, - options, - 1 + // Account entrypoint - 1 + // Kernel init - paymentMethod.circuits + // Payment method circuits - 2 + // TokenBridge claim_private + kernel inner - 2 + // BridgedAsset mint_to_private + kernel inner - 1 + // Kernel reset - 1, // Kernel tail - ); - - // Ensure we paid a fee - const tx = await claimInteraction.send(options).wait(); - expect(tx.transactionFee!).toBeGreaterThan(0n); - - // 4. Check the balance - - const balance = await crossChainTestHarness.getL2PrivateBalanceOf(benchysWallet.getAddress()); - expect(balance).toBe(bridgeAmount); - }); + function privateClaimTest(benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { + return it(`${accountType} contract bridges tokens from L1 claiming privately, pays using ${benchmarkingPaymentMethod}`, async () => { + // Generate a claim secret using pedersen + const l1TokenBalance = 1000000n; + const bridgeAmount = 100n; + + // 1. Mint tokens on L1 + await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); + + // 2. Deposit tokens to the TokenPortal + const claim = await crossChainTestHarness.sendTokensToPortalPrivate(bridgeAmount); + await crossChainTestHarness.makeMessageConsumable(claim.messageHash); + + // 3. Consume L1 -> L2 message and mint private tokens on L2 + const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod]; + const options: SimulateMethodOptions = { + fee: { paymentMethod: await paymentMethod.forWallet(benchysWallet) }, + }; + + const { recipient, claimAmount, claimSecret: secretForL2MessageConsumption, messageLeafIndex } = claim; + const claimInteraction = crossChainTestHarness.l2Bridge.methods.claim_private( + recipient, + claimAmount, + secretForL2MessageConsumption, + messageLeafIndex, + ); + + await capturePrivateExecutionStepsIfEnvSet( + `${accountType}+token_bridge_claim_private+${benchmarkingPaymentMethod}`, + claimInteraction, + options, + 1 + // Account entrypoint + 1 + // Kernel init + paymentMethod.circuits + // Payment method circuits + 2 + // TokenBridge claim_private + kernel inner + 2 + // BridgedAsset mint_to_private + kernel inner + 1 + // Kernel reset + 1, // Kernel tail + ); + + // Ensure we paid a fee + const tx = await claimInteraction.send(options).wait(); + expect(tx.transactionFee!).toBeGreaterThan(0n); + + // 4. Check the balance + + const balance = await crossChainTestHarness.getL2PrivateBalanceOf(benchysWallet.getAddress()); + expect(balance).toBe(bridgeAmount); + }); + } + + privateClaimTest('private_fpc'); + privateClaimTest('sponsored_fpc'); }); } }); diff --git a/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts b/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts index 630067e123fc..f44445771d56 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts @@ -31,58 +31,61 @@ describe('Deployment benchmark', () => { await t.teardown(); }); - deploymentBenchmark('ecdsar1', 'bridged_fee_juice'); - deploymentBenchmark('schnorr', 'bridged_fee_juice'); - deploymentBenchmark('ecdsar1', 'sponsored_fpc'); - deploymentBenchmark('schnorr', 'sponsored_fpc'); + deploymentBenchmark('ecdsar1'); + deploymentBenchmark('schnorr'); - function deploymentBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { + function deploymentBenchmark(accountType: AccountType) { return describe(`Deployment benchmark for ${accountType}`, () => { - it(`Deploys a ${accountType} account contract, pays using ${benchmarkingPaymentMethod}`, async () => { - const benchysAccountManager = await t.createBenchmarkingAccountManager(accountType); - const benchysWallet = await benchysAccountManager.getWallet(); + function deploymentTest(benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { + return it(`Deploys a ${accountType} account contract, pays using ${benchmarkingPaymentMethod}`, async () => { + const benchysAccountManager = await t.createBenchmarkingAccountManager(accountType); + const benchysWallet = await benchysAccountManager.getWallet(); - if (benchmarkingPaymentMethod === 'sponsored_fpc') { - await benchysWallet.registerContract(sponsoredFPC); - } + if (benchmarkingPaymentMethod === 'sponsored_fpc') { + await benchysWallet.registerContract(sponsoredFPC); + } - const deploymentInteraction = await benchysAccountManager.getDeployMethod(); + const deploymentInteraction = await benchysAccountManager.getDeployMethod(); - const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod]; - const wrappedPaymentMethod = await benchysAccountManager.getSelfPaymentMethod( - await paymentMethod.forWallet(benchysWallet), - ); - const fee = { paymentMethod: wrappedPaymentMethod }; - // Publicly deploy the contract, but skip the class registration as that is the - // "typical" use case - const options: DeployOptions = { - fee, - universalDeploy: true, - skipClassRegistration: true, - skipPublicDeployment: false, - skipInitialization: false, - contractAddressSalt: new Fr(benchysAccountManager.salt), - }; + const paymentMethod = t.paymentMethods[benchmarkingPaymentMethod]; + const wrappedPaymentMethod = await benchysAccountManager.getSelfPaymentMethod( + await paymentMethod.forWallet(benchysWallet), + ); + const fee = { paymentMethod: wrappedPaymentMethod }; + // Publicly deploy the contract, but skip the class registration as that is the + // "typical" use case + const options: DeployOptions = { + fee, + universalDeploy: true, + skipClassRegistration: true, + skipPublicDeployment: false, + skipInitialization: false, + contractAddressSalt: new Fr(benchysAccountManager.salt), + }; - await capturePrivateExecutionStepsIfEnvSet( - `deploy_${accountType}+${benchmarkingPaymentMethod}`, - deploymentInteraction, - options, - 1 + // Multicall entrypoint - 1 + // Kernel init - 2 + // ContractInstanceDeployer deploy + kernel inner - 2 + // ContractClassRegisterer assert_class_id_is_registered + kernel inner - 2 + // Account constructor + kernel inner - 2 + // Account entrypoint (wrapped fee payload) + kernel inner - paymentMethod.circuits + // Payment method circuits - 1 + // Kernel reset - 1, // Kernel tail - ); + await capturePrivateExecutionStepsIfEnvSet( + `deploy_${accountType}+${benchmarkingPaymentMethod}`, + deploymentInteraction, + options, + 1 + // Multicall entrypoint + 1 + // Kernel init + 2 + // ContractInstanceDeployer deploy + kernel inner + 2 + // ContractClassRegisterer assert_class_id_is_registered + kernel inner + 2 + // Account constructor + kernel inner + 2 + // Account entrypoint (wrapped fee payload) + kernel inner + paymentMethod.circuits + // Payment method circuits + 1 + // Kernel reset + 1, // Kernel tail + ); - // Ensure we paid a fee - const tx = await deploymentInteraction.send(options).wait(); - expect(tx.transactionFee!).toBeGreaterThan(0n); - }); + // Ensure we paid a fee + const tx = await deploymentInteraction.send(options).wait(); + expect(tx.transactionFee!).toBeGreaterThan(0n); + }); + } + + deploymentTest('bridged_fee_juice'); + deploymentTest('sponsored_fpc'); }); } }); diff --git a/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts b/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts index 2681c1b56ebc..dc193d0135b6 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts @@ -45,12 +45,10 @@ describe('Transfer benchmark', () => { await t.teardown(); }); - transferBenchmark('ecdsar1', 'private_fpc'); - transferBenchmark('ecdsar1', 'sponsored_fpc'); - transferBenchmark('schnorr', 'private_fpc'); - transferBenchmark('schnorr', 'sponsored_fpc'); + transferBenchmark('ecdsar1'); + transferBenchmark('schnorr'); - function transferBenchmark(accountType: AccountType, benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod) { + function transferBenchmark(accountType: AccountType) { return describe(`Transfer benchmark for ${accountType}`, () => { // Our benchmarking user let benchysWallet: AccountWallet; @@ -70,7 +68,11 @@ describe('Transfer benchmark', () => { await benchysWallet.registerContract(sponsoredFPC); }); - function recursionTest(recursions: number, notesToCreate: number) { + function recursionTest( + recursions: number, + notesToCreate: number, + benchmarkingPaymentMethod: BenchmarkingFeePaymentMethod, + ) { return describe(`Mint ${notesToCreate} notes and transfer using a ${accountType} account`, () => { // Total amount of coins minted across all notes let totalAmount: bigint; @@ -164,7 +166,8 @@ describe('Transfer benchmark', () => { for (let i = 0; i < MINIMUM_NOTES_FOR_RECURSION_LEVEL.length; i++) { // Create the minimum amount of notes for the test, which is just above the threshold for recursion at each level - recursionTest(i, MINIMUM_NOTES_FOR_RECURSION_LEVEL[i] + 1); + recursionTest(i, MINIMUM_NOTES_FOR_RECURSION_LEVEL[i] + 1, 'private_fpc'); + recursionTest(i, MINIMUM_NOTES_FOR_RECURSION_LEVEL[i] + 1, 'sponsored_fpc'); } }); } From 50a1962ed7663fd7efaf1caab2b23fe266e9edd8 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 27 Mar 2025 20:58:46 +0000 Subject: [PATCH 04/23] restored trace --- .../execution_trace/mega_execution_trace.hpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp index 851a2a7fe7f8..4f02d9dc3c27 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp @@ -330,16 +330,16 @@ static constexpr TraceStructure EXAMPLE_20{ .ecc_op = 1 << 11, /** * @brief Structuring tailored to the full e2e TS test (TO BE UPDATED ACCORDINGLY) */ -static constexpr TraceStructure E2E_FULL_TEST_STRUCTURE{ .ecc_op = 756, - .busread = 4119, - .lookup = 14482, - .pub_inputs = 1814, - .arithmetic = 55274, - .delta_range = 17186, - .elliptic = 5870, - .aux = 25370, - .poseidon2_external = 16082, - .poseidon2_internal = 91658, +static constexpr TraceStructure E2E_FULL_TEST_STRUCTURE{ .ecc_op = 1 << 10, + .busread = 6000, + .lookup = 200000, + .pub_inputs = 4000, + .arithmetic = 200000, + .delta_range = 25000, + .elliptic = 80000, + .aux = 100000, + .poseidon2_external = 45192, + .poseidon2_internal = 258000, .overflow = 0 }; template From 462e622ca9bdb1f059396234c81ceddb77ac8a97 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 28 Mar 2025 05:12:21 +0000 Subject: [PATCH 05/23] magic trace --- .../execution_trace/mega_execution_trace.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp index 4f02d9dc3c27..415619ccddae 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp @@ -331,15 +331,15 @@ static constexpr TraceStructure EXAMPLE_20{ .ecc_op = 1 << 11, * @brief Structuring tailored to the full e2e TS test (TO BE UPDATED ACCORDINGLY) */ static constexpr TraceStructure E2E_FULL_TEST_STRUCTURE{ .ecc_op = 1 << 10, - .busread = 6000, - .lookup = 200000, - .pub_inputs = 4000, - .arithmetic = 200000, - .delta_range = 25000, - .elliptic = 80000, - .aux = 100000, - .poseidon2_external = 45192, - .poseidon2_internal = 258000, + .busread = 5000, + .lookup = 15000, + .pub_inputs = 2000, + .arithmetic = 56000, + .delta_range = 18000, + .elliptic = 6000, + .aux = 26000, + .poseidon2_external = 17000, + .poseidon2_internal = 92000, .overflow = 0 }; template From 9a4a279560fe5a75c7ca21d9c2578537bf0c92c3 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 28 Mar 2025 05:46:56 +0000 Subject: [PATCH 06/23] monke --- .../translator_vm/translator_flavor.hpp | 2 +- .../end-to-end/src/bench/client_flows/amm.test.ts | 2 +- .../bench/client_flows/client_flows_benchmark.ts | 13 ++++++++----- .../src/bench/client_flows/data_extractor.ts | 3 +-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 530237a12b6b..7f6f84848a74 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -44,7 +44,7 @@ class TranslatorFlavor { // A minicircuit of such size allows for 10 rounds of folding (i.e. 20 circuits). // Lowest possible size for the translator circuit (this sets the mini_circuit_size) static constexpr size_t MINIMUM_MINI_CIRCUIT_SIZE = 2048; - static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 16384; + static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 12288; static_assert(TRANSLATOR_VM_FIXED_SIZE >= MINIMUM_MINI_CIRCUIT_SIZE); // The size of the circuit which is filled with non-zero values for most polynomials. Most relations (everything diff --git a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts index 75114b0513d1..43400205b0dc 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts @@ -1,4 +1,4 @@ -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'; diff --git a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts index bc32a7ff830f..650addd31537 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts @@ -14,7 +14,7 @@ import { createLogger, } from '@aztec/aztec.js'; import { CheatCodes } from '@aztec/aztec.js/testing'; -import { FEE_FUNDING_FOR_TESTER_ACCOUNT, SPONSORED_FPC_SALT } from '@aztec/constants'; +import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; import { type DeployL1ContractsArgs, RollupContract, createL1Clients, deployL1Contract } from '@aztec/ethereum'; import { ChainMonitor } from '@aztec/ethereum/test'; import { randomBytes } from '@aztec/foundation/crypto'; @@ -91,10 +91,12 @@ export class ClientFlowsBenchmark { public paymentMethods: Record = { + // eslint-disable-next-line camelcase bridged_fee_juice: { forWallet: this.getBridgedFeeJuicePaymentMethodForWallet.bind(this), circuits: 2, // FeeJuice claim + kernel inner }, + // eslint-disable-next-line camelcase private_fpc: { forWallet: this.getPrivateFPCPaymentMethodForWallet.bind(this), circuits: @@ -103,6 +105,7 @@ export class ClientFlowsBenchmark { 2 + // Account verify_private_authwit + kernel inner 2, // BananaCoin prepare_private_balance_increase + kernel inner }, + // eslint-disable-next-line camelcase sponsored_fpc: { forWallet: this.getSponsoredFPCPaymentMethodForWallet.bind(this), circuits: 2, // Sponsored FPC sponsor_unconditionally + kernel inner @@ -380,11 +383,11 @@ export class ClientFlowsBenchmark { return new FeeJuicePaymentMethodWithClaim(wallet, claim); } - public async getPrivateFPCPaymentMethodForWallet(wallet: Wallet) { - return new PrivateFeePaymentMethod(this.bananaFPC.address, wallet); + public getPrivateFPCPaymentMethodForWallet(wallet: Wallet) { + return Promise.resolve(new PrivateFeePaymentMethod(this.bananaFPC.address, wallet)); } - public async getSponsoredFPCPaymentMethodForWallet(wallet: Wallet) { - return new SponsoredFeePaymentMethod(this.sponsoredFPC.address); + public getSponsoredFPCPaymentMethodForWallet(_wallet: Wallet) { + return Promise.resolve(new SponsoredFeePaymentMethod(this.sponsoredFPC.address)); } } diff --git a/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts b/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts index d174cbcf48dc..1ee1a1815d84 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/data_extractor.ts @@ -163,7 +163,6 @@ async function main() { bytecode: acirStack[i], witness: witnessStack[i], })); - let minimumTrace: StructuredTrace | undefined; let stats: { duration: number; eventName: string; proofSize: number } | undefined; // eslint-disable-next-line @typescript-eslint/no-explicit-any let error: any | undefined; @@ -182,7 +181,7 @@ async function main() { stats = currentLogs[0].data as { duration: number; eventName: string; proofSize: number }; } - minimumTrace = getMinimumTrace(currentLogs, proverType); + const minimumTrace = getMinimumTrace(currentLogs, proverType); const steps = executionSteps.reduce((acc, step, i) => { const previousAccGateCount = i === 0 ? 0 : acc[i - 1].accGateCount!; From 7cfef135b8b97fdb7854b5eb85f85533829f5658 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 28 Mar 2025 06:03:22 +0000 Subject: [PATCH 07/23] Revert "Increase capacity to 17 kernels" This reverts commit 0717740433008550a86449f20c5b6d84b84eadb0. --- .../client_ivc/client_ivc.test.cpp | 30 ------------------- .../src/barretenberg/eccvm/eccvm_flavor.hpp | 3 +- .../cpp/src/barretenberg/goblin/goblin.hpp | 2 -- .../translator_vm/translator_flavor.hpp | 2 +- 4 files changed, 3 insertions(+), 34 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index f3c94e8fea4f..e60f986dd769 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -10,8 +10,6 @@ using namespace bb; -static constexpr size_t MAX_NUM_KERNELS = 17; - class ClientIVCTests : public ::testing::Test { protected: static void SetUpTestSuite() @@ -440,34 +438,6 @@ TEST(ClientIVCBenchValidation, Full6MockedVKs) ASSERT_NO_FATAL_FAILURE(run_test()); } -TEST(ClientIVCKernelCapacity, MaxCapacityPassing) -{ - bb::srs::init_crs_factory(bb::srs::get_ignition_crs_path()); - bb::srs::init_grumpkin_crs_factory(bb::srs::get_grumpkin_crs_path()); - - ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; - const size_t total_num_circuits{ 2 * MAX_NUM_KERNELS }; - PrivateFunctionExecutionMockCircuitProducer circuit_producer; - auto precomputed_vkeys = circuit_producer.precompute_verification_keys(total_num_circuits, ivc.trace_settings); - perform_ivc_accumulation_rounds(total_num_circuits, ivc, precomputed_vkeys); - auto proof = ivc.prove(); - bool verified = verify_ivc(proof, ivc); - EXPECT_TRUE(verified); -} - -TEST(ClientIVCKernelCapacity, MaxCapacityFailing) -{ - bb::srs::init_crs_factory(bb::srs::get_ignition_crs_path()); - bb::srs::init_grumpkin_crs_factory(bb::srs::get_grumpkin_crs_path()); - - ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; - const size_t total_num_circuits{ 2 * (MAX_NUM_KERNELS + 1) }; - PrivateFunctionExecutionMockCircuitProducer circuit_producer; - auto precomputed_vkeys = circuit_producer.precompute_verification_keys(total_num_circuits, ivc.trace_settings); - perform_ivc_accumulation_rounds(total_num_circuits, ivc, precomputed_vkeys); - EXPECT_ANY_THROW(ivc.prove()); -} - /** * @brief Test use of structured trace overflow block mechanism * @details Accumulate 4 circuits which have progressively more arithmetic gates. The final two overflow the prescribed diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index 6b13a2a13e38..bb702b6675a4 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -527,7 +527,8 @@ class ECCVMFlavor { size_t dyadic_num_rows = 1UL << (log_num_rows + (1UL << log_num_rows == num_rows ? 0 : 1)); if ((fixed_size) && (ECCVM_FIXED_SIZE < dyadic_num_rows)) { - throw_or_abort("The ECCVM circuit size has exceeded the fixed upper bound"); + info("The ECCVM circuit size has exceeded the fixed upper bound"); + ASSERT(false); } dyadic_num_rows = fixed_size ? ECCVM_FIXED_SIZE : dyadic_num_rows; diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 323e09d99b79..582d64e1e301 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -149,8 +149,6 @@ class GoblinProver { PROFILE_THIS_NAME("Goblin::prove"); - info("Constructing a Goblin proof with num ultra ops = ", op_queue->get_ultra_ops_table_num_rows()); - goblin_proof.merge_proof = merge_proof_in.empty() ? std::move(merge_proof) : std::move(merge_proof_in); { PROFILE_THIS_NAME("prove_eccvm"); diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 7f6f84848a74..0cf41a07c186 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -44,7 +44,7 @@ class TranslatorFlavor { // A minicircuit of such size allows for 10 rounds of folding (i.e. 20 circuits). // Lowest possible size for the translator circuit (this sets the mini_circuit_size) static constexpr size_t MINIMUM_MINI_CIRCUIT_SIZE = 2048; - static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 12288; + static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 8192; static_assert(TRANSLATOR_VM_FIXED_SIZE >= MINIMUM_MINI_CIRCUIT_SIZE); // The size of the circuit which is filled with non-zero values for most polynomials. Most relations (everything From 084f0a1eadf684bd01c3bc04afd428090167c7cf Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 28 Mar 2025 07:03:40 +0000 Subject: [PATCH 08/23] bb so fast I had to batch logs in playground --- playground/src/aztecEnv.ts | 39 ++++++++++++++----- .../src/components/logPanel/logPanel.tsx | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/playground/src/aztecEnv.ts b/playground/src/aztecEnv.ts index 715220205ee5..88fd335b1151 100644 --- a/playground/src/aztecEnv.ts +++ b/playground/src/aztecEnv.ts @@ -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; @@ -30,10 +32,23 @@ 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 pendingUpdate = true; + + 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); + instance.pendingUpdate = false; + }, WebLogger.updateIntervalMs); + } } static getInstance() { @@ -44,12 +59,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; + return function (this: Logger, ...data: Parameters) { + const loggingFn = prop as LogLevel; + const args = [loggingFn, prefix, ...data] as Parameters; 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]; @@ -65,8 +79,13 @@ 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() }); + this.pendingUpdate = true; + } + + private randomId(): string { + const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0]; + return uint32.toString(16); } } diff --git a/playground/src/components/logPanel/logPanel.tsx b/playground/src/components/logPanel/logPanel.tsx index d0567d6c114c..07e26250e310 100644 --- a/playground/src/components/logPanel/logPanel.tsx +++ b/playground/src/components/logPanel/logPanel.tsx @@ -117,7 +117,7 @@ export function LogPanel() { {logs.map((log, index) => ( -
+
{log.prefix}: 
From 48987af3c82ccc4f89589ffa31c75f6e5b9c244a Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 28 Mar 2025 11:30:07 +0000 Subject: [PATCH 09/23] skip permutation relation when possible --- .../translator_vm/translator_permutation_relation.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp index 6bb732644ad2..578e2ab86b80 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp @@ -14,6 +14,17 @@ template class TranslatorPermutationRelationImpl { 3 // left-shiftable polynomial sub-relation }; + /** + * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero + * + */ + template inline static bool skip(const AllEntities& in) + { + // If z_perm == z_perm_shift, this implies that none of the wire values for the present input are involved in + // non-trivial copy constraints. + return (in.z_perm - in.z_perm_shift).is_zero(); + } + inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } inline static auto& get_shifted_grand_product_polynomial(auto& in) { return in.z_perm_shift; } From 0957ad2e2932ed4b723af54418fef9d2c395bd3b Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 28 Mar 2025 12:00:05 +0000 Subject: [PATCH 10/23] allocate and deallocate full commitment key --- .../translator_vm/translator_prover.cpp | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp index bf80cd46b943..16ae4bca8959 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp @@ -134,8 +134,14 @@ void TranslatorProver::execute_relation_check_rounds() gate_challenges[idx] = transcript->template get_challenge("Sumcheck:gate_challenge_" + std::to_string(idx)); } + const size_t log_subgroup_size = static_cast(numeric::get_msb(Flavor::Curve::SUBGROUP_SIZE)); + // Create a temporary commitment key that is only used to initialise the ZKSumcheckData + // If proving in WASM, the commitment key that is part of the Translator proving key remains deallocated + // until we enter the PCS round + auto ck = std::make_shared(1 << (log_subgroup_size + 1)); + // // create masking polynomials for sumcheck round univariates and auxiliary data - zk_sumcheck_data = ZKData(key->proving_key->log_circuit_size, transcript, key->proving_key->commitment_key); + zk_sumcheck_data = ZKData(key->proving_key->log_circuit_size, transcript, ck); sumcheck_output = sumcheck.prove(key->proving_key->polynomials, relation_parameters, alpha, gate_challenges, zk_sumcheck_data); @@ -154,11 +160,12 @@ void TranslatorProver::execute_pcs_rounds() using SmallSubgroupIPA = SmallSubgroupIPAProver; using PolynomialBatcher = GeminiProver_::PolynomialBatcher; - SmallSubgroupIPA small_subgroup_ipa_prover(zk_sumcheck_data, - sumcheck_output.challenge, - sumcheck_output.claimed_libra_evaluation, - transcript, - key->proving_key->commitment_key); + // Check whether the commitment key has been deallocated and reinitialise it if necessary + auto& ck = key->proving_key->commitment_key; + ck = ck ? ck : std::make_shared(key->proving_key->circuit_size); + + SmallSubgroupIPA small_subgroup_ipa_prover( + zk_sumcheck_data, sumcheck_output.challenge, sumcheck_output.claimed_libra_evaluation, transcript, ck); small_subgroup_ipa_prover.prove(); PolynomialBatcher polynomial_batcher(key->proving_key->circuit_size); @@ -171,11 +178,11 @@ void TranslatorProver::execute_pcs_rounds() ShpleminiProver_::prove(key->proving_key->circuit_size, polynomial_batcher, sumcheck_output.challenge, - key->proving_key->commitment_key, + ck, transcript, small_subgroup_ipa_prover.get_witness_polynomials()); - PCS::compute_opening_proof(key->proving_key->commitment_key, prover_opening_claim, transcript); + PCS::compute_opening_proof(ck, prover_opening_claim, transcript); } HonkProof TranslatorProver::export_proof() @@ -198,6 +205,11 @@ HonkProof TranslatorProver::construct_proof() // Compute grand product(s) and commitments. execute_grand_product_computation_round(); + // #ifndef __wasm__ + // Free the commitment key + key->proving_key->commitment_key = nullptr; + // #endif + // Fiat-Shamir: alpha // Run sumcheck subprotocol. execute_relation_check_rounds(); @@ -206,6 +218,10 @@ HonkProof TranslatorProver::construct_proof() // Execute Shplemini PCS execute_pcs_rounds(); vinfo("computed opening proof"); + // #ifndef __wasm__ + // Free the commitment key + key->proving_key->commitment_key = nullptr; + // #endif return export_proof(); } From dc216091f9ff90f82d1fb03e8703754bf8d93f67 Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 28 Mar 2025 12:04:37 +0000 Subject: [PATCH 11/23] add worktodo and comments about constants --- barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp | 1 + barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp | 2 ++ .../cpp/src/barretenberg/translator_vm/translator_flavor.hpp | 2 ++ 3 files changed, 5 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 691d48616080..8d2be742374a 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -158,6 +158,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, // The commitment key is initialised with the number of points determined by the trace_settings' dyadic size. If a // circuit overflows past the dyadic size the commitment key will not have enough points so we need to increase it + // WORKTODO: we need to check that the size we set here is also enough to commit to the polynomials in translator if (proving_key->proving_key.circuit_size > trace_settings.dyadic_size()) { bn254_commitment_key = std::make_shared>(proving_key->proving_key.circuit_size); goblin.commitment_key = bn254_commitment_key; diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index 6b13a2a13e38..d910ce18e8bc 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -46,6 +46,8 @@ class ECCVMFlavor { // Indicates that this flavor runs with ZK Sumcheck. static constexpr bool HasZK = true; // Fixed size of the ECCVM circuits used in ClientIVC + // Important: these constants cannot be arbitrarily changes - please consult with a member of the Crypto team if + // they become too small. static constexpr size_t ECCVM_FIXED_SIZE = 1UL << CONST_ECCVM_LOG_N; static constexpr size_t NUM_WIRES = 85; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 530237a12b6b..c28ab5fa59be 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -43,6 +43,8 @@ class TranslatorFlavor { // A minicircuit of such size allows for 10 rounds of folding (i.e. 20 circuits). // Lowest possible size for the translator circuit (this sets the mini_circuit_size) + // Important: these constants cannot be arbitrarily changes - please consult with a member of the Crypto team if + // they become too small. static constexpr size_t MINIMUM_MINI_CIRCUIT_SIZE = 2048; static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 16384; static_assert(TRANSLATOR_VM_FIXED_SIZE >= MINIMUM_MINI_CIRCUIT_SIZE); From d7232f2ad82e61b4c6bb3b745dca34ac655cf020 Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 28 Mar 2025 12:27:14 +0000 Subject: [PATCH 12/23] don't deallocate at then end --- .../cpp/src/barretenberg/translator_vm/translator_prover.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp index 16ae4bca8959..7f3f0b3afad6 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp @@ -218,11 +218,6 @@ HonkProof TranslatorProver::construct_proof() // Execute Shplemini PCS execute_pcs_rounds(); vinfo("computed opening proof"); - // #ifndef __wasm__ - // Free the commitment key - key->proving_key->commitment_key = nullptr; - // #endif - return export_proof(); } From 672001d04613a1279f3d74c03d45a8886db2a87e Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 28 Mar 2025 13:01:52 +0000 Subject: [PATCH 13/23] benchmark parametrization --- .../src/bench/client_flows/amm.test.ts | 12 ++-- .../src/bench/client_flows/bridging.test.ts | 19 +++++-- .../client_flows/client_flows_benchmark.ts | 57 ++++++++++++++++++- .../bench/client_flows/deployments.test.ts | 12 ++-- .../src/bench/client_flows/transfers.test.ts | 15 +++-- 5 files changed, 95 insertions(+), 20 deletions(-) diff --git a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts index 43400205b0dc..baba8b954c39 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/amm.test.ts @@ -33,6 +33,8 @@ describe('AMM benchmark', () => { let liquidityToken: TokenContract; // Sponsored FPC contract let sponsoredFPC: SponsoredFPCContract; + // Benchmarking configuration + const config = t.config.amm; beforeAll(async () => { await t.applyBaseSnapshots(); @@ -48,8 +50,9 @@ describe('AMM benchmark', () => { 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}`, () => { @@ -154,8 +157,9 @@ describe('AMM benchmark', () => { }); } - addLiquidityTest('private_fpc'); - addLiquidityTest('sponsored_fpc'); + for (const paymentMethod of config.feePaymentMethods) { + addLiquidityTest(paymentMethod); + } }); } }); diff --git a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts index 075bfb58552f..c00a76afc0ea 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts @@ -8,7 +8,12 @@ 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 { + type AccountType, + type BenchmarkingFeePaymentMethod, + type ClientFlowConfig, + ClientFlowsBenchmark, +} from './client_flows_benchmark.js'; jest.setTimeout(300_000); @@ -22,6 +27,8 @@ describe('Bridging benchmark', () => { let bananaCoin: TokenContract; // Sponsored FPC contract let sponsoredFPC: SponsoredFPCContract; + // Benchmarking configuration + const config = t.config.bridging; beforeAll(async () => { await t.applyBaseSnapshots(); @@ -35,8 +42,9 @@ describe('Bridging benchmark', () => { await t.teardown(); }); - bridgingBenchmark('ecdsar1'); - bridgingBenchmark('schnorr'); + for (const accountType of config.accounts) { + bridgingBenchmark(accountType); + } function bridgingBenchmark(accountType: AccountType) { return describe(`Bridging benchmark for ${accountType}`, () => { @@ -112,8 +120,9 @@ describe('Bridging benchmark', () => { }); } - privateClaimTest('private_fpc'); - privateClaimTest('sponsored_fpc'); + for (const paymentMethod of config.feePaymentMethods) { + privateClaimTest(paymentMethod); + } }); } }); diff --git a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts index 650addd31537..711405e99929 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts @@ -47,12 +47,64 @@ import { type GasBridgingTestHarness, } from '../../shared/gas_portal_test_harness.js'; -const { E2E_DATA_PATH: dataPath } = process.env; +const { E2E_DATA_PATH: dataPath, BENCHMARK_CONFIG } = process.env; export type AccountType = 'ecdsar1' | 'schnorr'; export type FeePaymentMethodGetter = (wallet: Wallet) => Promise; export type BenchmarkingFeePaymentMethod = 'bridged_fee_juice' | 'private_fpc' | 'sponsored_fpc'; +export type ClientFlowConfig = { + accounts: AccountType[]; + feePaymentMethods: BenchmarkingFeePaymentMethod[]; + recursions?: number[]; +}; + +type ClientFlows = 'deployments' | 'transfers' | 'bridging' | 'amm'; + +type ClientFlowsConfig = { + [key in ClientFlows]: ClientFlowConfig; +}; + +const KEY_FLOWS_CONFIG: ClientFlowsConfig = { + deployments: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc'], + }, + amm: { + accounts: ['ecdsar1'], + feePaymentMethods: ['sponsored_fpc'], + }, + bridging: { + accounts: ['ecdsar1'], + feePaymentMethods: ['sponsored_fpc'], + }, + transfers: { + accounts: ['ecdsar1'], + feePaymentMethods: ['sponsored_fpc'], + recursions: [1], + }, +}; + +const FULL_FLOWS_CONFIG: ClientFlowsConfig = { + deployments: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['bridged_fee_juice', 'sponsored_fpc'], + }, + amm: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc', 'private_fpc'], + }, + bridging: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc', 'private_fpc'], + }, + transfers: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc', 'private_fpc'], + recursions: [0, 1, 2], + }, +}; + export class ClientFlowsBenchmark { private snapshotManager: ISnapshotManager; @@ -112,6 +164,8 @@ export class ClientFlowsBenchmark { }, }; + public config: ClientFlowsConfig; + constructor(testName?: string, setupOptions: Partial = {}) { this.logger = createLogger(`bench:client_flows${testName ? `:${testName}` : ''}`); this.snapshotManager = createSnapshotManager( @@ -120,6 +174,7 @@ export class ClientFlowsBenchmark { { startProverNode: true, ...setupOptions }, { ...setupOptions }, ); + this.config = BENCHMARK_CONFIG === 'key_flows' ? KEY_FLOWS_CONFIG : FULL_FLOWS_CONFIG; } async setup() { diff --git a/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts b/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts index f44445771d56..ee200b0e8d10 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/deployments.test.ts @@ -15,6 +15,8 @@ describe('Deployment benchmark', () => { let adminWallet: AccountWallet; // Sponsored FPC contract let sponsoredFPC: SponsoredFPCContract; + // Benchmarking configuration + const config = t.config.deployments; beforeAll(async () => { await t.applyBaseSnapshots(); @@ -31,8 +33,9 @@ describe('Deployment benchmark', () => { await t.teardown(); }); - deploymentBenchmark('ecdsar1'); - deploymentBenchmark('schnorr'); + for (const accountType of config.accounts) { + deploymentBenchmark(accountType); + } function deploymentBenchmark(accountType: AccountType) { return describe(`Deployment benchmark for ${accountType}`, () => { @@ -84,8 +87,9 @@ describe('Deployment benchmark', () => { }); } - deploymentTest('bridged_fee_juice'); - deploymentTest('sponsored_fpc'); + for (const paymentMethod of config.feePaymentMethods) { + deploymentTest(paymentMethod); + } }); } }); diff --git a/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts b/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts index dc193d0135b6..a49ba677bcbc 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts @@ -30,6 +30,8 @@ describe('Transfer benchmark', () => { let node: AztecNode; // Sponsored FPC contract let sponsoredFPC: SponsoredFPCContract; + // Benchmarking configuration + const config = t.config.transfers; beforeAll(async () => { await t.applyBaseSnapshots(); @@ -45,8 +47,9 @@ describe('Transfer benchmark', () => { await t.teardown(); }); - transferBenchmark('ecdsar1'); - transferBenchmark('schnorr'); + for (const accountType of config.accounts) { + transferBenchmark(accountType); + } function transferBenchmark(accountType: AccountType) { return describe(`Transfer benchmark for ${accountType}`, () => { @@ -164,10 +167,10 @@ describe('Transfer benchmark', () => { }); } - for (let i = 0; i < MINIMUM_NOTES_FOR_RECURSION_LEVEL.length; i++) { - // Create the minimum amount of notes for the test, which is just above the threshold for recursion at each level - recursionTest(i, MINIMUM_NOTES_FOR_RECURSION_LEVEL[i] + 1, 'private_fpc'); - recursionTest(i, MINIMUM_NOTES_FOR_RECURSION_LEVEL[i] + 1, 'sponsored_fpc'); + for (const paymentMethod of config.feePaymentMethods) { + for (const recursions of config.recursions ?? []) { + recursionTest(recursions, MINIMUM_NOTES_FOR_RECURSION_LEVEL[recursions] + 1, paymentMethod); + } } }); } From f0046f323d7abaa98830e209b95969f736fb25a0 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 28 Mar 2025 13:09:01 +0000 Subject: [PATCH 14/23] wtf --- .../cpp/src/barretenberg/translator_vm/translator_flavor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index f466a5a9de8c..c28ab5fa59be 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -46,7 +46,7 @@ class TranslatorFlavor { // Important: these constants cannot be arbitrarily changes - please consult with a member of the Crypto team if // they become too small. static constexpr size_t MINIMUM_MINI_CIRCUIT_SIZE = 2048; - static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 8192; + static constexpr size_t TRANSLATOR_VM_FIXED_SIZE = 16384; static_assert(TRANSLATOR_VM_FIXED_SIZE >= MINIMUM_MINI_CIRCUIT_SIZE); // The size of the circuit which is filled with non-zero values for most polynomials. Most relations (everything From 8d9c2a3fd6d3384ba0f6a4886206a10c9d7c99eb Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 28 Mar 2025 14:00:14 +0000 Subject: [PATCH 15/23] allow pointing bb.js node to any bb wasm --- .../barretenberg_wasm/fetch_code/node/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts b/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts index bc4a0a6c8e6b..049532fed10f 100644 --- a/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts @@ -16,7 +16,18 @@ 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; + 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; + } } From 64707712d28d17e013f652d8d67f4a375419714a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Fri, 28 Mar 2025 20:51:19 +0000 Subject: [PATCH 16/23] Fix extra import --- .../end-to-end/src/bench/client_flows/bridging.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts index c00a76afc0ea..851ba75091f9 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/bridging.test.ts @@ -8,12 +8,7 @@ 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, - type ClientFlowConfig, - ClientFlowsBenchmark, -} from './client_flows_benchmark.js'; +import { type AccountType, type BenchmarkingFeePaymentMethod, ClientFlowsBenchmark } from './client_flows_benchmark.js'; jest.setTimeout(300_000); From 04a079de454f658d9519e6a9242b82872067aac5 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 31 Mar 2025 02:54:17 +0000 Subject: [PATCH 17/23] use actual circuit content to size translator polynomials --- .../barretenberg/client_ivc/client_ivc.cpp | 7 +- .../barretenberg/client_ivc/client_ivc.hpp | 14 ++-- .../translator_vm/translator_flavor.hpp | 70 ++++++++++++++----- .../translator_vm/translator_prover.cpp | 36 +++++++--- .../translator_vm/translator_proving_key.hpp | 8 ++- 5 files changed, 96 insertions(+), 39 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 8d2be742374a..74a29afcb0fe 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -156,10 +156,9 @@ void ClientIVC::accumulate(ClientCircuit& circuit, // Construct the proving key for circuit std::shared_ptr proving_key = std::make_shared(circuit, trace_settings); - // The commitment key is initialised with the number of points determined by the trace_settings' dyadic size. If a - // circuit overflows past the dyadic size the commitment key will not have enough points so we need to increase it - // WORKTODO: we need to check that the size we set here is also enough to commit to the polynomials in translator - if (proving_key->proving_key.circuit_size > trace_settings.dyadic_size()) { + // If the current circuit overflows past the current size of the commitment key, reinitialize accordingly. + // WORKTODO: Make issue to set once and for all. Also, having to reset the goblin key is brittle. + if (proving_key->proving_key.circuit_size > bn254_commitment_key->dyadic_size) { bn254_commitment_key = std::make_shared>(proving_key->proving_key.circuit_size); goblin.commitment_key = bn254_commitment_key; } diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp index f6ef4ce0f320..4dfc9658e8d6 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp @@ -191,11 +191,17 @@ class ClientIVC { ClientIVC(TraceSettings trace_settings = {}) : trace_usage_tracker(trace_settings) , trace_settings(trace_settings) - , bn254_commitment_key(trace_settings.structure.has_value() - ? std::make_shared>(trace_settings.dyadic_size()) - : nullptr) , goblin(bn254_commitment_key) - {} + { + // Allocate BN254 commitment key based on the max dyadic Mega structured trace size and translator circuit size. + // WORKTODO: I'm accounting for the Translator here because things were breaking otherwise but it may make sense + // to only account for the translator once we're actually IN the translator. + size_t commitment_key_size = + std::max(trace_settings.dyadic_size(), + TranslatorFlavor::TRANSLATOR_VM_FIXED_SIZE * TranslatorFlavor::INTERLEAVING_GROUP_SIZE); + info("BN254 commitment key size: ", commitment_key_size); + bn254_commitment_key = std::make_shared>(commitment_key_size); + } void instantiate_stdlib_verification_queue( ClientCircuit& circuit, const std::vector>& input_keys = {}); diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index c28ab5fa59be..4f11c4eed7cc 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -341,6 +341,8 @@ class TranslatorFlavor { DerivedWitnessEntities::get_all()); }; + auto get_wires_to_be_shifted() { return WireToBeShiftedEntities::get_all(); }; + /** * @brief Get the entities constructed by interleaving. */ @@ -595,39 +597,61 @@ class TranslatorFlavor { public: // Define all operations as default, except copy construction/assignment ProverPolynomials() = default; - // Constructor to init all unshifted polys to the zero polynomial and set the shifted poly data - ProverPolynomials(size_t mini_circuit_size) + + /** + * @brief ProverPolynomials constructor + * @details Attempts to initialize polynomials efficiently by using the actual size of the mini circuit rather + * than the fixed dydaic size. + * + * @param actual_mini_circuit_size Actual number of rows in the mini circuit. + */ + ProverPolynomials(size_t actual_mini_circuit_size) { - size_t circuit_size = mini_circuit_size * INTERLEAVING_GROUP_SIZE; + const size_t mini_circuit_size = TRANSLATOR_VM_FIXED_SIZE; + const size_t circuit_size = TRANSLATOR_VM_FIXED_SIZE * INTERLEAVING_GROUP_SIZE; + + // WORKTODO: these are currently fully dense in the full circuit size but I'm guessing that doesnt need to + // be the case.. for (auto& ordered_range_constraint : get_ordered_range_constraints()) { ordered_range_constraint = Polynomial{ /*size*/ circuit_size - 1, - /*largest possible index*/ circuit_size, + /*virtual_size*/ circuit_size, 1 }; } - for (auto& interleaved : get_interleaved()) { - interleaved = Polynomial{ /*size*/ circuit_size, circuit_size }; - } z_perm = Polynomial{ /*size*/ circuit_size - 1, /*virtual_size*/ circuit_size, /*start_index*/ 1 }; - // All to_be_shifted witnesses except the ordered range constraints and z_perm are only non-zero in the mini - // circuit - for (auto& poly : get_to_be_shifted()) { - if (poly.is_empty()) { - poly = Polynomial{ /*size*/ mini_circuit_size - 1, - /*virtual_size*/ circuit_size, - /*start_index*/ 1 }; - } + // Initialize to be shifted wires based on actual size of the mini circuit + for (auto& poly : get_wires_to_be_shifted()) { + poly = Polynomial{ /*size*/ actual_mini_circuit_size - 1, + /*virtual_size*/ circuit_size, + /*start_index*/ 1 }; } + // Initialize interleaved polys based on actual mini circuit size times number of polys to be interleaved + const size_t actual_circuit_size = actual_mini_circuit_size * INTERLEAVING_GROUP_SIZE; + for (auto& poly : get_interleaved()) { + poly = Polynomial{ actual_circuit_size, circuit_size }; + } + + // Initialize some one-off polys with special structure + lagrange_first = Polynomial{ /*size*/ 1, /*virtual_size*/ circuit_size }; + lagrange_second = Polynomial{ /*size*/ 2, /*virtual_size*/ circuit_size }; + lagrange_even_in_minicircuit = Polynomial{ /*size*/ mini_circuit_size, /*virtual_size*/ circuit_size }; + lagrange_odd_in_minicircuit = Polynomial{ /*size*/ mini_circuit_size, /*virtual_size*/ circuit_size }; + + // WORKTODO: why does limiting this to actual_mini_circuit_size not work? + op = Polynomial{ circuit_size }; // Polynomial{ actual_mini_circuit_size, circuit_size }; + + // Catch-all for the rest of the polynomials + // WORKTODO: determine what exactly falls in here and be more specific (just the remaining precomputed?) for (auto& poly : get_unshifted()) { - if (poly.is_empty()) { - // Not set above + if (poly.is_empty()) { // Only set those polys which were not already set above poly = Polynomial{ circuit_size }; } } + // Set all shifted polynomials based on their unshifted counterpart set_shifted(); } ProverPolynomials& operator=(const ProverPolynomials&) = delete; @@ -671,10 +695,18 @@ class TranslatorFlavor { using Base::Base; ProvingKey() = default; - ProvingKey(const size_t dyadic_circuit_size, std::shared_ptr commitment_key = nullptr) - : Base(dyadic_circuit_size, 0, std::move(commitment_key)) + // WORKTODO: this is a constructor used only in tests. We should get rid of it or make it a test-only method. + ProvingKey(const size_t dyadic_circuit_size) + : Base(dyadic_circuit_size, 0) , polynomials(this->circuit_size) {} + + ProvingKey(const size_t dyadic_circuit_size, + std::shared_ptr commitment_key, + const size_t actual_mini_circuit_size) + : Base(dyadic_circuit_size, 0, std::move(commitment_key)) + , polynomials(actual_mini_circuit_size) + {} }; /** diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp index 7f3f0b3afad6..9c3cc1f41435 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp @@ -125,6 +125,20 @@ void TranslatorProver::execute_grand_product_computation_round() */ void TranslatorProver::execute_relation_check_rounds() { + // // DEBUG: Print actual size, size, and virtual size of polynomials + // for (auto& interleaved_poly : key->proving_key->polynomials.get_unshifted()) { + // // for (auto& interleaved_poly : key->proving_key->polynomials.get_all()) { + // size_t last_non_zero_index = 0; + // for (size_t i = 0; i < interleaved_poly.size(); i++) { + // if (interleaved_poly[i] != 0) { + // last_non_zero_index = i; + // } + // } + // // printing the last non-zero index of each polynomial vs virtual size of polynomial + // std::cout << "Actual size: " << last_non_zero_index + 1 << " vs size_: " << interleaved_poly.size() + // << " vs virtual_size_: " << interleaved_poly.virtual_size() << std::endl; + // } + using Sumcheck = SumcheckProver; auto sumcheck = Sumcheck(key->proving_key->circuit_size, transcript); @@ -134,14 +148,15 @@ void TranslatorProver::execute_relation_check_rounds() gate_challenges[idx] = transcript->template get_challenge("Sumcheck:gate_challenge_" + std::to_string(idx)); } - const size_t log_subgroup_size = static_cast(numeric::get_msb(Flavor::Curve::SUBGROUP_SIZE)); - // Create a temporary commitment key that is only used to initialise the ZKSumcheckData - // If proving in WASM, the commitment key that is part of the Translator proving key remains deallocated - // until we enter the PCS round - auto ck = std::make_shared(1 << (log_subgroup_size + 1)); + // const size_t log_subgroup_size = static_cast(numeric::get_msb(Flavor::Curve::SUBGROUP_SIZE)); + // // Create a temporary commitment key that is only used to initialise the ZKSumcheckData + // // If proving in WASM, the commitment key that is part of the Translator proving key remains deallocated + // // until we enter the PCS round + // auto ck = std::make_shared(1 << (log_subgroup_size + 1)); // // create masking polynomials for sumcheck round univariates and auxiliary data - zk_sumcheck_data = ZKData(key->proving_key->log_circuit_size, transcript, ck); + zk_sumcheck_data = ZKData(key->proving_key->log_circuit_size, transcript, key->proving_key->commitment_key); + // zk_sumcheck_data = ZKData(key->proving_key->log_circuit_size, transcript, ck); sumcheck_output = sumcheck.prove(key->proving_key->polynomials, relation_parameters, alpha, gate_challenges, zk_sumcheck_data); @@ -205,10 +220,11 @@ HonkProof TranslatorProver::construct_proof() // Compute grand product(s) and commitments. execute_grand_product_computation_round(); - // #ifndef __wasm__ - // Free the commitment key - key->proving_key->commitment_key = nullptr; - // #endif + // WORKTODO: figure out how to make this work. (shouldn't be excluded in WASM!) + // // #ifndef __wasm__ + // // Free the commitment key + // key->proving_key->commitment_key = nullptr; + // // #endif // Fiat-Shamir: alpha // Run sumcheck subprotocol. diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp index 2ec1c1382abb..b1956a876edb 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp @@ -3,6 +3,7 @@ #include "barretenberg/translator_vm/translator_flavor.hpp" namespace bb { +// WORKTODO: This class likely should not exist. Any reason not to use the ProvingKey in the flavor? class TranslatorProvingKey { public: using Flavor = TranslatorFlavor; @@ -38,10 +39,13 @@ class TranslatorProvingKey { { PROFILE_THIS_NAME("TranslatorProvingKey(TranslatorCircuit&)"); + // WORKTODO: the methods below just set the constant values TRANSLATOR_VM_FIXED_SIZE and + // TRANSLATOR_VM_FIXED_SIZE * INTERLEAVING_GROUP_SIZE compute_mini_circuit_dyadic_size(circuit); compute_dyadic_circuit_size(); - proving_key = std::make_shared(dyadic_circuit_size, std::move(commitment_key)); - proving_key->polynomials = Flavor::ProverPolynomials(mini_circuit_dyadic_size); + + proving_key = std::make_shared( + dyadic_circuit_size, std::move(commitment_key), /*actual_mini_circuit_size=*/circuit.num_gates); // Populate the wire polynomials from the wire vectors in the circuit for (auto [wire_poly_, wire_] : zip_view(proving_key->polynomials.get_wires(), circuit.wires)) { From fef826a5ae3e3dbbdd2811e46662e70ce31168b7 Mon Sep 17 00:00:00 2001 From: Gregorio Juliana Date: Mon, 31 Mar 2025 13:04:03 +0200 Subject: [PATCH 18/23] Update barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Venturo --- barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index 30211b646eed..ae42ea00eda3 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -46,7 +46,7 @@ class ECCVMFlavor { // Indicates that this flavor runs with ZK Sumcheck. static constexpr bool HasZK = true; // Fixed size of the ECCVM circuits used in ClientIVC - // Important: these constants cannot be arbitrarily changes - please consult with a member of the Crypto team if + // Important: these constants cannot be arbitrarily changed - please consult with a member of the Crypto team if // they become too small. static constexpr size_t ECCVM_FIXED_SIZE = 1UL << CONST_ECCVM_LOG_N; From 541aeb91da95fd80081ad4d88abfc55d30701965 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 31 Mar 2025 11:54:26 +0000 Subject: [PATCH 19/23] separated config --- .../client_flows/client_flows_benchmark.ts | 53 +------------------ .../src/bench/client_flows/config.ts | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 52 deletions(-) create mode 100644 yarn-project/end-to-end/src/bench/client_flows/config.ts diff --git a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts index 711405e99929..fe7b41c2a56e 100644 --- a/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts +++ b/yarn-project/end-to-end/src/bench/client_flows/client_flows_benchmark.ts @@ -46,6 +46,7 @@ import { FeeJuicePortalTestingHarnessFactory, type GasBridgingTestHarness, } from '../../shared/gas_portal_test_harness.js'; +import { type ClientFlowsConfig, FULL_FLOWS_CONFIG, KEY_FLOWS_CONFIG } from './config.js'; const { E2E_DATA_PATH: dataPath, BENCHMARK_CONFIG } = process.env; @@ -53,58 +54,6 @@ export type AccountType = 'ecdsar1' | 'schnorr'; export type FeePaymentMethodGetter = (wallet: Wallet) => Promise; export type BenchmarkingFeePaymentMethod = 'bridged_fee_juice' | 'private_fpc' | 'sponsored_fpc'; -export type ClientFlowConfig = { - accounts: AccountType[]; - feePaymentMethods: BenchmarkingFeePaymentMethod[]; - recursions?: number[]; -}; - -type ClientFlows = 'deployments' | 'transfers' | 'bridging' | 'amm'; - -type ClientFlowsConfig = { - [key in ClientFlows]: ClientFlowConfig; -}; - -const KEY_FLOWS_CONFIG: ClientFlowsConfig = { - deployments: { - accounts: ['ecdsar1', 'schnorr'], - feePaymentMethods: ['sponsored_fpc'], - }, - amm: { - accounts: ['ecdsar1'], - feePaymentMethods: ['sponsored_fpc'], - }, - bridging: { - accounts: ['ecdsar1'], - feePaymentMethods: ['sponsored_fpc'], - }, - transfers: { - accounts: ['ecdsar1'], - feePaymentMethods: ['sponsored_fpc'], - recursions: [1], - }, -}; - -const FULL_FLOWS_CONFIG: ClientFlowsConfig = { - deployments: { - accounts: ['ecdsar1', 'schnorr'], - feePaymentMethods: ['bridged_fee_juice', 'sponsored_fpc'], - }, - amm: { - accounts: ['ecdsar1', 'schnorr'], - feePaymentMethods: ['sponsored_fpc', 'private_fpc'], - }, - bridging: { - accounts: ['ecdsar1', 'schnorr'], - feePaymentMethods: ['sponsored_fpc', 'private_fpc'], - }, - transfers: { - accounts: ['ecdsar1', 'schnorr'], - feePaymentMethods: ['sponsored_fpc', 'private_fpc'], - recursions: [0, 1, 2], - }, -}; - export class ClientFlowsBenchmark { private snapshotManager: ISnapshotManager; diff --git a/yarn-project/end-to-end/src/bench/client_flows/config.ts b/yarn-project/end-to-end/src/bench/client_flows/config.ts new file mode 100644 index 000000000000..eaebb286eeaa --- /dev/null +++ b/yarn-project/end-to-end/src/bench/client_flows/config.ts @@ -0,0 +1,53 @@ +import type { AccountType, BenchmarkingFeePaymentMethod } from './client_flows_benchmark.js'; + +export type ClientFlowConfig = { + accounts: AccountType[]; + feePaymentMethods: BenchmarkingFeePaymentMethod[]; + recursions?: number[]; +}; + +type ClientFlows = 'deployments' | 'transfers' | 'bridging' | 'amm'; + +export type ClientFlowsConfig = { + [key in ClientFlows]: ClientFlowConfig; +}; + +export const KEY_FLOWS_CONFIG: ClientFlowsConfig = { + deployments: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc'], + }, + amm: { + accounts: ['ecdsar1'], + feePaymentMethods: ['sponsored_fpc'], + }, + bridging: { + accounts: ['ecdsar1'], + feePaymentMethods: ['sponsored_fpc'], + }, + transfers: { + accounts: ['ecdsar1'], + feePaymentMethods: ['sponsored_fpc'], + recursions: [1], + }, +}; + +export const FULL_FLOWS_CONFIG: ClientFlowsConfig = { + deployments: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['bridged_fee_juice', 'sponsored_fpc'], + }, + amm: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc', 'private_fpc'], + }, + bridging: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc', 'private_fpc'], + }, + transfers: { + accounts: ['ecdsar1', 'schnorr'], + feePaymentMethods: ['sponsored_fpc', 'private_fpc'], + recursions: [0, 1, 2], + }, +}; From b889e7089e5a0d723f0b51d911ce50e0cbfbc533 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 31 Mar 2025 11:55:49 +0000 Subject: [PATCH 20/23] add comments --- .../ts/src/barretenberg_wasm/fetch_code/browser/index.ts | 1 + barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/barretenberg/ts/src/barretenberg_wasm/fetch_code/browser/index.ts b/barretenberg/ts/src/barretenberg_wasm/fetch_code/browser/index.ts index 57b459b7ee81..f37c34405740 100644 --- a/barretenberg/ts/src/barretenberg_wasm/fetch_code/browser/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/fetch_code/browser/index.ts @@ -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 = diff --git a/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts b/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts index 049532fed10f..ddbc1e61df53 100644 --- a/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/fetch_code/node/index.ts @@ -16,6 +16,7 @@ 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'; + // 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 = From 30625c9cca28742a974f7a8cdb631ffc09027a66 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 31 Mar 2025 12:27:13 +0000 Subject: [PATCH 21/23] reverted bb changes --- .../translator_vm/translator_flavor.hpp | 9 --------- .../translator_vm/translator_prover.cpp | 14 -------------- 2 files changed, 23 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 55f35de113fc..ec40bdbffd3c 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -343,8 +343,6 @@ class TranslatorFlavor { DerivedWitnessEntities::get_all()); }; - auto get_wires_to_be_shifted() { return WireToBeShiftedEntities::get_all(); }; - /** * @brief Get the entities constructed by interleaving. */ @@ -708,13 +706,6 @@ class TranslatorFlavor { : Base(dyadic_circuit_size, 0, std::move(commitment_key)) , polynomials(actual_mini_circuit_size) {} - - ProvingKey(const size_t dyadic_circuit_size, - std::shared_ptr commitment_key, - const size_t actual_mini_circuit_size) - : Base(dyadic_circuit_size, 0, std::move(commitment_key)) - , polynomials(actual_mini_circuit_size) - {} }; /** diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp index 394af1a5a1d8..a22ef722b801 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_prover.cpp @@ -125,20 +125,6 @@ void TranslatorProver::execute_grand_product_computation_round() */ void TranslatorProver::execute_relation_check_rounds() { - // // DEBUG: Print actual size, size, and virtual size of polynomials - // for (auto& interleaved_poly : key->proving_key->polynomials.get_unshifted()) { - // // for (auto& interleaved_poly : key->proving_key->polynomials.get_all()) { - // size_t last_non_zero_index = 0; - // for (size_t i = 0; i < interleaved_poly.size(); i++) { - // if (interleaved_poly[i] != 0) { - // last_non_zero_index = i; - // } - // } - // // printing the last non-zero index of each polynomial vs virtual size of polynomial - // std::cout << "Actual size: " << last_non_zero_index + 1 << " vs size_: " << interleaved_poly.size() - // << " vs virtual_size_: " << interleaved_poly.virtual_size() << std::endl; - // } - using Sumcheck = SumcheckProver; auto sumcheck = Sumcheck(key->proving_key->circuit_size, transcript); From 0dd758816b38e2e11fe56b041ea2ac3de93ef691 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 31 Mar 2025 12:37:29 +0000 Subject: [PATCH 22/23] error from another branch --- yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts b/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts index 3119926730c8..a38f7714d09e 100644 --- a/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts +++ b/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts @@ -34,7 +34,7 @@ export async function setupL2Contracts( // Deploy Fee Juice const feeJuicePortalAddress = (await pxe.getNodeInfo()).l1ContractAddresses.feeJuicePortalAddress; log('setupL2Contracts: Setting up fee juice portal...'); - //await setupCanonicalL2FeeJuice(pxe, feeJuicePortalAddress, log, waitOpts, waitForProvenOptions); + await setupCanonicalL2FeeJuice(pxe, feeJuicePortalAddress, log, waitOpts, waitForProvenOptions); let deployedAccounts: InitialAccountData[] = []; if (testAccounts) { From c006784893f73d52906be3416300a08b0072b251 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 31 Mar 2025 15:57:30 +0000 Subject: [PATCH 23/23] removed unused var --- playground/src/aztecEnv.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/playground/src/aztecEnv.ts b/playground/src/aztecEnv.ts index 88fd335b1151..7896e55f89f1 100644 --- a/playground/src/aztecEnv.ts +++ b/playground/src/aztecEnv.ts @@ -35,8 +35,6 @@ export class WebLogger { private static updateIntervalMs = 1000; private static readonly MAX_LOGS_TO_KEEP = 200; - private pendingUpdate = true; - private constructor() {} static create(setLogs: (logs: Log[]) => void) { @@ -46,7 +44,6 @@ export class WebLogger { const instance = WebLogger.getInstance(); const newLogs = instance.logs.slice(0, WebLogger.MAX_LOGS_TO_KEEP).sort((a, b) => b.timestamp - a.timestamp); setLogs(newLogs); - instance.pendingUpdate = false; }, WebLogger.updateIntervalMs); } } @@ -80,7 +77,6 @@ export class WebLogger { data: any, ) { this.logs.unshift({ id: this.randomId(), type, prefix, message, data, timestamp: Date.now() }); - this.pendingUpdate = true; } private randomId(): string {