From 658e20c8e3ca6753bb1f12bdc9defc7195f35b6e Mon Sep 17 00:00:00 2001 From: Dream Wu Date: Mon, 12 Dec 2022 12:54:54 +0800 Subject: [PATCH 1/2] fix dummy error --- bus-mapping/src/evm/opcodes.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bus-mapping/src/evm/opcodes.rs b/bus-mapping/src/evm/opcodes.rs index 566eff7a58..a47a9184fa 100644 --- a/bus-mapping/src/evm/opcodes.rs +++ b/bus-mapping/src/evm/opcodes.rs @@ -254,14 +254,14 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps { } } -fn fn_gen_error_state_associated_ops(error: &ExecError) -> FnGenAssociatedOps { +fn fn_gen_error_state_associated_ops(error: &ExecError) -> Option { match error { - ExecError::InvalidJump => ErrorInvalidJump::gen_associated_ops, - ExecError::OutOfGas(OogError::Call) => OOGCall::gen_associated_ops, + ExecError::InvalidJump => Some(ErrorInvalidJump::gen_associated_ops), + ExecError::OutOfGas(OogError::Call) => Some(OOGCall::gen_associated_ops), // more future errors place here _ => { - warn!("Using dummy gen_associated_ops for error state {:?}", error); - Dummy::gen_associated_ops + warn!("TODO: error state {:?} not implemented", error); + None } } } @@ -306,16 +306,22 @@ pub fn gen_associated_ops( if exec_step.oog_or_stack_error() && !geth_step.op.is_call_or_create() { state.gen_restore_context_ops(&mut exec_step, geth_steps)?; } else { + let fn_gen_error_associated_ops = fn_gen_error_state_associated_ops(&exec_error); + // if fn_gen_error_associated_ops handles the target error, return the handled + // result + if let Some(fn_gen_error_ops) = fn_gen_error_associated_ops { + return fn_gen_error_ops(state, geth_steps); + } + + // here for some errors which fn_gen_error_associated_ops don't handle now, + // continue to use dummy handling until all errors implemented in + // fn_gen_error_associated_ops if geth_step.op.is_call_or_create() && !exec_step.oog_or_stack_error() { let call = state.parse_call(geth_step)?; // Switch to callee's call context state.push_call(call); - } else { - let fn_gen_error_associated_ops = fn_gen_error_state_associated_ops(&exec_error); - return fn_gen_error_associated_ops(state, geth_steps); } } - state.handle_return(geth_step)?; return Ok(vec![exec_step]); } From 7c7829864fdce294329353b3c053fccc2596e4b2 Mon Sep 17 00:00:00 2001 From: Dream Wu Date: Thu, 15 Dec 2022 15:14:59 +0800 Subject: [PATCH 2/2] minor refacotr --- bus-mapping/src/evm/opcodes.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/bus-mapping/src/evm/opcodes.rs b/bus-mapping/src/evm/opcodes.rs index a47a9184fa..0e3253d3c1 100644 --- a/bus-mapping/src/evm/opcodes.rs +++ b/bus-mapping/src/evm/opcodes.rs @@ -303,27 +303,23 @@ pub fn gen_associated_ops( exec_step.error = Some(exec_error.clone()); // TODO: after more error state handled, refactor all error handling in // fn_gen_error_state_associated_ops method - if exec_step.oog_or_stack_error() && !geth_step.op.is_call_or_create() { - state.gen_restore_context_ops(&mut exec_step, geth_steps)?; + // For exceptions that have been implemented + if let Some(fn_gen_error_ops) = fn_gen_error_state_associated_ops(&exec_error) { + return fn_gen_error_ops(state, geth_steps); } else { - let fn_gen_error_associated_ops = fn_gen_error_state_associated_ops(&exec_error); - // if fn_gen_error_associated_ops handles the target error, return the handled - // result - if let Some(fn_gen_error_ops) = fn_gen_error_associated_ops { - return fn_gen_error_ops(state, geth_steps); - } - - // here for some errors which fn_gen_error_associated_ops don't handle now, - // continue to use dummy handling until all errors implemented in - // fn_gen_error_associated_ops + // For exceptions that already enter next call context, but fail immediately + // (e.g. Depth, InsufficientBalance), we still need to parse the call. if geth_step.op.is_call_or_create() && !exec_step.oog_or_stack_error() { let call = state.parse_call(geth_step)?; - // Switch to callee's call context state.push_call(call); + // For exceptions that fail to enter next call context, we need + // to restore call context of current caller + } else { + state.gen_restore_context_ops(&mut exec_step, geth_steps)?; } + state.handle_return(geth_step)?; + return Ok(vec![exec_step]); } - state.handle_return(geth_step)?; - return Ok(vec![exec_step]); } // if no errors, continue as normal fn_gen_associated_ops(state, geth_steps)