Research
Smart Contract Invariants Protect Against Cybercriminals
Smart contract exploits have stolen more than one billion dollars in on-chain assets, and no technique has yet proven to make a real difference. The authors argue that the classical notion of a…

- arXiv
- 2608.13191
- Published
- 2026-08-13
- Authors
- Sofia Bobadilla, Humaira Afrin, Angela Novelli, Martin Monperrus
AI summary
Overview
- Research area: Blockchain and smart contract security (cs.CR), specifically runtime program invariants as a defense against exploits, combined with empirical software engineering and on-chain transaction replay.
- Technical level: Intermediate. Readers should know roughly what a smart contract, a transaction revert, and a Solidity
requirestatement are; no deep formal-verification background is needed. - Scope (one sentence): The paper builds a benchmark of 28 real Ethereum exploits each paired with a human-written invariant, and uses a replay framework to test whether those invariants block the attacks and whether they leave legitimate historical usage intact.
What This Paper Is About
Smart contract exploits have stolen more than one billion dollars in on-chain assets, and no technique has yet proven to make a real difference. The authors argue that the classical notion of a program invariant — a condition checked at runtime — may be the most powerful available defense, because a violated invariant reverts the transaction before any state change is committed. The paper tests two open questions: would an invariant actually have stopped past real-world attacks, and can today's automated invariant-generation tools discover such attack-stopping invariants?
Key Contributions
- A replay-grounded methodology for studying invariant effectiveness that rests entirely on real on-chain data — real calldata, real block state, real execution outcomes — rather than templates or synthetic properties.
- InvariantEval, a benchmark of 28 real Ethereum exploits (drawn from DeFiHackLabs), each paired with a human-authored invariant that blocks the attack. Access is currently available on request from the first author.
- PonDeReplay, an on-chain verification framework that replays both the attack transaction and the contract's full pre-attack transaction history against hardened bytecode, providing causal attribution of any behavioral change to the injected invariant. Its conclusions rest on 108,637 replays.
- An evaluation of three state-of-the-art invariant tools (FLAMES, InvCon, InvCon+) against the InvariantEval ground truth, showing that together they recover only 2 of the 28 attack-stopping invariants.
Main Findings
- All 28 attacks are blocked. Every ground-truth invariant causes both the DeFiHackLabs proof-of-concept exploit and the actual on-chain attack transaction to fail at the vulnerable step — a 28/28 (100%) result. In each case the transaction reverts with the revert message written in the invariant.
- The benchmark covers $1.07B in real losses. The five highest-loss incidents are BeautyChain (BEC, ~$900M, overflow), SmartMesh (SMT, ~$140M, overflow), WIFCOIN (~$13.2M, logic flaw), Yearn yDAI (~$11M, slippage), and OnyxDAO (~$3.8M, logic flaw).
- Eight distinct invariant families are needed. Price/oracle/slippage is the largest group (8 of 28 cases), followed by ledger/supply/conservation (6), then access control (4) and external-call/interaction safety (4, three of which are reentrancy locks). Business logic and arithmetic safety cover 2 cases each; input validation and initialization/configuration cover 1 case each. No single guard type dominates.
- Behavior is largely preserved. Of 108,637 replayed historical transactions, 106,815 (98.3%) are fully preserved under the hardened bytecode and 1,526 (1.4%) diverge; the divergences are each causally attributed to the invariant rather than to replay noise.
- Most divergences are direct reverts. Of the 1,526 divergences, 1,424 (93%) revert at the top level inside the contract, 43 revert inside a nested subcall, and 59 arise from storage drift.
- Divergences have five explained causes, and not all are bugs: past exploit (the historical transaction reuses the same attack path, e.g. all 10 non-preserved APEMAGA calls), misusage (e.g. 449 of Nimbus's 466 non-preserved calls are ordinary swappers pushing reserves past the protocol's constant-product rule), whitehat operation (e.g. Anyswap, where Etherscan labels the caller as a whitehat recovering funds), over-restrictive invariant (e.g. all 88 Yearn yDAI non-preserved calls come from a keeper bot that the
only governance can call earn()guard now blocks; QTN has 782 such cases), and tight numerical envelope (e.g. 33 of Inverse Finance's 41 non-preserved calls fall outside a ±10% price band during ordinary volatility). - Replay has documented limits. 296 replays are inconclusive, spanning twelve cases. The most frequent cause is original out-of-gas (173 cases), where PonDeReplay deliberately allocates sufficient gas to execute the invariant rather than capping at the caller's original gas limit. Two further causes are named — subcall out-of-gas and accumulated drift — but the provided content truncates before their counts and analysis are given.
- Automated tools fall far short. FLAMES, InvCon, and InvCon+ together recover only 2 of the 28 attack-stopping invariants. The authors note they checked whether the ground-truth invariant appears in tool output rather than re-running the full verification protocol, because the tools do not produce specific enough instructions to harden a contract.
Methodology in Plain English
The researchers started from DeFiHackLabs, a public repository of executable proof-of-concept exploits. Of its 871 attacks across multiple blockchains, they kept the 359 that target Ethereum, spanning July 2017 to June 2026.
For a subset of these, two authors independently wrote a "hardened contract": the original source code plus one added invariant placed at the vulnerable function, working under an eight-hour time limit per case and consulting post-mortems, the victim contract's source, and the proof-of-concept. A third author resolved disagreements. The authors state that for 25 attacks they did not succeed in writing a securing invariant, citing limited expertise in the target protocol and the time budget.
Each hardened contract was then validated on two axes. For security, they replayed both the proof-of-concept and the real attack transaction; the contract counts as secure only if both fail. For behavioral preservation, they collected every historical transaction before the attack that reached the hardened function and replayed it too.
The replay needed a tool that did not exist. Existing options each cover only half the problem: eth_call state overrides lack sub-block granularity, cast run cannot substitute bytecode, and Foundry vm.etch tests require hand-reconstructed scenarios. PonDeReplay instead forks mainnet at block N−1, injects the new bytecode at the contract's real address, and replays any earlier transactions in block N to reconstruct the exact pre-transaction state. Each replay produces three traces — the literal on-chain trace (O), a recompiled replay of the unmodified contract (R), and the hardened trace (H) — compared on transaction status, subcall outcomes, and storage diffs within a threshold ε. Comparing R to O checks that the replay itself is faithful (otherwise the case is inconclusive); comparing H to R isolates the invariant as the sole changing variable, so any difference is causally attributable to it.
Finally, the benchmark invariants were compared against the output of three off-the-shelf invariant tools.
Why This Matters
Impact on research. Prior work evaluated invariant tools only against synthetic properties, templates, or mined patterns. This paper supplies the first ground truth anchored in multi-million-dollar real incidents, plus an infrastructure for counterfactual replay ("what would this real transaction have done against hardened code?"). The 2-of-28 tool result is a direct challenge to the subfield: current inference techniques do not find the properties that would actually have stopped documented theft.
Real-world applications:
- Pre-deployment hardening: developers can add a single
requireguard at the vulnerable function — the BEC overflow, for instance, is stopped byrequire(_value <= uint256(-1) / cnt)— instead of relying on audits alone. - Post-incident forensics and patching: teams responding to a live exploit can test candidate guards against the actual attack transaction and the contract's history before shipping a fix.
- Audit prioritization: the eight-family taxonomy tells auditors which property classes have historically mattered, with price/oracle and ledger conservation at the top.
- Upgrade and governance review: PonDeReplay-style replay can quantify how a proposed change affects past legitimate traffic, not just future behavior.
Industry relevance. The failures are also commercially informative: over-restrictive guards silently break keeper bots (Yearn yDAI) and legitimate users during normal volatility (Inverse Finance), and tight numeric envelopes need calibration rather than abandonment. Any protocol deploying runtime guards must budget for this false-positive cost.
Future Directions
- Close the tooling gap. With only 2 of 28 invariants recoverable by FLAMES, InvCon, and InvCon+, the obvious next step is inference techniques that propose property semantics (oracle bounds, ledger conservation, reentrancy locks) rather than templates, and that output hardening instructions specific enough to re-run the full verification protocol.
- Make numerical guards adaptive. The "tight numerical envelope" finding suggests volatility-aware or context-sensitive bounds that preserve legitimate oracle reads while still rejecting flash-loan price spikes.
- Improve replay fidelity. The 296 inconclusive cases — dominated by the deliberate choice not to cap replay at the original gas limit, plus subcall out-of-gas and accumulated drift from co-located same-block transactions — point to more faithful reconstruction, for example gas-accurate replay or finer same-block state modeling.
- Broaden coverage. The benchmark covers 28 of 359 Ethereum exploits (and DeFiHackLabs holds 871 across Ethereum, BNB Chain, and Polygon); extending the protocol to other chains and to the attacks the authors could not harden within their time box would test whether the eight-family taxonomy generalizes.
Target Audience
Smart contract auditors and protocol security engineers will get the most direct value, since the taxonomy and the case studies translate into concrete guards and known false-positive patterns. Researchers in program analysis, runtime verification, and invariant inference will find the benchmark and the tool evaluation most relevant. Blockchain practitioners deciding whether runtime checks are worth the usability cost, and graduate students looking for a rigorously grounded empirical security methodology, are also well served. Readers wanting formal guarantees should note that this is an empirical, replay-based study — the invariants are hand-written and validated by execution, not proved.
Authors’ abstract
Blockchains are among the most adversarial environments in computing. Billions are stolen by cybercriminals who exploit vulnerabilities. This is an open problem and no concept or technique has proven to really make a difference. In this paper, we claim that the classical notion of program invariant is perhaps the most powerful solution to the problem. We devise anoriginal experimental protocol to 1) study how invariants would have protected against past real-world attacks…
The full abstract on arXiv