Build1 publisher2 min readPublished
Trail of Bits' agent-built Lean model turned up a Falcon signature forgery in the Miden audit
Trail of Bits' agent-built Lean model of the Miden VM, backed by 95 machine-checked proofs, surfaced a way for a malicious prover to forge Falcon signatures. A dev.to account says the agents built tooling first, so that Miden's stack assembly could be reviewed at all.
The Engineer · Build desk

What happened
- Before the Miden zkVM audit began, Trail of Bits used AI agents to build an LSP server, a decompiler, a static analysis engine and a Lean model of the VM executor.
- Miden's core library is written in MASM, a stack assembly in which instruction operands are implicit and procedures declare no signatures.
- The decompiler was the largest single effort, taking over a hundred AI-generated commits across multiple months.
- The Lean work surfaced an unvalidated prover-supplied input that would let a malicious prover forge Falcon signatures and steal funds from Miden account holders.
Compiled by The EngineerSomething wrong?How this is made
Why it matters
- capability With stack effects and instruction docs shown in the editor, a MASM reviewer can keep reading without the lookup breaks the post says limit manual review quality.
- decision Limiting an agent-built decompiler to what it can decompile correctly gives up coverage in exchange for output that is never silently wrong.
- cost An auditor copying this approach pays for months of agent work before review starts, a cost easier to justify when the target language has no tooling to reuse.
- contradiction The post applies the Miden result to review of AI-generated code in general, while its evidence comes from a tooling-poor language whose code it never calls AI-generated.
According to a dev.to post summarizing Trail of Bits' own writeup [17], the hard part of MASM is that stack effects are not local. A while-loop need not be stack neutral, so its condition can sit in a different slot on each iteration, and each branch can carry its own stack effect [3]. The net stack effect of a call is generally impossible to determine statically. Each analysis failure propagates up the call chain [4]. The documentation is near zero, and the calling conventions are exactly zero [5][2].
The engineering I would defend at a review is how the team checked the tooling its agents wrote. Claude handled planning and development, and Codex reviewed the decompiler [9]. The decompiler covers a well-defined subset of MASM, chosen because it could be decompiled correctly. The alternative, per the post, was a full pipeline that would be silently wrong [8]. Every new feature went through the same loop:
1. An agent builds the feature [9]. 2. Agents decompile a randomized set of core library procedures [10]. 3. The output is diffed against the original MASM to find regressions [10]. 4. Anything found is added as a regression test [10].
The original MASM is the oracle in that loop [10]. The second model's review sits on top of it [9]. I think that ordering is right for agent-generated code, because the diff does not depend on either model's judgment.
The payoff landed away from the effort. The decompiler absorbed the most work [7], yet the post says its main value was its internal analysis frameworks and intermediate representation, reused for static analysis [13]. "If you pay an agent to build tooling, the intermediate artifacts are often the prize, not the surface output," the author wrote [14]. The forgery finding came from the Lean model of the VM executor. Its proof work produced 95 machine-checked correctness proofs over a large component of the core library [11][12].
The post extends the lesson to review of AI-generated code generally. "A bigger reader model just makes the wrong thing faster," the author wrote [15]. The author argues the bottleneck in PR review is the hours a change waits in queue and the size of the surface to trust, and was never the minutes spent reading a diff [16]. The Miden case supports a narrower claim. For the result to transfer to an ordinary pull-request queue, the constraint in that queue would also have to be missing tooling. In the post's telling, that was the constraint for MASM, a custom assembly language with no developer tooling [5].
What to watch
- Trail of Bits' own writeup, for how the Lean proof work exposed the unvalidated Falcon input and what Miden changed in response.
- Whether the MASM LSP server, decompiler and Lean model are published for use by other Miden auditors and developers.
- The same approach applied to a language that already has mature tooling, as a test of the post's broader claim about AI-generated code review.