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

Commit

Permalink
Implement account existence / emptiness notions.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Oct 26, 2016
1 parent f0e200f commit 4f62f97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libethereum/ExtVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ class ExtVM: public ExtVMFace
virtual u256 txCount(Address _a) override final { return m_s.transactionsFrom(_a); }

/// Does the account exist?
virtual bool exists(Address _a) override final { return m_s.addressInUse(_a); }
virtual bool exists(Address _a) override final
{
if (evmSchedule().emptinessIsNonexistence())
return m_s.accountNonemptyOrExisting(_a);
else
return m_s.addressInUse(_a);
}

/// Suicide the associated contract to the given address.
virtual void suicide(Address _a) override final
Expand Down
4 changes: 4 additions & 0 deletions libethereum/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class State
/// Check if the address is in use.
bool addressInUse(Address const& _address) const;

/// Check if the account does not exist in the state or is empty (nonce == 0, balance == 0, code empty).
/// These two notions are equivalent after EIP158.
bool accountNonemptyOrExisting(Address const& _address) const;

/// Check if the address contains executable code.
bool addressHasCode(Address const& _address) const;

Expand Down
3 changes: 3 additions & 0 deletions libevmcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct EVMSchedule
bool exceptionalFailedCodeDeposit = true;
bool haveDelegateCall = true;
bool eip150Mode = false;
bool eip158Mode = false;
unsigned stackLimit = 1024;
std::array<unsigned, 8> tierStepGas;
unsigned expGas = 10;
Expand Down Expand Up @@ -72,6 +73,7 @@ struct EVMSchedule

bool staticCallDepthLimit() const { return !eip150Mode; }
bool suicideChargesNewAccountGas() const { return eip150Mode; }
bool emptinessIsNonexistence() const { return eip158Mode; }
};

static const EVMSchedule DefaultSchedule = EVMSchedule();
Expand All @@ -95,6 +97,7 @@ static const EVMSchedule EIP158Schedule = []
{
EVMSchedule schedule = EIP150Schedule;
schedule.expByteGas = 50;
schedule.eip158Mode = true;
return schedule;
}();

Expand Down

0 comments on commit 4f62f97

Please sign in to comment.