#evm #bytecode #human-readable #opcode #string #individual #disassembler

evm-disassembler

Disassemble EVM bytecode into individual Opcodes and format into human readable strings

5 releases (breaking)

0.5.0 Mar 15, 2024
0.4.0 Jan 19, 2024
0.3.0 Oct 24, 2023
0.2.0 Mar 13, 2023
0.1.0 Mar 10, 2023

#157 in Magic Beans

Download history 1683/week @ 2023-12-23 1582/week @ 2023-12-30 1561/week @ 2024-01-06 1838/week @ 2024-01-13 1749/week @ 2024-01-20 1806/week @ 2024-01-27 1908/week @ 2024-02-03 1832/week @ 2024-02-10 1761/week @ 2024-02-17 1737/week @ 2024-02-24 3027/week @ 2024-03-02 3036/week @ 2024-03-09 2607/week @ 2024-03-16 1493/week @ 2024-03-23 1749/week @ 2024-03-30 1657/week @ 2024-04-06

8,802 downloads per month

MIT/Apache

130KB
543 lines

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. 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.

Example

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));

}

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 and pyevasm).

Dependencies

~205KB