https://github.com/mtlynch/zenith
An implementation of the Ethereum virtual machine in pure Zig.
https://github.com/mtlynch/zenith
ethereum zig
Last synced: 20 days ago
JSON representation
An implementation of the Ethereum virtual machine in pure Zig.
- Host: GitHub
- URL: https://github.com/mtlynch/zenith
- Owner: mtlynch
- License: mit
- Created: 2024-02-11T21:07:46.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-22T01:53:22.000Z (10 months ago)
- Last Synced: 2025-04-10T01:55:10.730Z (7 months ago)
- Topics: ethereum, zig
- Language: Zig
- Homepage:
- Size: 249 KB
- Stars: 32
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zenith
[](https://dl.circleci.com/status-badge/redirect/gh/mtlynch/zenith/tree/master)
[](LICENSE)
An implementation of the Ethereum virtual machine in pure Zig.
## Project status
- [x] Execute basic EVM bytecode
- [ ] Support [EVMC interface](https://github.com/ethereum/evmc)
- [ ] Support all Ethereum opcodes (currently: [19 of 144](src/evm/opcodes.zig) supported)
- [ ] Support precompiled contracts
- [ ] Run [official Ethereum tests](https://github.com/ethereum/tests)
## Scope
For now, this is a just-for-fun experiment to learn more about Zig and Ethereum.
## Run VM
Run with maximum performance:
```bash
$ echo '60015f526001601ff3' | xxd -r -p | zig build run -Doptimize=ReleaseFast
EVM gas used: 17
execution time: 36.685µs
0x01
```
Run in debug mode:
```bash
$ echo '60015f526001601ff3' | xxd -r -p | zig build run
debug: PUSH1 0x01
debug: Stack: push 0x01
debug: Gas consumed: 3
debug: ---
debug: PUSH0
debug: Stack: push 0x00
debug: Gas consumed: 5
debug: ---
debug: MSTORE
debug: Stack: pop 0x00
debug: Stack: pop 0x01
debug: Memory: Writing value=0x1 to memory offset=0
debug: Gas consumed: 11
debug: ---
debug: PUSH1 0x01
debug: Stack: push 0x01
debug: Gas consumed: 14
debug: ---
debug: PUSH1 0x1f
debug: Stack: push 0x1f
debug: Gas consumed: 17
debug: ---
debug: RETURN
debug: Stack: pop 0x1f
debug: Stack: pop 0x01
debug: Memory: reading size=1 bytes from offset=31
debug: Return value: 0x01
debug: Gas consumed: 17
debug: ---
EVM gas used: 17
execution time: 611.780µs
0x01
```
## Run unit tests
```bash
zig build test --summary all
```