|
| 1 | +import { type AztecNodeService } from '@aztec/aztec-node'; |
| 2 | +import { type AccountWallet, EthAddress, PublicFeePaymentMethod, TxStatus } from '@aztec/aztec.js'; |
| 3 | +import { GasSettings } from '@aztec/circuits.js'; |
| 4 | +import { FPCContract, GasTokenContract, TestContract, TokenContract } from '@aztec/noir-contracts.js'; |
| 5 | +import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token'; |
| 6 | +import { ProverPool } from '@aztec/prover-client/prover-pool'; |
| 7 | + |
| 8 | +import { jest } from '@jest/globals'; |
| 9 | + |
| 10 | +import { getACVMConfig } from '../fixtures/get_acvm_config.js'; |
| 11 | +import { getBBConfig } from '../fixtures/get_bb_config.js'; |
| 12 | +import { type EndToEndContext, publicDeployAccounts, setup } from '../fixtures/utils.js'; |
| 13 | + |
| 14 | +jest.setTimeout(600_000); |
| 15 | + |
| 16 | +const txTimeoutSec = 600; |
| 17 | + |
| 18 | +describe('benchmarks/proving', () => { |
| 19 | + let ctx: EndToEndContext; |
| 20 | + let wallet: AccountWallet; |
| 21 | + let testContract: TestContract; |
| 22 | + let tokenContract: TokenContract; |
| 23 | + let fpContract: FPCContract; |
| 24 | + let acvmCleanup: () => Promise<void>; |
| 25 | + let bbCleanup: () => Promise<void>; |
| 26 | + let proverPool: ProverPool; |
| 27 | + |
| 28 | + // setup the environment quickly using fake proofs |
| 29 | + beforeAll(async () => { |
| 30 | + ctx = await setup( |
| 31 | + 1, |
| 32 | + { |
| 33 | + // do setup with fake proofs |
| 34 | + realProofs: false, |
| 35 | + proverAgents: 4, |
| 36 | + proverAgentPollInterval: 10, |
| 37 | + minTxsPerBlock: 1, |
| 38 | + }, |
| 39 | + {}, |
| 40 | + true, // enable gas |
| 41 | + ); |
| 42 | + |
| 43 | + wallet = ctx.wallet; |
| 44 | + |
| 45 | + await publicDeployAccounts(wallet, ctx.wallets); |
| 46 | + |
| 47 | + testContract = await TestContract.deploy(wallet).send().deployed(); |
| 48 | + tokenContract = await TokenContract.deploy(wallet, wallet.getAddress(), 'test', 't', 18).send().deployed(); |
| 49 | + const gas = await GasTokenContract.at( |
| 50 | + getCanonicalGasTokenAddress(ctx.deployL1ContractsValues.l1ContractAddresses.gasPortalAddress), |
| 51 | + wallet, |
| 52 | + ); |
| 53 | + fpContract = await FPCContract.deploy(wallet, tokenContract.address, gas.address).send().deployed(); |
| 54 | + |
| 55 | + await Promise.all([ |
| 56 | + gas.methods.mint_public(fpContract.address, 1e12).send().wait(), |
| 57 | + tokenContract.methods.mint_public(wallet.getAddress(), 1e12).send().wait(), |
| 58 | + ]); |
| 59 | + }); |
| 60 | + |
| 61 | + // remove the fake prover and setup the real one |
| 62 | + beforeAll(async () => { |
| 63 | + const [acvmConfig, bbConfig] = await Promise.all([getACVMConfig(ctx.logger), getBBConfig(ctx.logger)]); |
| 64 | + if (!acvmConfig || !bbConfig) { |
| 65 | + throw new Error('Missing ACVM or BB config'); |
| 66 | + } |
| 67 | + |
| 68 | + acvmCleanup = acvmConfig.cleanup; |
| 69 | + bbCleanup = bbConfig.cleanup; |
| 70 | + |
| 71 | + proverPool = ProverPool.nativePool( |
| 72 | + { |
| 73 | + ...acvmConfig, |
| 74 | + ...bbConfig, |
| 75 | + }, |
| 76 | + 4, |
| 77 | + 10, |
| 78 | + ); |
| 79 | + |
| 80 | + ctx.logger.info('Stopping fake provers'); |
| 81 | + await ctx.aztecNode.setConfig({ |
| 82 | + // stop the fake provers |
| 83 | + proverAgents: 0, |
| 84 | + // 4-tx blocks so that we have at least one merge level |
| 85 | + minTxsPerBlock: 4, |
| 86 | + }); |
| 87 | + |
| 88 | + ctx.logger.info('Starting real provers'); |
| 89 | + await proverPool.start((ctx.aztecNode as AztecNodeService).getProver().getProvingJobSource()); |
| 90 | + }); |
| 91 | + |
| 92 | + afterAll(async () => { |
| 93 | + await proverPool.stop(); |
| 94 | + await ctx.teardown(); |
| 95 | + await acvmCleanup(); |
| 96 | + await bbCleanup(); |
| 97 | + }); |
| 98 | + |
| 99 | + it('builds a full block', async () => { |
| 100 | + const txs = [ |
| 101 | + // fully private tx |
| 102 | + testContract.methods.emit_nullifier(42).send(), |
| 103 | + // tx with setup, app, teardown |
| 104 | + testContract.methods.emit_unencrypted(43).send({ |
| 105 | + fee: { |
| 106 | + gasSettings: GasSettings.default(), |
| 107 | + paymentMethod: new PublicFeePaymentMethod(tokenContract.address, fpContract.address, wallet), |
| 108 | + }, |
| 109 | + }), |
| 110 | + // tx with messages |
| 111 | + testContract.methods.create_l2_to_l1_message_public(45, 46, EthAddress.random()).send(), |
| 112 | + // tx with private and public exec |
| 113 | + testContract.methods.set_tx_max_block_number(100, true).send({ |
| 114 | + fee: { |
| 115 | + gasSettings: GasSettings.default(), |
| 116 | + paymentMethod: new PublicFeePaymentMethod(tokenContract.address, fpContract.address, wallet), |
| 117 | + }, |
| 118 | + }), |
| 119 | + ]; |
| 120 | + |
| 121 | + const receipts = await Promise.all(txs.map(tx => tx.wait({ timeout: txTimeoutSec }))); |
| 122 | + expect(receipts.every(r => r.status === TxStatus.MINED)).toBe(true); |
| 123 | + }); |
| 124 | +}); |
0 commit comments