Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 11, 2024
1 parent cda11f1 commit b2e3360
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 103 deletions.
20 changes: 0 additions & 20 deletions yarn-project/end-to-end/src/e2e_fees/fees_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import {
type AztecAddress,
type AztecNode,
type DebugLogger,
ExtendedNote,
Fr,
Note,
type PXE,
SignerlessWallet,
type TxHash,
createDebugLogger,
sleep,
} from '@aztec/aztec.js';
Expand Down Expand Up @@ -126,22 +122,6 @@ export class FeesTest {
expect(balanceAfter).toEqual(balanceBefore + amount);
}

/** Adds a pending shield transparent node for the banana coin token contract to the pxe. */
// TODO(benesjan): nuke this
async addPendingShieldNoteToPXE(owner: AztecAddress | AccountWallet, amount: bigint, secretHash: Fr, txHash: TxHash) {
const note = new Note([new Fr(amount), secretHash]);
const ownerAddress = 'getAddress' in owner ? owner.getAddress() : owner;
const extendedNote = new ExtendedNote(
note,
ownerAddress,
this.bananaCoin.address,
BananaCoin.storage.pending_shields.slot,
BananaCoin.notes.TransparentNote.id,
txHash,
);
await this.pxe.addNote(extendedNote, ownerAddress);
}

public async applyBaseSnapshots() {
await this.applyInitialAccountsSnapshot();
await this.applyPublicDeployAccountsSnapshot();
Expand Down
71 changes: 27 additions & 44 deletions yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
type AccountWallet,
type AztecAddress,
BatchCall,
Fr,
PrivateFeePaymentMethod,
computeSecretHash,
sleep,
} from '@aztec/aztec.js';
import { type AccountWallet, type AztecAddress, BatchCall, PrivateFeePaymentMethod, sleep } from '@aztec/aztec.js';
import { type GasSettings } from '@aztec/circuits.js';
import { type TokenContract as BananaCoin, FPCContract } from '@aztec/noir-contracts.js';

Expand Down Expand Up @@ -179,8 +171,8 @@ describe('e2e_fees private_payment', () => {
* BC increase total supply
*
* PUBLIC TEARDOWN
* increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note
* increase Alice's private banana balance by feeAmount by finalizing partial note
* increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note
* increase Alice's private banana balance by feeAmount by finalizing partial note
*/
const newlyMintedBananas = 10n;
const from = aliceAddress; // we are setting from to Alice here because of TODO(#9887)
Expand Down Expand Up @@ -221,23 +213,20 @@ describe('e2e_fees private_payment', () => {
* setup fee and refund partial notes
* setup public teardown call
*
*
* PRIVATE APP LOGIC
* N/A
* a partial note is prepared
*
* PUBLIC APP LOGIC
* BC decrease Alice public balance by shieldedBananas
* BC create transparent note of shieldedBananas
* BC finalizes the partial note with an amount --> this is where the note is created in public
*
* PUBLIC TEARDOWN
* increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note
* increase Alice's private banana balance by feeAmount by finalizing partial note
* increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note
* increase Alice's private banana balance by feeAmount by finalizing partial note
*/
const shieldedBananas = 1n;
const shieldSecret = Fr.random();
const shieldSecretHash = computeSecretHash(shieldSecret);
const amountTransferredToPrivate = 1n;
const tx = await bananaCoin.methods
.shield(aliceAddress, shieldedBananas, shieldSecretHash, 0n)
.transfer_to_private(aliceAddress, amountTransferredToPrivate)
.send({
fee: {
gasSettings,
Expand All @@ -256,30 +245,27 @@ describe('e2e_fees private_payment', () => {
await expectMapping(
t.getBananaPrivateBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[initialAlicePrivateBananas - feeAmount, 0n, initialSequencerPrivateBananas + feeAmount],
[
initialAlicePrivateBananas - feeAmount + amountTransferredToPrivate,
0n,
initialSequencerPrivateBananas + feeAmount,
],
);
await expectMapping(
t.getBananaPublicBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[initialAlicePublicBananas - shieldedBananas, initialFPCPublicBananas, 0n],
[initialAlicePublicBananas - amountTransferredToPrivate, initialFPCPublicBananas, 0n],
);
await expectMapping(
t.getGasBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas],
);

await expect(
t.addPendingShieldNoteToPXE(t.aliceWallet, shieldedBananas, shieldSecretHash, tx.txHash),
).resolves.toBeUndefined();
});

it('pays fees for tx that creates notes in both private and public', async () => {
const privateTransfer = 1n;
const shieldedBananas = 1n;
const shieldSecret = Fr.random();
const shieldSecretHash = computeSecretHash(shieldSecret);

const amountTransferredInPrivate = 1n;
const amountTransferredToPrivate = 2n;
/**
* PRIVATE SETUP
* check authwit
Expand All @@ -290,18 +276,19 @@ describe('e2e_fees private_payment', () => {
* PRIVATE APP LOGIC
* reduce Alice's private balance by privateTransfer
* create note for Bob with privateTransfer amount of private BC
* prepare partial note (in the transfer to private)
*
* PUBLIC APP LOGIC
* BC decrease Alice public balance by shieldedBananas
* BC create transparent note of shieldedBananas
* BC decrease Alice public balance by amountTransferredToPrivate
* BC finalize partial note with amountTransferredToPrivate (this is where the note is created in public)
*
* PUBLIC TEARDOWN
* increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note
* increase Alice's private banana balance by feeAmount by finalizing partial note
* increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note
* increase Alice's private banana balance by feeAmount by finalizing partial note
*/
const tx = await new BatchCall(aliceWallet, [
bananaCoin.methods.transfer(bobAddress, privateTransfer).request(),
bananaCoin.methods.shield(aliceAddress, shieldedBananas, shieldSecretHash, 0n).request(),
bananaCoin.methods.transfer(bobAddress, amountTransferredInPrivate).request(),
bananaCoin.methods.transfer_to_private(aliceAddress, amountTransferredToPrivate).request(),
])
.send({
fee: {
Expand All @@ -322,26 +309,22 @@ describe('e2e_fees private_payment', () => {
t.getBananaPrivateBalanceFn,
[aliceAddress, bobAddress, bananaFPC.address, sequencerAddress],
[
initialAlicePrivateBananas - feeAmount - privateTransfer,
initialBobPrivateBananas + privateTransfer,
initialAlicePrivateBananas - feeAmount - amountTransferredInPrivate + amountTransferredToPrivate,
initialBobPrivateBananas + amountTransferredInPrivate,
0n,
initialSequencerPrivateBananas + feeAmount,
],
);
await expectMapping(
t.getBananaPublicBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[initialAlicePublicBananas - shieldedBananas, initialFPCPublicBananas, 0n],
[initialAlicePublicBananas - amountTransferredToPrivate, initialFPCPublicBananas, 0n],
);
await expectMapping(
t.getGasBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas],
);

await expect(
t.addPendingShieldNoteToPXE(t.aliceWallet, shieldedBananas, shieldSecretHash, tx.txHash),
).resolves.toBeUndefined();
});

it('rejects txs that dont have enough balance to cover gas costs', async () => {
Expand Down
16 changes: 0 additions & 16 deletions yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import {
type DebugLogger,
type DeployL1Contracts,
EthAddress,
ExtendedNote,
type Fq,
Fr,
Note,
type PXE,
type TxHash,
createDebugLogger,
deployL1Contract,
} from '@aztec/aztec.js';
Expand Down Expand Up @@ -327,19 +324,6 @@ export class FullProverTest {
await this.acvmConfigCleanup?.();
}

async addPendingShieldNoteToPXE(accountIndex: number, amount: bigint, secretHash: Fr, txHash: TxHash) {
const note = new Note([new Fr(amount), secretHash]);
const extendedNote = new ExtendedNote(
note,
this.accounts[accountIndex].address,
this.fakeProofsAsset.address,
TokenContract.storage.pending_shields.slot,
TokenContract.notes.TransparentNote.id,
txHash,
);
await this.wallets[accountIndex].addNote(extendedNote);
}

async applyMintSnapshot() {
await this.snapshotManager.snapshot(
'mint',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import {
type AccountWallet,
type CompleteAddress,
type DebugLogger,
ExtendedNote,
Fr,
Note,
type TxHash,
createDebugLogger,
} from '@aztec/aztec.js';
import { type AccountWallet, type CompleteAddress, type DebugLogger, createDebugLogger } from '@aztec/aztec.js';
import { DocsExampleContract, TokenContract } from '@aztec/noir-contracts.js';

import { jest } from '@jest/globals';
Expand Down Expand Up @@ -123,19 +114,6 @@ export class TokenContractTest {
await this.snapshotManager.teardown();
}

async addPendingShieldNoteToPXE(accountIndex: number, amount: bigint, secretHash: Fr, txHash: TxHash) {
const note = new Note([new Fr(amount), secretHash]);
const extendedNote = new ExtendedNote(
note,
this.accounts[accountIndex].address,
this.asset.address,
TokenContract.storage.pending_shields.slot,
TokenContract.notes.TransparentNote.id,
txHash,
);
await this.wallets[accountIndex].addNote(extendedNote);
}

async applyMintSnapshot() {
await this.snapshotManager.snapshot(
'mint',
Expand Down

0 comments on commit b2e3360

Please sign in to comment.