Incorrect rebase percentage calculation
When a rebase would push the total supply above the maximum, the code caps the supply but still passes the full profit to the rebase storage function, so the rebase percentage is calculated on an amount that was not fully applied. This could misreport the rebase percentage, though the maximum supply is so large it is unlikely to be reached.
Originally disclosed on Code4rena
Submitted by csanuragjain
Note: this issue had originally been grouped with M-15. Approximately 1 week after judging and awarding were finalized, the judging team re-assessed that this issue should have been classified as a unique issue. It has been broken out here accordingly.
https://github.com/code-423n4/2022-06-yieldy/blob/main/src/contracts/Yieldy.sol#L91
It was observed that if updatedTotalSupply > MAXSUPPLY then updatedTotalSupply becomes MAXSUPPLY. This means _profit amount is not fully used. But _storeRebase function is still called with _profit amount.
This becomes a problem since _storeRebase function caluclates rebasePercent using this incorrect _profit amount.
Proof of Concept
- REBASE_ROLE calls rebase function with say profit 10. Assume currentTotalSupply is 90
- updatedTotalSupply is calculated as updatedTotalSupply = currentTotalSupply + _profit. Thus updatedTotalSupply becomes 90+10=100
- Assume MAXSUPPLY is 91. Since updatedTotalSupply>MAXSUPPLY so updatedTotalSupply is updated to be 91
- Now _storeRebase function is called with updatedTotalSupply (91), _profit(10)
- This is incorrect since 10 amount from _profit is not utilized and only 1 amount is utilized. This becomes a problem in rebasePercent calculation where it is calculated on full 10 amount instead of 1
Recommended Mitigation Steps
Use below:
if (updatedTotalSupply > MAX_SUPPLY) {
_profit=_profit - (updatedTotalSupply-MAX_SUPPLY);
updatedTotalSupply = MAX_SUPPLY;
}
toshiSat (Yieldy) acknowledged and commented:
Max Supply is nearly the max amount in uint256. The protection is there, but will most likely never hit.
Potentially, this should be a medium issue.
JasoonS (judge) decreased severity to Medium and commented:
Downgrading to medium
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 code caps updatedTotalSupply but does not adjust _profit before calling _storeRebase, so the rebase percentage is computed from the uncapped profit.
Impact
The stored rebase percentage could be incorrect, but the maximum supply is nearly the maximum uint256 value so the condition will most likely never be hit.
What the attacker needed
REBASE_ROLE privilege; total supply near maximum uint256
The fix
The code should reduce _profit by the excess over the maximum supply before calling _storeRebase, as shown in the recommended mitigation.
How it was found
- Call the rebase function with a profit amount while the current total supply is below the maximum.
- The code calculates updatedTotalSupply as currentTotalSupply plus profit.
- If updatedTotalSupply exceeds the maximum supply, it is capped to the maximum.
- The _storeRebase function is then called with the capped supply but the original profit amount.
- The rebase percentage is calculated using the full profit instead of the reduced amount actually applied.
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 rebase changes how many tokens each holder has, and the percentage change is stored. The code limits the total supply to a maximum, but when it hits that limit it still tells the storage function the original profit amount instead of the reduced one. That makes the stored percentage wrong, although the maximum is so high it is almost never reached.
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.