Cyber Risks · Trail of Bits Blog

Using Echidna to test a smart contract library

Summary: Trail of Bits demonstrates using the Echidna fuzzer to test AddressArrayUtils.sol, a library of 19 functions for managing arrays of addresses, by writing property-based tests rather than manual unit tests. The approach surfaces a bug in hasDuplicate where an empty array causes A.length - 1 to underflow, making the outer loop iterate over the entire uint256 range until the transaction runs out of gas.

Bottom line: Because libraries are shared by many high-value contracts, a single subtle bug like this one can let an attacker disable any contract that relies on hasDuplicate for an invariant such as a whitelist - possibly permanently.

Read the original at Trail of Bits Blog ↗