EVMHost: implement selfdestruct better

This commit is contained in:
Alex Beregszaszi 2022-09-30 17:56:54 +02:00
parent 08af255658
commit 24946ec318
2 changed files with 12 additions and 8 deletions

View File

@ -170,7 +170,7 @@ void EVMHost::reset()
}
}
void EVMHost::resetWarmAccess()
void EVMHost::newTransactionFrame()
{
// Clear EIP-2929 account access indicator
recorded_account_accesses.clear();
@ -178,6 +178,10 @@ void EVMHost::resetWarmAccess()
for (auto& [address, account]: accounts)
for (auto& [slot, value]: account.storage)
value.access_status = EVMC_ACCESS_COLD;
// Process selfdestruct list
for (auto& [address, _]: recorded_selfdestructs)
accounts.erase(address);
recorded_selfdestructs.clear();
}
void EVMHost::transfer(evmc::MockedAccount& _sender, evmc::MockedAccount& _recipient, u256 const& _value) noexcept
@ -190,12 +194,11 @@ void EVMHost::transfer(evmc::MockedAccount& _sender, evmc::MockedAccount& _recip
void EVMHost::selfdestruct(const evmc::address& _addr, const evmc::address& _beneficiary) noexcept
{
// TODO actual selfdestruct is even more complicated.
// TODO reuse MockedHost::selfdestruct.
transfer(accounts[_addr], accounts[_beneficiary], convertFromEVMC(accounts[_addr].balance));
accounts.erase(_addr);
// Record self destructs
recorded_selfdestructs.push_back({_addr, _beneficiary});
// Record self destructs. Clearing will be done in newTransactionFrame().
MockedHost::selfdestruct(_addr, _beneficiary);
}
void EVMHost::recordCalls(evmc_message const& _message) noexcept

View File

@ -82,7 +82,7 @@ public:
tx_context.block_number++;
tx_context.block_timestamp += 15;
recorded_logs.clear();
resetWarmAccess();
newTransactionFrame();
}
/// @returns contents of storage at @param _addr.
@ -98,8 +98,9 @@ private:
/// Transfer value between accounts. Checks for sufficient balance.
void transfer(evmc::MockedAccount& _sender, evmc::MockedAccount& _recipient, u256 const& _value) noexcept;
/// Clears EIP-2929 account and storage access indicator
void resetWarmAccess();
/// Start a new transaction frame.
/// This will perform selfdestructs and clear account/storage access indicator for EIP-2929.
void newTransactionFrame();
/// Records calls made via @param _message.
void recordCalls(evmc_message const& _message) noexcept;