Formalizing CPython broyojo.com · 10 points · 0 comments · HN thread TL;DR A pro...
HN Best 200 @best
Formalizing CPython broyojo.com · 10 points · 0 comments · HN thread
TL;DR A project by David Andrews and Chao Zhang used AI agents (Opus 5.5 is named) to copy CPython functions line by line into Lean, test each copy against real Python, and prove properties checked by Lean's proof checker and an independent AI reviewer. As of the post, 4,071 of 26,004 functions are accepted, and the work has produced 418 bug reports against Python, about 55 of them able to crash the interpreter or corrupt memory from ordinary code. The thread has no comments, so the discussion is empty.
- Each function is rewritten in Lean as a close copy of the C or Python source, then tested against real Python on tens of thousands of inputs before proofs are attempted.
- A second agent that did not write a function reviews its proofs and asks whether a broken version of the function could pass them too; early proofs were often vacuous, with fewer than half of reviewed functions holding up.
- Accepted statements are also run against real Python, which caught valid proofs about wrong copies, such as a memory-limit assumption and a nine-call nesting difference that appears only in a fresh process.
- The output is 613,318 lines of Lean in 1,539 files with 18,898 theorems and lemmas; 3,834 top-level properties are proved and 588 are disproved with counterexamples.
- Bug reports include scripts tested on Python 3.15.2, covering a segfault in setdefault on attribute dictionaries, ElementTree slice assignment corrupting children, and an email parser internal error.
- The authors give a checklist for other projects: pin one version, enumerate the full function list, copy code rather than docs, model misbehaving callbacks, and keep counterexamples.
Discussion No comments have been posted yet, so there is no discussion thread to summarize.
#formalVerification #Lean #Python #CPython #AIAgents #fuzzing