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.
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
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
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.