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..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 @@ -34,9 +34,16 @@ 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); }); + + 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 69ad995a7e33..1186a99a8fa2 100644 --- a/yarn-project/end-to-end/src/bench/utils.ts +++ b/yarn-project/end-to-end/src/bench/utils.ts @@ -127,15 +127,27 @@ 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(randomBytesAsBigInts(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 +156,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)); + 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`); @@ -191,3 +205,7 @@ export async function createNewPXE( await pxe.registerContract(contract); return pxe; } + +function randomBytesAsBigInts(length: number): bigint[] { + return [...Array(length)].map(_ => BigInt(Math.floor(Math.random() * 255))); +}