From f8ad99221d2d11c2b10aa97a52553f958395259a Mon Sep 17 00:00:00 2001 From: Lucas Clemente Vella Date: Tue, 29 Aug 2023 21:30:12 +0100 Subject: [PATCH 1/5] Removed the last dependencies breaking no-std build. Removed to_binary, which was used only in a debug display. Replaced once_cell with lazy_static. The no-std build of once_cell did not support the Sync version of OnceCell, that was needed when creating static variables. On the other hand, lazy_static is the complete solution for lazyly initialized (Sync) static variables, and is no-std. With this changes, revm builds on a no-std platform. --- Cargo.lock | 12 +-- crates/precompile/Cargo.toml | 10 ++- crates/precompile/src/lib.rs | 136 ++++++++++++++++-------------- crates/primitives/Cargo.toml | 17 +++- crates/primitives/src/bytecode.rs | 3 +- crates/primitives/src/lib.rs | 1 - 6 files changed, 95 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8a0ec01e3..0b2025468b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2412,8 +2412,8 @@ version = "2.0.3" dependencies = [ "hex", "k256", + "lazy_static", "num", - "once_cell", "revm-primitives", "ripemd", "secp256k1", @@ -2444,7 +2444,6 @@ dependencies = [ "ruint", "serde", "sha3", - "to-binary", ] [[package]] @@ -3148,15 +3147,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "to-binary" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424552bc848fd1afbcd81f0e8a54b7401b90fd81bb418655ad6dc6d0823bbe3" -dependencies = [ - "hex", -] - [[package]] name = "tokio" version = "1.32.0" diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index c137bd2935..2f8d1fa759 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -9,15 +9,18 @@ repository = "https://github.com/bluealloy/revm" version = "2.0.3" [dependencies] -revm-primitives = { path = "../primitives", version="1.1.2", default-features = false } +revm-primitives = { path = "../primitives", version = "1.1.2", default-features = false } bn = { package = "substrate-bn", version = "0.6", default-features = false } k256 = { version = "0.13", default-features = false, features = ["ecdsa"] } num = { version = "0.4.0", default-features = false, features = ["alloc"] } -once_cell = "1.17" ripemd = { version = "0.1", default-features = false } -secp256k1 = { version = "0.27.0", default-features = false, features = ["alloc", "recovery"], optional = true } +secp256k1 = { version = "0.27.0", default-features = false, features = [ + "alloc", + "recovery", +], optional = true } sha2 = { version = "0.10.5", default-features = false } sha3 = { version = "0.10.7", default-features = false } +lazy_static = "1.4" [dev-dependencies] hex = "0.4" @@ -28,4 +31,3 @@ default = ["secp256k1"] # Only problem that it has, it fails to build for wasm target on windows and mac as it is c lib. # If you dont require wasm on win/mac, i would recommend its usage. secp256k1 = ["dep:secp256k1"] - diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 888335ef13..342f3d61ad 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -10,7 +10,6 @@ mod identity; mod modexp; mod secp256k1; -use once_cell::sync::OnceCell; pub use primitives::{ precompile::{PrecompileError as Error, *}, Bytes, HashMap, @@ -23,6 +22,7 @@ pub type B256 = [u8; 32]; use alloc::vec::Vec; use core::fmt; +use lazy_static::lazy_static; pub fn calc_linear_cost_u32(len: usize, base: u64, word: u64) -> u64 { (len as u64 + 32 - 1) / 32 * word + base @@ -119,76 +119,88 @@ impl SpecId { impl Precompiles { pub fn homestead() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); - INSTANCE.get_or_init(|| { - let fun = [ - secp256k1::ECRECOVER, - hash::SHA256, - hash::RIPEMD160, - identity::FUN, - ] - .into_iter() - .map(From::from) - .collect(); - Self { fun } - }) + lazy_static! { + static ref INSTANCE: Precompiles = { + let fun = [ + secp256k1::ECRECOVER, + hash::SHA256, + hash::RIPEMD160, + identity::FUN, + ] + .into_iter() + .map(From::from) + .collect(); + Precompiles { fun } + }; + } + + &INSTANCE } pub fn byzantium() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); - INSTANCE.get_or_init(|| { - let mut precompiles = Self::homestead().clone(); - precompiles.fun.extend( - [ - // EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128. - // EIP-197: Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128. - bn128::add::BYZANTIUM, - bn128::mul::BYZANTIUM, - bn128::pair::BYZANTIUM, - // EIP-198: Big integer modular exponentiation. - modexp::BYZANTIUM, - ] - .into_iter() - .map(From::from), - ); - precompiles - }) + lazy_static! { + static ref INSTANCE: Precompiles = { + let mut precompiles = Precompiles::homestead().clone(); + precompiles.fun.extend( + [ + // EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128. + // EIP-197: Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128. + bn128::add::BYZANTIUM, + bn128::mul::BYZANTIUM, + bn128::pair::BYZANTIUM, + // EIP-198: Big integer modular exponentiation. + modexp::BYZANTIUM, + ] + .into_iter() + .map(From::from), + ); + precompiles + }; + } + + &INSTANCE } pub fn istanbul() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); - INSTANCE.get_or_init(|| { - let mut precompiles = Self::byzantium().clone(); - precompiles.fun.extend( - [ - // EIP-152: Add BLAKE2 compression function `F` precompile. - blake2::FUN, - // EIP-1108: Reduce alt_bn128 precompile gas costs. - bn128::add::ISTANBUL, - bn128::mul::ISTANBUL, - bn128::pair::ISTANBUL, - ] - .into_iter() - .map(From::from), - ); - precompiles - }) + lazy_static! { + static ref INSTANCE: Precompiles = { + let mut precompiles = Precompiles::byzantium().clone(); + precompiles.fun.extend( + [ + // EIP-152: Add BLAKE2 compression function `F` precompile. + blake2::FUN, + // EIP-1108: Reduce alt_bn128 precompile gas costs. + bn128::add::ISTANBUL, + bn128::mul::ISTANBUL, + bn128::pair::ISTANBUL, + ] + .into_iter() + .map(From::from), + ); + precompiles + }; + } + + &INSTANCE } pub fn berlin() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); - INSTANCE.get_or_init(|| { - let mut precompiles = Self::istanbul().clone(); - precompiles.fun.extend( - [ - // EIP-2565: ModExp Gas Cost. - modexp::BERLIN, - ] - .into_iter() - .map(From::from), - ); - precompiles - }) + lazy_static! { + static ref INSTANCE: Precompiles = { + let mut precompiles = Precompiles::istanbul().clone(); + precompiles.fun.extend( + [ + // EIP-2565: ModExp Gas Cost. + modexp::BERLIN, + ] + .into_iter() + .map(From::from), + ); + precompiles + }; + } + + &INSTANCE } pub fn latest() -> &'static Self { diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index ff36435883..7edb775f7b 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -14,18 +14,22 @@ bytes = { version = "1.4", default-features = false } hashbrown = "0.14" primitive-types = { version = "0.12", default-features = false } rlp = { version = "0.5", default-features = false } # used for create2 address calculation -ruint = { version = "1.8.0", features = ["primitive-types", "rlp"] } +ruint = { version = "1.8.0", default-features = false, features = [ + "primitive-types", + "rlp", +] } auto_impl = "1.1" bitvec = { version = "1", default-features = false, features = ["alloc"] } bitflags = { version = "2.4.0", default-features = false } # bits B256 B160 crate -fixed-hash = { version = "0.8", default-features = false, features = ["rustc-hex"] } +fixed-hash = { version = "0.8", default-features = false, features = [ + "rustc-hex", +] } #utility hex-literal = "0.4" hex = { version = "0.4", default-features = false, features = ["alloc"] } -to-binary = "0.4" derive_more = "0.99" enumn = "0.1" @@ -42,7 +46,12 @@ proptest-derive = { version = "0.3", optional = true } arbitrary = { version = "1.3", features = ["derive"] } proptest = "1.1" proptest-derive = "0.3" -ruint = { version = "1.10.1", features = ["primitive-types", "rlp", "proptest", "arbitrary"] } +ruint = { version = "1.10.1", features = [ + "primitive-types", + "rlp", + "proptest", + "arbitrary", +] } [features] default = ["std"] diff --git a/crates/primitives/src/bytecode.rs b/crates/primitives/src/bytecode.rs index 395c97cb8a..9d1e0e6d48 100644 --- a/crates/primitives/src/bytecode.rs +++ b/crates/primitives/src/bytecode.rs @@ -4,7 +4,6 @@ use bitvec::prelude::{bitvec, Lsb0}; use bitvec::vec::BitVec; use bytes::Bytes; use core::fmt::Debug; -use to_binary::BinaryString; /// A map of valid `jump` destinations. #[derive(Clone, Eq, PartialEq, Default)] @@ -14,7 +13,7 @@ pub struct JumpMap(pub Arc>); impl Debug for JumpMap { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("JumpMap") - .field("map", &BinaryString::from(self.0.as_raw_slice())) + .field("map", &self.0.as_raw_slice()) .finish() } } diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 6fe75693ef..9f9e85b63b 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -20,7 +20,6 @@ pub use bytes; pub use bytes::Bytes; pub use hex; pub use hex_literal; -pub use to_binary; /// Address type is last 20 bytes of hash of ethereum account pub type Address = B160; /// Hash, in Ethereum usually keccak256. From 45b3cb19abfca6a9f307915d6537046952491c45 Mon Sep 17 00:00:00 2001 From: Lucas Clemente Vella Date: Thu, 31 Aug 2023 16:59:19 +0100 Subject: [PATCH 2/5] Reverting back to OnceCell. --- Cargo.lock | 22 +++++- crates/precompile/Cargo.toml | 6 +- crates/precompile/src/lib.rs | 139 ++++++++++++++++------------------- crates/revm/Cargo.toml | 11 ++- 4 files changed, 97 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b2025468b..ca346544db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -259,6 +259,15 @@ dependencies = [ "rustc_version 0.4.0", ] +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + [[package]] name = "atty" version = "0.2.14" @@ -684,6 +693,12 @@ dependencies = [ "itertools", ] +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -1886,6 +1901,10 @@ name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +dependencies = [ + "atomic-polyfill", + "critical-section", +] [[package]] name = "oorandom" @@ -2383,7 +2402,6 @@ dependencies = [ "futures", "hex", "hex-literal", - "once_cell", "rayon", "revm-interpreter", "revm-precompile", @@ -2412,8 +2430,8 @@ version = "2.0.3" dependencies = [ "hex", "k256", - "lazy_static", "num", + "once_cell", "revm-primitives", "ripemd", "secp256k1", diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 2f8d1fa759..2bdb92ebdc 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -13,6 +13,7 @@ revm-primitives = { path = "../primitives", version = "1.1.2", default-features bn = { package = "substrate-bn", version = "0.6", default-features = false } k256 = { version = "0.13", default-features = false, features = ["ecdsa"] } num = { version = "0.4.0", default-features = false, features = ["alloc"] } +once_cell = { version = "1.17", default-features = false } ripemd = { version = "0.1", default-features = false } secp256k1 = { version = "0.27.0", default-features = false, features = [ "alloc", @@ -20,13 +21,14 @@ secp256k1 = { version = "0.27.0", default-features = false, features = [ ], optional = true } sha2 = { version = "0.10.5", default-features = false } sha3 = { version = "0.10.7", default-features = false } -lazy_static = "1.4" [dev-dependencies] hex = "0.4" [features] -default = ["secp256k1"] +default = ["std", "secp256k1"] +std = ["once_cell/std"] +critical-section = ["once_cell/critical-section"] # secp256k1 is used as faster alternative to k256 lib. And in most cases should be default. # Only problem that it has, it fails to build for wasm target on windows and mac as it is c lib. # If you dont require wasm on win/mac, i would recommend its usage. diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 342f3d61ad..f39ccfd67d 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -10,6 +10,10 @@ mod identity; mod modexp; mod secp256k1; +#[cfg(not(any(feature = "std", feature = "critical-section")))] +compile_error!("Either feature \"std\" or \"critical-section\" must be enabled, otherwise OnceCell is unavailable."); + +use once_cell::sync::OnceCell; pub use primitives::{ precompile::{PrecompileError as Error, *}, Bytes, HashMap, @@ -22,7 +26,6 @@ pub type B256 = [u8; 32]; use alloc::vec::Vec; use core::fmt; -use lazy_static::lazy_static; pub fn calc_linear_cost_u32(len: usize, base: u64, word: u64) -> u64 { (len as u64 + 32 - 1) / 32 * word + base @@ -119,88 +122,76 @@ impl SpecId { impl Precompiles { pub fn homestead() -> &'static Self { - lazy_static! { - static ref INSTANCE: Precompiles = { - let fun = [ - secp256k1::ECRECOVER, - hash::SHA256, - hash::RIPEMD160, - identity::FUN, - ] - .into_iter() - .map(From::from) - .collect(); - Precompiles { fun } - }; - } - - &INSTANCE + static INSTANCE: OnceCell = OnceCell::new(); + INSTANCE.get_or_init(|| { + let fun = [ + secp256k1::ECRECOVER, + hash::SHA256, + hash::RIPEMD160, + identity::FUN, + ] + .into_iter() + .map(From::from) + .collect(); + Self { fun } + }) } pub fn byzantium() -> &'static Self { - lazy_static! { - static ref INSTANCE: Precompiles = { - let mut precompiles = Precompiles::homestead().clone(); - precompiles.fun.extend( - [ - // EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128. - // EIP-197: Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128. - bn128::add::BYZANTIUM, - bn128::mul::BYZANTIUM, - bn128::pair::BYZANTIUM, - // EIP-198: Big integer modular exponentiation. - modexp::BYZANTIUM, - ] - .into_iter() - .map(From::from), - ); - precompiles - }; - } - - &INSTANCE + static INSTANCE: OnceCell = OnceCell::new(); + INSTANCE.get_or_init(|| { + let mut precompiles = Self::homestead().clone(); + precompiles.fun.extend( + [ + // EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128. + // EIP-197: Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128. + bn128::add::BYZANTIUM, + bn128::mul::BYZANTIUM, + bn128::pair::BYZANTIUM, + // EIP-198: Big integer modular exponentiation. + modexp::BYZANTIUM, + ] + .into_iter() + .map(From::from), + ); + precompiles + }) } pub fn istanbul() -> &'static Self { - lazy_static! { - static ref INSTANCE: Precompiles = { - let mut precompiles = Precompiles::byzantium().clone(); - precompiles.fun.extend( - [ - // EIP-152: Add BLAKE2 compression function `F` precompile. - blake2::FUN, - // EIP-1108: Reduce alt_bn128 precompile gas costs. - bn128::add::ISTANBUL, - bn128::mul::ISTANBUL, - bn128::pair::ISTANBUL, - ] - .into_iter() - .map(From::from), - ); - precompiles - }; - } - - &INSTANCE + static INSTANCE: OnceCell = OnceCell::new(); + INSTANCE.get_or_init(|| { + let mut precompiles = Self::byzantium().clone(); + precompiles.fun.extend( + [ + // EIP-152: Add BLAKE2 compression function `F` precompile. + blake2::FUN, + // EIP-1108: Reduce alt_bn128 precompile gas costs. + bn128::add::ISTANBUL, + bn128::mul::ISTANBUL, + bn128::pair::ISTANBUL, + ] + .into_iter() + .map(From::from), + ); + precompiles + }) } pub fn berlin() -> &'static Self { - lazy_static! { - static ref INSTANCE: Precompiles = { - let mut precompiles = Precompiles::istanbul().clone(); - precompiles.fun.extend( - [ - // EIP-2565: ModExp Gas Cost. - modexp::BERLIN, - ] - .into_iter() - .map(From::from), - ); - precompiles - }; - } - - &INSTANCE + static INSTANCE: OnceCell = OnceCell::new(); + INSTANCE.get_or_init(|| { + let mut precompiles = Self::istanbul().clone(); + precompiles.fun.extend( + [ + // EIP-2565: ModExp Gas Cost. + modexp::BERLIN, + ] + .into_iter() + .map(From::from), + ); + precompiles + }) } pub fn latest() -> &'static Self { diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index fa51284aad..2dcb1aa825 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -15,14 +15,16 @@ revm-interpreter = { path = "../interpreter", version = "1.1.2", default-feature #misc auto_impl = { version = "1.1", default-features = false } -once_cell = { version = "1.17", default-features = false } # Optional serde = { version = "1.0", features = ["derive", "rc"], optional = true } serde_json = { version = "1.0", features = ["preserve_order"], optional = true } # ethersdb -tokio = { version = "1.32", features = ["rt-multi-thread", "macros"], optional = true } +tokio = { version = "1.32", features = [ + "rt-multi-thread", + "macros", +], optional = true } ethers-providers = { version = "2.0", optional = true } ethers-core = { version = "2.0", optional = true } futures = { version = "0.3.27", optional = true } @@ -40,6 +42,9 @@ criterion = "0.5" [features] default = ["std", "secp256k1"] +# Without std, critical-section must be enabled and a critical section +# implementation must be provided. See crate "critical_section". +critical-section = ["revm-precompile/critical-section"] dev = [ "memory_limit", "optional_balance_check", @@ -56,7 +61,7 @@ optional_block_gas_limit = ["revm-interpreter/optional_block_gas_limit"] optional_eip3607 = ["revm-interpreter/optional_eip3607"] optional_gas_refund = ["revm-interpreter/optional_gas_refund"] optional_no_base_fee = ["revm-interpreter/optional_no_base_fee"] -std = ["revm-interpreter/std", "once_cell/std", "rayon"] +std = ["revm-interpreter/std", "revm-precompile/std", "rayon"] ethersdb = ["std", "tokio", "futures", "ethers-providers", "ethers-core"] serde = ["dep:serde", "dep:serde_json", "revm-interpreter/serde"] arbitrary = ["revm-interpreter/arbitrary"] From 102fa5282890017245cc6f3800ee31baf369278b Mon Sep 17 00:00:00 2001 From: Lucas Clemente Vella Date: Thu, 31 Aug 2023 17:03:26 +0100 Subject: [PATCH 3/5] Hex encoding debug print. --- crates/primitives/src/bytecode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/primitives/src/bytecode.rs b/crates/primitives/src/bytecode.rs index 9d1e0e6d48..2d5a1a379a 100644 --- a/crates/primitives/src/bytecode.rs +++ b/crates/primitives/src/bytecode.rs @@ -13,7 +13,7 @@ pub struct JumpMap(pub Arc>); impl Debug for JumpMap { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("JumpMap") - .field("map", &self.0.as_raw_slice()) + .field("map", &hex::encode(&self.0.as_raw_slice())) .finish() } } From ebb85b52f0673080bbe21f0c1fd5e3b3a1a4d59e Mon Sep 17 00:00:00 2001 From: Lucas Clemente Vella Date: Fri, 1 Sep 2023 10:33:51 +0100 Subject: [PATCH 4/5] Using race::OnceBox instead of critical-section. --- Cargo.lock | 19 ------------------- crates/precompile/Cargo.toml | 6 ++---- crates/precompile/src/lib.rs | 23 ++++++++++------------- crates/revm/Cargo.toml | 5 +---- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 875190bc9e..ae802d0394 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,15 +257,6 @@ dependencies = [ "rustc_version 0.4.0", ] -[[package]] -name = "atomic-polyfill" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" -dependencies = [ - "critical-section", -] - [[package]] name = "atty" version = "0.2.14" @@ -594,12 +585,6 @@ dependencies = [ "itertools", ] -[[package]] -name = "critical-section" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" - [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -1773,10 +1758,6 @@ name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -dependencies = [ - "atomic-polyfill", - "critical-section", -] [[package]] name = "oorandom" diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 2bdb92ebdc..3224f1b6d1 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -13,7 +13,7 @@ revm-primitives = { path = "../primitives", version = "1.1.2", default-features bn = { package = "substrate-bn", version = "0.6", default-features = false } k256 = { version = "0.13", default-features = false, features = ["ecdsa"] } num = { version = "0.4.0", default-features = false, features = ["alloc"] } -once_cell = { version = "1.17", default-features = false } +once_cell = { version = "1.17", default-features = false, features = ["alloc"] } ripemd = { version = "0.1", default-features = false } secp256k1 = { version = "0.27.0", default-features = false, features = [ "alloc", @@ -26,9 +26,7 @@ sha3 = { version = "0.10.7", default-features = false } hex = "0.4" [features] -default = ["std", "secp256k1"] -std = ["once_cell/std"] -critical-section = ["once_cell/critical-section"] +default = ["secp256k1"] # secp256k1 is used as faster alternative to k256 lib. And in most cases should be default. # Only problem that it has, it fails to build for wasm target on windows and mac as it is c lib. # If you dont require wasm on win/mac, i would recommend its usage. diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index f39ccfd67d..cccc2b0958 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -10,10 +10,7 @@ mod identity; mod modexp; mod secp256k1; -#[cfg(not(any(feature = "std", feature = "critical-section")))] -compile_error!("Either feature \"std\" or \"critical-section\" must be enabled, otherwise OnceCell is unavailable."); - -use once_cell::sync::OnceCell; +use once_cell::race::OnceBox; pub use primitives::{ precompile::{PrecompileError as Error, *}, Bytes, HashMap, @@ -24,7 +21,7 @@ pub use revm_primitives as primitives; pub type B160 = [u8; 20]; pub type B256 = [u8; 32]; -use alloc::vec::Vec; +use alloc::{boxed::Box, vec::Vec}; use core::fmt; pub fn calc_linear_cost_u32(len: usize, base: u64, word: u64) -> u64 { @@ -122,7 +119,7 @@ impl SpecId { impl Precompiles { pub fn homestead() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); + static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { let fun = [ secp256k1::ECRECOVER, @@ -133,14 +130,14 @@ impl Precompiles { .into_iter() .map(From::from) .collect(); - Self { fun } + Box::new(Self { fun }) }) } pub fn byzantium() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); + static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { - let mut precompiles = Self::homestead().clone(); + let mut precompiles = Box::new(Self::homestead().clone()); precompiles.fun.extend( [ // EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128. @@ -159,9 +156,9 @@ impl Precompiles { } pub fn istanbul() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); + static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { - let mut precompiles = Self::byzantium().clone(); + let mut precompiles = Box::new(Self::byzantium().clone()); precompiles.fun.extend( [ // EIP-152: Add BLAKE2 compression function `F` precompile. @@ -179,9 +176,9 @@ impl Precompiles { } pub fn berlin() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); + static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { - let mut precompiles = Self::istanbul().clone(); + let mut precompiles = Box::new(Self::istanbul().clone()); precompiles.fun.extend( [ // EIP-2565: ModExp Gas Cost. diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index a579230005..41ff5cb49d 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -42,9 +42,6 @@ criterion = "0.5" [features] default = ["std", "secp256k1"] -# Without std, critical-section must be enabled and a critical section -# implementation must be provided. See crate "critical_section". -critical-section = ["revm-precompile/critical-section"] dev = [ "memory_limit", "optional_balance_check", @@ -61,7 +58,7 @@ optional_block_gas_limit = ["revm-interpreter/optional_block_gas_limit"] optional_eip3607 = ["revm-interpreter/optional_eip3607"] optional_gas_refund = ["revm-interpreter/optional_gas_refund"] optional_no_base_fee = ["revm-interpreter/optional_no_base_fee"] -std = ["revm-interpreter/std", "revm-precompile/std", "rayon"] +std = ["revm-interpreter/std", "rayon"] ethersdb = ["std", "tokio", "futures", "ethers-providers", "ethers-core"] serde = ["dep:serde", "dep:serde_json", "revm-interpreter/serde"] arbitrary = ["revm-interpreter/arbitrary"] From 3f17224965b74e3fce481611a0bcd1218a3fc905 Mon Sep 17 00:00:00 2001 From: Lucas Clemente Vella Date: Fri, 1 Sep 2023 11:13:11 +0100 Subject: [PATCH 5/5] Lint error. --- crates/primitives/src/bytecode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/primitives/src/bytecode.rs b/crates/primitives/src/bytecode.rs index 2d5a1a379a..ea28c9137c 100644 --- a/crates/primitives/src/bytecode.rs +++ b/crates/primitives/src/bytecode.rs @@ -13,7 +13,7 @@ pub struct JumpMap(pub Arc>); impl Debug for JumpMap { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("JumpMap") - .field("map", &hex::encode(&self.0.as_raw_slice())) + .field("map", &hex::encode(self.0.as_raw_slice())) .finish() } }