Crates.io | evm-disassembler |
lib.rs | evm-disassembler |
version | 0.5.0 |
source | src |
created_at | 2023-03-10 09:00:43.720972 |
updated_at | 2024-03-15 10:38:55.155898 |
description | Disassemble EVM bytecode into individual Opcodes and format into human readable strings. |
homepage | https://docs.rs/evm_disassembler |
repository | https://github.com/ckoopmann/evm-disassembler |
max_upload_size | |
id | 806297 |
size | 605,549 |
Lightweight library with the sole purpose of decoding evm bytecode into individual Opcodes and formatting them in a human readable way
This library was inspired by the 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.
cargo add evm-disassembler
See the API reference here.
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<u8> with identical output as above
let instructions_from_bytes = disassemble_bytes(bytes).unwrap();
println!("{}", format_operations(instructions_from_bytes));
}
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
and pyevasm
).