Skip to content

Commit

Permalink
Merge pull request #531 from ethereum/528-tracernotify_execution
Browse files Browse the repository at this point in the history
Fix calling Tracer.notify_execution_start
  • Loading branch information
chfast authored Nov 28, 2022
2 parents fca591a + ff67ad0 commit 9bdb915
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& ana
auto* tracer = vm.get_tracer();
if (INTX_UNLIKELY(tracer != nullptr))
{
tracer->notify_execution_start(state.rev, *state.msg, code);
tracer->notify_execution_start(state.rev, *state.msg, state.original_code);
dispatch<true>(cost_table, state, code, tracer);
}
else
Expand Down
41 changes: 38 additions & 3 deletions test/unittests/tracing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class tracing : public Test
{
std::string m_name;
std::ostringstream& m_trace;
const uint8_t* m_code = nullptr;
bytes_view m_code;

void on_execution_start(
evmc_revision /*rev*/, const evmc_message& /*msg*/, bytes_view code) noexcept override
{
m_code = code.data();
m_code = code;
}

void on_execution_end(const evmc_result& /*result*/) noexcept override { m_code = nullptr; }
void on_execution_end(const evmc_result& /*result*/) noexcept override { m_code = {}; }

void on_instruction_start(uint32_t pc, const intx::uint256* /*stack_top*/,
int /*stack_height*/, const evmone::ExecutionState& /*state*/) noexcept override
Expand All @@ -67,6 +67,28 @@ class tracing : public Test
: m_name{std::move(name)}, m_trace{parent.trace_stream}
{}
};

class Inspector final : public evmone::Tracer
{
bytes m_last_code;

void on_execution_start(
evmc_revision /*rev*/, const evmc_message& /*msg*/, bytes_view code) noexcept override
{
m_last_code = code;
}

void on_execution_end(const evmc_result& /*result*/) noexcept override {}

void on_instruction_start(uint32_t /*pc*/, const intx::uint256* /*stack_top*/,
int /*stack_height*/, const evmone::ExecutionState& /*state*/) noexcept override
{}

public:
explicit Inspector() noexcept = default;

[[nodiscard]] const bytes& get_last_code() const noexcept { return m_last_code; }
};
};


Expand Down Expand Up @@ -255,3 +277,16 @@ TEST_F(tracing, trace_undefined_instruction)
{"error":"undefined instruction","gas":0,"gasUsed":1000000,"output":""}
)");
}

TEST_F(tracing, trace_code_containing_zero)
{
auto tracer_ptr = std::make_unique<Inspector>();
const auto& tracer = *tracer_ptr;
vm.add_tracer(std::move(tracer_ptr));

const auto code = bytecode{} + "602a6000556101c960015560068060166000396000f3600035600055";

trace(code);

EXPECT_EQ(tracer.get_last_code().size(), code.size());
}

0 comments on commit 9bdb915

Please sign in to comment.