From 2a2eb56995bf3836cf12222fa7be0b32171f5161 Mon Sep 17 00:00:00 2001 From: rakita Date: Sat, 18 Nov 2023 16:01:03 +0100 Subject: [PATCH 1/2] bump k256 and use normalize_s --- Cargo.lock | 8 ++++---- bins/revme/src/cmd/statetest/runner.rs | 4 +++- crates/precompile/Cargo.toml | 2 +- crates/precompile/src/secp256k1.rs | 14 ++++++++++---- crates/revm/src/inspector/eip3155.rs | 15 +++++++-------- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62e7412e88..54bb41574c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -868,9 +868,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" -version = "0.13.5" +version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" +checksum = "e9775b22bc152ad86a0cf23f0f348b884b26add12bf741e7ffc4d4ab2ab4d205" dependencies = [ "base16ct", "crypto-bigint", @@ -1641,9 +1641,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +checksum = "3f01b677d82ef7a676aa37e099defd83a28e15687112cafdd112d60236b6115b" dependencies = [ "cfg-if", "ecdsa", diff --git a/bins/revme/src/cmd/statetest/runner.rs b/bins/revme/src/cmd/statetest/runner.rs index 3a490174c4..8bfbccf64a 100644 --- a/bins/revme/src/cmd/statetest/runner.rs +++ b/bins/revme/src/cmd/statetest/runner.rs @@ -92,7 +92,9 @@ fn skip_test(path: &Path) -> bool { | "Call50000_sha256.json" | "static_Call50000_sha256.json" | "loopMul.json" - | "CALLBlake2f_MaxRounds.json" + | "CALLBlake2f_MaxRounds.json" //| "static_CallEcrecover0_completeReturnValue.json" + //| "CALLCODEEcrecoverH_prefixed0.json" + //| "CALLCODEEcrecover0_completeReturnValue.json" ) || path_str.contains("stEOF") } diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index cfe1ab4652..ac5d16fc02 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -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", diff --git a/crates/precompile/src/secp256k1.rs b/crates/precompile/src/secp256k1.rs index 52088c9ab3..4889a89488 100644 --- a/crates/precompile/src/secp256k1.rs +++ b/crates/precompile/src/secp256k1.rs @@ -17,12 +17,18 @@ mod secp256k1 { pub fn ecrecover(sig: &[u8; 65], msg: &B256) -> Result { // 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 diff --git a/crates/revm/src/inspector/eip3155.rs b/crates/revm/src/inspector/eip3155.rs index c0803282dc..6a3bf9a6c5 100644 --- a/crates/revm/src/inspector/eip3155.rs +++ b/crates/revm/src/inspector/eip3155.rs @@ -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, }; @@ -25,8 +23,6 @@ pub struct TracerEip3155 { opcode: u8, gas: u64, mem_size: usize, - #[allow(dead_code)] - memory: Option, skip: bool, } @@ -42,7 +38,6 @@ impl TracerEip3155 { opcode: 0, gas: 0, mem_size: 0, - memory: None, skip: false, } } @@ -71,7 +66,10 @@ impl Inspector 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( @@ -122,7 +120,7 @@ impl Inspector 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 = self.stack.data().iter().map(|&b| short_hex(b)).collect(); let log_line = json!({ "depth": depth, @@ -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 From b0defd723469dca96840ef17ccc8cd277e3b2110 Mon Sep 17 00:00:00 2001 From: rakita Date: Sat, 18 Nov 2023 16:11:29 +0100 Subject: [PATCH 2/2] fmt --- bins/revme/src/cmd/statetest/runner.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bins/revme/src/cmd/statetest/runner.rs b/bins/revme/src/cmd/statetest/runner.rs index 8bfbccf64a..3a490174c4 100644 --- a/bins/revme/src/cmd/statetest/runner.rs +++ b/bins/revme/src/cmd/statetest/runner.rs @@ -92,9 +92,7 @@ fn skip_test(path: &Path) -> bool { | "Call50000_sha256.json" | "static_Call50000_sha256.json" | "loopMul.json" - | "CALLBlake2f_MaxRounds.json" //| "static_CallEcrecover0_completeReturnValue.json" - //| "CALLCODEEcrecoverH_prefixed0.json" - //| "CALLCODEEcrecover0_completeReturnValue.json" + | "CALLBlake2f_MaxRounds.json" ) || path_str.contains("stEOF") }