← Lab /Software

OpenZeppelin ReentrancyGuard formally proven correct for three production contracts

The authors assert they have a machine-checked proof that the OpenZeppelin ReentrancyGuard blocks attacks and preserves correct execution on real Solidity contracts

Software arXiv 1 Jun 2026 Method Theory

Published as “Tridirectional Discriminating-Power Formal Verification of Smart Contract Reentrancy Defense Against Production-Deployed Solidity Source”

Why it matters

The proof provides high-assurance evidence that the widely-used OpenZeppelin ReentrancyGuard correctly prevents reentrancy attacks in real DeFi contracts, enabling auditors and developers to rely on a formally verified defense across multiple protocols.

Summary

The paper provides the first machine-checked correctness proof of the OpenZeppelin ReentrancyGuard pattern against a Lean 4 state-machine model of real Solidity source, covering three production protocols (DAO 2016, Compound v2, Aave V3) and a constructed mutant. It demonstrates a tridirectional discriminating-power claim-negative (attack reproduction), positive (guard correctness), and boundary (distinguishing safe vs. vulnerable variants)-and composes these proofs under a no-retrofit composition discipline in a single capstone meta-theorem. All thirteen theorems are fully verified with zero sorry and only the standard [propext] axiom, and the build is continuously gated by CI. No quantitative evaluation of performance or scalability is presented, so the strength of the evidence rests on the formal proof artifacts themselves.

What they found 2

  1. All thirteen theorems are fully machine-checked in Lean 4 with no sorry or user-introduced axioms.

    “Thirteen theorems machine-checked.”

  2. The capstone meta-theorem composes the three protocol-instantiation proofs, establishing the discriminating-power predicate across all instances.

    “The capstone meta-theorem states that if the Layer 6-A derivation, the Layer 6-B correctness theorem, and the Layer 6-C boundary pair all hold, then the methodology satisfies the discriminating-power predicate of §5.1 against the §2.4 production instantiations plus the §5.5 mutant.”

Caveats 7

  • The work focuses on a single attack class (reentrancy) and a single defense pattern (OpenZeppelin ReentrancyGuard), limiting broader applicability.
  • The boundary case relies on only one hand-crafted mutant (flashLoanVulnerable), giving a corpus size of N=1 for that direction.
  • The verification operates on Solidity source rather than EVM bytecode, introducing trust assumptions about the source-to-semantics translation.
  • The single-attack-class focus is a principled choice: reentrancy is the canonical class for which the OpenZeppelin guard was constructed and where the structural-adjacency boundary is well-defined and machine-checkable end-to-end.
  • The Layer 6-C boundary case includes one constructed variant - flashLoanVulnerable, a minimal-diff mutant (§5.5). Per the §1.3 reframing this is mutation testing for formal proofs (grounded in [9], [10]): the hand-constructed minimal-diff mutant is a principled choice, not a concession - it isolates the structural-adjacency boundary in a way naturally-occurring near-misses cannot, with the corpus N=1 by design.
  • Operating at Solidity source level (per §3.2) rather than raw EVM bytecode is a deliberate scoping choice: source level is where the guard pattern is expressed and its discriminating-power boundary sharpest, and it keeps the Lean-model-fidelity and solc-compilation assumptions (§3.3) explicit and separable.
  • The cross-protocol composition rests on three instantiations: DAO 2016 (historical exemplar), Compound v2 (lending), Aave V3 (lending / flash-loan facility). The two live protocols are both lending-family; the portability claim is therefore scoped to uniformity of the local guard invariant across divergent lending-family host architectures plus the historical reentrancy exemplar; broader-family instantiation is future work (§7.2).

What’s new here 4

  • First machine-checked proof of OpenZeppelin ReentrancyGuard against production-deployed Solidity source.
  • Introduces a tridirectional discriminating-power framework (negative, positive, boundary) applied to real contracts.
  • Demonstrates cross-protocol composition of proofs without retrofitting underlying lemmas (no-retrofit discipline).
  • Applies mutation-testing methodology to formal verification by constructing a minimal-diff mutant contract.