cpp: Add execute() overloading without evmc_context parameter

This commit is contained in:
Paweł Bylica 2019-11-05 15:59:26 +01:00
parent dee9b57328
commit b8dde4a142
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
3 changed files with 22 additions and 2 deletions

View File

@ -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

View File

@ -408,6 +408,23 @@ public:
return result{m_instance->execute(m_instance, &host, ctx, rev, &msg, code, code_size)};
}
/// Executes code without the Host context.
///
/// The same as
/// execute(const evmc_host_interface&, evmc_host_context*, evmc_revision,
/// const evmc_message&, const uint8_t*, size_t),
/// but without providing the Host context and interface.
/// 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;
};

View File

@ -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());