Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: feature flag compiler errors #256

Merged
merged 5 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ dev = [
"optional_eip3607",
"optional_gas_refund",
]
ethersdb = ["tokio", "futures", "ethers-providers", "ethers-core", "hex"]
k256 = ["revm_precompiles/k256_ecrecover"]
memory_limit = []
no_gas_measuring = []
optional_block_gas_limit = []
optional_eip3607 = []
optional_gas_refund = []
std = ["bytes/std", "num_enum/std", "rlp/std"]
secp256k1 = ["revm_precompiles/secp256k1"]
k256 = ["revm_precompiles/k256_ecrecover"]
web3db = []
Copy link
Contributor Author

@Wodann Wodann Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed deprecated feature flag web3db, as it will cause cargo t --all-features to fail

ethersdb = ["tokio", "futures", "ethers-providers", "ethers-core", "hex"]
with-serde = ["serde", "hex", "hex/serde", "hashbrown/serde"]
std = ["bytes/std", "num_enum/std", "rlp/std"]
with-serde = ["serde", "hex", "hex/serde", "hashbrown/serde", "ruint/serde"]
1 change: 1 addition & 0 deletions crates/revm_precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl Precompiles {
static INSTANCE: OnceCell<Precompiles> = OnceCell::new();
INSTANCE.get_or_init(|| {
let fun = vec![
#[cfg(any(feature = "k256_ecrecover", feature = "secp256k1"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont want to disable ECRECOVER if default is not present, it seems like a footgun. As I said here I am fine with build failure: #252 (comment)

Having this would make this more user-friendly: https://doc.rust-lang.org/std/macro.compile_error.html

Something like

#[cfg(all(not(feature = "k256_ecrecover"), not(feature = "secp256k1")))]
compile_error!(
    "To support ecrecover precompile please enable one of these two features, `k256_ecrecover` or `secp256k1`
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the above mentioned compile_error to the secp256k1 module

secp256k1::ECRECOVER,
hash::SHA256,
hash::RIPEMD160,
Expand Down
12 changes: 8 additions & 4 deletions crates/revm_precompiles/src/secp256k1.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#[cfg(any(feature = "k256_ecrecover", feature = "secp256k1"))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing feature cfg, as this only works when either the k256_ecrecover or secp256k1 feature flags are on. Ensures that cargo t --no-default-features succeeds.

use crate::{Error, Precompile, PrecompileAddress, PrecompileResult, StandardPrecompileFn};
use alloc::vec::Vec;
use core::cmp::min;

const ECRECOVER_BASE: u64 = 3_000;

#[cfg(any(feature = "k256_ecrecover", feature = "secp256k1"))]
pub const ECRECOVER: PrecompileAddress = PrecompileAddress(
crate::u64_to_b160(1),
Precompile::Standard(ec_recover_run as StandardPrecompileFn),
Expand Down Expand Up @@ -59,7 +57,13 @@ mod secp256k1 {
}
}

#[cfg(any(feature = "k256_ecrecover", feature = "secp256k1"))]
fn ec_recover_run(i: &[u8], target_gas: u64) -> PrecompileResult {
use alloc::vec::Vec;
Wodann marked this conversation as resolved.
Show resolved Hide resolved
use core::cmp::min;

const ECRECOVER_BASE: u64 = 3_000;

if ECRECOVER_BASE > target_gas {
return Err(Error::OutOfGas);
}
Expand Down