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

EIP 684: contract creation on nonempty code or nonzero nonce fails. #4384

Merged
merged 2 commits into from
Aug 24, 2017
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
30 changes: 10 additions & 20 deletions libethereum/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ bool Executive::executeCreate(Address const& _sender, u256 const& _endowment, u2

m_gas = _gas;
bool accountAlreadyExist = (m_s.addressHasCode(m_newAddress) || m_s.getNonce(m_newAddress) > 0);
if (accountAlreadyExist)
{
clog(StateSafeExceptions) << "Address already used: " << m_newAddress;
m_gas = 0;
m_excepted = TransactionException::AddressAlreadyUsed;
revert();
m_ext = {}; // cancel the _init execution if there are any scheduled.
return !m_ext;
}

// Transfer ether before deploying the code. This will also create new
// account if it does not exist yet.
Expand All @@ -353,26 +362,7 @@ bool Executive::executeCreate(Address const& _sender, u256 const& _endowment, u2
// Schedule _init execution if not empty.
if (!_init.empty())
m_ext = make_shared<ExtVM>(m_s, m_envInfo, m_sealEngine, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, sha3(_init), m_depth);

if (m_envInfo.number() < m_sealEngine.chainParams().u256Param("constantinopleForkBlock"))
{
if (m_s.addressHasCode(m_newAddress))
// Overwrite with empty code in case the account already has a code
// (address collision -- not real life case but we can check it with
// synthetic tests).
m_s.setCode(m_newAddress, {});
}
else
{
if (accountAlreadyExist)
{
clog(StateSafeExceptions) << "Address already used: " << m_newAddress;
m_gas = 0;
m_excepted = TransactionException::AddressAlreadyUsed;
revert();
m_ext = {}; // cancel the _init execution if there are any scheduled.
}
}

return !m_ext;
}

Expand Down