Skip to content

Commit

Permalink
rpcdaemon: fix memory size 0, special case on SELF_DESTRUCT (#2326)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Sep 11, 2024
1 parent f09c9c0 commit a7c840c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Checkout RPC Tests Repository & Install Requirements
run: |
rm -rf ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.49.1 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.50.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
cd ${{runner.workspace}}/rpc-tests
pip3 install -r requirements.txt
Expand Down
8 changes: 6 additions & 2 deletions silkworm/rpc/core/evm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void to_json(nlohmann::json& json, const TraceOp& trace_op) {
}

void to_json(nlohmann::json& json, const TraceEx& trace_ex) {
if (trace_ex.memory) {
if (trace_ex.memory && trace_ex.memory->len) {
const auto& memory = trace_ex.memory.value();
json["mem"] = memory;
} else {
Expand Down Expand Up @@ -651,7 +651,6 @@ void VmTraceTracer::on_instruction_start(uint32_t pc, const intx::uint256* stack
op.gas_cost = op.gas_cost - gas;
}
op.trace_ex->used = gas;

copy_memory(execution_state.memory, op.trace_ex->memory);
copy_stack(op.op_code, stack_top, op.trace_ex->stack);
}
Expand All @@ -667,6 +666,11 @@ void VmTraceTracer::on_instruction_start(uint32_t pc, const intx::uint256* stack
trace_op.pc = pc;
trace_op.trace_ex = std::make_optional<struct TraceEx>();

if (op_code == OP_SELFDESTRUCT) {
trace_op.sub = std::make_shared<VmTrace>();
trace_op.sub->code = "0x";
}

copy_memory_offset_len(op_code, stack_top, trace_op.trace_ex->memory);
copy_store(op_code, stack_top, trace_op.trace_ex->storage);

Expand Down
15 changes: 3 additions & 12 deletions silkworm/rpc/core/evm_trace_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5619,10 +5619,7 @@ TEST_CASE("VmTrace json serialization") {
{
"cost":42,
"ex":{
"mem":{
"data":"data",
"off":10
},
"mem": null,
"push":["0xdeadbeaf"],
"store":{
"key":"key",
Expand All @@ -5642,10 +5639,7 @@ TEST_CASE("VmTrace json serialization") {
CHECK(nlohmann::json(trace_op) == R"({
"cost":42,
"ex":{
"mem":{
"data":"data",
"off":10
},
"mem": null,
"push":["0xdeadbeaf"],
"store":{
"key":"key",
Expand All @@ -5661,10 +5655,7 @@ TEST_CASE("VmTrace json serialization") {
}
SECTION("TraceEx") {
CHECK(nlohmann::json(trace_ex) == R"({
"mem":{
"data":"data",
"off":10
},
"mem": null,
"push":["0xdeadbeaf"],
"store":{
"key":"key",
Expand Down

0 comments on commit a7c840c

Please sign in to comment.