Abstract
Smart contracts are programs running on cryptocurrency (e.g., Ethereum) blockchains, whose popularity stem from the possibility to perform financial transactions, such as payments and auctions, in a distributed environment without need for any trusted third party. Given their financial nature, bugs or vulnerabilities in these programs may lead to catastrophic consequences, as witnessed by recent attacks. Unfortunately, programming smart contracts is a delicate task that requires strong expertise: Ethereum smart contracts are written in Solidity, a dedicated language resembling JavaScript, and shipped over the blockchain in the EVM bytecode format. In order to rigorously verify the security of smart contracts, it is of paramount importance to formalize their semantics as well as the security properties of interest, in particular at the level of the bytecode being executed.
Introduction
The rise of decentralized finance has placed billions of dollars under the control of smart contracts. These self-executing programs, primarily deployed on the Ethereum blockchain, operate in a trustless environment where "code is law." However, this environment is unforgiving. High-profile exploits, such as the DAO hack which resulted in a $60 million loss, underscore the catastrophic risks associated with subtle programming errors in the underlying bytecode.
A significant challenge in securing these contracts lies in the gap between high-level development and low-level execution. While developers write in languages like Solidity, the Ethereum Virtual Machine (EVM) executes bytecode. Previous attempts to secure these contracts often relied on informal specifications or incomplete models, leading to tools that are either too permissive or prone to false alarms. This research addresses this gap by providing the first complete, small-step formal semantics for EVM bytecode, implemented within the F* proof assistant.
Formalizing EVM Semantics in F*
To build a reliable foundation for security analysis, the researchers developed a small-step semantics for the EVM. Unlike "big-step" semantics, which only describe the final outcome of a program's execution, small-step semantics model the execution of each individual instruction. This granularity is essential for capturing complex behaviors such as nested contract calls, gas consumption, and exception handling.
The choice of F as the formalization language is strategic. F is a functional programming language specifically designed for program verification, allowing for the mathematical proof of properties alongside executable code. By formalizing the EVM in F*, the researchers created a "ground truth" model that can be used to verify the correctness of both contracts and the tools used to analyze them.
Security Properties as Hyper-properties
Traditional safety properties often focus on a single execution trace (e.g., "this program should never reach an error state"). However, many critical smart contract vulnerabilities are better understood as hyper-properties, which involve comparing multiple execution traces. The framework formalizes several key security properties:
- Call Integrity: This property ensures that even if an external contract called by the main contract is malicious, the sequence of calls intended by the original contract remains unchanged. This provides a formal basis for preventing reentrancy attacks.
- Atomicity: This ensures that if a transaction fails (e.g., due to running out of gas), the contract state does not remain in an inconsistent, "half-baked" state.
- Miner Independence: This formalizes the degree to which a contract's outcome can be manipulated by a miner through parameters like block timestamps.
Validation and Comparative Analysis
To validate the accuracy of the F model, the researchers compiled their formalization into OCaml and tested it against the Official Ethereum Test Suite*. The implementation successfully passed 304 out of 624 tests. The remaining failures were attributed to opcodes (such as specific bitwise operations) that were not yet fully formalized at the time, rather than errors in the semantic logic itself.
The framework also served as a benchmark to evaluate existing security tools, most notably Oyente. The analysis revealed that Oyente often relies on syntactic patterns—looking for specific sequences of opcodes—rather than true semantic behavior. This leads to both false positives (flagging safe code) and false negatives (missing actual vulnerabilities). For example, the researchers proved that Oyente’s reentrancy and timestamp dependency checks could be bypassed by logically sound but syntactically different code.
Conclusion
By providing a rigorous mathematical foundation for EVM bytecode, this work moves smart contract security beyond heuristics and toward formal verification. While the current formalization covers a large fragment of the EVM, future work aims to achieve 100% opcode coverage and bridge the "trust gap" between Solidity source code and EVM bytecode through verified compilation. This framework paves the way for a new generation of formally-verified static analysis tools that can provide strong security guarantees for the blockchain ecosystem.
Summary updated