Skip to content

Commit

Permalink
fix: split setup/teardown when there's no app logic
Browse files Browse the repository at this point in the history
Co-authored-by: Mitchell Tracy <[email protected]>
  • Loading branch information
alexghr and just-mitch committed Mar 13, 2024
1 parent d666f6f commit 2acec5b
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
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

0 comments on commit 2acec5b

Please sign in to comment.