Skip to content
Business logic Audit finding Intermediate

Fee share calculation is incorrect

The fee share calculation in a smart contract incorrectly mints too many shares to the fee recipient, giving them more fees than intended and reducing interest for liquidity providers. An attacker could exploit this to drain value from the pool.

0x52 Follow with GimelSec, KingNFT and 2 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-surge-judging/issues/113

Found by

0x52, GimelSec, KingNFT, cccz, y1cunhui

Summary

Fees are given to the feeRecipient by minting them shares. The current share calculation is incorrect and always mints too many shares the fee recipient, giving them more fees than they should get.

Vulnerability Detail

The current equation is incorrect and will give too many shares, which is demonstrated in the example below.

Example:

_supplied = 100
_totalSupply = 100

_interest = 10
fee = 2

Calculate the fee with the current equation:

_accuredFeeShares = fee * _totalSupply / supplied = 2 * 100 / 100 = 2

This yields 2 shares. Next calculate the value of the new shares:

2 * 110 / 102 = 2.156

The value of these shares yields a larger than expected fee. Using a revised equation gives the correct amount of fees:

_accuredFeeShares = (_totalSupply * fee) / (_supplied + _interest - fee) = 2 * 100 / (100 + 10 - 2) = 1.852

1.852 * 110 / 101.852 = 2

This new equation yields the proper fee of 2.

Impact

Fee recipient is given more fees than intended, which results in less interest for LPs

Code Snippet

https://github.com/sherlock-audit/2023-02-surge/blob/main/surge-protocol-v1/src/Pool.sol#L161-L165

Tool used

Solidity YouTube Tutorial

Recommendation

Use the modified equation shown above:

    uint fee = _interest * _feeMantissa / 1e18;
    // 13. Calculate the accrued fee shares
-   _accruedFeeShares = fee * _totalSupply / _supplied; // if supplied is 0, we will have returned at step 7
+   _accruedFeeShares = fee * (_totalSupply * fee) / (_supplied + _interest - fee); // if supplied is 0, we will have returned at step 7
    // 14. Update the total supply
    _currentTotalSupply += _accruedFeeShares;

Discussion

xeious

Fixed

xeious

https://github.com/Surge-fi/surge-protocol-v1/commit/35e725cc25a97c0ee4a76fc5523ede90ac4ea130

IAm0x52

Fix looks good. Fee share calculation now correctly accounts for interest being paid

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

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 share calculation used the wrong denominator, not accounting for the interest and fee, leading to over-minting of shares.

Impact

The fee recipient receives more fees than intended, reducing the interest earned by liquidity providers.

What the attacker needed

None

The fix

The fee share calculation was fixed to use the correct formula that accounts for interest and fee.

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.

In a lending pool, when borrowers pay interest, a portion goes to the fee recipient as new shares. The formula for calculating those shares was wrong, so the fee recipient got more shares than they should, taking value away from the people who supplied money to the pool.

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 Surge

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.