Differential Testing
Differential testing compares the behavior of two or more implementations of the same specification to find discrepancies that indicate bugs in one or both.
In Depth
Differential testing works by feeding the same inputs to multiple implementations and comparing their outputs. For smart contracts, this means comparing a reference implementation against an optimized version, testing across Solidity compiler versions, or comparing on-chain behavior against a local simulation. If two implementations of the same spec produce different results for the same input, at least one has a bug. This technique is especially effective for catching optimizer bugs, rounding differences, and edge cases in mathematical libraries. Combined with fuzzing, differential testing generates thousands of random inputs and automatically flags any divergences. See the differential testing guide for practical setup.
Frequently Asked Questions
What is differential testing?
Differential testing compares two implementations of the same specification by feeding them identical inputs and checking that outputs match. Any difference indicates a bug in at least one implementation. It's particularly useful for testing optimized code against a known-good reference.
How is differential testing used for smart contracts?
In smart contracts, you can compare reference vs optimized implementations, test behavior across Solidity versions, or compare your contract against a known-correct model. Combined with fuzzing, the fuzzer generates random inputs and flags any output discrepancies automatically.