Skip to content
Audit finding Intermediate

Accrued perfomance fee calculation takes wrong assumptions for share decimals, leading to loss of shares or hyperinflation

The performance fee calculation assumes share decimals are always 18, so for tokens with fewer decimals the fee rounds to zero and the fee recipient loses shares, while for tokens with more decimals the fee recipient receives excessive shares, causing hyperinflation and making user shares worthless.

DadeKuma Follow with joestakey, Kumpa and 2 others

Originally disclosed on Code4rena

Submitted by DadeKuma, also found by joestakey, Kumpa, CRYP70, and 0xTraub

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/adapter/abstracts/AdapterBase.sol#L529-L542

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L447-L460

Vulnerability details

This issue applies to both AdapterBase.sol and Vault.sol. For the sake of simplicity and brevity, this POC will describe just the former.

Impact

Fee calculation is wrong and it either takes too few or too many shares than what is supposed to be when calculating the accruedPerformanceFee and the shares decimals are not 18.

The former causes a loss of shares that the FEE_RECIPIENT should earn, but the latter causes hyperinflation, which makes users’ shares worthless.

Proof of Concept

accruedPerformanceFee doesn’t take into consideration the shares’ decimals, and it supposes that it’s always 1e18.

This is supposed to be a percentage and it’s calculated as the following, rounding down.

function accruedPerformanceFee() public view returns (uint256) {
    uint256 highWaterMark_ = highWaterMark;
    uint256 shareValue = convertToAssets(1e18);
    uint256 performanceFee_ = performanceFee;

    return
        performanceFee_ > 0 && shareValue > highWaterMark_
            ? performanceFee_.mulDiv(
                (shareValue - highWaterMark_) * totalSupply(),
                1e36,
                Math.Rounding.Down
            )
            : 0;
}

This calculation is wrong because the assumption is:

totalSupply (1e18) * performanceFee_ (1e18) = 1e36

which is not always true because the totalSupply decimals can be greater or lesser than that.

Let’s see what would happen in this case.

Best case scenario: supply decimals < 1e18

In this case, the fee calculation will always round to zero, thus the FEE_RECIPIENT will never get the deserved accrued fees.

Worst case scenario: supply decimals > 1e18

The FEE_RECIPIENT will get a highly disproportionate number of shares.

This will lead to share hyperinflation, which will also impact the users, making their shares worthless.

Recommended Mitigation Steps

Modify the fee calculation so it’s divided with the correct denominator, that takes into account the share decimals:

performanceFee_ > 0 && shareValue > highWaterMark_
? performanceFee_.mulDiv(
    (shareValue - highWaterMark_) * totalSupply(),
    1e18 * (10 ** decimals()),
    Math.Rounding.Down
)
: 0;
``

RedVeil (Popcorn) confirmed, but disagreed with severity

LSDan (judge) decreased severity to Medium


The original report as published on Code4rena, by DadeKuma. 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 fee calculation uses a fixed denominator of 1e36, assuming totalSupply always has 18 decimals, instead of scaling by the actual share decimals.

Impact

For tokens with fewer than 18 decimals the fee recipient earns no shares; for tokens with more than 18 decimals the fee recipient gets a disproportionate number of shares, causing hyperinflation that makes users' shares worthless.

What the attacker needed

Vault uses a share token with decimals other than 18; performance fee is greater than zero; share value exceeds the high-water mark

The fix

The fee calculation should divide by 1e18 multiplied by 10 to the power of the share decimals, so the denominator matches the actual token precision.

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 by minting new shares to a fee recipient. The code assumes every share has 18 decimal places, but some tokens use fewer or more. If the token has fewer decimals, the fee rounds down to zero; if it has more, the fee becomes huge and dilutes everyone else.

More by DadeKuma

View all

19 more disclosed reports, best first.

More from Popcorn contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.