From 405c98a5e197d028a1c6f989fb5af4dc6acef5b3 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Mon, 25 Nov 2024 11:35:59 +0000 Subject: [PATCH] feat: add fee funding constant --- .../src/core/libraries/ConstantsGen.sol | 1 + .../crates/types/src/constants.nr | 1 + yarn-project/bootstrap.sh | 1 + yarn-project/circuits.js/src/constants.gen.ts | 1 + .../cli/src/cmds/devnet/bootstrap_network.ts | 4 +-- .../src/benchmarks/bench_prover.test.ts | 32 ++++++++++++------- .../src/benchmarks/bench_tx_size_fees.test.ts | 19 ++++++----- .../src/e2e_fees/account_init.test.ts | 24 +++++++++----- .../src/e2e_fees/dapp_subscription.test.ts | 4 +-- .../src/e2e_fees/fee_juice_payments.test.ts | 8 ++--- .../end-to-end/src/e2e_fees/fees_test.ts | 9 +++--- 11 files changed, 63 insertions(+), 41 deletions(-) diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 862d733f4f33..6f272bc1c3b2 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -98,6 +98,7 @@ library Constants { uint256 internal constant GENESIS_ARCHIVE_ROOT = 19007378675971183768036762391356802220352606103602592933942074152320327194720; uint256 internal constant FEE_JUICE_INITIAL_MINT = 20000000000000000000; + uint256 internal constant FEE_FUNDING_FOR_TESTER_ACCOUNT = 100000000000000000000; uint256 internal constant PUBLIC_DISPATCH_SELECTOR = 3578010381; uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 3000; uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index f3b07779b6cc..7525aa94663e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -139,6 +139,7 @@ pub global GENESIS_ARCHIVE_ROOT: Field = // The following and the value in `deploy_l1_contracts` must match. We should not have the code both places, but // we are running into circular dependency issues. #3342 global FEE_JUICE_INITIAL_MINT: Field = 20000000000000000000; +global FEE_FUNDING_FOR_TESTER_ACCOUNT: Field = 100000000000000000000; // 100e18 // Last 4 bytes of the Poseidon2 hash of 'public_dispatch(Field)'. pub global PUBLIC_DISPATCH_SELECTOR: Field = 0xd5441b0d; diff --git a/yarn-project/bootstrap.sh b/yarn-project/bootstrap.sh index c9ebca3a9e1e..43a8748fc254 100755 --- a/yarn-project/bootstrap.sh +++ b/yarn-project/bootstrap.sh @@ -22,6 +22,7 @@ fi if [ "$CMD" = "full" ]; then yarn install --immutable + yarn workspace @aztec/world-state build:cpp yarn build exit 0 elif [ "$CMD" = "fast-only" ]; then diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index a3a256a7d943..7a85b60a3308 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -84,6 +84,7 @@ export const BLOB_SIZE_IN_BYTES = 126976; export const AZTEC_MAX_EPOCH_DURATION = 32; export const GENESIS_ARCHIVE_ROOT = 19007378675971183768036762391356802220352606103602592933942074152320327194720n; export const FEE_JUICE_INITIAL_MINT = 20000000000000000000n; +export const FEE_FUNDING_FOR_TESTER_ACCOUNT = 100000000000000000000n; export const PUBLIC_DISPATCH_SELECTOR = 3578010381; export const MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 3000; export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; diff --git a/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts b/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts index 7d2aa560e2d1..e91e29486445 100644 --- a/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts +++ b/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts @@ -1,7 +1,7 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { BatchCall, type PXE, type Wallet, createCompatibleClient } from '@aztec/aztec.js'; import { L1FeeJuicePortalManager } from '@aztec/aztec.js'; -import { type AztecAddress, type EthAddress, Fq, Fr } from '@aztec/circuits.js'; +import { type AztecAddress, type EthAddress, FEE_FUNDING_FOR_TESTER_ACCOUNT, Fq, Fr } from '@aztec/circuits.js'; import { type ContractArtifacts, type L1Clients, @@ -252,7 +252,7 @@ async function fundFPC( debugLog, ); - const amount = 10n ** 21n; + const amount = FEE_FUNDING_FOR_TESTER_ACCOUNT; const { claimAmount, claimSecret, messageLeafIndex } = await feeJuicePortal.bridgeTokensPublic( fpcAddress, amount, diff --git a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts index 2934f662ff7e..c704be6b0aab 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts @@ -2,7 +2,7 @@ import { getSchnorrAccount, getSchnorrWallet } from '@aztec/accounts/schnorr'; import { PublicFeePaymentMethod, TxStatus, sleep } from '@aztec/aztec.js'; import { type AccountWallet } from '@aztec/aztec.js/wallet'; import { BBCircuitVerifier } from '@aztec/bb-prover'; -import { CompleteAddress, Fq, Fr, GasSettings } from '@aztec/circuits.js'; +import { CompleteAddress, FEE_FUNDING_FOR_TESTER_ACCOUNT, Fq, Fr, GasSettings } from '@aztec/circuits.js'; import { FPCContract, FeeJuiceContract, TestContract, TokenContract } from '@aztec/noir-contracts.js'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type PXEService, type PXEServiceConfig, createPXEService } from '@aztec/pxe'; @@ -108,15 +108,24 @@ describe('benchmarks/proving', () => { }); const { claimSecret, messageLeafIndex } = await feeJuiceBridgeTestHarness.prepareTokensOnL1( - 1_000_000_000_000n, + FEE_FUNDING_FOR_TESTER_ACCOUNT, initialFpContract.address, ); const from = initialSchnorrWallet.getAddress(); // we are setting from to initial schnorr wallet here because of TODO(#9887) await Promise.all([ - initialGasContract.methods.claim(initialFpContract.address, 1e12, claimSecret, messageLeafIndex).send().wait(), - initialTokenContract.methods.mint_to_public(initialSchnorrWallet.getAddress(), 1e12).send().wait(), - initialTokenContract.methods.mint_to_private(from, initialSchnorrWallet.getAddress(), 1e12).send().wait(), + initialGasContract.methods + .claim(initialFpContract.address, FEE_FUNDING_FOR_TESTER_ACCOUNT, claimSecret, messageLeafIndex) + .send() + .wait(), + initialTokenContract.methods + .mint_to_public(initialSchnorrWallet.getAddress(), FEE_FUNDING_FOR_TESTER_ACCOUNT) + .send() + .wait(), + initialTokenContract.methods + .mint_to_private(from, initialSchnorrWallet.getAddress(), FEE_FUNDING_FOR_TESTER_ACCOUNT) + .send() + .wait(), ]); }); @@ -190,17 +199,16 @@ describe('benchmarks/proving', () => { // (await getTestContractOnPXE(3)).methods.create_l2_to_l1_message_public(45, 46, EthAddress.random()), ]; + const wallet = await getWalletOnPxe(0); + const gasSettings = GasSettings.default({ maxFeesPerGas: await wallet.getCurrentBaseFees() }); + const feeFnCall0 = { - gasSettings: GasSettings.default(), - paymentMethod: new PublicFeePaymentMethod( - initialTokenContract.address, - initialFpContract.address, - await getWalletOnPxe(0), - ), + gasSettings, + paymentMethod: new PublicFeePaymentMethod(initialTokenContract.address, initialFpContract.address, wallet), }; // const feeFnCall1 = { - // gasSettings: GasSettings.default(), + // gasSettings, // paymentMethod: new PrivateFeePaymentMethod( // initialTokenContract.address, // initialFpContract.address, diff --git a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts index f831e265c376..63f485f9c1a0 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts @@ -7,7 +7,7 @@ import { PublicFeePaymentMethod, TxStatus, } from '@aztec/aztec.js'; -import { GasSettings } from '@aztec/circuits.js'; +import { FEE_FUNDING_FOR_TESTER_ACCOUNT, GasSettings } from '@aztec/circuits.js'; import { FPCContract, FeeJuiceContract, TokenContract } from '@aztec/noir-contracts.js'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; @@ -62,18 +62,21 @@ describe('benchmarks/tx_size_fees', () => { }); const { claimSecret: fpcSecret, messageLeafIndex: fpcLeafIndex } = - await feeJuiceBridgeTestHarness.prepareTokensOnL1(100_000_000_000n, fpc.address); + await feeJuiceBridgeTestHarness.prepareTokensOnL1(FEE_FUNDING_FOR_TESTER_ACCOUNT, fpc.address); const { claimSecret: aliceSecret, messageLeafIndex: aliceLeafIndex } = - await feeJuiceBridgeTestHarness.prepareTokensOnL1(100_000_000_000n, aliceWallet.getAddress()); + await feeJuiceBridgeTestHarness.prepareTokensOnL1(FEE_FUNDING_FOR_TESTER_ACCOUNT, aliceWallet.getAddress()); await Promise.all([ - feeJuice.methods.claim(fpc.address, 100e9, fpcSecret, fpcLeafIndex).send().wait(), - feeJuice.methods.claim(aliceWallet.getAddress(), 100e9, aliceSecret, aliceLeafIndex).send().wait(), + feeJuice.methods.claim(fpc.address, FEE_FUNDING_FOR_TESTER_ACCOUNT, fpcSecret, fpcLeafIndex).send().wait(), + feeJuice.methods + .claim(aliceWallet.getAddress(), FEE_FUNDING_FOR_TESTER_ACCOUNT, aliceSecret, aliceLeafIndex) + .send() + .wait(), ]); const from = aliceWallet.getAddress(); // we are setting from to Alice here because of TODO(#9887) - await token.methods.mint_to_private(from, aliceWallet.getAddress(), 100e9).send().wait(); - await token.methods.mint_to_public(aliceWallet.getAddress(), 100e9).send().wait(); + await token.methods.mint_to_private(from, aliceWallet.getAddress(), FEE_FUNDING_FOR_TESTER_ACCOUNT).send().wait(); + await token.methods.mint_to_public(aliceWallet.getAddress(), FEE_FUNDING_FOR_TESTER_ACCOUNT).send().wait(); }); it.each<[string, () => FeePaymentMethod | undefined /*bigint*/]>([ @@ -106,7 +109,7 @@ describe('benchmarks/tx_size_fees', () => { 'sends a tx with a fee with %s payment method', async (_name, createPaymentMethod /*expectedTransactionFee*/) => { const paymentMethod = createPaymentMethod(); - const gasSettings = GasSettings.default(); + const gasSettings = GasSettings.default({ maxFeesPerGas: await aliceWallet.getCurrentBaseFees() }); const tx = await token.methods .transfer(bobAddress, 1n) .send({ fee: paymentMethod ? { gasSettings, paymentMethod } : undefined }) diff --git a/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts b/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts index c36202f3bf87..80116cf224e6 100644 --- a/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts @@ -13,7 +13,13 @@ import { type Wallet, deriveKeys, } from '@aztec/aztec.js'; -import { type AztecAddress, type CompleteAddress, Fq, GasSettings } from '@aztec/circuits.js'; +import { + type AztecAddress, + type CompleteAddress, + FEE_FUNDING_FOR_TESTER_ACCOUNT, + Fq, + GasSettings, +} from '@aztec/circuits.js'; import { type TokenContract as BananaCoin, type FPCContract, SchnorrAccountContract } from '@aztec/noir-contracts.js'; import { jest } from '@jest/globals'; @@ -87,9 +93,9 @@ describe('e2e_fees account_init', () => { describe('account pays its own fee', () => { it('pays natively in the Fee Juice after Alice bridges funds', async () => { - await t.mintAndBridgeFeeJuice(bobsAddress, t.INITIAL_GAS_BALANCE); + await t.mintAndBridgeFeeJuice(bobsAddress, FEE_FUNDING_FOR_TESTER_ACCOUNT); const [bobsInitialGas] = await t.getGasBalanceFn(bobsAddress); - expect(bobsInitialGas).toEqual(t.INITIAL_GAS_BALANCE); + expect(bobsInitialGas).toEqual(FEE_FUNDING_FOR_TESTER_ACCOUNT); const paymentMethod = new FeeJuicePaymentMethod(bobsAddress); const tx = await bobsAccountManager.deploy({ fee: { gasSettings, paymentMethod } }).wait(); @@ -99,16 +105,18 @@ describe('e2e_fees account_init', () => { }); it('pays natively in the Fee Juice by bridging funds themselves', async () => { - const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(t.INITIAL_GAS_BALANCE, bobsAddress); + const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(FEE_FUNDING_FOR_TESTER_ACCOUNT, bobsAddress); const paymentMethod = new FeeJuicePaymentMethodWithClaim(bobsAddress, claim); const tx = await bobsAccountManager.deploy({ fee: { gasSettings, paymentMethod } }).wait(); expect(tx.transactionFee!).toBeGreaterThan(0n); - await expect(t.getGasBalanceFn(bobsAddress)).resolves.toEqual([t.INITIAL_GAS_BALANCE - tx.transactionFee!]); + await expect(t.getGasBalanceFn(bobsAddress)).resolves.toEqual([ + FEE_FUNDING_FOR_TESTER_ACCOUNT - tx.transactionFee!, + ]); }); it('pays privately through an FPC', async () => { // Alice mints bananas to Bob - const mintedBananas = t.INITIAL_GAS_BALANCE; + const mintedBananas = FEE_FUNDING_FOR_TESTER_ACCOUNT; await t.mintPrivateBananas(mintedBananas, bobsAddress); // Bob deploys his account through the private FPC @@ -136,7 +144,7 @@ describe('e2e_fees account_init', () => { }); it('pays publicly through an FPC', async () => { - const mintedBananas = t.INITIAL_GAS_BALANCE; + const mintedBananas = FEE_FUNDING_FOR_TESTER_ACCOUNT; await bananaCoin.methods.mint_to_public(bobsAddress, mintedBananas).send().wait(); const paymentMethod = new PublicFeePaymentMethod(bananaCoin.address, bananaFPC.address, bobsWallet); @@ -164,7 +172,7 @@ describe('e2e_fees account_init', () => { describe('another account pays the fee', () => { it('pays natively in the Fee Juice', async () => { // mint Fee Juice to alice - await t.mintAndBridgeFeeJuice(aliceAddress, t.INITIAL_GAS_BALANCE); + await t.mintAndBridgeFeeJuice(aliceAddress, FEE_FUNDING_FOR_TESTER_ACCOUNT); const [alicesInitialGas] = await t.getGasBalanceFn(aliceAddress); // bob generates the private keys for his account on his own diff --git a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts index 96b69c84e756..32be6b2c5db8 100644 --- a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts @@ -8,7 +8,7 @@ import { PublicFeePaymentMethod, SentTx, } from '@aztec/aztec.js'; -import { GasSettings } from '@aztec/circuits.js'; +import { FEE_FUNDING_FOR_TESTER_ACCOUNT, GasSettings } from '@aztec/circuits.js'; import { DefaultDappEntrypoint } from '@aztec/entrypoints/dapp'; import { type AppSubscriptionContract, @@ -75,7 +75,7 @@ describe('e2e_fees dapp_subscription', () => { await expectMapping( t.getGasBalanceFn, [aliceAddress, sequencerAddress, subscriptionContract.address, bananaFPC.address], - [0n, 0n, t.INITIAL_GAS_BALANCE, t.INITIAL_GAS_BALANCE], + [0n, 0n, FEE_FUNDING_FOR_TESTER_ACCOUNT, FEE_FUNDING_FOR_TESTER_ACCOUNT], ); await expectMapping( diff --git a/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts b/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts index dcaabbf882b8..112425fafaf6 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts @@ -4,7 +4,7 @@ import { FeeJuicePaymentMethod, FeeJuicePaymentMethodWithClaim, } from '@aztec/aztec.js'; -import { type GasSettings } from '@aztec/circuits.js'; +import { FEE_FUNDING_FOR_TESTER_ACCOUNT, type GasSettings } from '@aztec/circuits.js'; import { type TokenContract as BananaCoin, type FeeJuiceContract } from '@aztec/noir-contracts.js'; import { FeesTest } from './fees_test.js'; @@ -50,7 +50,7 @@ describe('e2e_fees Fee Juice payments', () => { }); it('claims bridged funds and pays with them on the same tx', async () => { - const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(t.INITIAL_GAS_BALANCE, aliceAddress); + const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(FEE_FUNDING_FOR_TESTER_ACCOUNT, aliceAddress); const paymentMethod = new FeeJuicePaymentMethodWithClaim(aliceAddress, claim); const receipt = await bananaCoin.methods .transfer_in_public(aliceAddress, bobAddress, 1n, 0n) @@ -59,8 +59,8 @@ describe('e2e_fees Fee Juice payments', () => { const endBalance = await feeJuiceContract.methods.balance_of_public(aliceAddress).simulate(); expect(endBalance).toBeGreaterThan(0n); - expect(endBalance).toBeLessThan(t.INITIAL_GAS_BALANCE); - expect(endBalance).toEqual(t.INITIAL_GAS_BALANCE - receipt.transactionFee!); + expect(endBalance).toBeLessThan(FEE_FUNDING_FOR_TESTER_ACCOUNT); + expect(endBalance).toEqual(FEE_FUNDING_FOR_TESTER_ACCOUNT - receipt.transactionFee!); }); }); diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index ca79d2d64f36..b29ad717455e 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -10,7 +10,7 @@ import { sleep, } from '@aztec/aztec.js'; import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint'; -import { EthAddress, GasSettings, computePartialAddress } from '@aztec/circuits.js'; +import { EthAddress, FEE_FUNDING_FOR_TESTER_ACCOUNT, GasSettings, computePartialAddress } from '@aztec/circuits.js'; import { createL1Clients } from '@aztec/ethereum'; import { TestERC20Abi } from '@aztec/l1-artifacts'; import { @@ -79,7 +79,6 @@ export class FeesTest { public getBananaPublicBalanceFn!: BalancesFn; public getBananaPrivateBalanceFn!: BalancesFn; - public readonly INITIAL_GAS_BALANCE = BigInt(1e22); public readonly ALICE_INITIAL_BANANAS = BigInt(1e22); public readonly SUBSCRIPTION_AMOUNT = BigInt(1e19); public readonly APP_SPONSORED_TX_GAS_LIMIT = BigInt(10e9); @@ -232,7 +231,7 @@ export class FeesTest { this.logger.info(`BananaPay deployed at ${bananaFPC.address}`); - await this.feeJuiceBridgeTestHarness.bridgeFromL1ToL2(this.INITIAL_GAS_BALANCE, bananaFPC.address); + await this.feeJuiceBridgeTestHarness.bridgeFromL1ToL2(FEE_FUNDING_FOR_TESTER_ACCOUNT, bananaFPC.address); return { bananaFPCAddress: bananaFPC.address, @@ -290,7 +289,7 @@ export class FeesTest { await this.snapshotManager.snapshot( 'fund_alice_with_fee_juice', async () => { - await this.mintAndBridgeFeeJuice(this.aliceAddress, this.INITIAL_GAS_BALANCE); + await this.mintAndBridgeFeeJuice(this.aliceAddress, FEE_FUNDING_FOR_TESTER_ACCOUNT); }, () => Promise.resolve(), ); @@ -320,7 +319,7 @@ export class FeesTest { // Mint some Fee Juice to the subscription contract // Could also use bridgeFromL1ToL2 from the harness, but this is more direct - await this.mintAndBridgeFeeJuice(subscriptionContract.address, this.INITIAL_GAS_BALANCE); + await this.mintAndBridgeFeeJuice(subscriptionContract.address, FEE_FUNDING_FOR_TESTER_ACCOUNT); return { counterContractAddress: counterContract.address, subscriptionContractAddress: subscriptionContract.address,