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: k256 compile error #451

Merged
merged 3 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions crates/interpreter/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions crates/interpreter/src/host/dummy_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 16 additions & 12 deletions crates/precompile/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B256, Error> {
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)
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down