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

Commit

Permalink
Implement EXTCODEHASH in LegacyVM
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 26, 2018
1 parent 86b33c8 commit 424f181
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 206 deletions.
3 changes: 3 additions & 0 deletions libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct EVMSchedule
bool haveReturnData = false;
bool haveStaticCall = false;
bool haveCreate2 = false;
bool haveExtcodehash = false;
std::array<unsigned, 8> tierStepGas;
unsigned expGas = 10;
unsigned expByteGas = 10;
Expand Down Expand Up @@ -68,6 +69,7 @@ struct EVMSchedule

unsigned extcodesizeGas = 20;
unsigned extcodecopyGas = 20;
unsigned extcodehashGas = 400;
unsigned balanceGas = 20;
unsigned suicideGas = 0;
unsigned blockhashGas = 20;
Expand Down Expand Up @@ -132,6 +134,7 @@ static const EVMSchedule ConstantinopleSchedule = []
schedule.blockhashGas = 800;
schedule.haveCreate2 = true;
schedule.haveBitwiseShifting = true;
schedule.haveExtcodehash = true;
return schedule;
}();

Expand Down
5 changes: 5 additions & 0 deletions libethereum/ExtVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ size_t ExtVM::codeSizeAt(dev::Address _a)
return m_s.codeSize(_a);
}

h256 ExtVM::codeHashAt(Address _a)
{
return m_s.codeHash(_a);
}

void ExtVM::setStore(u256 _n, u256 _v)
{
m_s.setStorage(myAddress, _n, _v);
Expand Down
42 changes: 24 additions & 18 deletions libethereum/ExtVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,51 @@ class ExtVM : public ExtVMFace
}

/// Read storage location.
virtual u256 store(u256 _n) override final { return m_s.storage(myAddress, _n); }
u256 store(u256 _n) final { return m_s.storage(myAddress, _n); }

/// Write a value in storage.
virtual void setStore(u256 _n, u256 _v) override final;
/// Write a value in storage.
void setStore(u256 _n, u256 _v) final;

/// Read address's code.
virtual bytes const& codeAt(Address _a) override final { return m_s.code(_a); }
/// Read address's code.
bytes const& codeAt(Address _a) final { return m_s.code(_a); }

/// @returns the size of the code in bytes at the given address.
virtual size_t codeSizeAt(Address _a) override final;
/// @returns the size of the code in bytes at the given address.
size_t codeSizeAt(Address _a) final;

/// Create a new contract.
CreateResult create(u256 _endowment, u256& io_gas, bytesConstRef _code, Instruction _op, u256 _salt, OnOpFunc const& _onOp = {}) final;
/// @returns the size of the code in bytes at the given address.
h256 codeHashAt(Address _a) final;

/// Create a new contract.
CreateResult create(u256 _endowment, u256& io_gas, bytesConstRef _code, Instruction _op, u256 _salt, OnOpFunc const& _onOp = {}) final;

/// Create a new message call.
CallResult call(CallParameters& _params) final;

/// Read address's balance.
virtual u256 balance(Address _a) override final { return m_s.balance(_a); }
u256 balance(Address _a) final { return m_s.balance(_a); }

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

/// Suicide the associated contract to the given address.
virtual void suicide(Address _a) override final;
void suicide(Address _a) final;

/// Return the EVM gas-price schedule for this execution context.
virtual EVMSchedule const& evmSchedule() const override final { return m_sealEngine.evmSchedule(envInfo().number()); }
/// Return the EVM gas-price schedule for this execution context.
EVMSchedule const& evmSchedule() const final
{
return m_sealEngine.evmSchedule(envInfo().number());
}

State const& state() const { return m_s; }
State const& state() const { return m_s; }

/// Hash of a block if within the last 256 blocks, or h256() otherwise.
h256 blockHash(u256 _number) override;
h256 blockHash(u256 _number) final;

private:
State& m_s; ///< A reference to the base state.
Expand Down
3 changes: 3 additions & 0 deletions libevm/ExtVMFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class ExtVMFace: public evmc_context
/// @returns the size of the code in bytes at the given address.
virtual size_t codeSizeAt(Address) { return 0; }

/// @returns the hash of the code at the given address.
virtual h256 codeHashAt(Address) { return h256{}; }

/// Does the account exist?
virtual bool exists(Address) { return false; }

Expand Down
3 changes: 2 additions & 1 deletion libevm/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::EXTCODECOPY, { "EXTCODECOPY", 4, 0, Tier::Special } },
{ Instruction::RETURNDATASIZE,{"RETURNDATASIZE", 0, 1, Tier::Base } },
{ Instruction::RETURNDATACOPY,{"RETURNDATACOPY", 3, 0, Tier::VeryLow } },
{ Instruction::BLOCKHASH, { "BLOCKHASH", 1, 1, Tier::Special } },
{ Instruction::EXTCODEHASH, { "EXTCODEHASH", 1, 1, Tier::Special }},
{ Instruction::BLOCKHASH, { "BLOCKHASH", 1, 1, Tier::Special } },
{ Instruction::COINBASE, { "COINBASE", 0, 1, Tier::Base } },
{ Instruction::TIMESTAMP, { "TIMESTAMP", 0, 1, Tier::Base } },
{ Instruction::NUMBER, { "NUMBER", 0, 1, Tier::Base } },
Expand Down
Loading

0 comments on commit 424f181

Please sign in to comment.