From 7930efa3dc3417a6fdb8a5ad4eb2bec0972282d5 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Thu, 13 Feb 2025 18:06:44 +0000 Subject: [PATCH 1/4] chore: add block building benchmark test for public-compute-heavy txs --- .../benchmarking_contract/src/main.nr | 6 ++++ .../src/bench/bench_build_block.test.ts | 7 ++++- yarn-project/end-to-end/src/bench/utils.ts | 30 ++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr index d4eb3cff944c..895b386838d8 100644 --- a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr @@ -52,4 +52,10 @@ pub contract Benchmarking { fn broadcast(owner: AztecAddress) { context.emit_public_log(storage.balances.at(owner).read()); } + + // Does a bunch of heavy compute + #[public] + fn sha256_hash_2048(data: [u8; 2048]) -> [u8; 32] { + std::hash::sha256(data) + } } diff --git a/yarn-project/end-to-end/src/bench/bench_build_block.test.ts b/yarn-project/end-to-end/src/bench/bench_build_block.test.ts index a850c51463e0..65f86231ef3b 100644 --- a/yarn-project/end-to-end/src/bench/bench_build_block.test.ts +++ b/yarn-project/end-to-end/src/bench/bench_build_block.test.ts @@ -34,9 +34,14 @@ describe('benchmarks/build_block', () => { }); const TX_COUNT = 32; - it(`builds a block with ${TX_COUNT} txs`, async () => { + it(`builds a block with ${TX_COUNT} standard txs`, async () => { await sequencer.updateSequencerConfig({ minTxsPerBlock: TX_COUNT }); const sentTxs = await sendTxs(TX_COUNT, context, contract); await waitTxs(sentTxs, context); }); + it(`builds a block with ${TX_COUNT} compute-heavy txs`, async () => { + await sequencer.updateSequencerConfig({ minTxsPerBlock: TX_COUNT }); + const sentTxs = await sendTxs(TX_COUNT, context, contract, /*heavyPublicComput=*/ true); + await waitTxs(sentTxs, context); + }); }); diff --git a/yarn-project/end-to-end/src/bench/utils.ts b/yarn-project/end-to-end/src/bench/utils.ts index 69ad995a7e33..de43d4b902ac 100644 --- a/yarn-project/end-to-end/src/bench/utils.ts +++ b/yarn-project/end-to-end/src/bench/utils.ts @@ -1,5 +1,5 @@ import { type AztecNodeService } from '@aztec/aztec-node'; -import { type AztecNode, BatchCall, INITIAL_L2_BLOCK_NUM, type SentTx, type WaitOpts } from '@aztec/aztec.js'; +import { type AztecNode, BatchCall, Fr, INITIAL_L2_BLOCK_NUM, type SentTx, type WaitOpts } from '@aztec/aztec.js'; import { mean, stdDev, timesParallel } from '@aztec/foundation/collection'; import { randomInt } from '@aztec/foundation/crypto'; import { BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking'; @@ -127,15 +127,25 @@ export function getFolderSize(path: string): number { * @param index - Index of the call within a block. * @param context - End to end context. * @param contract - Benchmarking contract. + * @param heavyPublicCompute - Whether the transactions include heavy public compute (like a big sha256). * @returns A BatchCall instance. */ -export async function makeCall(index: number, context: EndToEndContext, contract: BenchmarkingContract) { +export async function makeCall( + index: number, + context: EndToEndContext, + contract: BenchmarkingContract, + heavyPublicCompute: boolean, +) { const owner = context.wallet.getAddress(); const sender = owner; - return new BatchCall(context.wallet, [ - await contract.methods.create_note(owner, sender, index + 1).request(), - await contract.methods.increment_balance(owner, index + 1).request(), - ]); + if (heavyPublicCompute) { + return new BatchCall(context.wallet, [await contract.methods.sha256_hash_2048(randomByteFrs(2048)).request()]); + } else { + return new BatchCall(context.wallet, [ + await contract.methods.create_note(owner, sender, index + 1).request(), + await contract.methods.increment_balance(owner, index + 1).request(), + ]); + } } /** @@ -144,14 +154,16 @@ export async function makeCall(index: number, context: EndToEndContext, contract * @param txCount - How many txs to send * @param context - End to end context. * @param contract - Target contract. + * @param heavyPublicCompute - Whether the transactions include heavy public compute (like a big sha256). * @returns Array of sent txs. */ export async function sendTxs( txCount: number, context: EndToEndContext, contract: BenchmarkingContract, + heavyPublicCompute: boolean = false, ): Promise { - const calls = await timesParallel(txCount, index => makeCall(index, context, contract)); + let calls = await timesParallel(txCount, index => makeCall(index, context, contract, heavyPublicCompute)); context.logger.info(`Creating ${txCount} txs`); const provenTxs = await Promise.all(calls.map(call => call.prove({ skipPublicSimulation: true }))); context.logger.info(`Sending ${txCount} txs`); @@ -191,3 +203,7 @@ export async function createNewPXE( await pxe.registerContract(contract); return pxe; } + +function randomByteFrs(length: number): Fr[] { + return [...Array(length)].map(_ => new Fr(Math.floor(Math.random() * 255))); +} From 6e5c34a6a64eee758859848b3feff56fd917a6f6 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Thu, 13 Feb 2025 18:28:13 +0000 Subject: [PATCH 2/4] fix --- yarn-project/end-to-end/src/bench/utils.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yarn-project/end-to-end/src/bench/utils.ts b/yarn-project/end-to-end/src/bench/utils.ts index de43d4b902ac..c663c6d702a9 100644 --- a/yarn-project/end-to-end/src/bench/utils.ts +++ b/yarn-project/end-to-end/src/bench/utils.ts @@ -139,7 +139,10 @@ export async function makeCall( const owner = context.wallet.getAddress(); const sender = owner; if (heavyPublicCompute) { - return new BatchCall(context.wallet, [await contract.methods.sha256_hash_2048(randomByteFrs(2048)).request()]); + return new BatchCall(context.wallet, [ + await contract.methods.sha256_hash_2048(randomBytesAsBigInts(2048)).request(), + await contract.methods.sha256_hash_2048(randomBytesAsBigInts(2048)).request(), + ]); } else { return new BatchCall(context.wallet, [ await contract.methods.create_note(owner, sender, index + 1).request(), @@ -204,6 +207,6 @@ export async function createNewPXE( return pxe; } -function randomByteFrs(length: number): Fr[] { - return [...Array(length)].map(_ => new Fr(Math.floor(Math.random() * 255))); +function randomBytesAsBigInts(length: number): bigint[] { + return [...Array(length)].map(_ => BigInt(Math.floor(Math.random() * 255))); } From 29d8b955f53ff09532fec40f47db17f4285979b0 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Thu, 13 Feb 2025 19:01:48 +0000 Subject: [PATCH 3/4] fix --- yarn-project/end-to-end/src/bench/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/bench/utils.ts b/yarn-project/end-to-end/src/bench/utils.ts index c663c6d702a9..0bec922c5022 100644 --- a/yarn-project/end-to-end/src/bench/utils.ts +++ b/yarn-project/end-to-end/src/bench/utils.ts @@ -1,5 +1,5 @@ import { type AztecNodeService } from '@aztec/aztec-node'; -import { type AztecNode, BatchCall, Fr, INITIAL_L2_BLOCK_NUM, type SentTx, type WaitOpts } from '@aztec/aztec.js'; +import { type AztecNode, BatchCall, INITIAL_L2_BLOCK_NUM, type SentTx, type WaitOpts } from '@aztec/aztec.js'; import { mean, stdDev, timesParallel } from '@aztec/foundation/collection'; import { randomInt } from '@aztec/foundation/crypto'; import { BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking'; @@ -166,7 +166,7 @@ export async function sendTxs( contract: BenchmarkingContract, heavyPublicCompute: boolean = false, ): Promise { - let calls = await timesParallel(txCount, index => makeCall(index, context, contract, heavyPublicCompute)); + const calls = await timesParallel(txCount, index => makeCall(index, context, contract, heavyPublicCompute)); context.logger.info(`Creating ${txCount} txs`); const provenTxs = await Promise.all(calls.map(call => call.prove({ skipPublicSimulation: true }))); context.logger.info(`Sending ${txCount} txs`); From 9a7239560e3b22da596ed7a661e17dbd56396d48 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Thu, 13 Feb 2025 20:01:54 +0000 Subject: [PATCH 4/4] fix --- .../end-to-end/src/bench/bench_build_block.test.ts | 8 +++++--- yarn-project/end-to-end/src/bench/utils.ts | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/yarn-project/end-to-end/src/bench/bench_build_block.test.ts b/yarn-project/end-to-end/src/bench/bench_build_block.test.ts index 65f86231ef3b..c5f8d9464f8c 100644 --- a/yarn-project/end-to-end/src/bench/bench_build_block.test.ts +++ b/yarn-project/end-to-end/src/bench/bench_build_block.test.ts @@ -39,9 +39,11 @@ describe('benchmarks/build_block', () => { const sentTxs = await sendTxs(TX_COUNT, context, contract); await waitTxs(sentTxs, context); }); - it(`builds a block with ${TX_COUNT} compute-heavy txs`, async () => { - await sequencer.updateSequencerConfig({ minTxsPerBlock: TX_COUNT }); - const sentTxs = await sendTxs(TX_COUNT, context, contract, /*heavyPublicComput=*/ true); + + const TX_COUNT_HEAVY_COMPUTE = 8; + it(`builds a block with ${TX_COUNT_HEAVY_COMPUTE} compute-heavy txs`, async () => { + await sequencer.updateSequencerConfig({ minTxsPerBlock: TX_COUNT_HEAVY_COMPUTE }); + const sentTxs = await sendTxs(TX_COUNT_HEAVY_COMPUTE, context, contract, /*heavyPublicComput=*/ true); await waitTxs(sentTxs, context); }); }); diff --git a/yarn-project/end-to-end/src/bench/utils.ts b/yarn-project/end-to-end/src/bench/utils.ts index 0bec922c5022..1186a99a8fa2 100644 --- a/yarn-project/end-to-end/src/bench/utils.ts +++ b/yarn-project/end-to-end/src/bench/utils.ts @@ -141,7 +141,6 @@ export async function makeCall( if (heavyPublicCompute) { return new BatchCall(context.wallet, [ await contract.methods.sha256_hash_2048(randomBytesAsBigInts(2048)).request(), - await contract.methods.sha256_hash_2048(randomBytesAsBigInts(2048)).request(), ]); } else { return new BatchCall(context.wallet, [