From 249531c0670cd341532a1da2a321b45dea280501 Mon Sep 17 00:00:00 2001 From: rakita Date: Tue, 28 Jan 2025 23:13:49 +0100 Subject: [PATCH] fix(Inspector): frame_end called multiple times (#2037) --- .../handler/interface/src/item_or_result.rs | 1 + crates/inspector/src/inspector.rs | 23 ++++++------------- crates/precompile/src/bn128.rs | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/crates/handler/interface/src/item_or_result.rs b/crates/handler/interface/src/item_or_result.rs index ed07a470c1..8d1a6df30c 100644 --- a/crates/handler/interface/src/item_or_result.rs +++ b/crates/handler/interface/src/item_or_result.rs @@ -1,5 +1,6 @@ use crate::Frame; +#[derive(Clone, Debug)] pub enum ItemOrResult { Item(ITEM), Result(RES), diff --git a/crates/inspector/src/inspector.rs b/crates/inspector/src/inspector.rs index f40de682c9..7cf098e0f8 100644 --- a/crates/inspector/src/inspector.rs +++ b/crates/inspector/src/inspector.rs @@ -266,14 +266,9 @@ where .handler .frame_init_first(context, frame_context, frame_input); - match &mut ret { - Ok(ItemOrResult::Result(res)) => { - context.frame_end(res); - } - Ok(ItemOrResult::Item(frame)) => { - context.initialize_interp(frame.interpreter()); - } - _ => (), + // only if new frame is created call initialize_interp hook. + if let Ok(ItemOrResult::Item(frame)) = &mut ret { + context.initialize_interp(frame.interpreter()); } ret } @@ -297,14 +292,10 @@ where let mut ret = self .handler .frame_init(frame, context, frame_context, frame_input); - match &mut ret { - Ok(ItemOrResult::Result(res)) => { - context.frame_end(res); - } - Ok(ItemOrResult::Item(frame)) => { - context.initialize_interp(frame.interpreter()); - } - _ => (), + + // only if new frame is created call initialize_interp hook. + if let Ok(ItemOrResult::Item(frame)) = &mut ret { + context.initialize_interp(frame.interpreter()); } ret } diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index 0447a87591..f54f9b7fff 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -283,7 +283,7 @@ mod tests { .unwrap(); let res = run_add(&input, BYZANTIUM_ADD_GAS_COST, 499); - println!("{:?}", res); + assert!(matches!( res, Err(PrecompileErrors::Error(PrecompileError::OutOfGas))