# Hardcoded gas used in ERC20 queries allows for block production halt from infinite recursion

Nibiru funtoken precompile hardcodes 100k gas for ERC20 balanceOf/transfer callbacks, breaking 63/64 rule and enabling infinite recursion that halts block production.

- Payout: Audit contest
- Severity: high
- Program: Nibiru
- Found by: 3docSec
- Disclosed: 2025-02-24
- Write-up quality: 8/10
- Original: https://github.com/code-423n4/2024-11-nibiru-findings/issues/4
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-nibiru%3AH-06
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:dos

**Target:** Cosmos SDK EVM funtoken precompile (x/evm/precompile/funtoken.go)
**Root cause:** ERC20 BalanceOf/Transfer callbacks from the funtoken precompile use a hardcoded Erc20GasLimitQuery of 100,000 gas charged only after the call returns, instead of forwarding at most 63/64 of available EVM gas, so recursion is never bounded.
**Steps:**
1. Deploy a malicious ERC20 whose balanceOf (or transfer) calls back into the funtoken precompile at 0x800, e.g. `address(0x800).call(abi.encodeWithSignature("sendToBank(address,uint256,string)", address(this), ...))`
2. Register the token as a funtoken (permissionless, small fee)
3. Call the recursing function; each precompile invocation grants a fresh 100k gas to the nested ERC20 call
4. Observe nibid memory grow ~10Mb/sec until killed and localnet stops producing blocks
**How found:** Code review of the funtoken precompile's ERC20 callback path; noticed Erc20GasLimitQuery hardcoded to 100_000 and charged post-call, violating EIP-150's 63/64 gas forwarding invariant that bounds recursion.
**Exploitation:** Attacker registers a malicious ERC20 as funtoken and triggers a self-recursive balanceOf/transfer; each nested precompile call receives a fresh hardcoded 100k gas, so recursion never terminates, exhausting validator memory and halting block production (consensus timeout), risking slashing.
**Insight:** When a precompile or host function calls back into the EVM, check whether gas is forwarded per EIP-150 (63/64) or hardcoded; any fixed gas grant on a re-entrant path lets an attacker recurse unboundedly and DoS the chain.

## Proof of concept (copied exactly from the original report)

**Malicious ERC20 transfer recursing via sendToBank precompile**

```
function transfer(address to, uint256 amount) public override returns (bool) {
        (bool res, bytes memory data) = address(0x800).call(
            abi.encodeWithSignature(
                "sendToBank(address,uint256,string)",
                address(this),
                Strings.toHexString(uint160(to))
            )
        );
        require(res, string(data));
        return true;
    }
```

