TL;DR
This paper introduces FASVERIF, an automated system that infers and verifies financial security properties of Ethereum smart contracts. By automatically generating security properties and models, FASVERIF aims to provide a more accurate and comprehensive analysis of vulnerabilities that can lead to financial losses, outperforming existing tools in both accuracy and coverage.
What Problem Does This Paper Address?
The Ethereum ecosystem has seen a massive proliferation of smart contracts, many of which manage significant financial assets. This makes them attractive targets for attackers, as evidenced by numerous high-profile hacks resulting in millions of dollars in losses. While existing tools attempt to detect smart contract vulnerabilities, they often fall short. Automated bug-finding tools rely on pre-defined patterns and lack precision, while formal verification frameworks typically require manual property definition or user assistance, making them impractical for analyzing a large number of contracts. Existing automated verifiers also have limitations, such as not specifically targeting financial security or lacking soundness. This gap highlights the need for a system that can automatically analyze a vast number of smart contracts for financial security with high accuracy and broad coverage.
Methods
FASVERIF employs a four-module design:
- Independent Modeling: This module takes smart contract source code and generates a partial model representing the contract's initial state and general rules for state transitions. It also models potential adversary behaviors. This model is independent of specific security properties.
- Property Generation: FASVERIF automatically generates a set of security properties that the smart contract should satisfy. It proposes two types of properties:
- Invariant Properties: These ensure that certain propositions (relationships between variable values) hold true after a transaction completes, assuming they held before. These are particularly useful for detecting issues like incorrect token balance calculations.
- Equivalence Properties: These check if the adversary's balances (ether or token) remain unchanged regardless of transaction order or other external factors. This helps detect vulnerabilities that allow adversaries to profit by manipulating execution flow.
- Complementary Modeling: This module refines the partial model by adding specific rules tailored to each generated property. This aims to reduce the model's size and focus the verification process.
- Verification: FASVERIF uses the formal verification tool Tamarin prover, augmented with Z3 for numerical constraint solving. This allows for the verification of the generated properties against the complementary models.
A key innovation is that FASVERIF generates properties based on observed financial losses rather than known vulnerability patterns, aiming for broader coverage. The system also uses a custom semantics of Solidity (KSolidity) to prove the soundness of its modeling.
Datasets
- Vulnerability Dataset: This dataset consists of 549 contracts collected from previous works, specifically focusing on contracts with vulnerabilities that can cause financial loss.
- Real-world Dataset: This dataset comprises 17,648 Solidity files containing 30,577 contracts, obtained by crawling Etherscan and filtering for duplicates. This dataset was used for statistical analysis and to evaluate FASVERIF's effectiveness on a large scale.
Key Insights and Ideas
- Finance-Related Contracts Dominate: Statistical analysis of a large real-world dataset revealed that a significant majority (91.11%) of smart contracts are finance-related, validating the focus on financial security.
- Property Generation from Observation: Instead of relying on pre-defined vulnerability patterns, FASVERIF infers properties based on observed financial losses, leading to broader detection capabilities, including novel or variant vulnerabilities.
- Two-Tiered Property Approach: The combination of invariant and equivalence properties provides a robust way to capture different types of financial security flaws, from incorrect state updates to exploitable manipulation of execution order.
- Automated Inference is Key: The core idea is to automate the entire process from model generation to property inference and verification, making it scalable for the vast number of smart contracts.
Key Results
- Outperforms Existing Tools: On a vulnerability dataset of 549 contracts, FASVERIF demonstrated higher accuracy and F1 scores compared to representative automated tools across various vulnerability types.
- Detects Previously Undetected Bugs: FASVERIF identified 13 exploitable vulnerabilities in a real-world dataset of 1700 contracts, including 10 contracts with "transferMint" vulnerabilities that evaded detection by other automated tools.
- Broad Coverage: FASVERIF is claimed to be the only tool among those compared that can detect all types of vulnerabilities listed in their comparison table.
- Efficiency Trade-off: While FASVERIF is more accurate and comprehensive, its analysis time per contract is longer (average 829.61 seconds) compared to other tools.
Limitations and Future Work
- Analysis Time: FASVERIF's analysis time is longer than many other automated tools.
- Financial Loss Focus: It does not detect vulnerabilities that do not directly cause financial losses (e.g., DoS vulnerabilities).
- Property Coverage: FASVERIF's effectiveness is limited to vulnerabilities covered by its generated properties and assumptions (e.g., it does not consider exchange rate fluctuations).
- Solidity Support: Full support for Solidity's features is challenging due to its Turing-completeness. FASVERIF has restrictions on unbounded loops, revert statements, contracts creating contracts via function calls, and calling unknown external codes. Despite these, it covers a significant portion of real-world contracts.
- Key Variable/Invariant Accuracy: The automated identification of key variables and property generation might occasionally misclassify contracts or miss vulnerabilities. The system allows manual specification to mitigate this.
- Future Work: The authors suggest extending FASVERIF to cover more vulnerabilities (e.g., airdrop hunting, self-destruction), incorporating exchange rate analysis, and further exploring Tamarin's capabilities for more complex verification scenarios.
Summary updated