MCPcopy Index your code
hub / github.com/Yashiru/evm-rs-emulator

github.com/Yashiru/evm-rs-emulator @0.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.1.4 ↗ · + Follow
253 symbols 1,376 edges 29 files 160 documented · 63%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

EVM Rust Emulator

The EVM Rust Emulator is a simple in-memory Ethereum Virtual Machine (EVM) emulator written in Rust. It is designed to be a lightweight and easy-to-use tool for developers who want to test EVM bytecode execution directly in a command line or in a Rust crate, without using a full EVM node with his RPC to interact with a blockchain.

Github action Test coverage


Rust crate

Install crate

cargo add evm-rs-emulator

Usage

use evm_rs_emulator::Runner;

fn main() {
  let caller = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0xc4, 0x11, 0xe8,
  ];
  let origin: Option<[u8; 20]> = None;
  let address: Option<[u8; 20]> = None
  let value: Option<[u8; 32]> = None;
  let data: Option<Vec<u8>> = None;
  let bytecode: Vec<u8> = vec![0x60, 0xff, 0x60, 0xff];

  // Create a new interpreter
  let mut runner =
      Runner::new(caller, origin, address, value, data, None);

  // Run all the bytecode
  let _ = interpreter.interpret(bytecode, Some(255), true);

  // Or run the bytecode OPCODE by OPCODE
  runner.bytecode = bytecode;
  runner.debug_level = Some(255);
  // Run the first 3 opcodes
  let _ = runner.interpret_op_code(runner.bytecode[runner.pc]);
  let _ = runner.interpret_op_code(runner.bytecode[runner.pc]);
  let _ = runner.interpret_op_code(runner.bytecode[runner.pc]);
}

🚧 Warning 🚧

This project is currently experimental and subject to frequent changes as we are still working on stabilizing EVM emulation. It has not been audited for security purposes and should not be used in production yet.

Missing features (Contributions welcome ❤️)

  • [ ] EVM gas usage (see this branch)
  • [ ] EVM gas price (display tx price using the fork)
  • [ ] EVM gas limit
  • [x] Mocked data with RPC
  • [ ] Block data
  • [x] Call to external contract
  • [x] External crate features
  • [x] Deploy contract
  • [x] Call contract
  • [ ] Get logs

Contributions

Contributions are welcome! Feel free to open an issue or submit a pull request if you have a way to improve this project.

Github repo

To contribute to the EVM Rust Emulator, you will need to have Rust and Cargo installed on your system.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Once you have these tools installed, you can clone the project.

git clone https://github.com/Yashiru/evm-rs-emulator.git

To run the tests, you can use the following command.

cargo test

To run the coverage task

cargo make cov

License

The underlying source code is free and unencumbered software released into the public domain. Check LICENSE file for more information.

Core symbols most depended-on inside this repo

pop
called by 184
src/core_module/stack.rs
print_debug
called by 132
src/core_module/runner.rs
push
called by 126
src/core_module/stack.rs
pad_left
called by 117
src/core_module/utils/bytes.rs
increment_pc
called by 101
src/core_module/runner.rs
to_hex_string
called by 94
src/core_module/utils/debug.rs
interpret
called by 55
src/core_module/runner.rs
_hex_string_to_bytes
called by 34
src/core_module/utils/bytes.rs

Shape

Function 207
Method 39
Class 6
Enum 1

Languages

Rust100%

Modules by API surface

src/core_module/op_codes/environment.rs50 symbols
src/core_module/op_codes/stack/dup.rs32 symbols
src/core_module/op_codes/system.rs17 symbols
src/core_module/runner.rs16 symbols
src/core_module/op_codes/stack/swap.rs16 symbols
src/core_module/op_codes/bitwise.rs14 symbols
src/core_module/state.rs13 symbols
src/core_module/op_codes/flow.rs13 symbols
src/core_module/op_codes/comparison.rs12 symbols
src/core_module/op_codes/log.rs10 symbols
src/core_module/memory.rs9 symbols
src/core_module/op_codes/arithmetic/unsigned.rs8 symbols

For agents

$ claude mcp add evm-rs-emulator \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page