Skip to content
DoS Audit finding Beginner

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:

https://github.com/sherlock-audit/2024-11-autonomint/blob/0d324e04d4c0ca306e1ae4d4c65f0cb9d681751b/Blockchain/Blockchian/contracts/Core_logic/Treasury.sol#L616C1-L625C6

Solidity
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

  1. Set totalInterest to 50 and totalInterestFromLiquidation to 100.
  2. Attempt to withdraw an amount of 75.
  3. The require passes because 75 ≤ 150.
  4. Subtracting 75 from totalInterest (50) causes an underflow and reverts.

Mitigation

Implement logic to deduct the amount from totalInterest and totalInterestFromLiquidation proportionally or sequentially:

Solidity
if (amount <= totalInterest) {
    totalInterest -= amount;
} else {
    uint256 remaining = amount - totalInterest;
    totalInterest = 0;
    totalInterestFromLiquidation -= remaining;
}

The original report as published on Sherlock, by 0x73696d616f. 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 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

  1. Set totalInterest to 50 and totalInterestFromLiquidation to 100.
  2. Attempt to withdraw an amount of 75.
  3. The require check passes because 75 is less than or equal to 150.
  4. 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.

More by 0x73696d616f

View all

172 more disclosed reports, best first.

More from Autonomint Colored Dollar V1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.