From c3654221e53c338e1a6914294dcb9cb752f2db20 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Mon, 5 Aug 2024 15:21:13 +0100 Subject: [PATCH] feat(evm): support `wasm32-wasip1` (#10083) --- .github/assets/check_wasm.sh | 2 +- crates/evm/execution-types/Cargo.toml | 2 ++ crates/evm/execution-types/src/chain.rs | 7 ++++++- crates/evm/execution-types/src/lib.rs | 3 +++ crates/evm/src/builder.rs | 3 +++ crates/evm/src/either.rs | 2 +- crates/evm/src/execute.rs | 11 ++++------- crates/evm/src/noop.rs | 2 +- crates/evm/src/system_calls.rs | 14 +++++++++++--- 9 files changed, 32 insertions(+), 14 deletions(-) diff --git a/.github/assets/check_wasm.sh b/.github/assets/check_wasm.sh index 01ccc8604526e..7cd93f6ac5c47 100755 --- a/.github/assets/check_wasm.sh +++ b/.github/assets/check_wasm.sh @@ -6,12 +6,12 @@ wasm_crates=( # The following were confirmed not working in the past, but could be enabled if issues have been resolved # reth-consensus # reth-db - # reth-evm # reth-evm-ethereum # The following are confirmed working reth-codecs reth-errors reth-ethereum-forks + reth-evm reth-network-peers reth-primitives reth-primitives-traits diff --git a/crates/evm/execution-types/Cargo.toml b/crates/evm/execution-types/Cargo.toml index 57181537c5424..cf50b47a03b25 100644 --- a/crates/evm/execution-types/Cargo.toml +++ b/crates/evm/execution-types/Cargo.toml @@ -26,5 +26,7 @@ alloy-primitives.workspace = true alloy-eips.workspace = true [features] +default = ["std"] optimism = ["dep:reth-chainspec"] serde = ["dep:serde", "reth-trie/serde", "revm/serde"] +std = [] diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index 42d407370b96f..ceb73f96f3f12 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -1,5 +1,11 @@ //! Contains [Chain], a chain of blocks and their final state. +#[cfg(not(feature = "std"))] +use alloc::{borrow::Cow, collections::BTreeMap}; +use core::{fmt, ops::RangeInclusive}; +#[cfg(feature = "std")] +use std::{borrow::Cow, collections::BTreeMap}; + use crate::ExecutionOutcome; use reth_execution_errors::{BlockExecutionError, InternalBlockExecutionError}; use reth_primitives::{ @@ -8,7 +14,6 @@ use reth_primitives::{ }; use reth_trie::updates::TrieUpdates; use revm::db::BundleState; -use std::{borrow::Cow, collections::BTreeMap, fmt, ops::RangeInclusive}; /// A chain of blocks and their final state. /// diff --git a/crates/evm/execution-types/src/lib.rs b/crates/evm/execution-types/src/lib.rs index 881b2a33dad0d..86abd98de1d94 100644 --- a/crates/evm/execution-types/src/lib.rs +++ b/crates/evm/execution-types/src/lib.rs @@ -8,6 +8,9 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#[cfg(not(feature = "std"))] +extern crate alloc; + mod chain; pub use chain::*; diff --git a/crates/evm/src/builder.rs b/crates/evm/src/builder.rs index 68888983ee5e4..e238ba8ccaffe 100644 --- a/crates/evm/src/builder.rs +++ b/crates/evm/src/builder.rs @@ -1,5 +1,8 @@ //! Builder for creating an EVM with a database and environment. +#[cfg(not(feature = "std"))] +use alloc::boxed::Box; + use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector}; use revm_primitives::EnvWithHandlerCfg; diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index 0a490b813596e..84e1733e4812f 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -1,6 +1,6 @@ //! Helper type that represents one of two possible executor types -use std::fmt::Display; +use core::fmt::Display; use crate::execute::{BatchExecutor, BlockExecutorProvider, Executor}; use reth_execution_errors::BlockExecutionError; diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index 68c398506120e..2109d557f8ec9 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -1,18 +1,15 @@ //! Traits for execution. // Re-export execution types +pub use reth_execution_errors::{BlockExecutionError, BlockValidationError}; pub use reth_execution_types::{BlockExecutionInput, BlockExecutionOutput, ExecutionOutcome}; +pub use reth_storage_errors::provider::ProviderError; + +use core::fmt::Display; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use revm_primitives::db::Database; -use std::fmt::Display; - -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - -pub use reth_execution_errors::{BlockExecutionError, BlockValidationError}; -pub use reth_storage_errors::provider::ProviderError; /// A general purpose executor trait that executes an input (e.g. block) and produces an output /// (e.g. state changes and receipts). diff --git a/crates/evm/src/noop.rs b/crates/evm/src/noop.rs index beac15be16625..ff8e893b2b6ba 100644 --- a/crates/evm/src/noop.rs +++ b/crates/evm/src/noop.rs @@ -1,6 +1,6 @@ //! A no operation block executor implementation. -use std::fmt::Display; +use core::fmt::Display; use reth_execution_errors::BlockExecutionError; use reth_execution_types::{BlockExecutionInput, BlockExecutionOutput, ExecutionOutcome}; diff --git a/crates/evm/src/system_calls.rs b/crates/evm/src/system_calls.rs index 58759a866556a..142a763abcce8 100644 --- a/crates/evm/src/system_calls.rs +++ b/crates/evm/src/system_calls.rs @@ -1,5 +1,13 @@ //! System contract call functions. +#[cfg(feature = "std")] +use std::fmt::Display; +#[cfg(not(feature = "std"))] +use { + alloc::{boxed::Box, format, string::ToString, vec::Vec}, + core::fmt::Display, +}; + use crate::ConfigureEvm; use alloy_eips::{ eip4788::BEACON_ROOTS_ADDRESS, @@ -35,7 +43,7 @@ pub fn pre_block_beacon_root_contract_call( ) -> Result<(), BlockExecutionError> where DB: Database + DatabaseCommit, - DB::Error: std::fmt::Display, + DB::Error: Display, EvmConfig: ConfigureEvm, { // apply pre-block EIP-4788 contract call @@ -148,7 +156,7 @@ pub fn post_block_withdrawal_requests_contract_call( ) -> Result, BlockExecutionError> where DB: Database + DatabaseCommit, - DB::Error: std::fmt::Display, + DB::Error: Display, EvmConfig: ConfigureEvm, { // apply post-block EIP-7002 contract call @@ -278,7 +286,7 @@ pub fn post_block_consolidation_requests_contract_call( ) -> Result, BlockExecutionError> where DB: Database + DatabaseCommit, - DB::Error: std::fmt::Display, + DB::Error: Display, EvmConfig: ConfigureEvm, { // apply post-block EIP-7251 contract call