Skip to content
Business logic Audit finding Intermediate

StrategyLeverage.harvest doesn’t account flashloan fee

The harvest function repays debt using a flashloan but does not subtract the flashloan fee from the calculated new deployed amount, making it appear larger than reality. This causes the protocol to receive less management fee when profit accrues.

rvierdiiev Follow

Originally disclosed on Code4rena

Submitted by rvierdiiev

StrategyLeverage.harvest function checks position state. In case if position LTV is bigger than max LTV, then extra debt is repaid to decrease LTV back to normal.

In order to repay part of debt, flashloan is taken and contract should pay fee for it.

So overall after adjusting our debt is decreased with deltaDebt but our collateral is decreased with deltaDebt + fee.

The problem is that this is not reflected in the newDeployedAmount calculation as it thinks that both collateral and debt were decreased by deltaDebt.

As result of this, newDeployedAmount is bigger than it is in reality (in reality it is newDeployedAmount - fee), which means that later when some profit accrued, protocol may not receive it. For example if profit is < fee, then protocol won’t receive it and if profit is > fee, then protocol will receive management fee based on profit - fee amount.

Impact

Protocol may receive smaller amount of fees.

Tools Used

VsCode

Recommended Mitigation Steps

Make _adjustDebt returns fee as well and use it to decrease collateral.

hvasconcelos (BakerFi) confirmed

ickas (BakerFi) commented:

Fixed → https://github.com/baker-fi/bakerfi-contracts/pull/48


The original report as published on Code4rena, by rvierdiiev. 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

Impact

The protocol may receive a smaller amount of fees because the inflated newDeployedAmount reduces the profit used for management fee calculation.

What the attacker needed

Position LTV exceeds max LTV; flashloan fee applies

The fix

The fix was to make _adjustDebt return the fee and use it to decrease collateral.

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 repaid within the same transaction, usually with a small fee. The code repays some debt using a flashloan but forgets to account for the fee when updating the collateral amount, so the protocol later thinks it has more collateral than it does and charges a smaller fee.

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 rvierdiiev

View all

72 more disclosed reports, best first.

More from BakerFi Invitational

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.