You run a transaction or a test and get back something like panic: arithmetic underflow or overflow (0x11), Panic due to OVERFLOW(17), or raw revert data starting with 0x4e487b71. All of these are the same Solidity error, and it is almost always a bug you can fix.
Quick answer: Panic code 0x11 means a Solidity 0.8+ contract did math whose result fell outside its type’s range (for example 0 - 1 on a uint256, or 255 + 1 on a uint8) outside an unchecked { ... } block, so the compiler-inserted check reverted the call. To fix it, find the exact line with a trace, then add an explicit check (such as require(balance >= amount)), widen the type, or use a safe cast. Only use unchecked when you have proven the math cannot over- or underflow.
What “Panic code 0x11” actually means
Since Solidity 0.8.0, arithmetic operations revert on underflow and overflow by default. Before 0.8.0 they silently wrapped around, which is why older code relied on libraries like SafeMath. When a checked operation fails, the compiler does not use a plain string. It reverts with error data equal to a call to Panic(uint256), with a code describing what went wrong.
The Solidity docs section “Panic via assert and Error via require” defines code 0x11 as: “If an arithmetic operation results in underflow or overflow outside of an unchecked { ... } block.” The same docs also say that properly working code should never create a Panic, not even on invalid external input. A 0x11 is therefore a sign that your contract is missing a check, not that the user did something “wrong”.
The revert data is always 36 bytes: the 4-byte selector plus the code as a 32-byte word. We confirmed the selector locally with Foundry’s cast:
$ cast sig "Panic(uint256)"
0x4e487b71
# full revert data for panic 0x11
0x4e487b710000000000000000000000000000000000000000000000000000000000000011
0x11 is 17 in decimal, which is why some tools print Panic(17).
How the error looks in Foundry, ethers, viem and Hardhat
We wrote a tiny test contract with a uint8 counter set to 255 and a withdraw() that does balance[msg.sender] -= amt, then ran it with Foundry (forge 1.9.0, solc 0.8.38) and a local Anvil node. These are the exact messages we saw:
- forge test:
[FAIL: panic: arithmetic underflow or overflow (0x11)] test_ShowTrace() - cast call:
Error: execution reverted: panic: arithmetic underflow or overflow (0x11)followed bydata: "0x4e487b71...0011" - cast send: it failed earlier, at gas estimation:
Failed to estimate gas: ... execution reverted: panic: arithmetic underflow or overflow (0x11) ... Panic(17) - ethers v6.17 (
staticCall):code: CALL_EXCEPTION,reason: "Panic due to OVERFLOW(17)",revert: {"signature":"Panic(uint256)","name":"Panic","args":[17]} - viem 2.58 (
simulateContract):The contract function "withdraw" reverted with the following reason: Arithmetic operation resulted in underflow or overflow.
Notice that ethers prints “OVERFLOW” even though our test was actually an underflow (0 – 1). The panic code does not tell the two apart, so read the label as “out of range” either way. If ethers shows you a generic error instead, our guide to the “execution reverted” error explains how to pull out the raw revert data. The ethers CallExceptionError docs list the data and reason fields.
We did not run Hardhat in this test. According to the Hardhat Network docs, a failed call throws an exception with a combined JavaScript and Solidity stack trace, which points to the contract file and line.
Same panic data on Core mainnet (read-only)
To check that a live chain returns the same bytes, we sent a read-only eth_call (no transaction, nothing broadcast) to https://rpc.coredao.org (chain ID 1116, confirmed with eth_chainId = 0x45c). The call simulated deploying a contract whose constructor computes 0 - 1. On 21 Nov 2026 the RPC replied:
{"error":{"code":3,
"message":"execution reverted: arithmetic underflow or overflow",
"data":"0x4e487b710000000000000000000000000000000000000000000000000000000000000011"}}
So Core, like other EVM chains, returns the standard Panic encoding. If you’d rather debug against real Core state on your own machine, see how to fork Core mainnet with Anvil.
How to fix panic code 0x11, step by step
1. Find the exact line
Reproduce the failure in a test and run it with full traces:
forge test --match-test test_ShowTrace -vvvv
In our run the trace pointed straight at the failing function:
├─ [24017] Overflow::withdraw(1)
│ └─ ← [Revert] panic: arithmetic underflow or overflow (0x11)
Backtrace:
at Overflow.withdraw
If the failure already happened on a live chain, Foundry’s debugging docs show cast run <txhash> --rpc-url $RPC_URL to replay it with a trace. Our Foundry cast commands guide for Core covers the setup. In Hardhat, read the Solidity part of the stack trace.
2. Check the boundary cases
Once you know the function, list every +, -, *, **, ++, -- and compound assignment on that path. The usual causes are:
- Subtracting from a zero or smaller balance:
balance -= amountwhenamount > balance. This also covers fees, rewards, and timestamps (deadline - block.timestampafter the deadline has passed). - Small types:
uint8tops out at 255,uint16at 65,535, anduint32at about 4.29 billion. Counters and packed struct fields hit these limits quickly. - Decimals math: multiplying two 18-decimal values before dividing, or scaling a 6-decimal token amount with
10**decimalsin a narrow type, can overflow intermediate results. - Signed edge cases: the docs note that negating
type(int).minoverflows, because the negative range holds one more value than the positive range.
3. Replace the panic with an explicit check
A clear custom error is better for users and front ends than a raw panic:
error InsufficientBalance(uint256 available, uint256 required);
function withdraw(uint256 amt) external {
uint256 bal = balance[msg.sender];
if (bal < amt) revert InsufficientBalance(bal, amt);
balance[msg.sender] = bal - amt;
}
This is the same idea that token contracts use. For an example, see our breakdown of “ERC20: transfer amount exceeds balance”.
4. Widen the type or cast safely
If a value can legitimately grow, use a bigger type. Watch out for casts, though. The Solidity docs state that explicit type conversions always truncate and never cause a failing assertion (except integer-to-enum). In our test uint8(256) returned 0 and uint8(300) returned 44, with no revert, and forge build printed an unsafe-typecast lint warning. A bad cast does not give you 0x11. It gives you silently wrong numbers. Use OpenZeppelin’s SafeCast (for example SafeCast.toUint8(x)), which reverts with SafeCastOverflowedUintDowncast when the value does not fit.

5. Use unchecked only when it is provably safe
Wrapping code in unchecked { ... } turns the panic into silent wraparound. In our test, unchecked { small += 1; } on a uint8 holding 255 left it at 0, and unchecked { return 0 - 1; } on uint256 returned type(uint256).max. That saves a little gas, but it is only safe when an earlier check guarantees the result is in range. A classic example is if (bal >= amt) { unchecked { bal - amt; } }, or a loop counter bounded by an array length. According to the docs, unchecked only affects statements syntactically inside the block, not functions called from it. It cannot disable division-by-zero checks, and bitwise shifts are never checked.
6. Add a regression test
forge-std ships stdError helpers for every panic type. Both of these passed in our run:
vm.expectRevert(stdError.arithmeticError);
c.addOne();
vm.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x11));
c.withdraw(1);
Other Solidity panic codes
Here are the panic codes listed in the Solidity docs, so you can tell 0x11 apart from its neighbours:
| Code | Meaning (per Solidity docs) |
|---|---|
| 0x00 | Generic compiler-inserted panic |
| 0x01 | assert with a false argument |
| 0x11 | Arithmetic underflow or overflow outside unchecked |
| 0x12 | Division or modulo by zero |
| 0x21 | Value too big or negative converted to an enum |
| 0x22 | Incorrectly encoded storage byte array |
| 0x31 | .pop() on an empty array |
| 0x32 | Array, bytesN or slice index out of bounds |
| 0x41 | Too much memory allocated or array too large |
| 0x51 | Zero-initialized internal function variable called |
In our test, 1 / 0 matched stdError.divisionError (0x12), not 0x11.
FAQ
Is panic code 0x11 overflow or underflow?
It can be either. The same code covers both directions, and some tools label it “OVERFLOW” even for 0 - 1. Check the operands on the failing line.
Can a user trigger 0x11 by sending bad input?
Yes, if the contract does not validate that input. That is a contract bug. The Solidity docs say properly functioning code should never panic, even on invalid external input. Add a require or custom error instead.
Why did my old 0.7.x contract never show this error?
Before 0.8.0, arithmetic wrapped silently. Code compiled with 0.7 or earlier will not panic with 0x11, but it can produce wrong values unless it uses checks like SafeMath.
Should I wrap everything in unchecked to save gas?
No. Only use it where an earlier check or a loop bound proves the math stays in range. Otherwise you swap a loud revert for a silent accounting bug.
Disclaimer: This article is for educational purposes only and is not financial or security advice. Always test changes thoroughly and get a professional audit before deploying contracts that hold real funds.
