Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split setup/teardown functions when there's no public app logic #5156

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 77 additions & 4 deletions yarn-project/end-to-end/src/e2e_fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ describe('e2e_fees', () => {
let InitialAlicePublicBananas: bigint;
let InitialAliceGas: bigint;

let InitialBobPrivateBananas: bigint;

let InitialFPCPrivateBananas: bigint;
let InitialFPCPublicBananas: bigint;
let InitialFPCGas: bigint;
Expand All @@ -220,16 +222,82 @@ describe('e2e_fees', () => {
RefundSecret = Fr.random();

[
[InitialAlicePrivateBananas, InitialFPCPrivateBananas],
[InitialAlicePrivateBananas, InitialBobPrivateBananas, InitialFPCPrivateBananas],
[InitialAlicePublicBananas, InitialFPCPublicBananas],
[InitialAliceGas, InitialFPCGas, InitialSequencerGas],
] = await Promise.all([
bananaPrivateBalances(aliceAddress, bananaFPC.address, sequencerAddress),
bananaPublicBalances(aliceAddress, bananaFPC.address, sequencerAddress),
bananaPrivateBalances(aliceAddress, bobAddress, bananaFPC.address),
bananaPublicBalances(aliceAddress, bananaFPC.address),
gasBalances(aliceAddress, bananaFPC.address, sequencerAddress),
]);
});

it("pays fees for tx that don't run public app logic", async () => {
/**
* PRIVATE SETUP
* check authwit
* reduce alice BC.private by MaxFee
* enqueue public call to increase FPC BC.public by MaxFee
* enqueue public call for fpc.pay_fee_with_shielded_rebate
*
* PRIVATE APP LOGIC
* reduce Alice's BC.private by transferAmount
* create note for Bob of transferAmount
*
* PUBLIC SETUP
* increase FPC BC.public by MaxFee
*
* PUBLIC APP LOGIC
* N/A
*
* PUBLIC TEARDOWN
* call gas.pay_fee
* decrease FPC AZT by FeeAmount
* increase sequencer AZT by FeeAmount
* call banana.shield
* decrease FPC BC.public by RefundAmount
* create transparent note with RefundAmount
*
* this is expected to squash notes and nullifiers
*/
const transferAmount = 5n;
const tx = await bananaCoin.methods
.transfer(aliceAddress, bobAddress, transferAmount, 0n)
.send({
fee: {
maxFee: MaxFee,
paymentMethod: new PrivateFeePaymentMethod(
bananaCoin.address,
bananaFPC.address,
aliceWallet,
RefundSecret,
),
},
})
.wait();

await expectMapping(
bananaPrivateBalances,
[aliceAddress, bobAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePrivateBananas - MaxFee - transferAmount, transferAmount, InitialFPCPrivateBananas, 0n],
);
await expectMapping(
bananaPublicBalances,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePublicBananas, InitialFPCPublicBananas + MaxFee - RefundAmount, 0n],
);
await expectMapping(
gasBalances,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAliceGas, InitialFPCGas - FeeAmount, InitialSequencerGas + FeeAmount],
);

await expect(
// this rejects if note can't be added
addPendingShieldNoteToPXE(0, RefundAmount, computeMessageSecretHash(RefundSecret), tx.txHash),
).resolves.toBeUndefined();
});

it('pays fees for tx that creates notes in private', async () => {
/**
* PRIVATE SETUP
Expand Down Expand Up @@ -412,7 +480,12 @@ describe('e2e_fees', () => {
await expectMapping(
bananaPrivateBalances,
[aliceAddress, bobAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePrivateBananas - MaxFee - privateTransfer, privateTransfer, InitialFPCPrivateBananas, 0n],
[
InitialAlicePrivateBananas - MaxFee - privateTransfer,
InitialBobPrivateBananas + privateTransfer,
InitialFPCPrivateBananas,
0n,
],
);
await expectMapping(
bananaPublicBalances,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ export abstract class AbstractPhaseManager {
[PublicKernelPhase.TEARDOWN]: [],
[PublicKernelPhase.TAIL]: [],
};
} else if (firstRevertibleCallIndex === -1) {
// there's no app logic, split the functions between setup (many) and teardown (just one function call)
return {
[PublicKernelPhase.SETUP]: publicCallsStack.slice(0, -1),
[PublicKernelPhase.APP_LOGIC]: [],
[PublicKernelPhase.TEARDOWN]: [publicCallsStack[publicCallsStack.length - 1]],
[PublicKernelPhase.TAIL]: [],
};
} else {
return {
[PublicKernelPhase.SETUP]: publicCallsStack.slice(0, firstRevertibleCallIndex - 1),
Expand Down
Loading