开发者 hirosassa 对基于 Java 实现的 Clojure 核心库进行了形式化验证,结合 Lean 4 证明助手和差分测试技术,共发现了 17 个此前未在 JIRA 或 ask.clojure.org 上报告的 Bug 1。此次测试使用了于 2026 年 11 月 18 日发布的 Clojure 1.12.7 版本以及 JDK 21 1。尽管 PersistentHashMap 和 PersistentHashSet 在历经 300 万次差分测试操作后未发现数据不匹配的情况,但底层逻辑中仍存在若干关键缺陷 1。
具体而言,vector-of 结构的 reduce 操作存在严重问题:当元素数量大于或等于 65505 时,由于 gvec.clj 文件第 79 行使用了错误的位掩码 0xffe0,导致程序陷入无限循环 1。HAMT(哈希数组映射树)结构中也存在显著错误,其 HashCollisionNode.without 方法错误地引用了参数 hash 而非实例字段 this.hash,从而引发键查找失败及潜在的数据丢失风险 1。此外,测试还揭示了 drop 函数在处理极大整数时因溢出导致负索引异常,以及在缺乏类型提示的情况下,.removeIf 方法的反射调用行为与有类型提示的直接调用存在不一致性 1。作者通过建模整数和位运算详细复现并修复了这些底层逻辑错误,证实 Lean 模型能够成功验证修复后的代码满足规范属性 1。
A developer identified as hirosassa discovered 17 bugs in the Clojure core library that had not been previously reported on JIRA or ask.clojure.org 1. The investigation utilized the Lean 4 proof assistant alongside differential testing techniques to formally verify Java-based persistent data structures within Clojure version 1.12.7, which was released on November 18, 2026, and ran on JDK 21 1. Despite extensive testing, no mismatches were found between PersistentHashMap and PersistentHashSet during three million differential test operations, indicating that these specific structures behaved consistently under the tested conditions 1.
The findings include critical logical errors such as an infinite loop in the reduce function for vector-of when the element count reaches or exceeds 65,505 1. This issue stems from an incorrect bit mask value of 0xffe0 used at line 79 of the gvec.clj source file 1. Another significant defect involved the HashCollisionNode.without method in the Hash Array Mapped Trie (HAMT) implementation, which erroneously referenced the parameter hash instead of the instance field this.hash, resulting in failed key lookups 1. Additionally, the drop function exhibited overflow behavior with extremely large integers, causing exceptions related to negative indices 1.
Beyond logic errors, the verification highlighted inconsistencies in reflection usage. Specifically, calls to .removeIf without type hints executed via reflection produced different results compared to direct calls with type hints 1. The author demonstrated that by modeling integer arithmetic and bitwise operations within the Lean framework, it was possible to reproduce these low-level errors and validate that the proposed fixes satisfied the intended specification properties 1.
评论
还没有评论,欢迎留下第一条。