From 7a4d6dd982bb3db6d604e289890ef303c22d998d Mon Sep 17 00:00:00 2001 From: Roshan <48975233+pythonberg1997@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:58:25 +0800 Subject: [PATCH 1/2] fix: return empty vec when `bls_signature_validation_run` verifying failed (#68) --- crates/precompile/src/bls.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/precompile/src/bls.rs b/crates/precompile/src/bls.rs index bcece2bc..6e5bebba 100644 --- a/crates/precompile/src/bls.rs +++ b/crates/precompile/src/bls.rs @@ -64,7 +64,7 @@ fn bls_signature_validation_run(input: &Bytes, gas_limit: u64) -> PrecompileResu if (pub_keys.len() == 1 && !bls::verify(&pub_keys[0], msg_hash, signature, &BLS_DST.to_vec())) || !bls::aggregate_verify(pub_keys, msg_hashes, signature, &BLS_DST.to_vec()) { - output = Bytes::from(vec![0]); + output = Bytes::from(vec![]); } Ok(PrecompileOutput::new(cost, output)) @@ -118,7 +118,7 @@ mod tests { input.extend_from_slice(&signature); input.extend_from_slice(&pub_key); - let excepted_output = Bytes::from(vec![0]); + let excepted_output = Bytes::from(vec![]); let result = match bls_signature_validation_run(&Bytes::from(input.clone()), 100_000_000) { Ok(o) => o.bytes, Err(e) => panic!("BLS signature validation failed, {:?}", e), @@ -187,7 +187,7 @@ mod tests { input.extend_from_slice(&pub_key1); input.extend_from_slice(&pub_key2); input.extend_from_slice(&pub_key3); - let excepted_output = Bytes::from(vec![0]); + let excepted_output = Bytes::from(vec![]); let result = match bls_signature_validation_run(&Bytes::from(input.clone()), 100_000_000) { Ok(o) => o.bytes, Err(e) => panic!("BLS signature validation failed, {:?}", e), @@ -242,7 +242,7 @@ mod tests { input.extend_from_slice(&pub_key1); input.extend_from_slice(&pub_key2); input.extend_from_slice(&pub_key3); - let excepted_output = Bytes::from(vec![0]); + let excepted_output = Bytes::from(vec![]); let result = match bls_signature_validation_run(&Bytes::from(input.clone()), 100_000_000) { Ok(o) => o.bytes, Err(e) => panic!("BLS signature validation failed, {:?}", e), From dc4cc146b409a51ab6e7840bb3e9b2ea6d8f259c Mon Sep 17 00:00:00 2001 From: yutianwu Date: Fri, 6 Sep 2024 11:18:16 +0800 Subject: [PATCH 2/2] feat: update order of the hardforks for Fjord (#70) * feat: update order of the hardforks * compatible with optimims * fix ci * fix ci * fix ci * fix ci --------- Co-authored-by: Roshan <48975233+pythonberg1997@users.noreply.github.com> --- crates/interpreter/src/function_stack.rs | 3 +-- crates/precompile/src/lib.rs | 6 +++++- crates/revm/src/evm.rs | 6 ++---- crates/revm/src/optimism/handler_register.rs | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/interpreter/src/function_stack.rs b/crates/interpreter/src/function_stack.rs index e6482d8e..7851add1 100644 --- a/crates/interpreter/src/function_stack.rs +++ b/crates/interpreter/src/function_stack.rs @@ -51,9 +51,8 @@ impl FunctionStack { /// Pops a frame from the stack and sets current_code_idx to the popped frame's idx. pub fn pop(&mut self) -> Option { - self.return_stack.pop().map(|frame| { + self.return_stack.pop().inspect(|frame| { self.current_code_idx = frame.idx; - frame }) } diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index cb476d3f..a214d9f9 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -485,14 +485,18 @@ impl PrecompileSpecId { PRAGUE | PRAGUE_EOF => Self::PRAGUE, #[cfg(feature = "optimism")] BEDROCK | REGOLITH | CANYON => Self::BERLIN, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "opbnb")))] ECOTONE | FJORD => Self::CANCUN, + #[cfg(all(feature = "optimism", feature = "opbnb"))] + ECOTONE => Self::CANCUN, #[cfg(feature = "opbnb")] FERMAT => Self::FERMAT, #[cfg(any(feature = "bsc", feature = "opbnb"))] HABER => Self::HABER, #[cfg(feature = "opbnb")] WRIGHT => Self::HABER, + #[cfg(all(feature = "optimism", feature = "opbnb"))] + FJORD => Self::HABER, #[cfg(feature = "bsc")] HABER_FIX => Self::HABER, #[cfg(feature = "bsc")] diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index a7ceec6b..1c45187e 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -199,9 +199,8 @@ impl Evm<'_, EXT, DB> { .handler .validation() .initial_tx_gas(&self.context.evm.env) - .map_err(|e| { + .inspect_err(|_| { self.clear(); - e })?; let output = self.transact_preverified_inner(initial_gas_spend); let output = self.handler.post_execution().end(&mut self.context, output); @@ -228,9 +227,8 @@ impl Evm<'_, EXT, DB> { /// This function will validate the transaction. #[inline] pub fn transact(&mut self) -> EVMResult { - let initial_gas_spend = self.preverify_transaction_inner().map_err(|e| { + let initial_gas_spend = self.preverify_transaction_inner().inspect_err(|_| { self.clear(); - e })?; let output = self.transact_preverified_inner(initial_gas_spend); diff --git a/crates/revm/src/optimism/handler_register.rs b/crates/revm/src/optimism/handler_register.rs index 6098dc73..a19d7729 100644 --- a/crates/revm/src/optimism/handler_register.rs +++ b/crates/revm/src/optimism/handler_register.rs @@ -149,7 +149,7 @@ pub fn last_frame_return( pub fn load_precompiles() -> ContextPrecompiles { let mut precompiles = ContextPrecompiles::new(PrecompileSpecId::from_spec_id(SPEC::SPEC_ID)); - if SPEC::enabled(SpecId::FJORD) { + if SPEC::enabled(SpecId::FJORD) || SPEC::enabled(SpecId::HABER) { precompiles.extend([ // EIP-7212: secp256r1 P256verify secp256r1::P256VERIFY,