EVM / Solidity Error 0x4e487b71: Panic(0x11): arithmetic overflow/underflow
0x4e487b71 is Panic(uint256); code 0x11 means checked arithmetic over- or underflowed (Solidity ≥0.8). Usually a subtraction where b > a. Validate inputs and revert with a custom error first.
Identify: does your log match?
ContractFunctionExecutionError: The contract function "claim" reverted with the following reason: Arithmetic operation resulted in underflow or overflow. Contract Call: address: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 function: claim(uint256 amount) args: (5000000000000000000) Raw revert data: 0x4e487b710000000000000000000000000000000000000000000000000000000000000011 Version: viem@2.21.37
- High
Subtracting a larger value
balance - amount or end - start where the right side is bigger. 0.8.x checked math reverts with Panic(0x11) instead of wrapping.
- Medium
Overflow in multiplication
amount * price * 1e18 exceeds 2^256-1 for large inputs, or a downcast like uint128(x) overflows via explicit math.
- Medium
Decrementing a zero counter
totalStaked-- or count -= 1 after state was already cleared by another path.
Fix
Check bounds and revert with a clear error
function claim(uint256 amount) external { rewards[msg.sender] -= amount; // Panic(0x11) if amount > rewards token.transfer(msg.sender, amount); }
error ClaimExceedsRewards(uint256 available, uint256 requested); function claim(uint256 amount) external { uint256 available = rewards[msg.sender]; if (amount > available) revert ClaimExceedsRewards(available, amount); unchecked { rewards[msg.sender] = available - amount; } token.safeTransfer(msg.sender, amount); }
The explicit check gives callers a decodable reason. unchecked is safe after the check and saves gas.
Verify: reproduce it on purpose
$ cast decode-error 0x4e487b710000000000000000000000000000000000000000000000000000000000000011 --sig "Panic(uint256)"Run it against a dev environment to trigger 0x4e487b71 on purpose and test your error handler.
Prevent
- Fuzz arithmetic with forge test --fuzz-runs 10000.
- Use SafeCast for downcasts.
- Treat any Panic in production as a bug, not a user error.
FAQ
What do the other Panic codes mean?
0x01 assert failed, 0x12 division by zero, 0x21 invalid enum, 0x31 pop on empty array, 0x32 index out of bounds, 0x41 out of memory, 0x51 uninitialized function pointer.
Why no overflow before Solidity 0.8?
Earlier versions wrapped silently, which is why SafeMath existed. 0.8.0 made checked arithmetic the default.
Does a Panic consume all gas?
No. Since 0.8.0 Panic uses the REVERT opcode and refunds remaining gas; only pre-0.8 assert used INVALID and consumed all gas.
Related errors
Last verified 2026-10-19 · Source: 4byte/OpenChain signatures + OpenZeppelin v5 custom errors + Panic codes · Official docs ↗ · ~2,900 searches/mo