Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling Tracer.notify_execution_start #531

Merged
merged 2 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}