EVMHost: Remove unneeded methods

This commit is contained in:
Paweł Bylica 2019-11-30 00:10:41 +01:00 committed by Alex Beregszaszi
parent 0bd80ed958
commit cdcfea73ab
3 changed files with 7 additions and 84 deletions

View File

@ -111,23 +111,6 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
tx_context.chain_id = convertToEVMC(u256(1));
}
evmc_storage_status EVMHost::set_storage(const evmc::address& _addr, const evmc::bytes32& _key, const evmc::bytes32& _value) noexcept
{
evmc::bytes32 previousValue = accounts[_addr].storage[_key].value;
accounts[_addr].storage[_key].value = _value;
// TODO EVMC_STORAGE_MODIFIED_AGAIN should be also used
if (previousValue == _value)
return EVMC_STORAGE_UNCHANGED;
else if (previousValue == evmc::bytes32{})
return EVMC_STORAGE_ADDED;
else if (_value == evmc::bytes32{})
return EVMC_STORAGE_DELETED;
else
return EVMC_STORAGE_MODIFIED;
}
void EVMHost::selfdestruct(const evmc::address& _addr, const evmc::address& _beneficiary) noexcept
{
// TODO actual selfdestruct is even more complicated.

View File

@ -38,6 +38,9 @@ using Address = h160;
class EVMHost: public evmc::MockedHost
{
public:
using MockedHost::get_code_size;
using MockedHost::get_balance;
/// Tries to dynamically load libevmone. @returns nullptr on failure.
/// The path has to be provided for the first successful run and will be ignored
/// afterwards.
@ -45,18 +48,6 @@ public:
explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm = getVM());
evmc::MockedAccount const* account(evmc::address const& _address) const
{
auto it = accounts.find(_address);
return it == accounts.end() ? nullptr : &it->second;
}
evmc::MockedAccount* account(evmc::address const& _address)
{
auto it = accounts.find(_address);
return it == accounts.end() ? nullptr : &it->second;
}
void reset() { accounts.clear(); m_currentAddress = {}; }
void newBlock()
{
@ -67,59 +58,7 @@ public:
bool account_exists(evmc::address const& _addr) const noexcept final
{
return account(_addr) != nullptr;
}
evmc::bytes32 get_storage(evmc::address const& _addr, evmc::bytes32 const& _key) const noexcept final
{
if (auto* acc = account(_addr))
{
auto it = acc->storage.find(_key);
if (it != acc->storage.end())
return it->second.value;
}
return {};
}
evmc_storage_status set_storage(
evmc::address const& _addr,
evmc::bytes32 const& _key,
evmc::bytes32 const& _value
) noexcept final;
evmc::uint256be get_balance(evmc::address const& _addr) const noexcept final
{
if (auto const* acc = account(_addr))
return acc->balance;
return {};
}
size_t get_code_size(evmc::address const& _addr) const noexcept final
{
if (auto const* acc = account(_addr))
return acc->code.size();
return 0;
}
evmc::bytes32 get_code_hash(evmc::address const& _addr) const noexcept final
{
if (auto const* acc = account(_addr))
return acc->codehash;
return {};
}
size_t copy_code(
evmc::address const& _addr,
size_t _codeOffset,
uint8_t* _bufferData,
size_t _bufferSize
) const noexcept final
{
size_t i = 0;
if (auto const* acc = account(_addr))
for (; i < _bufferSize && _codeOffset + i < acc->code.size(); i++)
_bufferData[i] = acc->code[_codeOffset + i];
return i;
return evmc::MockedHost::account_exists(_addr);
}
void selfdestruct(evmc::address const& _addr, evmc::address const& _beneficiary) noexcept final;

View File

@ -233,9 +233,10 @@ u256 ExecutionFramework::balanceAt(Address const& _addr)
bool ExecutionFramework::storageEmpty(Address const& _addr)
{
if (auto const* acc = m_evmHost->account(EVMHost::convertToEVMC(_addr)))
const auto it = m_evmHost->accounts.find(EVMHost::convertToEVMC(_addr));
if (it != m_evmHost->accounts.end())
{
for (auto const& entry: acc->storage)
for (auto const& entry: it->second.storage)
if (!(entry.second.value == evmc::bytes32{}))
return false;
}