diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ffca20541..769665acf2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,3 +51,6 @@ jobs: - name: cargo clippy run: cargo +nightly clippy --all --all-features -- -D warnings + + - name: cargo check no-default-features + run: cargo check --no-default-features diff --git a/bins/revme/Cargo.toml b/bins/revme/Cargo.toml index 9ba7440e55..adb1f18097 100644 --- a/bins/revme/Cargo.toml +++ b/bins/revme/Cargo.toml @@ -20,7 +20,6 @@ primitive-types = { version = "0.12", features = ["rlp", "serde"] } revm = { path = "../../crates/revm", version = "3.1.0", default-features = false, features = [ "ethersdb", "std", - "secp256k1", "serde", ] } rlp = { version = "0.5", default-features = false } diff --git a/crates/interpreter/src/host.rs b/crates/interpreter/src/host.rs index 9ee343d499..d6e907a5ee 100644 --- a/crates/interpreter/src/host.rs +++ b/crates/interpreter/src/host.rs @@ -5,6 +5,7 @@ use crate::{ primitives::{Bytes, Env, B160, B256, U256}, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter, SelfDestructResult, }; +pub use alloc::vec::Vec; pub use dummy_host::DummyHost; /// EVM context host. diff --git a/crates/interpreter/src/host/dummy_host.rs b/crates/interpreter/src/host/dummy_host.rs index 095007edcc..dfe2044612 100644 --- a/crates/interpreter/src/host/dummy_host.rs +++ b/crates/interpreter/src/host/dummy_host.rs @@ -3,6 +3,7 @@ use crate::{ primitives::{Env, Log, B160, B256, KECCAK_EMPTY}, CallInputs, CreateInputs, Gas, Host, InstructionResult, Interpreter, SelfDestructResult, }; +use alloc::vec::Vec; pub struct DummyHost { pub env: Env, diff --git a/crates/precompile/src/secp256k1.rs b/crates/precompile/src/secp256k1.rs index f0066b9af9..7bd44d09d6 100644 --- a/crates/precompile/src/secp256k1.rs +++ b/crates/precompile/src/secp256k1.rs @@ -8,23 +8,27 @@ pub const ECRECOVER: PrecompileAddress = PrecompileAddress( #[cfg(not(feature = "secp256k1"))] #[allow(clippy::module_inception)] mod secp256k1 { - use core::convert::TryFrom; - use k256::{ - ecdsa::{recoverable, Error}, - elliptic_curve::sec1::ToEncodedPoint, - PublicKey as K256PublicKey, - }; + use k256::ecdsa::{Error, RecoveryId, Signature, VerifyingKey}; use sha3::{Digest, Keccak256}; use crate::B256; pub fn ecrecover(sig: &[u8; 65], msg: &B256) -> Result { - let sig = recoverable::Signature::try_from(sig.as_ref())?; - let verify_key = sig.recover_verifying_key_from_digest_bytes(msg.into())?; - let public_key = K256PublicKey::from(&verify_key); - let public_key = public_key.to_encoded_point(/* compress = */ false); - let public_key = public_key.as_bytes(); - let hash = Keccak256::digest(&public_key[1..]); + // parse signature + let recid = RecoveryId::from_byte(sig[64]).expect("Recovery id is valid"); + let signature = Signature::from_slice(&sig[..64])?; + + // recover key + let recovered_key = VerifyingKey::recover_from_prehash(msg, &signature, recid)?; + + // hash it + let hash = Keccak256::digest( + &recovered_key + .to_encoded_point(/* compress = */ false) + .as_bytes()[1..], + ); + + // truncate to 20 bytes let mut hash: B256 = hash[..].try_into().unwrap(); hash.iter_mut().take(12).for_each(|i| *i = 0); Ok(hash) diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index dc70a7f292..a1417ef225 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -12,10 +12,10 @@ use crate::primitives::{ }; use crate::{db::Database, journaled_state::JournaledState, precompile, Inspector}; use alloc::vec::Vec; +use core::cmp::Ordering; use core::{cmp::min, marker::PhantomData}; use revm_interpreter::{MAX_CODE_SIZE, MAX_INITCODE_SIZE}; use revm_precompile::{Precompile, Precompiles}; -use std::cmp::Ordering; pub struct EVMData<'a, DB: Database> { pub env: &'a mut Env,