Skip to content
Business logic Audit finding Intermediate

Flashloan users can be forced to pay higher fees than expected

The flashloan fee in AlgebraPool is set by the first swap in each block, so a swap before a flashloan can change the fee. An attacker could frontrun a flashloan with a swap to force the borrower to pay a higher fee.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52

AlgebraPool.sol#L891-L949

The first swap of the block sets the fee that will apply to all other actions during that block, including the fee that will be applied to flashloans. If a swap occurs in the same block before the flashloan, the fee taken from the flashloan will be different than expected potentially much different. This could be used by an adversary to force a flashloan user to pay higher fees. They would frontrun the flashloan call with a swap that would push the fees higher. This is dependent on the current state of the swap beforehand but liquidity providers would have a strong incentive to monitor the pool to maximize their profits.

Recommended Mitigation Steps

Using the swap fee as the flashloan fee seems counterintuitive to me. It doesn’t cause any impermanent loss to the liquidity providers, which is what the dynamic fee is designed to offset. There are two possible solutions to this. The first solution would be to allow the flashloan user to specify a max fee they will pay. The other solution, which I believe makes more sense, is to just use a flat fee on flashloans. This provides more consistent outcomes for flashloan users, making the product more attractive.

IliaAzhel (QuickSwap & StellaSwap) acknowledged and commented:

Indeed, the flashloan fee may depend on previous transactions in the block. However, fee can not only increase, but also decrease.


The original report as published on Code4rena, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The flashloan fee is derived from the swap fee, which is set by the first swap in each block, making it manipulable by frontrunning.

Impact

An adversary could force a flashloan user to pay a higher fee, though the fee could also decrease.

What the attacker needed

Flashloan user initiates a loan; attacker can frontrun with a swap

The fix

The report recommends either allowing the flashloan user to specify a maximum fee or using a flat fee for flashloans.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A flashloan is a loan that must be borrowed and repaid in the same transaction. The fee for the loan is supposed to be predictable, but here it depends on the first swap in the block. Someone else can make a swap just before the loan, causing the borrower to pay more.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0x52

View all

211 more disclosed reports, best first.

More from QuickSwap and StellaSwap contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.