From 034e45cb1b5ce2bbac714892917a52410c411e57 Mon Sep 17 00:00:00 2001 From: Sixtysixter <20945591+Sixtysixter@users.noreply.github.com> Date: Fri, 3 May 2024 17:34:10 +0200 Subject: [PATCH] rpcdaemon: fix crash in trace_replay* API (#1995) --- silkworm/rpc/core/evm_trace.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/silkworm/rpc/core/evm_trace.cpp b/silkworm/rpc/core/evm_trace.cpp index 368c448549..6be3a7306b 100644 --- a/silkworm/rpc/core/evm_trace.cpp +++ b/silkworm/rpc/core/evm_trace.cpp @@ -573,9 +573,8 @@ void VmTraceTracer::on_execution_start(evmc_revision rev, const evmc_message& ms } else { index_prefix_.push(std::to_string(transaction_index_) + "-"); } - } else if (!vm_trace_.ops.empty()) { + } else if (!traces_stack_.empty()) { auto& vm_trace = traces_stack_.top().get(); - auto index_prefix = index_prefix_.top(); index_prefix = index_prefix + std::to_string(vm_trace.ops.size() - 1) + "-"; index_prefix_.push(index_prefix); @@ -654,11 +653,14 @@ void VmTraceTracer::on_precompiled_run(const evmc_result& result, int64_t gas, c SILK_DEBUG << "VmTraceTracer::on_precompiled_run:" << " status: " << result.status_code << ", gas: " << std::dec << gas << "\n"; - if (!vm_trace_.ops.empty()) { - auto& op = vm_trace_.ops[vm_trace_.ops.size() - 1]; - op.precompiled_call_gas = gas; - op.sub = std::make_shared(); - op.sub->code = "0x"; + if (!traces_stack_.empty()) { + auto& vm_trace = traces_stack_.top().get(); + if (!vm_trace.ops.empty()) { + auto& op = vm_trace.ops[vm_trace.ops.size() - 1]; + op.precompiled_call_gas = gas; + op.sub = std::make_shared(); + op.sub->code = "0x"; + } } }