https://github.com/ckoopmann/evm-disassembler
Rust library to disassemble evm bytecode
https://github.com/ckoopmann/evm-disassembler
Last synced: about 1 month ago
JSON representation
Rust library to disassemble evm bytecode
- Host: GitHub
- URL: https://github.com/ckoopmann/evm-disassembler
- Owner: ckoopmann
- Created: 2023-03-08T05:31:05.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-21T05:32:00.000Z (9 months ago)
- Last Synced: 2025-04-15T11:12:39.775Z (about 1 month ago)
- Language: Rust
- Size: 180 KB
- Stars: 20
- Watchers: 1
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-ethereum-rust - evm-disassembler
README
# Disassemble EVM bytecode
Lightweight library with the sole purpose of decoding evm bytecode into individual Opcodes and formatting them in a human readable way# Inspiration
This library was inspired by the [pyevmasm](https://github.com/crytic/pyevmasm). When formatting the decoded operations using the inbuilt function the output should be equivalent to that of `pyevasm`, which is tested on the bytecode of several large evm contracts.# Installation
`cargo add evm-disassembler`# Documentation
See the API reference [here](https://docs.rs/evm-disassembler/).# Example
```rust
use evm_disassembler::{disassemble_str, disassemble_bytes, format_operations};
fn main() {
let bytecode = "608060405260043610603f57600035";
// Decode from string directly
let instructions = disassemble_str(bytecode).unwrap();
println!("{}", format_operations(instructions));let bytes = hex::decode(bytecode).unwrap();
// Decode from Vec with identical output as above
let instructions_from_bytes = disassemble_bytes(bytes).unwrap();
println!("{}", format_operations(instructions_from_bytes));}
```# Tests
You can run the tests as usual with `cargo test`.
The main tests compare the output of this library when decoding contract bytecode against the output from `pyevasm`. The input and reference files for these tests are saved in `testdata`.
To generate new testdata for these tests you can run the `generate_testdata.sh` script with an array of ethereum mainnet addresses. (Requires prior installation of [`foundry`](https://book.getfoundry.sh/) and `pyevasm`).