A toy VM for Ethereum smart contracts, written in Rust from scratch with minimal dependencies.
- alloy-primitives: I256 & U256 types
- sha3: keccak256 implementation
- hex: decode hex strings
- Implemented:
- Opcodes: 110 / 148 (~ 75%)
- Gas: N/A
- Memory / Storage / Transient storage / Event log: Yes
The following smart contract (written in Solidity) can run successfully:
- store_1.sol: initialize a storage value && do_store to increment it with constant value (6)
- store_2.sol: initialize a storage value && do_store to increment it with function argument (provided in call data)
- event.sol: log events (with 3 event types)
- sha3.sol: keccak256 opcode + call data arguments encode
- cargo build
- ./target/debug/tiny_evm --sc resources/output/Store1.bin
Note: call_data for Store1.bin is automatically computed (for this quickstart).
Provide Smart contract bin file path && call data (as a hex string):
- RUST_LOG=debug ./target/debug/tiny_evm --sc resources/output/AddAndEvent.bin -c 5b3ee9310000000000000000000000000000000000000000000000000000000000000000
- cd resources
- docker run -v ./:/sources ethereum/solc:stable -o /sources/output --abi --bin --optimize --overwrite /sources/store_1.sol
For podman user, run this before docker run ...
:
- export DOCKER_HOST=unix://${XDG_RUNTIME_DIR}/podman/podman.sock
- https://noxx.substack.com/p/evm-deep-dives-the-path-to-shadowy
- opcodes:
- https://www.youtube.com/watch?v=RxL_1AfV7N4&t=2s
- Add example with contract call
- Add faster stack impl
- More opcodes && more optimizations