Cyber Risks · Trail of Bits Blog

Using benchmarks to speed up Echidna

Summary: A Trail of Bits associate used GHC profiling tools to trace a memory leak in hevm, the Haskell EVM library that Echidna depends on, and found that repeatedly splicing and resplicing immutable bytearrays caused the bytearray memory type to grow without discarding old versions. The fix, proposed earlier by manager Artur Cygan, moved hevm's EVM state handling to the ST monad and a mutable vector, cutting the slowdown in the last test case from around 5.5 to around 3 and reducing memory use by several gigabytes on some test cases.

Key Takeaway: The leak let a simple hashing program consume hundreds of gigabytes of RAM, and because Echidna spends most of its fuzzing time inside hevm, that cost landed directly on fuzzing throughput. Profiling also showed the optics library's operators dominating CPU time only because they weren't inlined, a reminder that profiled builds can mislead unless checked against optimized ones.

Read the original at Trail of Bits Blog ↗