Differential Test
What is differential testing?
Differential testing cross references multiple implementations of the same function by comparing each one's output. Imagine we have a function specification
F(X), and two implementations of that specification:f1(X)andf2(X). We expectf1(x) == f2(x)for all x that exist in an appropriate input space. Iff1(x) != f2(x), we know that at least one function is incorrectly implementingF(X). This process of testing for equality and identifying discrepancies is the core of differential testing.Differential fuzzing is an extension of differential testing. Differential fuzzing programatically generates many values of
xto find discrepancies and edge cases that manually chosen inputs might not reveal.
Example: Exp.sol and exp.py
We are testing the correctness of Exp.sol against an implementation exp.py that we trust:
We need the eth_abi package:
Writing the differential test:
The test contains two functions. In ffi_exp(), we are collecting the output of exp.py via FFI:
Last updated
Was this helpful?
