Skip to content
josemariasosaPublic

About

An experimental EVM-to-RISC-V compiler.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

128 Commits

Folders and files

Repository files navigation

Ferreth Compiler logo

Rust RISC-V EVM Status License

An experimental EVM-to-RISC-V compiler.

Built for open architectures, reproducible research, and hardware exploration.

Why Ferreth?

We believe the future of computing should be built on open architectures.

Ferreth explores whether Ethereum Virtual Machine (EVM) bytecode can be compiled into RISC-V instructions while preserving EVM execution semantics.

Our long-term ambition is to investigate a universal EVM-to-RISC-V compilation approach, independent of any particular processor implementation, emulator, or hardware platform.

By combining the EVM's execution model with RISC-V's open instruction set architecture, we hope to make Ethereum-oriented execution more accessible to researchers, compiler engineers, and hardware enthusiasts.

Ferreth compiles bounded, straight-line Cancun EVM bytecode to RV64. The v0.2.0 release candidate, The Metered Machine, supports STOP, PUSH1, PUSH32, POP, DUP1, ADD, SUB, and GAS.

How It Works

Ferreth currently follows a single canonical pipeline:

┌──────────────────────┐
│  EVM bytecode input  │
└──────────┬───────────┘
           │
           ▼
┌──────────────────────────────────────────┐
│ Decode and admit supported instructions  │
│ STOP, PUSH1, PUSH32, POP, DUP1,          │
│ ADD, SUB, GAS                           │
└──────────┬───────────────────────────────┘
           │
           ▼
┌──────────────────────────────────────────┐
│ Lower to symbolic RV64 opcode fragments  │
│ with guest-owned fixed-cost gas checks   │
└──────────┬───────────────────────────────┘
           │
           ▼
┌──────────────────────────────────────────┐
│ Compose a complete RV64 image and        │
│ assemble it with pinned tooling          │
└──────────┬───────────────────────────────┘
           │
           ▼
┌──────────────────────────────────────────┐
│ Verify encoded control transfers         │
│ against declared fragment links          │
└──────────┬───────────────────────────────┘
           │
           ▼
┌──────────────────────────────────────────┐
│ Independently verify final image layout, │
│ publishers, charges, PUSH32 values and   │
│ structural invariants                    │
└──────────┬───────────────────────────────┘
           │
           ▼
┌──────────────────────────────────────────┐
│ Execute on rvemu, then validate the      │
│ published guest result frame             │
└──────────────────────────────────────────┘

Use compiler::compile_evm_bytecode to obtain the verified image and orchestrator::execute_guest_evm_bytecode(bytecode, gas_limit) to run it. Generated RV64 code owns stack operations, arithmetic and fixed-cost frame gas. Rust supplies the budget, initializes the guest and validates its published stack, status and settled gas. ADR-001 guest ABI · ADR-002 frame metering

The architecture separates compilation from execution through a backend-neutral interface, allowing future experiments with other emulators or native RISC-V hardware.

Current Status

Ferreth is in early development.

Component Status
EVM bytecode decoding Partial
RV64 code generation Experimental
STOP, PUSH1, PUSH32, POP, DUP1, ADD, SUB, GAS Implemented
Guest stack and runtime ABI Implemented
Whole-program RV64 execution Implemented for supported opcodes
Differential validation against REVM Cancun Direct frame tests for termination, settled gas and successful stacks, plus separate transaction-based tests
Additional EVM opcodes Planned
Alternative RISC-V backends Future research
RTL and hardware acceleration Future research

Frames complete normally at the first STOP or EOF. Positive-cost opcodes check and debit guest gas before stack validation. GAS pushes the post-charge balance. Guest exceptions settle remaining frame gas to zero. PUSH32 uses big-endian immediates padded on the right at EOF. The decoder rejects PUSH0 and the compiler rejects PUSH2–PUSH31. The experimental scope excludes transaction intrinsic gas, refunds, dynamic gas pricing, EVM control flow, memory, storage and calls. Current execution evidence uses rvemu.

The guest stack holds up to 1,024 words, and the executable image is capped at 1,048,572 bytes. Assembler resource limits can reject a program even when its image would fit. Execution has a shared body and publisher step bound of one step per encoded RV64 word. Capacity and release evidence

execute --op retains the metered singleton interface. Opcode::assembly, execution::Rv64Runner and translate --op ADD|SUB retain standalone arithmetic. ProgramRunner, the unlinked RV64 generators and carriers, and translate --op PUSH1 have been removed. Compatibility and migration

Getting Started

The recorded cutover checks used Rust and Cargo 1.98.1 on aarch64-apple-darwin. Use the checked-in Cargo.lock with --locked. The compiler uses alloy-primitives 1.7.3, asm-rs 0.2.0, and rvemu 0.0.11. The separate ferreth-conformance crate uses REVM 43.0.3 with revm-interpreter 43.0.2 resolved in the lockfile. Lockfile · Cutover evidence

From the repository root, run the full workspace regression suite.

cargo test --locked --workspace --no-fail-fast

The default cargo test --locked runs compiler tests. The workspace suite also runs all 508 migrated PUSH32 programs against direct Cancun REVM. PUSH32 implementation checkpoint

Execute a simple EVM program:

cargo run --locked -p ferreth-compiler -- execute --bytecode 600560030100 --gas 9

This program uses two PUSH1s, ADD and STOP to produce stack [8] with zero gas remaining from a frame budget of 9.

Inspect the standalone RV64 ADD routine:

cargo run --locked -p ferreth-compiler -- translate --op ADD

Run the arithmetic benchmarks with a working dtc on PATH for JSON capture. Benchmark stdout requirements

cargo run --locked -p ferreth-conformance -- \
  bench --op ALL --cases 1000 --seed 42 --format json

For more commands and examples:

Research Directions

The Metered Machine release candidate awaits maintainer acceptance. ADR-003 (The Dragon) follows v0.2.0. Broader opcode support, dynamic execution, zkVM integration and formal verification remain research directions. Release notes · Release checklist

EVM-to-RISC-V Compilation

Expand opcode coverage, improve code generation, and investigate EVM semantic compatibility across different RISC-V execution environments.

Conformance and Verification

Develop reproducible differential tests and validation tools to compare compiled execution against established EVM implementations.

Open Hardware Exploration

Investigate native RISC-V execution, FPGA implementations, RTL designs, and potential Ethereum-oriented hardware acceleration.

No performance or efficiency advantage is assumed; these are questions to be investigated experimentally.

Contributing

Ferreth is an open research effort, and contributions are welcome.

Whether you are interested in Rust, compilers, Ethereum, RISC-V, emulators, verification, or digital hardware design, there is room to explore.

You can contribute by improving opcode coverage, adding differential tests, reviewing architecture decisions, investigating execution backends, improving documentation, or proposing experiments.

Open an issue to discuss an idea, report a bug, or propose a research direction. Pull requests are welcome.

You don't need to be an EVM or RISC-V expert to contribute. Curiosity and a willingness to experiment are enough.

License

Licensed under either of:

at your option.


Ferreth — Exploring Ethereum execution through open instruction sets.

About

An experimental EVM-to-RISC-V compiler.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages