From 7e98fefb9ed256403c232ddbd47a32839eaf75f8 Mon Sep 17 00:00:00 2001 From: Wodann Date: Tue, 27 Dec 2022 13:19:49 -0600 Subject: [PATCH] fix: feature flag compiler errors (#256) * fix: compiler errors related to feature flags * fixup compiler errors * make k256 default and have secp256k1 as feature Co-authored-by: rakita --- crates/revm/Cargo.toml | 11 +++++------ crates/revm_precompiles/Cargo.toml | 7 +++++-- crates/revm_precompiles/src/secp256k1.rs | 13 +++++++------ crates/revmjs/Cargo.toml | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 35050a33fe..d6ae924e83 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -47,16 +47,15 @@ dev = [ "optional_eip3607", "optional_gas_refund", ] +ethersdb = ["tokio", "futures", "ethers-providers", "ethers-core"] +# deprecated feature +web3db = [] +secp256k1 = ["revm_precompiles/secp256k1"] memory_limit = [] no_gas_measuring = [] optional_balance_check = [] optional_block_gas_limit = [] optional_eip3607 = [] optional_gas_refund = [] -std = ["bytes/std", "num_enum/std", "rlp/std", "hex/std"] -secp256k1 = ["revm_precompiles/secp256k1"] -k256 = ["revm_precompiles/k256_ecrecover"] -ethersdb = ["tokio", "futures", "ethers-providers", "ethers-core"] +std = ["bytes/std", "num_enum/std", "rlp/std"] with-serde = ["serde", "hex/serde", "hashbrown/serde", "ruint/serde"] -# deprecated feature -web3db = [] diff --git a/crates/revm_precompiles/Cargo.toml b/crates/revm_precompiles/Cargo.toml index 7299e3998e..5a0b7ef3fb 100644 --- a/crates/revm_precompiles/Cargo.toml +++ b/crates/revm_precompiles/Cargo.toml @@ -12,7 +12,7 @@ version = "1.1.2" bn = { package = "substrate-bn", version = "0.6", default-features = false } bytes = { version = "1.1", default-features = false } hashbrown = { version = "0.13" } -k256 = { version = "0.11", default-features = false, features = ["ecdsa", "keccak256"], optional = true } +k256 = { version = "0.11", default-features = false, features = ["ecdsa", "keccak256"] } num = { version = "0.4.0", default-features = false, features = ["alloc"] } once_cell = "1.14" ripemd = { version = "0.1", default-features = false } @@ -26,5 +26,8 @@ hex = "0.4" [features] default = ["secp256k1"] -k256_ecrecover = ["k256"] +# 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. +secp256k1 = ["dep:secp256k1"] diff --git a/crates/revm_precompiles/src/secp256k1.rs b/crates/revm_precompiles/src/secp256k1.rs index 66e2d7ed92..77b38c45b2 100644 --- a/crates/revm_precompiles/src/secp256k1.rs +++ b/crates/revm_precompiles/src/secp256k1.rs @@ -1,15 +1,11 @@ use crate::{Error, Precompile, PrecompileAddress, PrecompileResult, StandardPrecompileFn}; -use alloc::vec::Vec; -use core::cmp::min; - -const ECRECOVER_BASE: u64 = 3_000; pub const ECRECOVER: PrecompileAddress = PrecompileAddress( crate::u64_to_b160(1), Precompile::Standard(ec_recover_run as StandardPrecompileFn), ); -#[cfg(feature = "k256_ecrecover")] +#[cfg(feature = "secp256k1")] #[allow(clippy::module_inception)] mod secp256k1 { use core::convert::TryFrom; @@ -35,7 +31,7 @@ mod secp256k1 { } } -#[cfg(all(not(feature = "k256_ecrecover"), feature = "secp256k1"))] +#[cfg(not(feature = "secp256k1"))] #[allow(clippy::module_inception)] mod secp256k1 { use crate::B256; @@ -60,6 +56,11 @@ mod secp256k1 { } fn ec_recover_run(i: &[u8], target_gas: u64) -> PrecompileResult { + use alloc::vec::Vec; + use core::cmp::min; + + const ECRECOVER_BASE: u64 = 3_000; + if ECRECOVER_BASE > target_gas { return Err(Error::OutOfGas); } diff --git a/crates/revmjs/Cargo.toml b/crates/revmjs/Cargo.toml index 4fed2156d4..6caf27c561 100644 --- a/crates/revmjs/Cargo.toml +++ b/crates/revmjs/Cargo.toml @@ -17,7 +17,7 @@ bytes = "1.2" getrandom = { version = "0.2", features = ["js"] } hex = "0.4" js-sys = "0.3" -revm = { path = "../revm", version = "2.0", default-features = false, features = ["k256"] } +revm = { path = "../revm", version = "2.0", default-features = false } ruint = { version = "1.7.0", features = ["bn-rs"] } wasm-bindgen = "0.2" primitive-types = "0.12" \ No newline at end of file