How Can an Underflow Be Exploited to Drain Funds from a Contract?

An underflow can be exploited by an attacker to manipulate a contract's balance checks or withdrawal logic. If a contract subtracts a user's withdrawal amount from their balance without a safe math check, and the balance is zero, the subtraction can underflow, causing the balance to wrap to the maximum possible value (e.g.

2^256 – 1). The contract then incorrectly believes the user has a massive balance, allowing them to withdraw an amount far exceeding their actual deposit, thereby draining the contract's funds.

How Can Investors Check a token’S Contract for Potential’rug Pull’ Functions?
What Happens to My Investment If a Rebase Token’s Smart Contract Is Exploited?
What Is the Difference between ‘Last Look’ and ‘Pre-Trade Credit Check’ in Derivatives Trading?
How Does the Signed Integer Type Change the Definition of Overflow/underflow?
What Is a “Bridge” in the Context of Cross-Chain Transfers?
Provide an Example of How Two Functions Might Share a State That Could Be Exploited
What Is an Integer Overflow and How Does It Impact Token Balances?
What Is a Reentrancy Attack in Smart Contract Security?

Glossar