Research
Tridirectional Discriminating-Power Formal Verification of Smart Contract Reentrancy Defense Against Production-Deployed Solidity Source
Smart contract reentrancy—where an attacker re-enters a contract mid-execution to drain funds—has caused over US$500M in documented losses since 2016, yet the widely used OpenZeppelin ReentrancyGuard…

- arXiv
- 2606.01794
- Published
- 2026-06-01
- Authors
- Ray Iskander
AI summary
Overview
Research area: Smart contract security, specifically formal verification of reentrancy defenses in Solidity contracts (cs.CR).
Technical level: Advanced. The paper assumes familiarity with proof assistants (Lean 4), dependent type theory, EVM execution semantics, and DeFi protocol architecture.
Scope (one sentence): The paper presents a machine-checked Lean 4 proof corpus of thirteen theorems establishing that the OpenZeppelin reentrancy-guard pattern catches a historical attack, clears a live production lending protocol, and distinguishes a safe contract function from a deliberately mutated vulnerable variant, composed into a single cross-protocol meta-theorem.
What This Paper Is About
Smart contract reentrancy—where an attacker re-enters a contract mid-execution to drain funds—has caused over US$500M in documented losses since 2016, yet the widely used OpenZeppelin ReentrancyGuard pattern has never been formally proven correct against real production source code in a way that also proves it can tell apart safe and unsafe contracts. This paper builds a Lean 4 state-machine model of actual deployed Solidity code (DAO 2016, Compound v2 cTokens, Aave V3 flashLoan) and machine-checks three directions of evidence: that the methodology catches a vulnerable contract, clears a correctly guarded one, and separates a safe function from a minimally altered broken twin. It then proves a single capstone theorem composing those three results, under a discipline that forbids editing earlier proofs to make the composition work.
Key Contributions
- First machine-checked correctness proof of the OpenZeppelin reentrancy-guard pattern against a Lean 4 model of production-deployed Solidity source, comprising thirteen theorems with zero
sorry, zero user-introduced axioms, and an axiom footprint bounded by[propext]across the entire corpus. - A "tridirectional discriminating-power" structure that combines, in one corpus, a negative instance (six theorems reproducing the DAO 2016 attack), a positive instance (three theorems on the Compound v2 cToken family), and a boundary case (three theorems distinguishing Aave V3
flashLoanfrom a constructed minimal-diff mutantflashLoanVulnerable). - A cross-protocol composition meta-theorem (
tridirectionalDiscriminatingPower_certificate) proven under a "no-retrofit composition discipline": each protocol proof was sealed before the capstone was authored, and the capstone is a direct conjunction requiring no modification of underlying proofs. The paper frames this as a stronger claim than composition of co-developed proofs, and distinguishes it from co-developed compositional verification work such as CompCert and Iris. - Mutation-testing methodology applied to formal verification, via the hand-authored
flashLoanVulnerablemutant that differs from productionflashLoanin a single security-critical respect, plus a four-block CI configuration that re-checks every theorem and its axiom record on every push.
Main Findings
- Thirteen theorems machine-checked: six Layer 6-A theorems (DAO 2016 negative instance), three Layer 6-B theorems (Compound v2 cToken positive instance), three Layer 6-C theorems (Aave V3 boundary case), and one Layer 6-D capstone meta-theorem.
- Build and axiom status:
lake buildis green at 901 jobs; the axiom-record check passes for every theorem; zerosorry; zero introduced axioms; axiom footprint bounded by[propext]. - The negative instance works as intended: the DAO 2016 reentrancy attack is formally derivable from the contract's source semantics. The paper is explicit that the DAO predates the OpenZeppelin guard library, so this leg is a guard-absent baseline demonstrating the methodology recognizes the vulnerability class, not a guard-correctness result.
- The positive instance works as intended: the Compound v2 cToken family's withdrawal function is proven to correctly implement the OpenZeppelin guard pattern under the paper's formal definition of reentrancy.
- The boundary case discriminates: the constructed mutant
flashLoanVulnerableis proven to fail the formal discriminating-power property that productionflashLoansatisfies, despite identical function signature, borrower-callback shape, near-identical control flow, and identical surface API. - Composition held at the first cross-protocol stress test: the Compound v2 → Aave V3 boundary passed without retrofitting either underlying proof. The paper carefully separates this as observed (N=1 empirical instance), argued (the sealed-before-capstone discipline forecloses the co-development explanation), and conjectured (broader portability pending further cross-pair validation).
- Composition scope is limited: both live protocol instantiations are lending-family, so the cross-protocol claim covers within-lending portability plus the DAO 2016 exemplar. Cross-domain extension is left as future work.
- Historical loss context cited: the DAO 2016 attack drained ≈3.6M ETH (≈US$60M at attack-time price); Lendf.Me April 2020 lost ≈US$25M (ERC-777 callback reentrancy); Fei/Rari Capital Fuse pools 2022 lost ≈US$80M; cumulative documented reentrancy losses exceed US$500M.
- Formalization rests on five stated trust assumptions: Solidity compiler correctness (pre-0.4.x lineage for DAO 2016, 0.5.x for Compound v2, 0.8.x for Aave V3), Lean-model fidelity to the modeled Solidity fragment, Lean 4 kernel and mathlib4 correctness, an honest-borrower assumption scoped to protocol-level accounting, and explicitly no miner or validator behavior assumption.
Methodology in Plain English
The author builds a simplified but faithful mathematical model—a state machine—of three real contracts' Solidity code. That model tracks storage slots, the sequence of function calls including external calls, and transaction atomicity, which are the ingredients that make reentrancy possible. Then, using the Lean 4 proof assistant, the author writes precise mathematical statements about what these contracts do under attack and proves them, with the compiler's type checker acting as the referee.
Three proof layers are built. The first proves that an attacker can drain the DAO contract—an attack the model should catch. The second proves that the Compound cToken withdrawal correctly blocks re-entry—a contract the model should clear. The third takes Aave's safe flashLoan and a hand-made broken copy that differs in one security-critical way, and proves the model can tell them apart—a case where mere code-pattern matching would fail.
A key procedural rule is that each theorem statement was fixed before any proof was written, and each protocol file was sealed before the final combined theorem was attempted. This prevents the common temptation to quietly weaken a statement or tweak a lemma until the composition goes through. Finally, the whole corpus is checked automatically on every code push, including a check that each theorem only depends on permitted axioms, so that a future dependency change cannot silently weaken the guarantees.
Why This Matters
Impact on research: The paper argues that prior work formalized either guard correctness on toy models or attack feasibility on isolated vulnerable contracts, but not both directions plus boundary cases against production source. It also treats cross-protocol composition as a load-bearing result rather than an afterthought, with its no-retrofit discipline offering a concrete alternative to the co-development pattern common in large compositional verification projects.
Real-world applications:
- Auditing DeFi protocols that use
ReentrancyGuard, giving auditors machine-checked evidence rather than pattern recognition alone at structural-adjacency boundaries where pattern recognition degrades. - Regression testing of production-grade logic, where the minimal-diff mutant experiment suggests a way to detect single-line security regressions.
- CI-integrated verification gating, where axiom records are checked on every push to prevent silent weakening of guarantees over time.
- Standardization and reviewer confidence for widely-adopted defensive libraries, since a single missed modifier produces no compiler warning in Solidity.
Industry relevance: The pattern is described as the de facto reentrancy defense across most production DeFi protocols (Compound, Aave, Uniswap-style AMMs, and most TVL-significant deployments), and the Compound v2 cToken family is cited as securing roughly US$2-5B in lending TVL. In-scope contract addresses include cUSDC at 0x39AA39c021dfbaE8faC545936693aC917d5E7563, cDAI at 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643, and the Aave V3 Pool at 0x87870bca3f3fd6335c3F4ce8392D69350B4fA4E2.
Future Directions
- Cross-domain portability: extending the composition claim beyond the lending family. The paper states the current result is within-lending only and that broader-family portability is future work.
- Further cross-pair validation: the Compound v2 → Aave V3 result is N=1; additional protocol pairs are needed to move the composition claim from observed to broadly established.
- Mechanized model-to-source soundness: replacing the hand-argued Lean-model fidelity assumption with a verified-translation pipeline in the KEVM / F*-EVM-semantics line, which the paper explicitly puts out of scope.
- Extending beyond reentrancy: the paper lists oracle manipulation, MEV and transaction-ordering attacks, governance attacks, cross-chain bridge attacks, front-running, centralization risks, and non-reentrancy economic attacks as out of scope but potential future targets.
Target Audience
Formal verification researchers and proof engineers working on smart contracts; smart contract security auditors and security firms evaluating whether to adopt machine-checked evidence; DeFi protocol developers and maintainers of defensive libraries such as OpenZeppelin's ReentrancyGuard; and technically sophisticated reviewers who need to assess the exact scope and trust assumptions behind a formal correctness claim. The paper is not beginner-friendly: it assumes comfort with Lean 4, dependent type theory, axiom records, and EVM call semantics.
Authors’ abstract
We present the first machine-checked correctness proof of the OpenZeppelin reentrancy-guard pattern against a Lean 4 state-machine model of production-deployed Solidity source. All thirteen theorems are machine-checked with zero sorry, zero user-introduced axioms, and an axiom footprint bounded by [propext] (a standard mathlib4 axiom), gated under continuous integration. Smart contract reentrancy has caused over…
The full abstract on arXiv