Verifying Clojure Core with Lean Uncovers Previously Unreported Bugs
A developer investigating Clojure’s core functionality using Lean and differential testing has successfully identified several previously unreported bugs within the platform’s data structures, including specific issues in the HAMT and vector implementations. Inspired by formal verification efforts applied to Rust software, the investigation aimed to test whether mature persistent data structures used in Clojure since its early versions still harbored hidden edge-case flaws.
By modeling small foundational functions in Lean 4 and checking them across comprehensive input ranges, combined with differential testing against standard Java utility collections, the evaluation uncovered seventeen distinct bugs that were absent from official tracking systems. These anomalies were primarily located in boundary interactions, such as arithmetic operations, hashing mechanisms, and method calls lacking proper type hints, rather than within the core tree structures themselves.
One notable discovery involves vector-of implementations using primitive arrays in Clojure’s core library. Specifically, applying a reduction operation after dropping elements from vectors exceeding a specific threshold caused infinite loops due to bitmask logic errors that rounded down indexes incorrectly. While major data structures demonstrated high stability across millions of randomized operations, these findings highlight the effectiveness of applying formal verification and automated differential testing to established software ecosystems.