What is formal verification in smart contracts?

Formal verification is proving, with mathematical tools, that a contract satisfies a written specification for every possible input and state. A test shows the code works for the cases it tried, while a proof shows that no case breaks the property, as long as the specification says what you meant (ethereum.org).

Last updated . 2 minute read. By the QuillAudits Team.

How does formal verification differ from testing?

Approach Covers Result
Unit tests The inputs you chose Passes for those cases
Fuzzing Many generated inputs No failure found in the runs made
Formal verification Every input and reachable state Proved, a counterexample, or no answer in time

ethereum.org groups the tools into specification languages, program verifiers such as the Certora Prover, the Solidity SMTChecker and KEVM, and theorem provers (ethereum.org). Trail of Bits lists Halmos, Certora and KEVM as formal verification tools for checking invariants (Trail of Bits).

What does a property look like?

The simplest specification is an assert. With the CHC engine turned on (--model-checker-engine=chc), the SMTChecker built into the compiler tries to prove every assertion for all inputs, treating require conditions as assumptions (Solidity docs).

A cap written as an assertion the SMTChecker can try to prove (illustrative, not audited code) CappedVault.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract CappedVault {
    uint256 public constant CAP = 1_000_000 ether;
    uint256 public totalDeposits;

    function deposit(uint256 amount) external {
        require(totalDeposits + amount <= CAP, "over cap");
        totalDeposits += amount;
        assert(totalDeposits <= CAP); // must hold for every amount and every earlier state
    }
}

Where does formal verification fall short?

A proof is only as good as its specification: a property nobody wrote is never checked, and ethereum.org stresses that the specification must describe the behavior you expect and that writing one takes skill and time. The Solidity docs also warn that a reported bug can be a false positive caused by abstractions in the checker, and that the solver can time out without an answer (Solidity docs). A practical split is to prove the few properties whose failure would lose funds and to test the rest.

FAQ

Is formal verification the same as symbolic execution?

They overlap without being the same thing. Symbolic execution is one technique some verifiers use, exploring paths with symbolic inputs, while formal verification is the goal of proving a property for all inputs, which can also rely on model checking or theorem proving.

Sources

QuillShield is building the security layer between AI and money, so you can keep shipping between audits.

Sign-up is free, and new accounts get $50 in credit, good for up to half of an order.

  1. 1Sign up and import a repo
  2. 2See the exact price before anything is charged
  3. 3Approve it, and the audit starts