[!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
bash
git clone https://github.com/PraneshASP/smol-evm-rs.git
cd smol-evm-rsbash
cargo buildbash
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]andDUP[1-16]
gas calculation. smol-evm.$ claude mcp add smol-evm-rs \
-- python -m otcore.mcp_server <graph>