# Solidity Revert Reasons & Error Patterns

Common revert reasons encountered in DeFi transactions and their meanings.

## Standard ERC-20 Errors

- **"ERC20: transfer amount exceeds balance"** — The sender's token balance is less than the transfer amount.
- **"ERC20: transfer amount exceeds allowance"** — The spender hasn't been approved for the requested amount. Call `approve()` first.
- **"ERC20: insufficient allowance"** — Same as above (OpenZeppelin v5+).
- **"ERC20InsufficientBalance(address,uint256,uint256)"** — Custom error (Solidity 0.8.4+). Shows sender, balance, and needed amount.
- **"ERC20InsufficientAllowance(address,uint256,uint256)"** — Custom error showing spender, current allowance, needed amount.

## Uniswap V2 Errors

- **"UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT"** — Slippage exceeded. The output tokens are less than `amountOutMin`.
- **"UniswapV2: INSUFFICIENT_LIQUIDITY"** — The pool doesn't have enough reserves for the swap.
- **"UniswapV2: EXPIRED"** — The transaction deadline (block.timestamp) has passed.
- **"UniswapV2: TRANSFER_FAILED"** — The underlying token transfer failed during the swap.
- **"UniswapV2: K"** — The constant product invariant (x*y=k) was violated.
- **"UniswapV2: INSUFFICIENT_INPUT_AMOUNT"** — The input token amount is zero or rounded down to zero.

## Uniswap V3 Errors

- **"Too little received"** — Slippage check failed on exactInput/exactOutput.
- **"Too much requested"** — The requested output exceeds what the pool can provide.
- **"STF"** — SafeTransferFrom failed during the swap.
- **"TF"** — TransferFrom failed.
- **"AS"** — Already settled (router state error).
- **"SPL"** — SqrtPriceLimitX96 exceeded.

## Aave V3 Errors

- **Error code 1** — The caller is not a pool admin.
- **Error code 26** — Collateral is not enabled for borrowing.
- **Error code 27** — Supply amount is below the minimum.
- **Error code 35** — Health factor below liquidation threshold.
- **Error code 36** — Borrowing not enabled on this reserve.
- **"CALLER_NOT_POOL"** — The function can only be called by the Aave pool contract.
- **"INCONSISTENT_FLASHLOAN_PARAMS"** — Flash loan parameters don't match.

## Compound V2/V3 Errors

- **"Comptroller rejection"** — The Comptroller blocked the operation (e.g., insufficient collateral).
- **"INSUFFICIENT_LIQUIDITY"** — Not enough liquidity in the market.
- **"MATH_ERROR"** — Integer overflow/underflow in Compound's math library.

## Solidity Panic Codes (0x4e487b71)

- **Panic(0x01)** — `assert()` statement failed.
- **Panic(0x11)** — Arithmetic overflow/underflow (caught by Solidity 0.8+).
- **Panic(0x12)** — Division or modulo by zero.
- **Panic(0x21)** — Conversion to invalid enum value.
- **Panic(0x31)** — `.pop()` on an empty array.
- **Panic(0x32)** — Out-of-bounds array access.
- **Panic(0x41)** — Too much memory allocated.
- **Panic(0x51)** — Called a zero-initialized function pointer.

## Access Control Errors

- **"Ownable: caller is not the owner"** — OpenZeppelin Ownable modifier failed.
- **"AccessControl: account is missing role"** — The caller doesn't have the required role.
- **"Pausable: paused"** — The contract is paused by an admin.
- **"ReentrancyGuard: reentrant call"** — A reentrancy attempt was blocked.

## Common Gas Issues

- **Out of gas** — Transaction consumed all allocated gas. Increase gas limit.
- **Gas utilization > 95%** — Dangerously close to the limit. Increase by 30%+.
- **Intrinsic gas too low** — Gas limit is below the minimum (21,000 for simple transfers).

## Fee-on-Transfer Tokens

Some tokens (SafeMoon, SHIB clones) charge a tax on transfers. Swapping these tokens on standard AMMs requires:
- Slippage set to at least the tax percentage (commonly 10-15%).
- Using `…SupportingFeeOnTransferTokens` variant functions.
- Some DEXs show "TRANSFER_FAILED" when the actual amount received differs from expected.

## Nonce Issues

- **"nonce too low"** — A transaction with this nonce has already been mined.
- **"nonce too high"** — There are gaps in the nonce sequence; pending transactions may be blocking.
- **"replacement transaction underpriced"** — Trying to replace a pending tx with insufficient gas price bump.
