Merge pull request #10899 from ethereum/evmhost_storage_trace

EVMHost: Add function to print storage at all addresses in the host.
This commit is contained in:
Bhargava Shastry 2021-03-01 22:06:16 +01:00 committed by GitHub
commit ad48b71318
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -37,6 +37,8 @@ using namespace solidity::util;
using namespace solidity::test;
using namespace evmc::literals;
using StorageMap = std::unordered_map<evmc::bytes32, evmc::storage_value>;
evmc::VM& EVMHost::getVM(string const& _path)
{
static evmc::VM NullVM{nullptr};
@ -754,3 +756,20 @@ evmc::result EVMHost::resultWithGas(
result.output_size = _data.size();
return result;
}
void EVMHost::print_all_storage(ostringstream& _os)
{
for (auto const& [addr, mockedAccount]: accounts)
{
_os << "Address: " << convertFromEVMC(addr) << endl;
for (auto const& [slot, value]: get_address_storage(addr))
if (get_storage(addr, slot))
_os << convertFromEVMC(slot) << ": " << convertFromEVMC(value.value) << endl;
}
}
StorageMap const& EVMHost::get_address_storage(evmc::address const& _addr)
{
assertThrow(account_exists(_addr), Exception, "Account does not exist.");
return accounts[_addr].storage;
}

View File

@ -61,6 +61,11 @@ public:
tx_context.block_timestamp += 15;
recorded_logs.clear();
}
/// Prints contents of storage at all addresses in host to @param _os.
void print_all_storage(std::ostringstream& _os);
/// @returns contents of storage at @param _addr.
std::unordered_map<evmc::bytes32, evmc::storage_value> const& get_address_storage(evmc::address const& _addr);
bool account_exists(evmc::address const& _addr) const noexcept final
{