Skip to content

Commit

Permalink
fix: feature flag compiler errors (#256)
Browse files Browse the repository at this point in the history
* fix: compiler errors related to feature flags

* fixup compiler errors

* make k256 default and have secp256k1 as feature

Co-authored-by: rakita <[email protected]>
  • Loading branch information
Wodann and rakita authored Dec 27, 2022
1 parent 85f2b54 commit 7e98fef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
11 changes: 5 additions & 6 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
7 changes: 5 additions & 2 deletions crates/revm_precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"]

13 changes: 7 additions & 6 deletions crates/revm_precompiles/src/secp256k1.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/revmjs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 7e98fef

Please sign in to comment.