From 2395af3014ff2c7c3148e2511350b92059c0325b Mon Sep 17 00:00:00 2001 From: esau <152162806+sklppy88@users.noreply.github.com> Date: Fri, 30 Aug 2024 22:33:55 +0200 Subject: [PATCH] fix: remove fee juice mint public (#8260) Addresses #8081 One thing that I was wondering, will this new introduction of bridging here add too much overhead in the tests ? --- .../contracts/fee_juice_contract/src/main.nr | 11 ----- .../src/benchmarks/bench_prover.test.ts | 18 +++++++- .../src/benchmarks/bench_tx_size_fees.test.ts | 41 +++++++++++++++---- .../src/e2e_fees/account_init.test.ts | 4 +- .../end-to-end/src/e2e_fees/fees_test.ts | 14 +++---- 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr index 6a7cf65b303..c238e3f4736 100644 --- a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr @@ -113,17 +113,6 @@ contract FeeJuice { storage.balances.at(to).write(new_balance); } - // TODO(@just-mitch): remove this function before mainnet deployment - // convenience function for testing - // the true canonical Fee Juice contract will not have this function - #[aztec(public)] - fn mint_public(to: AztecAddress, amount: Field) { - let amount = U128::from_integer(amount); - let new_balance = storage.balances.at(to).read().add(amount); - - storage.balances.at(to).write(new_balance); - } - #[aztec(public)] #[aztec(view)] fn check_balance(fee_limit: Field) { 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 5d435fed52e..eaf95ea0724 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 @@ -12,6 +12,7 @@ import { jest } from '@jest/globals'; import { getACVMConfig } from '../fixtures/get_acvm_config.js'; import { getBBConfig } from '../fixtures/get_bb_config.js'; import { type EndToEndContext, setup } from '../fixtures/utils.js'; +import { FeeJuicePortalTestingHarnessFactory } from '../shared/gas_portal_test_harness.js'; // TODO(@PhilWindle): Some part of this test are commented out until we speed up proving. @@ -91,8 +92,23 @@ describe('benchmarks/proving', () => { initialGasContract = await FeeJuiceContract.at(FeeJuiceAddress, initialSchnorrWallet); initialFpContract = await FPCContract.deploy(initialSchnorrWallet, initialTokenContract.address).send().deployed(); + const feeJuiceBridgeTestHarness = await FeeJuicePortalTestingHarnessFactory.create({ + aztecNode: ctx.aztecNode, + pxeService: ctx.pxe, + publicClient: ctx.deployL1ContractsValues.publicClient, + walletClient: ctx.deployL1ContractsValues.walletClient, + wallet: ctx.wallets[0], + logger: ctx.logger, + }); + + const { secret } = await feeJuiceBridgeTestHarness.prepareTokensOnL1( + 1_000_000_000_000n, + 1_000_000_000_000n, + initialFpContract.address, + ); + await Promise.all([ - initialGasContract.methods.mint_public(initialFpContract.address, 1e12).send().wait(), + initialGasContract.methods.claim(initialFpContract.address, 1e12, secret).send().wait(), initialTokenContract.methods.mint_public(initialSchnorrWallet.getAddress(), 1e12).send().wait(), initialTokenContract.methods.privately_mint_private_note(1e12).send().wait(), ]); 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 3d7d176099e..402afe3bdda 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 @@ -13,11 +13,14 @@ import { FeeJuiceAddress } from '@aztec/protocol-contracts/fee-juice'; import { jest } from '@jest/globals'; -import { publicDeployAccounts, setup } from '../fixtures/utils.js'; +import { type EndToEndContext, publicDeployAccounts, setup } from '../fixtures/utils.js'; +import { FeeJuicePortalTestingHarnessFactory } from '../shared/gas_portal_test_harness.js'; jest.setTimeout(100_000); describe('benchmarks/tx_size_fees', () => { + let ctx: EndToEndContext; + let aliceWallet: AccountWalletWithSecretKey; let bobAddress: AztecAddress; let sequencerAddress: AztecAddress; @@ -27,17 +30,17 @@ describe('benchmarks/tx_size_fees', () => { // setup the environment beforeAll(async () => { - const { wallets, aztecNode } = await setup(3, {}, {}, true); + ctx = await setup(3, {}, {}, true); - aliceWallet = wallets[0]; - bobAddress = wallets[1].getAddress(); - sequencerAddress = wallets[2].getAddress(); + aliceWallet = ctx.wallets[0]; + bobAddress = ctx.wallets[1].getAddress(); + sequencerAddress = ctx.wallets[2].getAddress(); - await aztecNode.setConfig({ + await ctx.aztecNode.setConfig({ feeRecipient: sequencerAddress, }); - await publicDeployAccounts(aliceWallet, wallets); + await publicDeployAccounts(aliceWallet, ctx.wallets); }); // deploy the contracts @@ -49,9 +52,29 @@ describe('benchmarks/tx_size_fees', () => { // mint tokens beforeAll(async () => { + const feeJuiceBridgeTestHarness = await FeeJuicePortalTestingHarnessFactory.create({ + aztecNode: ctx.aztecNode, + pxeService: ctx.pxe, + publicClient: ctx.deployL1ContractsValues.publicClient, + walletClient: ctx.deployL1ContractsValues.walletClient, + wallet: ctx.wallets[0], + logger: ctx.logger, + }); + + const { secret: fpcSecret } = await feeJuiceBridgeTestHarness.prepareTokensOnL1( + 100_000_000_000n, + 100_000_000_000n, + fpc.address, + ); + const { secret: aliceSecret } = await feeJuiceBridgeTestHarness.prepareTokensOnL1( + 100_000_000_000n, + 100_000_000_000n, + aliceWallet.getAddress(), + ); + await Promise.all([ - feeJuice.methods.mint_public(aliceWallet.getAddress(), 100e9).send().wait(), - feeJuice.methods.mint_public(fpc.address, 100e9).send().wait(), + feeJuice.methods.claim(fpc.address, 100e9, fpcSecret).send().wait(), + feeJuice.methods.claim(aliceWallet.getAddress(), 100e9, aliceSecret).send().wait(), ]); await token.methods.privately_mint_private_note(100e9).send().wait(); await token.methods.mint_public(aliceWallet.getAddress(), 100e9).send().wait(); 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 45d5b34bde2..0a3c08f7f5e 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 @@ -85,7 +85,7 @@ 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.mintFeeJuice(bobsAddress, t.INITIAL_GAS_BALANCE); + await t.mintAndBridgeFeeJuice(bobsAddress, t.INITIAL_GAS_BALANCE); const [bobsInitialGas] = await t.getGasBalanceFn(bobsAddress); expect(bobsInitialGas).toEqual(t.INITIAL_GAS_BALANCE); @@ -179,7 +179,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.mintFeeJuice(aliceAddress, t.INITIAL_GAS_BALANCE); + await t.mintAndBridgeFeeJuice(aliceAddress, t.INITIAL_GAS_BALANCE); 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/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index ff0c18a2978..4beb1b07dee 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 @@ -109,12 +109,10 @@ export class FeesTest { expect(balanceAfter).toEqual(balanceBefore + amount); } - // Mint fee juice AND mint funds to the portal to emulate the L1 -> L2 bridge - async mintFeeJuice(address: AztecAddress, amount: bigint) { - await this.feeJuiceContract.methods.mint_public(address, amount).send().wait(); - // Need to also mint funds to the portal - const portalAddress = EthAddress.fromString(this.feeJuiceBridgeTestHarness.tokenPortal.address); - await this.feeJuiceBridgeTestHarness.mintTokensOnL1(amount, portalAddress); + async mintAndBridgeFeeJuice(address: AztecAddress, amount: bigint) { + const { secret } = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(amount, amount, address); + + await this.feeJuiceContract.methods.claim(address, amount, secret).send().wait(); } /** Alice mints bananaCoin tokens privately to the target address and redeems them. */ @@ -368,7 +366,7 @@ export class FeesTest { await this.snapshotManager.snapshot( 'fund_alice_with_fee_juice', async () => { - await this.mintFeeJuice(this.aliceAddress, this.INITIAL_GAS_BALANCE); + await this.mintAndBridgeFeeJuice(this.aliceAddress, this.INITIAL_GAS_BALANCE); }, () => Promise.resolve(), ); @@ -398,7 +396,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.mintFeeJuice(subscriptionContract.address, this.INITIAL_GAS_BALANCE); + await this.mintAndBridgeFeeJuice(subscriptionContract.address, this.INITIAL_GAS_BALANCE); return { counterContractAddress: counterContract.address, subscriptionContractAddress: subscriptionContract.address,