Skip to content
Business logic Audit finding Intermediate

Protocol receives less harvest fees

The vault's performance fee calculation mints shares based on the pre-mint total supply, so the fee receiver receives slightly fewer shares than intended. This causes the protocol to collect a smaller fee than it should.

rvierdiiev Follow

Originally disclosed on Code4rena

Submitted by rvierdiiev

In case position has grown, then protocol receives performance fee.

https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/Vault.sol#L153-L158

                    uint256 feeInEthScaled = uint256(balanceChange) *
                        settings().getPerformanceFee();
                    uint256 sharesToMint = (feeInEthScaled * totalSupply()) /
                        _totalAssets(maxPriceAge) /
                        PERCENTAGE_PRECISION;
                    _mint(settings().getFeeReceiver(), sharesToMint);

We will check how shares amount is calculated and why it’s less than it should be.

Suppose that totalSupply() == 100000 and _totalAssets(maxPriceAge) == 100100, so we earned 100 eth as additional profit. balanceChange == 100 and performance fee is 10%, which is 10 eth.

sharesToMint = 10 * 100000 / 100100 = 9.99001

This means that with 9.990001 shares protocol should be able to grab 10 eth fee, which is indeed like that if we convert 9.99001 * 100100 / 100000 = 10.

The problem is that minting is done later, which means that totalSupply() will increase with 9.99001 shares. So if we calculate fees amount now we will get a smaller amount: 9.99001 * 100100 / 100009.99001 = 9.999001

Impact

Protocol receives smaller amount of fees.

Tools Used

VsCode

Recommended Mitigation Steps

The formula should be adjusted to count increase of total supply.

hvasconcelos (BakerFi) acknowledged


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

Root cause

Likely the fee shares are calculated using the total supply before minting, rather than the post-mint total supply, so the dilution effect is not accounted for.

Impact

The protocol receives a slightly smaller amount of fees than intended; the text does not mention any defence or limitation.

What the attacker needed

Position has grown (profit)

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 vault charges a performance fee when its value grows. It pays that fee by creating new shares for the protocol. The code calculates how many shares to create using the old total number of shares, but after creating them the total is larger, so each new share is worth a little less. The result is the protocol gets slightly less than the intended 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.