Potential Underflow in `withdrawInterest`
The withdrawInterest function checks that the requested amount is covered by the sum of two interest balances, but then subtracts the full amount only from the first balance. If that first balance is smaller than the amount, the subtraction underflows and the transaction reverts, blocking a legitimate withdrawal.
0x73696d616f Follow with 0xAadi, Audinarey and 12 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/228
Found by
0x73696d616f, 0xAadi, Audinarey, AuditorPraise, Aymen0909, Cybrid, Galturok, PeterSR, Ragnarok, RampageAudit, Waydou, nuthan2x, onthehunt, super_jack, volodya
Summary
In the withdrawInterest function, if totalInterest is less than amount, subtracting amount from totalInterest will cause an underflow and revert the transaction due to Solidity 0.8.x's checked arithmetic, even if totalInterestFromLiquidation has sufficient balance to cover the withdrawal.
Root Cause
The function checks the combined balance but only subtracts from totalInterest:
require(amount <= (totalInterest + totalInterestFromLiquidation), "Treasury don't have enough interest");
totalInterest -= amount;
If totalInterest < amount, this subtraction underflows and reverts.
Internal pre-conditions
none
External pre-conditions
none
Attack Path
No response
Impact
DOS, underflow and revert.
PoC
- Set
totalInterestto 50 andtotalInterestFromLiquidationto 100. - Attempt to withdraw an
amountof 75. - The
requirepasses because 75 ≤ 150. - Subtracting 75 from
totalInterest(50) causes an underflow and reverts.
Mitigation
Implement logic to deduct the amount from totalInterest and totalInterestFromLiquidation proportionally or sequentially:
if (amount <= totalInterest) {
totalInterest -= amount;
} else {
uint256 remaining = amount - totalInterest;
totalInterest = 0;
totalInterestFromLiquidation -= remaining;
}
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 balance check uses the sum of two variables, but the deduction is applied only to one of them, so the subtraction can underflow when that variable is smaller than the amount.
Impact
Legitimate withdrawals can be blocked with a revert, causing a denial of service for users whose funds are split across the two interest balances.
What the attacker needed
None
The fix
The withdrawal should deduct from totalInterest first and then from totalInterestFromLiquidation for any remainder, so the combined balance is actually used.
How it was found
- Set totalInterest to 50 and totalInterestFromLiquidation to 100.
- Attempt to withdraw an amount of 75.
- The require check passes because 75 is less than or equal to 150.
- Subtracting 75 from totalInterest (50) causes an underflow and reverts.
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 smart contract keeps two pots of interest money. When someone withdraws, the code checks that the two pots together hold enough, but then it takes the whole withdrawal out of only the first pot. If that first pot is too small, the maths goes negative, which the programming language refuses, so the withdrawal fails even though the money exists.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.