MCPcopy Index your code
hub / github.com/PraneshASP/smol-evm-rs

github.com/PraneshASP/smol-evm-rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
47 symbols 89 edges 8 files 2 documented · 4%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

smol-evm-rs • License CI Built Using Rust


[!WARNING]
It is important to note that the code is not optimized and may contain bugs. It is primarily intended for educational purposes. So don't use any code from this repo for production.

smol-evm-rs is a toy implementation of the Ethereum Virtual Machine, inspired by the smol-evm project, originally implemented in Python by karmacoma. The primary goal of the project is to increase my Rust proficiency. - [X] Part 1: The execution context - [X] Part 2: Branching instructions - [X] Part 3: Calldata & comparison instructions

Getting started:

Prerequisites

Build Instructions

  1. Clone the repository: bash git clone https://github.com/PraneshASP/smol-evm-rs.git cd smol-evm-rs
  2. Build the project: bash cargo build
  3. Run the project: bash cargo run <BYTECODE>

### Example: Run: cargo run 60048060005b8160125760005360016000f35b8201906001900390600556

The above bytecode calculates 4.pow(2) (four-squared)

It should return0x10 as output along with the memory, stack and program counter values.


Opcode: 96
"PUSH1" @ pc=0
Stack: [4]
Memory: []
---------
Opcode: 128
"DUP1" @ pc=2
Stack: [4, 4]
Memory: []
---------
Opcode: 96
"PUSH1" @ pc=3
Stack: [4, 4, 0]
Memory: []
---------
Opcode: 3
"SUB" @ pc=25
Stack: [4, 8, 2]
Memory: []
---------
Opcode: 144
"SWAP1" @ pc=26
Stack: [4, 2, 8]
Memory: []
---------

...

...

...

---------
Opcode: 87
"JUMPI" @ pc=9
Stack: [4, 0, 16]
Memory: []
---------
Opcode: 96
"PUSH1" @ pc=10
Stack: [4, 0, 16, 0]
Memory: []
---------
"MSTORE8" @ pc=12
Stack: [4, 0]
Memory: [16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---------
"PUSH1" @ pc=13
Stack: [4, 0, 1]
Memory: [16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---------
"PUSH1" @ pc=15
Stack: [4, 0, 1, 0]
Memory: [16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---------
"RETURN" @ pc=17
Stack: [4, 0]
Memory: [16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---------
Output : 0x1000000000000000

[!NOTE]
Supported Opcodes: ADD,SUB,MUL,PUSH1, MSTORE8, RETURN, STOP,JUMP, JUMPI,JUMPDEST,GT,LT,ISZERO,SHR,SHL,CALLDATALOAD, CALLDATASIZE, CALLVALUE,SWAP[1-16], PUSH[0-32]and DUP[1-16]

Improvement ideas:

  • Make word size 32 instead of 16.
  • Implement remaining opcodes like MSTORE, MLOAD, CALLDATACOPY
  • Implement gas calculation.
  • Add more tests.

Acknowledgments

  • karmacoma-eth for the original Python implementation of smol-evm.

Extension points exported contracts — how you extend this code

OpcodeExecutor (Interface)
(no doc) [1 implementers]
src/opcodes.rs

Core symbols most depended-on inside this repo

push
called by 76
src/stack.rs
read_code
called by 33
src/execution_context.rs
pop
called by 25
src/stack.rs
swap
called by 18
src/stack.rs
peek
called by 16
src/stack.rs
store
called by 11
src/memory.rs
expand_if_needed
called by 4
src/memory.rs
active_words
called by 3
src/memory.rs

Shape

Method 25
Function 11
Class 5
Enum 5
Interface 1

Languages

Rust100%

Modules by API surface

src/memory.rs13 symbols
src/stack.rs11 symbols
src/execution_context.rs7 symbols
src/calldata.rs6 symbols
src/opcodes.rs5 symbols
src/instruction.rs4 symbols
src/main.rs1 symbols

For agents

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

⬇ download graph artifact