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

Commit c477606

Browse files
authored
Merge pull request #5718 from ethereum/selfdestruct-optimizations
Selfdestruct optimizations for Frontier and Homestead
2 parents 6c3628e + 00c643e commit c477606

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- 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.
4949
- Fixed: [#5706](https://github.com/ethereum/aleth/pull/5706) Stop tracking sent transactions after they've been imported into the blockchain.
5050
- Fixed: [#5687](https://github.com/ethereum/aleth/pull/5687) Limit transaction queue's dropped transaction history to 1024 transactions.
51+
- 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.
5152

5253
## [1.6.0] - 2019-04-16
5354

libaleth-interpreter/VM.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,19 @@ void VM::interpretCases()
377377
if (m_message->flags & EVMC_STATIC)
378378
throwDisallowedStateChange();
379379

380-
evmc_address destination = toEvmC(asAddress(m_SP[0]));
380+
evmc_address const destination = toEvmC(asAddress(m_SP[0]));
381381

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

395395
updateIOGas();
@@ -1442,4 +1442,4 @@ void VM::interpretCases()
14421442
WHILE_CASES
14431443
}
14441444
}
1445-
}
1445+
}

libethcore/EVMSchedule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ struct EVMSchedule
8383
boost::optional<u256> blockRewardOverwrite;
8484

8585
bool staticCallDepthLimit() const { return !eip150Mode; }
86-
bool suicideChargesNewAccountGas() const { return eip150Mode; }
8786
bool emptinessIsNonexistence() const { return eip158Mode; }
8887
bool zeroValueTransferChargesNewAccountGas() const { return !eip158Mode; }
8988
};

libevm/LegacyVM.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,19 @@ void LegacyVM::interpretCases()
331331
if (m_ext->staticCall)
332332
throwDisallowedStateChange();
333333

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

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

344348
updateIOGas();
345349
m_ext->suicide(dest);

0 commit comments

Comments
 (0)