[Paper Review] Analyzing Smart Contracts: From EVM to a sound Control-Flow Graph
This paper presents a sound, stack-sensitive control-flow graph (CFG) construction for Ethereum Virtual Machine (EVM) smart contracts by statically analyzing EVM bytecode. It addresses the challenge of precise control-flow modeling due to stack-based jumps—where jump targets are stored on the stack rather than encoded in instructions—by cloning blocks according to distinct stack states, ensuring complete and accurate path representation for static analysis.
The EVM language is a simple stack-based language with words of 256 bits, with one significant difference between the EVM and other virtual machine languages (like Java Bytecode or CLI for .Net programs): the use of the stack for saving the jump addresses instead of having it explicit in the code of the jumping instructions. Static analyzers need the complete control flow graph (CFG) of the EVM program in order to be able to represent all its execution paths. This report addresses the problem of obtaining a precise and complete stack-sensitive CFG by means of a static analysis, cloning the blocks that might be executed using different states of the execution stack. The soundness of the analysis presented is proved.
Motivation & Objective
- Smart contract analysis requires a complete and precise control-flow graph (CFG) to model all possible execution paths.
- The EVM's use of the stack to store jump addresses, rather than encoding them directly in instructions, complicates static analysis and can lead to incomplete or unsound CFGs.
- Existing approaches fail to account for stack-sensitive control flow, risking missing execution paths or over-approximating behavior.
- The paper aims to close this gap by constructing a sound, stack-sensitive CFG that captures all possible execution paths based on stack states at jump points.
- The key objective is to provide a formal foundation for precise static analysis of EVM programs by modeling control flow as a function of stack configurations.
Proposed method
- The method constructs a control-flow graph (CFG) where each block is replicated for each distinct stack state that can reach it, ensuring stack-sensitivity.
- It introduces a formal semantics for EVM bytecode that tracks program counter, stack depth, and stack content, enabling precise state tracking during execution.
- The analysis uses a symbolic representation of stack states to model all possible stack configurations at each program point.
- Blocks are cloned based on the stack state at the time of a jump, with each clone representing a distinct execution path corresponding to a unique stack configuration.
- The method defines two types of edges: 'next' edges for sequential execution and 'jump' edges for control transfers, both indexed by stack states to preserve precision.
- Soundness is formally proven via induction on execution trace length, showing that every valid execution trace corresponds to a directed walk in the CFG.
Experimental results
Research questions
- RQ1How can a control-flow graph for EVM bytecode be constructed that is both complete and precise despite stack-based jump instructions?
- RQ2What formal semantics is required to model stack-sensitive execution states in EVM programs?
- RQ3How can block cloning be used to represent multiple execution paths arising from different stack states at jump points?
- RQ4What conditions ensure that the resulting CFG is sound with respect to all possible execution traces?
- RQ5Can a static analysis based on this CFG model detect all possible execution paths without over-approximation?
Key findings
- The proposed method constructs a sound, stack-sensitive CFG that captures all possible execution paths of EVM programs by replicating blocks according to distinct stack states at jump points.
- The analysis correctly models the EVM's stack-based jump mechanism, where jump destinations are stored on the stack rather than encoded in the instruction, resolving a key source of imprecision in prior approaches.
- The formal proof of soundness demonstrates that every valid execution trace corresponds to a directed walk in the CFG, ensuring no execution path is missed.
- The method handles both unconditional jumps (JUMP) and conditional jumps (JUMPI), with distinct edge construction rules based on stack state and jump target.
- The approach enables precise static analysis of EVM programs, including those with recursion or higher-order patterns, by bounding stack size and treating jump addresses as constants.
- The resulting CFG is formally sound and complete under the constraints of constant stack size and constant jump targets, making it suitable for formal verification and vulnerability detection.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.