Skip to content

Commit

Permalink
cpp: Add execute() overloading without evmc_context parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 5, 2019
1 parent f284e42 commit cee05a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning].
[[#372](https://github.com/ethereum/evmc/pull/372)]
- The **Berlin** EVM revision has been added.
[[#407](https://github.com/ethereum/evmc/pull/407)]
- In C++ API, an overload for `VM::execute()` has been added that omits
the Host context and interface parameters. This is useful for Precompiles VMs
that do not interact with the Host.
[[#302](https://github.com/ethereum/evmc/pull/302)]

### Changed

Expand Down
16 changes: 16 additions & 0 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,22 @@ class VM
return result{m_instance->execute(m_instance, &host, ctx, rev, &msg, code, code_size)};
}

/// Executes code without the Host context.
///
/// The same as
/// execute(evmc_context&, evmc_revision, const evmc_message&, const uint8_t*, size_t),
/// but without providing the Host context.
/// This method is for experimental precompiles support where execution is guaranteed
/// not to require any Host access.
result execute(evmc_revision rev,
const evmc_message& msg,
const uint8_t* code,
size_t code_size) noexcept
{
return result{
m_instance->execute(m_instance, nullptr, nullptr, rev, &msg, code, code_size)};
}

private:
evmc_vm* m_instance = nullptr;
};
Expand Down
3 changes: 1 addition & 2 deletions test/unittests/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ TEST(cpp, vm_execute_precompiles)
msg.input_size = input.size();
msg.gas = 18;

constexpr evmc_host_interface null_interface{};
auto res = vm.execute(null_interface, nullptr, EVMC_MAX_REVISION, msg, nullptr, 0);
auto res = vm.execute(EVMC_MAX_REVISION, msg, nullptr, 0);
EXPECT_EQ(res.status_code, EVMC_SUCCESS);
EXPECT_EQ(res.gas_left, 0);
ASSERT_EQ(res.output_size, input.size());
Expand Down

0 comments on commit cee05a7

Please sign in to comment.