Skip to content
Permalink
Browse files

EVMHost: Remove unneeded methods

  • Loading branch information
chfast authored and axic committed Nov 29, 2019
1 parent 0bd80ed commit cdcfea73ab540c75e80eda18121069d475788629
Showing with 7 additions and 84 deletions.
  1. +0 −17 test/EVMHost.cpp
  2. +4 −65 test/EVMHost.h
  3. +3 −2 test/ExecutionFramework.cpp
@@ -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.
@@ -38,25 +38,16 @@ 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.
static evmc::VM& getVM(std::string const& _path = {});

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 @@ class EVMHost: public evmc::MockedHost

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

0 comments on commit cdcfea7

Please sign in to comment.
You can’t perform that action at this time.