If AI Writes the Smart Contract, Who Checks the Logic?

AI-generated smart contracts can pass conventional tests while retaining security flaws. Formal verification allows developers to check specific properties of contract logic, including arithmetic, permissions, and state transitions.
Improvements in AI-generated code have not been matched by comparable gains in software security.
In Veracode’s 2025 analysis of more than 100 large language models, only 55% of code-generation tasks produced secure code. In the remaining 45%, the model introduced a known security flaw. More strikingly, security performance remained largely flat even as newer models became much better at generating syntactically correct code.
For blockchain developers, the gap between “works” and “works securely” matters more than it does in many other areas of software. A bug in a conventional application may cause downtime. A bug in on-chain logic can affect assets and state that are already live on a public network.
Smart contract developers therefore need ways to verify AI-generated logic independently of the model that produced it.
One possible answer is formal verification — describing critical properties of a program mathematically and proving that the implementation satisfies them. Ethereum’s own developer documentation lists formal verification as a way to obtain stronger guarantees of functional correctness than testing alone, while emphasizing an important caveat: a proof is only as useful as the specification it is proving.
The idea is also becoming more practical. In October 2026, Anthropic and Theorem reported using Claude to produce formal proofs of security properties for 239 entry points across 123 open-source libraries at the RISC-V assembly-code level. Their argument is not that AI makes proofs infallible, but that it may reduce one of formal verification’s biggest historical costs: the amount of expert work required to construct and maintain them.
Formal Verification and Conventional Testing
Even a large integration-test suite only covers scenarios someone thought to test. A test can check a normal transaction, an invalid address, or a handful of edge cases. It is much harder to use tests to establish a universal claim such as: Can this value ever overflow? Can this counter ever exceed its limit? Can a failed operation ever modify state?
Those questions are closer to invariants than test cases. They describe properties expected to remain true across every valid execution covered by the model.
One practical Solana example comes from engineer Alexander Kalankhodzhaev’s work on AI-assisted development and formal verification, illustrating one of several approaches in the Rust ecosystem. In I Don’t Review My AI’s Arithmetic: A Theorem Prover Does, the architecture separates a small runtime-facing layer from a pure decision-making core that can be checked with Creusot, a deductive verifier for Rust.
The runtime-facing layer handles accounts, PDAs, time, transfers, and persistence. It remains small enough to review manually. The business logic – such as how many tickets can be sold or which fields may change – is moved into separate functions with formal rules attached to them.
Those rules describe the boundaries of allowed behavior rather than every step of the implementation. A sale, for example, may increase the number of tickets sold, but it must not silently rewrite the price or organizer. If the implementation violates that rule, the failure should appear as a failed proof rather than as a bug someone may or may not notice in a large diff.
Lana Ivina, a blockchain researcher and Rust engineer with experience at StarkWare and Parity Technologies, says that applying Kalankhodzhaev’s approach in her own Rust work allowed her to assess its effectiveness in practice.
What stood out to me most was the ability to focus formal verification on critical logic and automatically re-check defined properties after every code change. In one case, I used a contract specifying that an operation must leave state unchanged on failure. That moved verification of the requirement from manual review into a repeatable automated check: if a later refactor causes one error path to modify state, the proof no longer passes. For me, one of the main advantages of the approach is reducing reliance on manual checks for specific properties and making critical parts of the codebase more predictable.
A verifier cannot determine whether a specification accurately reflects the developer’s intentions. If the specification is wrong, it can rigorously prove the wrong requirement.
That is why a practical design may use more than one independent layer of constraints. A local rule can define what a particular function may change, while a broader state-transition model defines what no operation should ever violate. For example, the ticket price and organizer may remain fixed, the sales counter may only increase, and status changes may only follow a predefined set of transitions.
That redundancy is intentional. If one contract becomes too permissive, another layer can still stop an invalid change.
Security Starts Before the Theorem Prover
Formal verification is more useful when it sits inside a broader security model.
The first layer is the development environment. In the Solana workflow described in An AI Writes My Solana Programs. Here’s the Environment That Makes That Safe, the development setup uses pinned toolchains, reproducible containers, and one consistent command surface for the developer, CI, and the AI agent.
The logic is straightforward: if the same command runs different checks in different environments, a “green” result stops being a reliable signal. Reproducible environments help ensure that developers, AI agents, and CI pipelines run the same security checks.
The next layer is input data. An on-chain program can contain correct business logic and still be vulnerable if it accepts the wrong account type, an invalid owner, or bytes that should never be considered valid state.
In The Safest Solana Parser Is the One That Refuses Bad Bytes, the proposed approach moves those restrictions into the parsing layer itself: invalid data should be rejected before the business logic has any chance to operate on it.
The same principle runs through all three layers: a critical rule is stronger when it is not left as something “the developer must remember.” Whenever possible, it should live in a place where violating it automatically becomes an error.
And none of this removes the need for more traditional security practices. Formal verification is better understood as a complement to testing, static and dynamic analysis, fuzzing, and independent review — each of which catches a different class of failure.
Why AI May Change the Economics of Formal Verification
Formal methods have existed for decades, but practical adoption has long been constrained by cost. Specifications have to be written, maintained alongside the code, and revisited whenever proofs fail after a change.
AI may be able to take over part of that repetitive work. An agent can draft a specification, modify an implementation after a failed proof, interpret verifier output, and run the process again.
Lana Ivina adds that her experience with the approach also showed that formal verification can be introduced incrementally, without restructuring or attempting to verify an entire codebase at once.
In my case, the most effective way to start was with a single operation where the cost of failure was especially high: isolate its business logic, define the invariants, and verify the allowed state transitions. That scope was small enough to integrate formal verification into the existing development process without disrupting the rest of the system. This is an important advantage of Kalankhodzhaev’s approach: teams can begin with one critical part of the codebase and expand the verification boundary as needed. Surrounding off-chain components – such as indexers, APIs, or external integrations – can remain outside the formally verified core and continue to be covered by code review and integration tests.
That does not mean AI should be allowed to decide the most important question: what the system is actually supposed to guarantee.
Instead, human attention shifts toward a smaller and more important artifact — the specification itself. What must always remain true? Which changes are allowed? Which states are unacceptable? Where does the proven part of the system end and the trusted part begin?
That model is particularly interesting for blockchain because it is not necessary to formally verify an entire application. A more realistic approach is to isolate a small critical core — financial arithmetic, access control, and state transitions — while leaving the rest of the system under integration tests, fuzzing, runtime checks, and audits.
A narrower verification boundary can make formal verification more practical: proofs are applied where the cost of failure is highest, while the trusted surface remains small enough for humans to inspect.
A Proof Is Not a Certificate of Absolute Security
Formal verification does not mean a product is “secure” in an absolute sense. It proves a specific claim about a specific model.
If the specification omits an important scenario, the verifier will not invent it. If the bug lives in the trusted part of the program, proving the pure core will not fix it. And if an external system behaves differently from what the model assumes, a mathematically valid proof may still be insufficient in production.
That is why the value of formal verification depends on more than the power of the theorem prover. It depends on the quality of the specification, the size of the trusted surface, and how well verification is integrated into the normal development workflow.
For AI-assisted development, this may be the more important shift. The faster machines generate code, the worse a security model based entirely on humans reading every line will scale.
Some of that trust can be replaced with verifiable constraints: reproducible environments, strict input validation, tests, runtime checks, and — where the cost of failure justifies it — formal proofs.
Conclusion
AI-assisted development is making code cheaper to produce, but not automatically easier to trust. Formal verification does not replace audits, testing, or runtime protections; it adds a way to turn selected assumptions about arithmetic, permissions, and state transitions into claims that must be proved.
For blockchain teams, that may become increasingly valuable. For blockchain developers, formal verification could reduce the manual effort required to check critical contract properties after each code change.







