Getting Started
In five minutes you will compile Guillotine Mini, run real EVM bytecode from Zig, watch 18 units of gas disappear one opcode at a time, and trigger your first controlled failure.
Prerequisites
| Tool | Version | Why it is required |
|---|---|---|
| Zig | 0.15.1+ (CI uses 0.15.2) | Compiles the EVM, tests, native archive, and WASI module |
| Rust / Cargo | Stable + wasm32-unknown-unknown (for WASM) | Builds Voltaire's Rust crypto static libraries (blst, BN254, KZG) |
Adjacent ../voltaire checkout | Pinned in native-dependencies.json | build.zig.zon resolves voltaire as a sibling path dependency |
| Node.js | 22+ (optional) | Runs zig build test-wasm and examples/wasm.mjs |
Python 3 + uv | Optional | Generates execution-specs fixtures for zig build specs |
Build from source
Clone the repository alongside voltaire at the revision recorded in native-dependencies.json:
git clone --recurse-submodules https://github.com/evmts/guillotine-mini.git
git clone https://github.com/evmts/voltaire.git
git -C voltaire checkout "$(jq -r .voltaire.revision guillotine-mini/native-dependencies.json)"
cd guillotine-mini
zig build
zig build test-traceIf zig build test-trace exits 0, your compiler, linker, and Voltaire crypto libraries all work.
Wire it into a Zig project
In build.zig.zon, declare guillotine_mini (and voltaire if you construct Address or ZERO_ADDRESS directly):
.dependencies = .{
.guillotine_mini = .{ .path = "../guillotine-mini" },
.voltaire = .{ .path = "../voltaire" },
},In build.zig, import both modules. Voltaire's primitives module carries its Rust crypto archive and system libraries, so no linkLibrary calls are needed:
const guillotine_dep = b.dependency("guillotine_mini", .{
.target = target,
.optimize = optimize,
});
const voltaire_dep = b.dependency("voltaire", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("guillotine_mini", guillotine_dep.module("guillotine_mini"));
exe.root_module.addImport("voltaire", voltaire_dep.module("primitives"));Your first execution
Our first contract returns the 32-byte word 42 (0x2a). In EVM assembly, that takes six instructions — ten bytes of raw bytecode:
00 PUSH1 0x2a # put 42 on the stack
02 PUSH1 0x00 # memory offset 0
04 MSTORE # write 32-byte big-endian 42 at memory[0..32]
05 PUSH1 0x20 # return length = 32 bytes
07 PUSH1 0x00 # return offset = 0
09 RETURN # halt and return memory[0..32]Here is a complete, runnable src/main.zig:
const std = @import("std");
const guillotine = @import("guillotine_mini");
const voltaire = @import("voltaire");
pub fn main() !void {
const Evm = guillotine.Evm(.{});
var vm: Evm = undefined;
try vm.init(
std.heap.page_allocator,
null, // host: null uses the EVM's internal maps
.CANCUN, // hardfork: always pass explicitly
null, // block context: null uses chain_id = 1 and zeroed fields
voltaire.ZERO_ADDRESS, // tx.origin
0, // tx.gasprice
null, // log level: null keeps default (.none)
);
defer vm.deinit();
const target = voltaire.Address.fromU256(0x42);
const bytecode = [_]u8{
0x60, 0x2a, // PUSH1 42
0x60, 0x00, // PUSH1 0
0x52, // MSTORE
0x60, 0x20, // PUSH1 32
0x60, 0x00, // PUSH1 0
0xf3, // RETURN
};
try vm.code.put(target, &bytecode);
const result = vm.call(.{ .call = .{
.caller = voltaire.ZERO_ADDRESS,
.to = target,
.value = 0,
.input = &.{},
.gas = 100_000,
} });
std.debug.print("success={} gas_left={} output_len={}\n", .{
result.success, result.gas_left, result.output.len,
});
if (result.output.len == 32) {
const word = std.mem.readInt(u256, result.output[0..32], .big);
std.debug.print("word={d} (0x{x})\n", .{ word, word });
}
}Output:
success=true gas_left=99982 output_len=32
word=42 (0x2a)Where did those 18 gas go?
Watch the stack and gas meter move across every instruction:
Push 42 onto the stack.
Offset 0 is now on top.
3 base + 3 to expand memory from 0 → 32 bytes.
Return length = 32 bytes.
Return offset = 0.
Memory already 32B; returns 0x00..002a.
3 + 3 + (3 + 3) + 3 + 3 + 0 = 18 gas. 100,000 - 18 = 99,982.
Now break it on purpose
Good docs show the failure path too. Change .gas = 100_000 to .gas = 10:
PUSH1 0x2a(3 gas) → 7 leftPUSH1 0x00(3 gas) → 4 leftMSTOREneeds 6 gas (3 base + 3 memory expansion) → OutOfGas!
Now result comes back with:
result.success == false
result.gas_left == 0
result.output.len == 0
result.error_info == "OutOfGas"Compare that with replacing 0xf3 (RETURN) with 0xfd (REVERT) at .gas = 100_000:
result.success == false
result.gas_left == 99982 // unspent gas is refunded on REVERT!
result.output.len == 32 // revert payload is preserved
result.error_info == null // REVERT is a clean halt, not a CallErrorNext steps
- Tutorial 1: Your First Contract Call — read calldata, emit
LOG1events, and decodeREVERTpayloads. - Tutorial 4: Running in WebAssembly — run this exact bytecode from Node 22+ via WASI.
- Opcode & Gas Explorer — step through
602a60005260206000f3interactively in your browser.