---
title: "Missing input validation"
url: https://dontgetrekt.today/dev/input-validation
section: "What does it trust?"
owasp: SC05:2026
---

# Missing input validation

The contract trusts an address or a value that the caller gives: a fake token, a fake pool, a fake market. The attacker passes a contract they wrote.

## How the attack works

1. A function takes an address parameter: a token, a pair, a vault, a market, a receiver.
2. The function does not check that the address is one that the protocol knows.
3. The attacker deploys a contract that returns any value they want (a balance, a price, a successful transfer) and passes its address.
4. The protocol credits the attacker with real funds against a fake deposit. Variants: no zero check, no bounds on a fee or a ratio, arrays of different length.

## Vulnerable code

```solidity
function deposit(address pool, uint256 amt) external {
    IPool(pool).transferFrom(msg.sender, address(this), amt); // fake pool returns true
    uint256 value = IPool(pool).valueOf(amt);                  // fake pool says 1e30
    credit[msg.sender] += value;
}
```

## Fixed code

```solidity
mapping(address => bool) public allowedPool;

function deposit(address pool, uint256 amt) external {
    require(allowedPool[pool], "unknown pool");
    require(amt > 0, "zero");
    uint256 before = IERC20(asset).balanceOf(address(this));
    IERC20(asset).safeTransferFrom(msg.sender, address(this), amt);
    uint256 received = IERC20(asset).balanceOf(address(this)) - before;
    credit[msg.sender] += IPool(pool).valueOf(received);
}
```

## Review checklist

- Check every address parameter against a whitelist or a factory registry.
- Measure the balance before and after a transfer. Do not trust the amount in the call or the return value of an unknown contract.
- Check zero values, zero addresses, array lengths, and the upper and lower bounds of fees and ratios.
- Validate inputs in admin functions too: a wrong value from a tired admin can drain a protocol.

## How to test for it

- Fuzz every external function with random addresses and amounts.
- Write a test with a malicious mock token or pool that returns false values. The call must revert.

## Real exploits (62)

- 2022-01-27 Qubit Finance ($80.0M): Qubit Finance lost about $80M on BSC because the legacy QBridge deposit function accepted a zero tokenAddress, so a deposit succeeded without any ETH being locked. [rekt.news](https://rekt.news/qubit-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2022-01/Qubit_exp.sol)
- 2022-03-23 Cashio ($48.0M): Cashio on Solana lost about $48M to an infinite mint of CASH because collateral account validation was incomplete, so fake accounts were accepted. [rekt.news](https://rekt.news/cashio-rekt)
- 2024-04-19 Hedgey Finance ($44.7M): Hedgey Finance lost about $44.7M across Arbitrum ($42.6M) and Ethereum ($2.1M) because createLockedCampaign did not validate user-supplied claimLockup parameters, so the contract approved tokens to the attacker. [rekt.news](https://rekt.news/hedgey-finance-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2024-04/HedgeyFinance_exp.sol)
- 2021-11-30 MonoX ($31.4M): MonoX lost about $31.4M on Polygon and Ethereum because swaps allowed the same token as tokenIn and tokenOut, which let the attacker inflate the MONO price. [rekt.news](https://rekt.news/monox-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2021-11/Mono_exp.sol)
- 2020-11-22 Pickle Finance ($19.7M): Pickle Finance lost 19.7 million DAI from its cDAI jar because swapExactJarForJar accepted attacker-made fake jars with no whitelist. [rekt.news](https://rekt.news/pickle-finance-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2020-11/Pickle_exp.sol)
- 2026-04-16 Rhea Finance ($18.4M): Rhea Finance on NEAR lost about $18.4M when its margin trading code summed intermediate swap minimums from an attacker-built route of fake pools and never checked the real swap output. [rekt.news](https://rekt.news/rhea-finance-rekt)
- 2025-05-28 Cork Protocol ($12.0M): Cork Protocol lost about $12 million (3,761 wstETH) because its CorkHook beforeSwap accepted attacker-supplied hook data and fake tokens without validation, letting exchange rates be manipulated. [rekt.news](https://rekt.news/cork-protocol-rekt)
- 2024-03-28 PrismaFi ($11.6M): PrismaFi lost about $11.6M (3258 wstETH) because MigrateTroveZap's onFlashloan() did not validate its input data, letting an attacker close and open troves for other users. [rekt.news](https://rekt.news/prismafi-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2024-03/Prisma_exp.sol)
- 2026-07-11 Bonzo Finance ($9.1M): Bonzo Finance on Hedera lost about $9.05M after Supra's oracle verifier accepted a forged price update with an all-zero BLS signature and public key. [rekt.news](https://rekt.news/bonzo-finance-rekt)
- 2022-07-02 Crema Finance ($8.8M): Crema Finance, a Solana concentrated liquidity AMM, lost about $8.8M when an attacker passed a fake price tick account that the claim method did not validate, and so claimed inflated LP fees. [rekt.news](https://rekt.news/crema-finance-rekt)

## References

- [OWASP SC05:2026](https://scs.owasp.org/sctop10/SC05-LackOfInputValidation/)
- [OWASP Smart Contract Weakness Enumeration](https://scs.owasp.org/SCWE/)
