lisa-analyzer/evm-lisa

GitHub: lisa-analyzer/evm-lisa

基于抽象解释的 EVM 字节码静态分析器,能够对以太坊智能合约构建可靠的控制流图并检测常见安全漏洞。

Stars: 35 | Forks: 3

# EVMLiSA:基于抽象解释的 EVM 字节码静态分析器 ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/lisa-analyzer/evm-lisa/gradle-master.yml) ![GitHub last commit](https://img.shields.io/github/last-commit/lisa-analyzer/evm-lisa) ![GitHub commit activity](https://img.shields.io/github/commit-activity/y/lisa-analyzer/evm-lisa) ![GitHub issues](https://img.shields.io/github/issues-raw/lisa-analyzer/evm-lisa) [![Built on LiSA](https://img.shields.io/badge/Built%20on-LiSA-informational)](https://github.com/lisa-analyzer/lisa) EVMLiSA 是一个基于抽象解释的静态分析器,用于分析部署在以太坊区块链上并基于 [LiSA](https://unive-ssv.github.io/lisa/) 构建的智能合约的 [EVM 字节码](https://www.ethervm.io/)。给定一个 EVM 字节码智能合约,EVMLiSA 会构建该智能合约的可靠且精确的控制流图。 EVMLiSA 基于以下同行评审出版物: 1. Vincenzo Arceri, Saverio Mattia Merenda, Luca Negrini, Luca Olivieri, Enea Zaffanella. _**"EVMLiSA: Sound Static Control-Flow Graph Construction for EVM Bytecode"**_. Blockchain: Research and Applications, 2025 (doi: [10.1016/j.bcra.2025.100384](https://doi.org/10.1016/j.bcra.2025.100384)). 2. Vincenzo Arceri, Saverio Mattia Merenda, Greta Dolcetti, Luca Negrini, Luca Olivieri, Enea Zaffanella. _**"Towards a Sound Construction of EVM Bytecode Control-Flow Graphs"**_. In Proceedings of the 26th ACM International Workshop on Formal Techniques for Java-like Programs (FTfJP 2024), co-located with ECOOP 2024 (doi: [10.1145/3678721.3686227](https://dl.acm.org/doi/10.1145/3678721.3686227)). ## 目录 - [环境要求](#requirements) - [安装](#installation) - [环境设置](#environment-setup) - [执行方式](#execution-methods) - [使用 Docker](#using-docker) - [使用 CLI](#using-command-line) - [选项](#options) - [抽象栈集域](#the-abstract-stack-set-domain) - [跳转分类](#jump-classification) - [使用示例](#usage-example) - [输出示例](#example-output) - [作为库使用 EVMLiSA](#EVMLiSA-as-a-library) ## 环境要求 构建并运行 EVMLiSA,你需要: - JDK 11 或更高版本(使用 Docker 时可选) - [Gradle](https://gradle.org/releases/) 8.0 或更高版本(使用 Docker 时可选) - [Etherscan API key](https://etherscan.io/myapikey) ## 安装 1. 克隆仓库: git clone https://github.com/lisa-analyzer/evm-lisa.git cd evm-lisa 2. (可选)将项目作为 Gradle 项目导入 Eclipse 或 IntelliJ。 ### 环境设置 在运行 EVMLiSA 之前,你必须配置你的 Etherscan API key: 1. 在项目根目录下创建一个 `.env` 文件。 2. 在文件中添加以下内容: ETHERSCAN_API_KEY= 3. 将 `` 替换为你从 [Etherscan](https://etherscan.io/myapikey) 获取的实际密钥。 或者,你可以在执行分析器时使用 `--etherscan-api-key ` 选项直接传递 API 密钥。 ## 执行方式 ### 使用 Docker 1. 构建 Docker 容器: mkdir -p execution/docker && docker build -t evm-lisa:latest . 2. 使用 Docker 运行 EVMLiSA: docker run --rm -it \ -v $(pwd)/.env:/app/.env \ -v $(pwd)/execution/docker:/app/execution/results \ evm-lisa:latest \ [options] - `-v $(pwd)/.env:/app/.env`:挂载你的环境文件 - `-v $(pwd)/execution/docker:/app/execution/results`:共享结果目录 ### 使用命令行 1. 构建项目: ./gradlew assemble 2. 运行 EVMLiSA: java -jar build/libs/evm-lisaall.jar [options] ## 选项 ``` Options: -a,--address Address of an Ethereum smart contract. --abi ABI of the bytecode to be analyzed (JSON format). --abi-path Filepath of the ABI file. -b,--bytecode Bytecode to be analyzed (e.g., 0x6080...). --benchmark Filepath of the benchmark. --bytecode-path Filepath of the bytecode file. -c,--cores Number of cores used in benchmark. --checker-all Enable all security checkers. --checker-reentrancy Enable reentrancy checker. --checker-timestampdependency Enable timestamp-dependency checker. --checker-txorigin Enable tx-origin checker. --etherscan-api-key Insert your Etherscan API key. --link-unsound-jumps-to-all-jumpdest Link all unsound jumps to all jumpdest. --output-directory-path Filepath of the output directory. --show-all-instructions-in-cfg Show all instructions in the CFG representation. --stack-set-size Dimension of stack-set (default: 8). --stack-size Dimension of stack (default: 32). --use-live-storage Use the live storage in SLOAD. ``` ## 抽象栈集域 在分析 EVM 字节码程序时,EVMLiSA 采用抽象栈集合域来提高精度,特别是对于包含循环的代码。 分析器引入了抽象栈幂集域 $\texttt{SetSt}_{k,h,l}$,该域由最多包含 $l$ 个元素且最大高度为 $h$ 的抽象栈集合组成。该域允许分析器维护抽象栈的集合,从而避免计算最小上界,并允许抽象栈中的每个元素都是一个 $k$ 整数集。 ## 跳转分类 EVMLiSA 将跳转指令分为以下几类: - **已解析**:跳转节点的所有目标都已成功解析 - **绝对不可达**:跳转节点不可达(以底部抽象状态到达) - **可能不可达**:跳转节点无法从入口点到达,但可能通过潜在不可靠的跳转节点到达 - **不可靠**:跳转节点到达时栈中包含未知的数值,该数值可能对应于有效的跳转目标 - **可能不可靠**:栈集超过了配置的最大栈大小 ## 使用示例 使用特定配置参数分析智能合约: **使用命令行:** ``` java -jar build/libs/evm-lisa-all.jar \ -a 0x7c21C4Bbd63D05Fa9F788e38d14e18FC52E9557B \ --stack-size 64 \ --stack-set-size 10 \ --link-unsound-jumps-to-all-jumpdest ``` **使用 Docker:** ``` docker run --rm -it \ -v $(pwd)/.env:/app/.env \ -v $(pwd)/execution/docker:/app/execution/results \ evm-lisa:latest \ -a 0x7c21C4Bbd63D05Fa9F788e38d14e18FC52E9557B \ --stack-size 64 \ --stack-set-size 10 \ --link-unsound-jumps-to-all-jumpdest ``` ### 输出示例 ``` ############## Total opcodes: 344 Total jumps: 45 Resolved jumps: 44 Definitely unreachable jumps: 1 Maybe unreachable jumps: 0 Unsound jumps: 0 Maybe unsound jumps: 0 ############## ``` ## 作为库使用 EVMLiSA EVMLiSA 可以作为 Java 库集成,以编程方式分析 EVM 智能合约: ``` // Analyze by contract address EVMLiSA.analyzeContract(new SmartContract("0x123456...")); // Analyze from bytecode file path EVMLiSA.analyzeContract(new SmartContract(Path.of("bytecode", "code.bytecode"))); // Analyze from bytecode string EVMLiSA.analyzeContract(new SmartContract().setBytecode("0x6080...")); // Analyze multiple contracts EVMLiSA.analyzeSetOfContracts(Path.of("list-of-contracts.txt")); ``` ## 贡献者
标签:CISA项目, DeFi安全, DNS枚举, EVM字节码, JS文件枚举, LiSA, Web3安全, 云安全监控, 以太坊, 区块链, 后台面板检测, 形式化验证, 抽象解释, 控制流图, 智能合约安全, 网络安全工具, 请求拦截, 静态分析