Skip to content

Commit

Permalink
rpcdaemon: undefined instruction error message in TraceTracer (#2010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixtysixter authored May 12, 2024
1 parent 2c037b7 commit f663334
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
38 changes: 4 additions & 34 deletions silkworm/rpc/core/evm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ void TraceTracer::on_instruction_start(uint32_t pc, const intx::uint256* /*stack
const auto opcode = execution_state.original_code[pc];
auto opcode_name = get_op_name(opcode_names_, opcode);

current_opcode_ = opcode;
SILK_DEBUG << "TraceTracer::on_instruction_start:"
<< " pc: " << std::dec << pc
<< ", opcode: 0x" << std::hex << evmc::hex(opcode)
Expand Down Expand Up @@ -854,7 +855,7 @@ void TraceTracer::on_execution_end(const evmc_result& result, const silkworm::In
trace.trace_result.reset();
break;
case evmc_status_code::EVMC_UNDEFINED_INSTRUCTION:
trace.error = "bad instruction";
trace.error = "invalid opcode: opcode 0x" + evmc::hex(current_opcode_.value_or(0)) + " not defined";
trace.trace_result.reset();
break;
case evmc_status_code::EVMC_INVALID_INSTRUCTION:
Expand All @@ -875,6 +876,8 @@ void TraceTracer::on_execution_end(const evmc_result& result, const silkworm::In
break;
}

current_opcode_.reset();

SILK_DEBUG << "TraceTracer::on_execution_end:"
<< " result.status_code: " << result.status_code
<< " start_gas: " << std::dec << start_gas
Expand Down Expand Up @@ -907,17 +910,7 @@ void TraceTracer::on_reward_granted(const silkworm::CallResult& result, const si

switch (result.status) {
case evmc_status_code::EVMC_SUCCESS:
trace.trace_result->gas_used = initial_gas_ - int64_t(result.gas_left);
if (!result.data.empty()) {
if (trace.trace_result->code) {
trace.trace_result->code = result.data;
} else if (trace.trace_result->output) {
trace.trace_result->output = result.data;
}
}
break;
case evmc_status_code::EVMC_REVERT:
trace.error = "Reverted";
trace.trace_result->gas_used = initial_gas_ - int64_t(result.gas_left);
if (!result.data.empty()) {
if (trace.trace_result->code) {
Expand All @@ -927,30 +920,7 @@ void TraceTracer::on_reward_granted(const silkworm::CallResult& result, const si
}
}
break;
case evmc_status_code::EVMC_OUT_OF_GAS:
case evmc_status_code::EVMC_STACK_OVERFLOW:
trace.error = "out of gas";
trace.trace_result.reset();
break;
case evmc_status_code::EVMC_UNDEFINED_INSTRUCTION:
trace.error = "bad instruction";
trace.trace_result.reset();
break;
case evmc_status_code::EVMC_INVALID_INSTRUCTION:
trace.error = "invalid opcode: INVALID";
trace.trace_result.reset();
break;
case evmc_status_code::EVMC_STACK_UNDERFLOW:
trace.error = "stack underflow";
trace.trace_result.reset();
break;
case evmc_status_code::EVMC_BAD_JUMP_DESTINATION:
trace.error = "invalid jump destination";
trace.trace_result.reset();
break;
default:
trace.error = "";
trace.trace_result.reset();
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions silkworm/rpc/core/evm_trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class TraceTracer : public silkworm::EvmTracer {
bool is_precompile_{false};
std::vector<Trace>& traces_;
silkworm::IntraBlockState& initial_ibs_;
std::optional<uint8_t> current_opcode_;
const char* const* opcode_names_ = nullptr;
int64_t initial_gas_{0};
int32_t current_depth_{-1};
Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/evm_trace_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ TEST_CASE_METHOD(TraceCallExecutorTest, "TraceCallExecutor::trace_call with erro
"to": "0x6951c35e335fa18c97cb207119133cd8009580cd",
"value": "0x0"
},
"error": "bad instruction",
"error": "invalid opcode: opcode 0x4b not defined",
"result": null,
"subtraces": 0,
"traceAddress": [],
Expand Down

0 comments on commit f663334

Please sign in to comment.