Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Selfdestruct optimizations for Frontier and Homestead #5718

Merged
merged 3 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- Fixed: [#5666](https://github.com/ethereum/aleth/pull/5666) aleth-interpreter returns `EVMC_INVALID_INSTRUCTION` when `INVALID` opcode is encountered and `EVMC_UNKNOWN_INSTRUCTION` for undefined opcodes.
- Fixed: [#5706](https://github.com/ethereum/aleth/pull/5706) Stop tracking sent transactions after they've been imported into the blockchain.
- Fixed: [#5687](https://github.com/ethereum/aleth/pull/5687) Limit transaction queue's dropped transaction history to 1024 transactions.
- Fixed: [#5718](https://github.com/ethereum/aleth/pull/5718) Avoid checking contract balance or destination account existence when executing self-destruct operations on Frontier and Homestead.

## [1.6.0] - 2019-04-16

Expand Down
24 changes: 12 additions & 12 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,19 +377,19 @@ void VM::interpretCases()
if (m_message->flags & EVMC_STATIC)
throwDisallowedStateChange();

evmc_address destination = toEvmC(asAddress(m_SP[0]));
evmc_address const destination = toEvmC(asAddress(m_SP[0]));

// After EIP158 zero-value suicides do not have to pay account creation gas.
u256 const balance =
fromEvmC(m_context->host->get_balance(m_context, &m_message->destination));
if (balance > 0 || m_rev < EVMC_SPURIOUS_DRAGON)
// Starting with EIP150 (Tangerine Whistle), self-destructs need to pay account creation
// gas. Starting with EIP158 (Spurious Dragon), 0-value suicides don't have to pay this
// charge.
if (m_rev >= EVMC_TANGERINE_WHISTLE)
{
// After EIP150 hard fork charge additional cost of sending
// ethers to non-existing account.
int destinationExists =
m_context->host->account_exists(m_context, &destination);
if (m_rev >= EVMC_TANGERINE_WHISTLE && !destinationExists)
m_runGas += VMSchedule::callNewAccount;
if (m_rev == EVMC_TANGERINE_WHISTLE ||
fromEvmC(m_context->host->get_balance(m_context, &m_message->destination)) > 0)
{
if (!m_context->host->account_exists(m_context, &destination))
m_runGas += VMSchedule::callNewAccount;
}
}

updateIOGas();
Expand Down Expand Up @@ -1442,4 +1442,4 @@ void VM::interpretCases()
WHILE_CASES
}
}
}
}
1 change: 0 additions & 1 deletion libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ struct EVMSchedule
boost::optional<u256> blockRewardOverwrite;

bool staticCallDepthLimit() const { return !eip150Mode; }
bool suicideChargesNewAccountGas() const { return eip150Mode; }
bool emptinessIsNonexistence() const { return eip158Mode; }
bool zeroValueTransferChargesNewAccountGas() const { return !eip158Mode; }
};
Expand Down
16 changes: 10 additions & 6 deletions libevm/LegacyVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,19 @@ void LegacyVM::interpretCases()
if (m_ext->staticCall)
throwDisallowedStateChange();

// Self-destructs only have gas cost starting with EIP 150
m_runGas = toInt63(m_schedule->suicideGas);
Address dest = asAddress(m_SP[0]);

// After EIP158 zero-value suicides do not have to pay account creation gas.
if (m_ext->balance(m_ext->myAddress) > 0 || m_schedule->zeroValueTransferChargesNewAccountGas())
// After EIP150 hard fork charge additional cost of sending
// ethers to non-existing account.
if (m_schedule->suicideChargesNewAccountGas() && !m_ext->exists(dest))
Address const dest = asAddress(m_SP[0]);
// Starting with EIP150, self-destructs need to pay both gas cost and account creation
// gas cost. Starting with EIP158, 0-value self-destructs don't need to pay this account
// creation cost.
if (m_schedule->eip150Mode &&
(!m_schedule->eip158Mode || m_ext->balance(m_ext->myAddress) > 0))
{
if (!m_ext->exists(dest))
m_runGas += m_schedule->callNewAccountGas;
}

updateIOGas();
m_ext->suicide(dest);
Expand Down