⏱️ Reading time: 8 min
Clojure 1.12.7, released on 2026-11-18, has seventeen unreported bugs in its core: spread across the immutable hash map, the immutable vector and Java interop, according to a developer going by Conao3, who ran them through Lean 4, a proof assistant, combined with differential testing against Java’s collections (source). It matters to anyone running Clojure 1.12.x in production, especially those using vector-of to store large numeric series or relying on dissoc on maps where keys could collide on their hash. The links in the investigation itself point to the clojure-1.12.7 tag, the exact version Conao3 used to reproduce each bug.
📑 En este artículo
- How bugs are found in Clojure using Lean 4 and differential testing
- The 2010 mask that hangs reduce in vector-of
- The HAMT survived 3 million tests, but dissoc has a gap
- What this means for anyone running Clojure in production
- Lean 4 versus differential testing and property-based testing
- The limits: the JVM is outside the model
- References
How bugs are found in Clojure using Lean 4 and differential testing
The idea didn’t start with Clojure. Conao3 had read a Japanese-language article by Koukyosyumei that formally verified well-known Rust projects with Lean 4, and wherever the proof failed, a real bug showed up in the original code (source). He decided to apply the same procedure, described in the hirosassa/lean-verify repository, to the part of Clojure’s core written in Java.
Lean 4 is a proof assistant: you write a small function and a mathematical property about it, and the bv_decide tactic automatically searches for a counterexample among every possible value of a bounded type. Conao3 modeled Java’s integers (long and int) as BitVec 64 and BitVec 32, so that overflow in an addition or multiplication, and the rounding of / and %, behave the same way they do on the JVM.
Lean only works for small functions that reduce to integer and bit arithmetic; large structures, the hash map’s HAMT and the vector’s tree, don’t fit that model. For those, Conao3 used differential testing: he applied the same random sequence of operations to PersistentHashMap and to java.util.HashMap and compared the result. For the HAMT he ran 1,500 operations for each of 2,000 seeds, with keys that mix partial collisions at every 5-bit level with fully identical hashes; for the vector he compared against ArrayList around the boundaries where the tree gains a level: 32, 1,056, 32,800 and 1,048,608 elements (source). Before publishing, he checked whether anyone had already reported each bug: he queried Clojure’s JIRA REST API and searched ask.clojure.org, and found no matches for any of the 17.
📌 Note: none of the 17 bugs appear yet in Clojure’s official JIRA or on ask.clojure.org.
flowchart TD
A["Clojure core function"] --> B{"Reduces to bit arithmetic"}
B -- "Yes" --> C["Model in Lean 4 and run bv_decide"]
B -- "No, it's a large structure" --> D["Differential testing against java.util"]
C --> E["Bug: counterexample and proof of the fix"]
D --> F["Bug: operation sequence that diverges"]
The 2010 mask that hangs reduce in vector-of
vector-of stores its values in primitive arrays and lives in gvec.clj, separate from PersistentVector. If a vector-of with 65,505 elements or more gets drop followed by reduce, the call never finishes (source). With 65,504 elements, the same pattern returns a normal result (source).
The cause is on line 79 of gvec.clj, where the seq’s reduce calculates the start of the next 32-element block using a hexadecimal mask, 0xffe0, meant to round down to a multiple of 32 (source). The problem is that the mask also clears bit 16 and everything above it. With 65,505 elements, the last block starts at index 65,504; the next one should start at 65,536, but the mask turns that into 0, so reduce jumps back to the start of the vector over and over. The mask hasn’t been touched since the 2010 commit that added internal-reduce (source).
Conao3 tested this in Lean with a simple property: from a position that’s a multiple of 32 and less than 0x7fffffe0, the next block starts 32 positions ahead. The proof over the original mask fails with the counterexample a = 1,073,741,792, the same value that makes the mask return 0 instead of 65,536 (source). Over a corrected mask, the bitwise complement of 0x1f, the proof closes.
The HAMT survived 3 million tests, but dissoc has a gap
Clojure’s hash map is a HAMT: it splits each key’s hash into 5-bit chunks and uses them to walk down the tree. Keys whose 32-bit hash fully matches share a HashCollisionNode at the bottom of the tree, and that node tells them apart by comparing them with =.
What stands out is where the problem wasn’t. The HAMT, as a tree, showed no discrepancy across 3 million operations of differential testing, and the vector’s tree didn’t fail around its boundaries either (source). The 17 bugs aren’t in the core structure: they’re in the surrounding code, at the points where two different mechanisms meet, like equality and hashing.
One of those points is HashCollisionNode.without, the method that builds the new node when dissoc removes a key from a group with an identical hash. It should assign the resulting node its own hash, but according to the source, in some cases the result leaves another key from the same group unreachable: dissoc deletes one key and, in the process, hides a second one. Conao3 also reports a third group of bugs in Java interop, in calls to functional interfaces without a type hint, found by comparing the same call with and without that annotation.
What this means for anyone running Clojure in production
If your Clojure service stores time series, signal buffers or any large numeric collection in a vector-of, and at some point applies drop followed by reduce, check the size: above 65,504 elements, that combination hangs the process today. It doesn’t take anything exotic; it’s a common pattern in data pipelines.
If you use dissoc on maps where the keys can be chosen by a third party, for example a cache indexed by user-supplied input, the HashCollisionNode bug matters more than it looks, because an attacker forcing hash collisions could exploit that gap. Since the project hasn’t confirmed a fix yet, the mitigation for now is to avoid that pattern of third-party-controlled keys until a patch ships.
Lean 4 versus differential testing and property-based testing
All three methods coexist in this investigation and in the Clojure ecosystem at large, but they guarantee different things:
| Approach | What it guarantees | Practical scale | What it found in this case |
|---|---|---|---|
| Lean 4 + bv_decide | Exhaustive proof over every value of the modeled type (for example, every BitVec 64) | Only small functions reducible to integer and bit arithmetic | The 0xffe0 mask that hangs reduce in vector-of, with its counterexample and the proof of the fix |
| Differential testing against java.util | Compares real behavior with a reference implementation under the same sequence of operations | Large structures (HAMT, vector tree), limited to the seeds and operations run | Zero discrepancies across 3 million operations on the HAMT; confirmed the problem was outside the tree |
| test.check (Clojure) | Generates random cases guided by properties the developer declares | Any Clojure function, with no need to model it in another language | Not used in this investigation; still the community’s standard tool for property-based testing |
test.check wasn’t used in this investigation: Conao3 went straight to Lean 4 because his goal was reproducing Koukyosyumei’s method, not comparing tools. But for anyone maintaining a Clojure library without time to learn Lean, it’s still the most accessible way to catch edge cases with properties declared in the language itself.
The limits: the JVM is outside the model
Lean with bv_decide proves an isolated function, not the whole system. In a comment about the finding on Hacker News, user gritzko summed it up this way: the practical side of Clojure runs on a huge JVM that’s probably impossible to fully verify, even if the theoretical side of the experiment is “very exciting” (Hacker News comment). Differential testing doesn’t prove the absence of bugs either; it only confirms that, within the 2,000 seeds and the size limits Conao3 ran, the HAMT and the vector tree match their Java counterparts. A pattern of operations outside that range could hide another bug this investigation didn’t catch.
References
- Conao3 Notes: I checked Clojure’s core with Lean and differential testing and found unreported bugs in HAMT and vector-of: the primary source, with the detail on the 17 bugs, the mask code and the Lean 4 proofs.
- hirosassa/lean-verify: the Lean 4 modeling procedure Conao3 adapted to audit Clojure’s core.
- clojure/clojure: Clojure’s official repository, with the clojure-1.12.7 tag referenced in the investigation.
- Hacker News thread: initial discussion of the unreported bugs finding.
- Second Hacker News thread: discussion of the 17 unreported bugs.
Featured image: Foto de Markus Spiske en Unsplash
How each article is made (sources, testing and editorial criteria): How we work.
Did it work for you? Got a different error? Say so below: questions get answered and help the next reader.
Leave a comment
0 Comments