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

Commit

Permalink
Increment nonce for newly CREATEd accounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Nov 4, 2016
1 parent 9ca9c94 commit ab82b0a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion libethereum/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g
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);

m_s.createContract(m_newAddress);
bool incrementNonce = m_envInfo.number() >= m_sealEngine->chainParams().u256Param("EIP158ForkBlock");
m_s.createContract(m_newAddress, incrementNonce);
m_s.transferBalance(_sender, m_newAddress, _endowment);

if (_init.empty())
Expand Down
8 changes: 6 additions & 2 deletions libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,13 @@ void State::subBalance(Address const& _id, bigint const& _amount)
a->addBalance(-_amount);
}

void State::createContract(Address const& _address)
void State::createContract(Address const& _address, bool _incrementNonce)
{
m_cache[_address] = Account(requireAccountStartNonce(), balance(_address), Account::ContractConception);
m_cache[_address] = Account(
requireAccountStartNonce() + (_incrementNonce ? 1 : 0),
balance(_address),
Account::ContractConception
);
}

void State::ensureAccountExists(const Address& _address)
Expand Down
3 changes: 2 additions & 1 deletion libethereum/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class State
void setStorage(Address const& _contract, u256 const& _location, u256 const& _value) { m_cache[_contract].setStorage(_location, _value); }

/// Create a contract at the given address (with unset code and unchanged balance).
void createContract(Address const& _address);
/// If @a _incrementNonce is true, increment the nonce upon creation.
void createContract(Address const& _address, bool _incrementNonce);

/// Similar to `createContract`, but used in a normal transaction that targets _address.
void ensureAccountExists(Address const& _address);
Expand Down

0 comments on commit ab82b0a

Please sign in to comment.