Ethereum Rust Execution L1 and L2 client.
This client supports running in two different modes:
- As a regular Ethereum execution client
- As a ZK-Rollup, where block execution is proven and the proof sent to an L1 network for verification, thus inheriting the L1's security.
We call the first one ethrex L1 and the second one ethrex L2.
Many long-established clients accumulate bloat over time. This often occurs due to the need to support legacy features for existing users or through attempts to implement overly ambitious software. The result is often complex, difficult-to-maintain, and error-prone systems.
In contrast, our philosophy is rooted in simplicity. We strive to write minimal code, prioritize clarity, and embrace simplicity in design. We believe this approach is the best way to build a client that is both fast and resilient. By adhering to these principles, we will be able to iterate fast and explore next-generation features early, either from the Ethereum roadmap or from innovations from the L2s.
Read more about our engineering philosophy here
- Ensure effortless setup and execution across all target environments.
- Be vertically integrated. Have the minimal amount of dependencies.
- Be structured in a way that makes it easy to build on top of it, i.e rollups, vms, etc.
- Have a simple type system. Avoid having generics leaking all over the codebase.
- Have few abstractions. Do not generalize until you absolutely need it. Repeating code two or three times can be fine.
- Prioritize code readability and maintainability over premature optimizations.
- Avoid concurrency split all over the codebase. Concurrency adds complexity. Only use where strictly necessary.
An Ethereum execution client consists roughly of the following parts:
- A storage component, in charge of persisting the chain's data. This requires, at the very least, storing it in a Merkle Patricia Tree data structure to calculate state roots. It also requires some on-disk database; we currently use libmdbx but intend to change that in the future.
- A JSON RPC API. A set of HTTP endpoints meant to provide access to the data above and also interact with the network by sending transactions. Also included here is the
Engine API
, used for communication between the execution and consensus layers. - A Networking layer implementing the peer to peer protocols used by the Ethereum Network. The most important ones are:
- The
disc
protocol for peer discovery, using a Kademlia DHT for efficient searches. - The
RLPx
transport protocol used for communication between nodes; used by other protocols that build on top to exchange information, sync state, etc. These protocols built on top are usually calledcapabilities
. - The Ethereum Wire Protocol (
ETH
), used for state synchronization and block/transaction propagation, among other things. This runs on top ofRLPx
. - The
SNAP
protocol, used for exchanging state snapshots. Mainly needed for snap sync, a more optimized way of doing state sync than the old fast sync (you can read more about it here).
- The
- Block building and Fork choice management (i.e. logic to both build blocks so a validator can propose them and set where the head of the chain is currently at, according to what the consensus layer determines). This is essentially what our
blockchain
crate contains. - The block execution logic itself, i.e., an EVM implementation. We are finishing an implementation of our own called levm (Lambda EVM).
Because most of the milestones below do not overlap much, we are currently working on them in parallel.
Implement the bare minimum required to:
- Execute incoming blocks and store the resulting state on an on-disk database (
libmdbx
). No support for reorgs/forks, every block has to be the child of the current head. - Serve state through a JSON RPC API. No networking yet otherwise (i.e. no p2p).
In a bit more detail:
Task Description | Status |
---|---|
Add libmdbx bindings and basic API, create tables for state (blocks, transactions, etc) |
β |
EVM wrapper for block execution | β |
JSON RPC API server setup | β |
RPC State-serving endpoints | ποΈ (almost done, a few endpoints are left) |
Basic Engine API implementation. Set new chain head (forkchoiceUpdated ) and new block (newPayload ). |
β |
See detailed issues and progress for this milestone here.
Implement support for block reorganizations and historical state queries. This milestone involves persisting the state trie to enable efficient access to historical states and implementing a tree structure for the blockchain to manage multiple chain branches. It also involves a real implementation of the engine_forkchoiceUpdated
Engine API when we do not have to build the block ourselves (i.e. when payloadAttributes
is null).
Task Description | Status |
---|---|
Persist data on an on-disk Merkle Patricia Tree using libmdbx |
β |
Engine API forkchoiceUpdated implementation (without payloadAttributes ) |
ποΈ |
Support for RPC historical queries, i.e. queries (eth_call , eth_getBalance , etc) at any block |
β |
Detailed issues and progress here.
Add the ability to build new payloads (blocks), so the consensus client can propose new blocks based on transactions received from the RPC endpoints.
Task Description | Status |
---|---|
engine_forkchoiceUpdated implementation with a non-null payloadAttributes |
ποΈ |
engine_getPayload endpoint implementation that builds blocks. |
ποΈ |
Implement a mempool and the eth_sendRawTransaction endpoint where users can send transactions |
β |
Detailed issues and progress here.
Implement the peer to peer networking stack, i.e. the DevP2P protocol. This includes discv4
, RLPx
and the eth
capability. This will let us get and retrieve blocks and transactions from other nodes. We'll add the transactions we receive to the mempool. We'll also download blocks from other nodes when we get payloads where the parent isn't in our local chain.
Task Description | Status |
---|---|
Implement discv4 for peer discovery |
β |
Implement the RLPx transport protocol |
ποΈ |
Implement the eth capability |
ποΈ |
Detailed issues and progress here.
Add support for the SNAP
protocol, which lets us get a recent copy of the blockchain state instead of going through all blocks from genesis. This is used for used for snap sync. Since we don't support older versions of the spec by design, this is a prerequisite to being able to sync the node with public networks, including mainnet.
Task Description | Status |
---|---|
Implement SNAP protocol for snap syncing |
β |
Detailed issues and progress here.
make localnet
This make target will:
- Build our node inside a docker image.
- Fetch our fork ethereum package, a private testnet on which multiple ethereum clients can interact.
- Start the localnet with kurtosis.
If everything went well, you should be faced with our client's logs (ctrl-c to leave)
To stop everything, simply run:
make stop-localnet
To build the node, you will need the rust toolchain:
- First, install asdf:
- Add the rust plugin:
asdf plugin-add rust https://github.com/asdf-community/asdf-rust.git
- cd into the project and run:
asdf install
You now should be able to build the client:
make build
Currently, the database is libmdbx
, it will be set up
when you start the client. The location of the db's files will depend on your OS:
- Mac:
~/Library/Application Support/ethrex
- Linux:
~/.config/ethrex
You can delete the db with:
cargo run --bin ethrex -- removedb
For testing, we're using three kinds of tests.
These are the official execution spec tests, you can execute them with:
make test
This will download the test cases from the official execution spec tests repo and run them with our glue code
under cmd/ef_tests/tests
.
The second kind are each crate's tests, you can run them like this:
make test CRATE=<crate>
For example:
make test CRATE="ethrex-blockchain"
Finally, we have End-to-End tests with hive. Hive is a system which simply sends RPC commands to our node, and expects a certain response. You can read more about it here.
We need to have go installed for the first time we run hive, an easy way to do this is adding the asdf go plugin:
asdf plugin add golang https://github.com/asdf-community/asdf-golang.git
# If you need to se GOROOT please follow: https://github.com/asdf-community/asdf-golang?tab=readme-ov-file#goroot
And uncommenting the golang line in the asdf .tool-versions
file:
rust 1.81.0
golang 1.23.2
Hive tests are categorized by "simulations', and test instances can be filtered with a regex:
make run-hive-debug SIMULATION=<simulation> TEST_PATTERN=<test-regex>
This is an example of a Hive simulation called ethereum/rpc-compat
, which will specificaly
run chain id and transaction by hash rpc tests:
make run-hive SIMULATION=ethereum/rpc-compat TEST_PATTERN="/eth_chainId|eth_getTransactionByHash"
If you want debug output from hive, use the run-hive-debug instead:
make run-hive-debug SIMULATION=ethereum/rpc-compat TEST_PATTERN="*"
This example runs every test under rpc, with debug output
Example run:
cargo run --bin ethrex -- --network test_data/genesis-kurtosis.json
The network
argument is mandatory, as it defines the parameters of the chain.
For more information about the different cli arguments check out the next section.
ethrex supports the following command line arguments:
--network <FILE>
: Receives aGenesis
struct in json format. This is the only argument which is required. You can look at some example genesis files attest_data/genesis*
.--datadir <DIRECTORY>
: Receives the name of the directory where the Database is located.--import <FILE>
: Receives an rlp encodedChain
object (aka a list ofBlock
s). You can look at the example chain file attest_data/chain.rlp
.--http.addr <ADDRESS>
: Listening address for the http rpc server. Default value: localhost.--http.port <PORT>
: Listening port for the http rpc server. Default value: 8545.--authrpc.addr <ADDRESS>
: Listening address for the authenticated rpc server. Default value: localhost.--authrpc.port <PORT>
: Listening port for the authenticated rpc server. Default value: 8551.--authrpc.jwtsecret <FILE>
: Receives the jwt secret used for authenticated rpc requests. Default value: jwt.hex.--p2p.addr <ADDRESS>
: Default value: 0.0.0.0.--p2p.port <PORT>
: Default value: 30303.--discovery.addr <ADDRESS>
: UDP address for P2P discovery. Default value: 0.0.0.0.--discovery.port <PORT>
: UDP port for P2P discovery. Default value: 30303.--bootnodes <BOOTNODE_LIST>
: Comma separated enode URLs for P2P discovery bootstrap.--log.level <LOG_LEVEL>
: The verbosity level used for logs. Default value: info. possible values: info, debug, trace, warn, error--syncmode <SYNC_MODE>
: The way in which the node will sync its state. Can be either "full" or "snap" with "snap" as default value.
In this mode, the ethrex code is repurposed to run a rollup that settles on Ethereum as the L1.
The main differences between this mode and regular ethrex are:
- There is no consensus, the node is turned into a sequencer that proposes blocks for the network.
- Block execution is proven using a RISC-V zkVM and its proofs are sent to L1 for verification.
- A set of Solidity contracts to be deployed to the L1 are included as part of network initialization.
- Two new types of transactions are included: deposits (native token mints) and withdrawals.
At a high level, the following new parts are added to the node:
- A
proposer
component, in charge of continually creating new blocks from the mempool transactions. This replaces the regular flow that an Ethereum L1 node has, where new blocks come from the consensus layer through theforkChoiceUpdate
->getPayload
->NewPayload
Engine API flow in communication with the consensus layer. - A
prover
subsystem, which itself consists of two parts:- A
proverClient
that takes new blocks from the node, proves them, then sends the proof back to the node to send to the L1. This is a separate binary running outside the node, as proving has very different (and higher) hardware requirements than the sequencer. - A
proverServer
component inside the node that communicates with the prover, sending witness data for proving and receiving proofs for settlement on L1.
- A
- L1 contracts with functions to commit to new state and then verify the state transition function, only advancing the state of the L2 if the proof verifies. It also has functionality to process deposits and withdrawals to/from the L2.
- The EVM is lightly modified with new features to process deposits and withdrawals accordingly.
Milestone | Description | Status |
---|---|---|
0 | Users can deposit Eth in the L1 (Ethereum) and receive the corresponding funds on the L2. | β |
1 | The network supports basic L2 functionality, allowing users to deposit and withdraw funds to join and exit the network, while also interacting with the network as they do normally on the Ethereum network (deploying contracts, sending transactions, etc). | β |
2 | The block execution is proven with a RISC-V zkVM and the proof is verified by the Verifier L1 contract. | β |
3 | The network now commits to state diffs instead of the full state, lowering the commit transactions costs. These diffs are also submitted in compressed form, further reducing costs. It also supports EIP 4844 for L1 commit transactions, which means state diffs are sent as blob sidecars instead of calldata. | ποΈ |
4 | Use our own EVM implementation | ποΈ |
5 | The L2 supports native account abstraction following EIP 7702, allowing for custom transaction validation logic and paymaster flows. | β |
6 | Support multiple L2s sharing the same bridge contract on L1 for seamless interoperability. | β |
7 | The L2 can also be deployed using a custom native token, meaning that a certain ERC20 can be the common currency that's used for paying network fees. | β |
8 | The L2 has added security mechanisms in place, running on Trusted Execution Environments and Multi Prover setup where multiple guarantees (Execution on TEEs, zkVMs/proving systems) are required for settlement on the L1. This better protects against possible security bugs on implementations. | β |
9 | The L2 can be initialized in Validium Mode, meaning the Data Availability layer is no longer the L1, but rather a DA layer of the user's choice. | β |
10 | The network can be run as a Based Rollup, meaning sequencing is done by the Ethereum Validator set; transactions are sent to a private mempool and L1 Validators that opt into the L2 sequencing propose blocks for the L2 on every L1 block. | β |
Users can deposit Eth in the L1 (Ethereum) and receive the corresponding funds on the L2.
Description | Status |
---|---|
Add a new privilegedL2Transaction type for deposits on the sequencer, which mints funds on the L2 and sends the processed deposits to the L1 on each commit transaction. |
β |
Adapt the EVM to handle deposit transactions (minting money to the corresponding account). | β |
Make the proposer continuously build and execute new blocks by internally calling the appropriate Engine API methods | β |
Add an L1Watcher component that listens for and handles L1 deposits, executing the appropriate mint transaction on the L2. |
β |
Add a proposer component that commits to new blocks and sends block execution proofs to the L1. |
β |
Add a CLI with commands for initializing the network, managing network config, operating in the L2 and allowing for deposits. | β |
The network supports basic L2 functionality, allowing users to deposit and withdraw funds to join and exit the network, while also interacting with the network as they do normally on the Ethereum network (deploying contracts, sending transactions, etc).
Description | Status |
---|---|
Add a new privilegedL2Transaction type for withdrawals on the sequencer, which burns funds on L2 and unlocks funds on L1 by sending the merkle root of each block's withdrawals. |
β |
Add a claimWithdrawal function on the commonBridge so users can claim their funds on L1 after the L2 withdrawal transaction is finalized on L1. |
β |
Add a CLI feature for making withdrawals | β |
The L2's block execution is proven with a RISC-V zkVM and the proof is verified by the Verifier L1 contract. This work is being done in parallel with other milestones as it doesn't block anything else.
Task Description | Status |
---|---|
On the EVM, return all storage touched during block execution to pass to the prover as a witness | β |
Make the onChainproposer L1 contract verify the SNARK proof on the verify function. |
β |
Add a proverClient binary that asks the sequencer for witness data to prove, generates proofs of execution and submits proofs to the proverServer component (see below) |
β |
Add a proverServer component that feeds the proverClient with block witness data to be proven and delivers proofs to the proposer to send the L1 transaction for block verification |
β |
The network now commits to state diffs instead of the full state, lowering the commit transactions costs. These diffs are also submitted in compressed form, further reducing costs.
It also supports EIP 4844 for L1 commit transactions, which means state diffs are sent as blob sidecars instead of calldata.
Task Description | Status |
---|---|
The sequencer sends state diffs to the prover instead of full transaction data. | β |
On the prover, prove the state diffs compression | β |
On the proposer , send the state diffs through a blob in a EIP 4844 transaction. |
β |
Adapt the prover to prove a KZG commitment to the state diff and use the point evaluation precompile to show that the blob sent to the L1 is indeed the correct one through a proof of equivalence protocol | β |
Add a command to the CLI to reconstructing the full L2 state from all the blob data on the L1. | β |
Finish our own EVM implementation (levm
) to be able to add custom behaviour to the network (like account abstraction below).
Task Description | Status |
---|---|
Implement all opcodes | β |
Pass all execution (non-precompile) EF tests | ποΈ |
Implement all precompiles | ποΈ |
Pass all execution EF tests | ποΈ |
Full Ethereum Rust Integration (pass all Hive tests) | ποΈ |
The L2 supports native account abstraction following EIP 7702, allowing for custom transaction validation logic and paymaster flows.
Task Description | Status |
---|---|
Add support for SET_CODE_TX_TYPE transactions (i.e. implement EIP 7702). |
β |
Add examples of WebAuthn signing and paymaster flows using EIP 7702 | β |
Support multiple L2s sharing the same bridge contract on L1 for seamless interoperability.
Task Description | Status |
---|---|
Change state of the commonBridge and onChainProposer to be a mapping over chainId |
β |
Adapt sequencer to be aware of its chain id and interact with the L1 contracts accordingly | β |
TODO: Expand on tasks about proper interoperability between chains (seamlessly bridging between chains, etc).
The L2 can also be deployed using a custom native token, meaning that a certain ERC20 can be the common currency that's used for paying network fees.
Task Description | Status |
---|---|
On the commonBridge , keep track of the chain's native token. For custom native token withdrawals, infer the native token and reimburse the user in that token |
β |
On the commonBridge , for custom native token deposits, msg.value should always be zero, and the amount of the native token to mint should be a new valueToMintOnL2 argument. The amount should be deducted from the caller thorugh a transferFrom . |
β |
On the CLI, add support for custom native token deposits and withdrawals | β |
The L2 has added security mechanisms in place, running on Trusted Execution Environments and Multi Prover setup where multiple guarantees (Execution on TEEs, zkVMs/proving systems) are required for settlement on the L1. This better protects against possible security bugs on implementations.
Task Description | Status |
---|---|
Support proving with multiple different zkVMs | β |
Support verifying multiple different zkVM executions on the onChainProposer L1 contract. |
β |
Support running the operator on a TEE environment | β |
The L2 can be initialized in Validium Mode, meaning the Data Availability layer is no longer the L1, but rather a DA layer of the user's choice.
The network can be run as a Based Rollup, meaning sequencing is done by the Ethereum Validator set; transactions are sent to a private mempool and L1 Validators that opt into the L2 sequencing propose blocks for the L2 on every L1 block.
Task Description | Status |
---|---|
Add methods on the onChainProposer L1 contract for proposing new blocks so the sequencing can be done from the L1 |
β |
TODO: Expand on this.
Task Description | Status |
---|---|
Make the onChainProposer L1 contract conditional on the data availability mode. On validium, don't check for data availability. |
β |
The sequencer can initialize on Validium mode, not sending state diff data on commit transactions |
β |
Add a DA integration example for Validium mode | β |
Important
Before this step:
- Make sure you are inside the
crates/l2
directory. - Make sure the Docker daemon is running.
- Make sure you have created a
.env
file following the.env.example
file.
make init
This will setup a local Ethereum network as the L1, deploy all the needed contracts on it, then start an ethrex L2 node pointing to it.
Warning
This command will cleanup your running L1 and L2 nodes.
make restart
Most of them are here, but there's an extra one:
{
"address": "0x3d1e15a1a55578f7c920884a9943b3b35d0d885b",
"private_key": "0x385c546456b6a603a1cfcaa9ec9494ba4832da08dd6bcf4de9a71e4a01b74924"
}
The following links, repos, companies and projects have been important in the development of this repo, we have learned a lot from them and want to thank and acknowledge them.
- Ethereum
- ZKsync
- Starkware
- Polygon
- Optimism
- Arbitrum
- Geth
- Taiko
- RISC Zero
- SP1
- Aleo
- Neptune
- Mina
- Nethermind
If we forgot to include anyone, please file an issue so we can add you. We always strive to reference the inspirations and code we use, but as an organization with multiple people, mistakes can happen, and someone might forget to include a reference.