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.