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

bump k256 and use normalize_s #870

Merged
merged 2 commits into from
Nov 19, 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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ aurora-engine-modexp = { version = "1.0", default-features = false }
c-kzg = { version = "0.4.0", default-features = false, optional = true }

# ecRecover precompile
k256 = { version = "0.13", default-features = false, features = ["ecdsa"] }
k256 = { version = "0.13.2", default-features = false, features = ["ecdsa"] }
secp256k1 = { version = "0.28.0", default-features = false, features = [
"alloc",
"recovery",
Expand Down
14 changes: 10 additions & 4 deletions crates/precompile/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ mod secp256k1 {

pub fn ecrecover(sig: &[u8; 65], msg: &B256) -> Result<B256, Error> {
// parse signature
let recid = RecoveryId::from_byte(sig[64]).expect("Recovery id is valid");
let signature = Signature::from_slice(&sig[..64])?;
let mut recid = sig[64];
let mut sig = Signature::from_slice(&sig[..64])?;

// recover key
let recovered_key = VerifyingKey::recover_from_prehash(&msg[..], &signature, recid)?;
// normalize signature and flip recovery id if needed.
if let Some(sig_normalized) = sig.normalize_s() {
sig = sig_normalized;
recid = recid ^ 1;
};
let recid = RecoveryId::from_byte(recid).expect("Recovery id is valid");

// recover key
let recovered_key = VerifyingKey::recover_from_prehash(&msg[..], &sig, recid)?;
// hash it
let mut hash = keccak256(
&recovered_key
Expand Down
15 changes: 7 additions & 8 deletions crates/revm/src/inspector/eip3155.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{
inspectors::GasInspector,
interpreter::{
opcode, CallInputs, CreateInputs, Interpreter, InterpreterResult, SharedMemory, Stack,
},
interpreter::{opcode, CallInputs, CreateInputs, Interpreter, InterpreterResult, Stack},
primitives::{db::Database, hex, Address, U256},
EvmContext, Inspector,
};
Expand All @@ -25,8 +23,6 @@ pub struct TracerEip3155 {
opcode: u8,
gas: u64,
mem_size: usize,
#[allow(dead_code)]
memory: Option<SharedMemory>,
skip: bool,
}

Expand All @@ -42,7 +38,6 @@ impl TracerEip3155 {
opcode: 0,
gas: 0,
mem_size: 0,
memory: None,
skip: false,
}
}
Expand Down Expand Up @@ -71,7 +66,10 @@ impl<DB: Database> Inspector<DB> for TracerEip3155 {
return;
};

self.print_log_line(context.journaled_state.depth());
self.print_log_line(
context.journaled_state.depth(),
interp.shared_memory.context_memory(),
);
}

fn call(
Expand Down Expand Up @@ -122,7 +120,7 @@ impl<DB: Database> Inspector<DB> for TracerEip3155 {
}

impl TracerEip3155 {
fn print_log_line(&mut self, depth: u64) {
fn print_log_line(&mut self, depth: u64, _memory: &[u8]) {
let short_stack: Vec<String> = self.stack.data().iter().map(|&b| short_hex(b)).collect();
let log_line = json!({
"depth": depth,
Expand All @@ -132,6 +130,7 @@ impl TracerEip3155 {
"gas": format!("0x{:x}", self.gas),
"gasCost": format!("0x{:x}", self.gas_inspector.last_gas_cost()),
//memory?
//"memory": format!("{}", hex::encode(memory)),
"memSize": self.mem_size,
"stack": short_stack,
//returnData
Expand Down
Loading