# What is fuzzing in smart contracts?

URL: https://shield.quillaudits.com/learn/glossary/fuzzing/

Fuzzing is testing with generated inputs: instead of checking a function with a few values you picked, a fuzzer calls it with many values of its own choosing and reports any input that makes a stated property fail. In Solidity projects it usually means property tests that take parameters, which the test framework fills in on every run.

Last updated 3 December 2026. 2 minute read. By the QuillAudits Team.

## How does a fuzz test work in Foundry?

Forge fuzzes any test function that takes parameters and runs it 256 times by default with different inputs ([Foundry](https://getfoundry.sh/forge/fuzz-testing)), and the `runs` setting under `[fuzz]` changes the count ([Foundry config](https://www.getfoundry.sh/config/reference/testing)).

**A fee function and a fuzz test of its properties (illustrative, not audited code)** `FeeMathFuzz.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract FeeMath {
    // 0.3% fee, rounded down.
    function split(uint256 amount) public pure returns (uint256 net, uint256 fee) {
        fee = (amount * 3) / 1000;
        net = amount - fee;
    }
}

contract FeeMathFuzzTest {
    FeeMath internal math = new FeeMath();

    // Forge calls this with a new `amount` on every run.
    function testFuzz_splitAddsUp(uint256 amount) public view {
        amount = amount % 1e30; // keep amount * 3 from overflowing
        (uint256 net, uint256 fee) = math.split(amount);
        assert(net + fee == amount);
        assert(fee <= amount / 100);
    }
}
```

The inputs aren't purely random. By default 40% of them come from a dictionary of values seen in the project, including storage values of the contracts a run touches ([Foundry config](https://www.getfoundry.sh/config/reference/testing)), and a failing run is reported with its seed so it can be replayed ([Foundry](https://getfoundry.sh/forge/fuzz-testing)).

## What does fuzzing find, and what does it miss?

It finds the edge values people skip: zero, one wei, the largest amounts and the inputs where rounding or casting goes wrong. It struggles with bugs that need a particular series of calls, and with conditions so narrow that random inputs rarely meet them.

| Technique | Inputs | Finds |
| --- | --- | --- |
| Fuzzing | Generated values for one call | Edge values that break a property of one function |
| [Invariant testing](https://shield.quillaudits.com/learn/glossary/invariant-testing/) | Generated sequences of calls | States that break a system-wide property |
| [Symbolic execution](https://shield.quillaudits.com/learn/glossary/symbolic-execution/) | Solved from the branch conditions | Narrow inputs that random values rarely hit |

Trail of Bits names Medusa, Echidna and Foundry as fuzzers for testing invariants ([Trail of Bits](https://blog.trailofbits.com/2025/02/12/the-call-for-invariant-driven-development/)).

## FAQ

### How many fuzz runs are enough?

There is no fixed number. Start from the Foundry default of 256 ([Foundry](https://getfoundry.sh/forge/fuzz-testing)), raise it in CI for code that handles funds, and bound inputs to realistic ranges so the runs spend their time where bugs live.

## Sources

- [Testing: fuzz testing, Foundry docs](https://getfoundry.sh/forge/fuzz-testing) · checked 3 December 2026
- [Testing configuration reference, Foundry docs](https://www.getfoundry.sh/config/reference/testing) · checked 3 December 2026
- [The call for invariant-driven development, Trail of Bits](https://blog.trailofbits.com/2025/02/12/the-call-for-invariant-driven-development/) · checked 3 December 2026
