Skip to content

Commit

Permalink
feat: add fee funding constant
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Nov 25, 2024
1 parent 624145c commit 405c98a
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 41 deletions.
1 change: 1 addition & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/cli/src/cmds/devnet/bootstrap_network.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 20 additions & 12 deletions yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
]);
});

Expand Down Expand Up @@ -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,
Expand Down
19 changes: 11 additions & 8 deletions yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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*/]>([
Expand Down Expand Up @@ -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 })
Expand Down
24 changes: 16 additions & 8 deletions yarn-project/end-to-end/src/e2e_fees/account_init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
Expand All @@ -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!);
});
});

Expand Down
9 changes: 4 additions & 5 deletions yarn-project/end-to-end/src/e2e_fees/fees_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 405c98a

Please sign in to comment.