Unlocking Arweave with EVM Precompiles in Reth

Unlocking Arweave with EVM Precompiles in Reth

August 15, 2024

In volume 2 of our WeaveVM precompiles series, we focus on our experience and development path in creating custom precompiles for Reth. This article shares insights gained throughout our journey, offering a deeper look into the process of implementing custom precompiles in Reth.

(Volume 1 can be found here)

What is Arweave?

Arweave is a novel type of storage that backs data with sustainable and perpetual endowments, allowing users and developers to store data forever. Aiming to provide scalable, on-chain storage in a way that is permanent and cost-effective, Arweave’s decentralised network is built on a new type of blockchain called the blockweave.

Unlike traditional blockchains that form a linear chain of blocks, Arweave’s unique blockchain architecture is a graph-like structure called a ‘blockweave’, where each block is linked to two prior blocks: the previous block in the ’chain’ (as with traditional blockchain protocols), and a randomly chosen ‘recall block’ from the previous history of the blockchain.

arweave blockweave size

Although Arweave’s blockweave data structure is not strictly a chain (i.e., a singly linked list), its innovative design allows for a ‘Proof of Access’ consensus mechanism, which selects a recall block from any previous block for the creation of a new block. This allows miners to efficiently store parts of the blockchain and verify new blocks without requiring full blockchain history.

What are precompiles?

In Ethereum, a contract is code deployed on the Ethereum network and executed on the Ethereum Virtual Machine (EVM). When deploying a contract, it’s compiled from a high-level language like Solidity or Vyper into an EVM bytecode that the EVM can execute.

precompiles and the host program

A precompiled contract is a special contract pre-installed on the Ethereum network, usable by other contracts without separate deployment. These contracts typically handle computationally expensive operations, like cryptographic functions, that would be too costly to perform on-chain within a regular contract.

Precompiles are implemented in the programming language used to run the Ethereum Virtual Machine (EVM). For instance, in Reth—a Rust-based implementation of the Ethereum protocol— precompiles are written in Rust.

How are we unlocking Arweave for the EVM with precompiles?

With WeaveVM, our mission is to integrate the benefits of EVM with the unique advantages of Arweave storage solution. WeaveVM is specifically designed to optimize file storage within the EVM ecosystem, leveraging Arweave’s cost-effective permanent storage. By doing so, we atomically combine the functionality of EVM with a decentralized permanent storage solution.

Currently, we have implemented two precompiles:

0x17 (Arweave writer): It enables writing data to Arweave from inside your WeaveVM contract.

arweave writer precompile

0x18 (Arweave Reader): It enables reading transactions

arweave reader precompile

By utilizing precompiles, we enable the core functionality of Arweave to be integrated within an EVM environment. This opens up numerous use cases, such as storing NFTs directly onchain and creating self-sufficient smart contracts that do not rely on external storage providers. This approach enhances the efficiency and autonomy of smart contracts by embedding storage capabilities within the contract itself - programmable data.

To learn more in depth about the 0x17 and 0x18 precompiles, refer to the first precompiles article here.

Challenges of implementing custom precompiles as a Reth Developer

WeaveVM uses Reth as its core codebase, having forked it to create a customized version that remains aligned with Reth’s updates. This approach allows us to maintain compatibility while giving us the flexibility to pursue our own objectives and implement unique features at the code level. Although, implementing our own precompiles required certain structural challenges as to how we bootstrap the binary of Reth.

ExecutorBuilder reth code

In this code, we needed to create our own ExecutorBuilder component which dictates how Reth is going to be loaded and what will be loaded in it. If we take a closer look into these references:

precompile code references precompile function

We can see how our precompiles are injected inside the EVM before Reth is bootstrapped.

Why does this matter?

With extensions to the configuration of Reth, WeaveVM gets full control over how the EVM runtime becames. This is especially useful when:

  • Implementing internal logic (like precompiles)
  • Changing the structure of the chain (for example, new parameters inside blocks or transactions)
  • Extending node behavior

Conclusion

Reth has been key to WeaveVM’s progress in merging data and execution layers into one platform. It’s helped us build efficient, cost-effective features, including precompiles and ExEx (more on that later).

Using Rust, the language Reth is built in, has been a big plus. It offers low-level control but feels familiar to those used to higher-level languages, speeding up our development.

WeaveVM aims to make waves in on-chain storage and computation. We’re excited to see how tools like precompiles can help you and your projects work more easily with our chain and use Arweave for storage.