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

Implement EXTCODEHASH in LegacyVM #5134

Merged
merged 5 commits into from
Jul 31, 2018
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
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 exists(_a) ? m_s.codeHash(_a) : h256{};
}

void ExtVM::setStore(u256 _n, u256 _v)
{
m_s.setStorage(myAddress, _n, _v);
Expand Down
90 changes: 48 additions & 42 deletions libethereum/ExtVM.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
This file is part of cpp-ethereum.
This file is part of cpp-ethereum.

cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
Expand Down Expand Up @@ -54,50 +54,56 @@ class ExtVM : public ExtVMFace
assert(m_s.addressInUse(_myAddress));
}

/// Read storage location.
virtual u256 store(u256 _n) override final { return m_s.storage(myAddress, _n); }
/// Read storage location.
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 hash of the code at the given address.
h256 codeHashAt(Address _a) final;

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

/// Read address's balance.
virtual u256 balance(Address _a) override final { return m_s.balance(_a); }
/// Create a new message call.
CallResult call(CallParameters& _params) final;

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

/// Suicide the associated contract to the given address.
virtual void suicide(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.
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;
/// Hash of a block if within the last 256 blocks, or h256() otherwise.
h256 blockHash(u256 _number) final;

private:
State& m_s; ///< A reference to the base state.
SealEngineFace const& m_sealEngine;
State& m_s; ///< A reference to the base state.
SealEngineFace const& m_sealEngine;
};

}
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
Loading