Skip to content

Commit

Permalink
Merge pull request ethereum#4888 from ethereum/create-tx
Browse files Browse the repository at this point in the history
 evm: Pass the "is CREATE" information to EVM-C VM
  • Loading branch information
axic authored Mar 14, 2018
2 parents c8f91cf + 73cfc40 commit 67d4065
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 289 deletions.
7 changes: 5 additions & 2 deletions libethereum/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co
{
bytes const& c = m_s.code(_p.codeAddress);
h256 codeHash = m_s.codeHash(_p.codeAddress);
m_ext = make_shared<ExtVM>(m_s, m_envInfo, m_sealEngine, _p.receiveAddress, _p.senderAddress, _origin, _p.apparentValue, _gasPrice, _p.data, &c, codeHash, m_depth, _p.staticCall);
m_ext = make_shared<ExtVM>(m_s, m_envInfo, m_sealEngine, _p.receiveAddress,
_p.senderAddress, _origin, _p.apparentValue, _gasPrice, _p.data, &c, codeHash,
m_depth, false, _p.staticCall);
}
}

Expand Down Expand Up @@ -362,7 +364,8 @@ 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);
m_ext = make_shared<ExtVM>(m_s, m_envInfo, m_sealEngine, m_newAddress, _sender, _origin,
_endowment, _gasPrice, bytesConstRef(), _init, sha3(_init), m_depth, true, false);

return !m_ext;
}
Expand Down
13 changes: 5 additions & 8 deletions libethereum/Executive.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Executive.h
* @author Gav Wood <[email protected]>
* @date 2014
*/

#pragma once

#include <functional>
#include <json/json.h>
#include "Transaction.h"

#include <libdevcore/Log.h>
#include <libethcore/Common.h>
#include <libevm/VMFace.h>
#include "Transaction.h"

#include <json/json.h>
#include <functional>

namespace Json
{
Expand Down Expand Up @@ -72,7 +70,6 @@ class StandardTrace
private:
bool m_showMnemonics = false;
std::vector<Instruction> m_lastInst;
bytes m_lastCallData;
Json::Value m_trace;
DebugOptions m_options;
};
Expand Down
46 changes: 24 additions & 22 deletions libethereum/ExtVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file ExtVM.h
* @author Gav Wood <[email protected]>
* @date 2014
*/

#pragma once

#include <map>
#include <functional>
#include "Executive.h"
#include "State.h"

#include <libethcore/Common.h>
#include <libevm/ExtVMFace.h>
#include <libethcore/SealEngine.h>
#include "State.h"
#include "Executive.h"
#include <libevm/ExtVMFace.h>

#include <functional>
#include <map>

namespace dev
{
Expand All @@ -36,21 +34,25 @@ namespace eth

class SealEngineFace;

/**
* @brief Externality interface for the Virtual Machine providing access to world state.
*/
class ExtVM: public ExtVMFace
/// Externality interface for the Virtual Machine providing access to world state.
class ExtVM : public ExtVMFace
{
public:
/// Full constructor.
ExtVM(State& _s, EnvInfo const& _envInfo, SealEngineFace const& _sealEngine, Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, h256 const& _codeHash, unsigned _depth = 0, bool _staticCall = false):
ExtVMFace(_envInfo, _myAddress, _caller, _origin, _value, _gasPrice, _data, _code.toBytes(), _codeHash, _depth, _staticCall), m_s(_s), m_sealEngine(_sealEngine)
{
// Contract: processing account must exist. In case of CALL, the ExtVM
// is created only if an account has code (so exist). In case of CREATE
// the account must be created first.
assert(m_s.addressInUse(_myAddress));
}
/// Full constructor.
ExtVM(State& _s, EnvInfo const& _envInfo, SealEngineFace const& _sealEngine, Address _myAddress,
Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data,
bytesConstRef _code, h256 const& _codeHash, unsigned _depth, bool _isCreate,
bool _staticCall)
: ExtVMFace(_envInfo, _myAddress, _caller, _origin, _value, _gasPrice, _data, _code.toBytes(),
_codeHash, _depth, _isCreate, _staticCall),
m_s(_s),
m_sealEngine(_sealEngine)
{
// Contract: processing account must exist. In case of CALL, the ExtVM
// is created only if an account has code (so exist). In case of CREATE
// the account must be created first.
assert(m_s.addressInUse(_myAddress));
}

/// Read storage location.
virtual u256 store(u256 _n) override final { return m_s.storage(myAddress, _n); }
Expand Down
14 changes: 7 additions & 7 deletions libevm/EVMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ class EVM
Result execute(ExtVMFace& _ext, int64_t gas)
{
auto mode = toRevision(_ext.evmSchedule());
evm_call_kind kind = _ext.isCreate ? EVM_CREATE : EVM_CALL;
uint32_t flags = _ext.staticCall ? EVM_STATIC : 0;
evm_message msg = {toEvmC(_ext.myAddress), toEvmC(_ext.caller),
toEvmC(_ext.value), _ext.data.data(),
_ext.data.size(), toEvmC(_ext.codeHash), gas,
static_cast<int32_t>(_ext.depth), EVM_CALL, flags};
return Result{m_instance->execute(
m_instance, &_ext, mode, &msg, _ext.code.data(), _ext.code.size()
)};
assert(flags != EVM_STATIC || kind == EVM_CALL); // STATIC implies a CALL.
evm_message msg = {toEvmC(_ext.myAddress), toEvmC(_ext.caller), toEvmC(_ext.value),
_ext.data.data(), _ext.data.size(), toEvmC(_ext.codeHash), gas,
static_cast<int32_t>(_ext.depth), kind, flags};
return Result{
m_instance->execute(m_instance, &_ext, mode, &msg, _ext.code.data(), _ext.code.size())};
}

private:
Expand Down
41 changes: 16 additions & 25 deletions libevm/ExtVMFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,31 +270,22 @@ evm_context_fn_table const fnTable = {

}

ExtVMFace::ExtVMFace(
EnvInfo const& _envInfo,
Address _myAddress,
Address _caller,
Address _origin,
u256 _value,
u256 _gasPrice,
bytesConstRef _data,
bytes _code,
h256 const& _codeHash,
unsigned _depth,
bool _staticCall
):
evm_context{&fnTable},
m_envInfo(_envInfo),
myAddress(_myAddress),
caller(_caller),
origin(_origin),
value(_value),
gasPrice(_gasPrice),
data(_data),
code(std::move(_code)),
codeHash(_codeHash),
depth(_depth),
staticCall(_staticCall)
ExtVMFace::ExtVMFace(EnvInfo const& _envInfo, Address _myAddress, Address _caller, Address _origin,
u256 _value, u256 _gasPrice, bytesConstRef _data, bytes _code, h256 const& _codeHash,
unsigned _depth, bool _isCreate, bool _staticCall)
: evm_context{&fnTable},
m_envInfo(_envInfo),
myAddress(_myAddress),
caller(_caller),
origin(_origin),
value(_value),
gasPrice(_gasPrice),
data(_data),
code(std::move(_code)),
codeHash(_codeHash),
depth(_depth),
isCreate(_isCreate),
staticCall(_staticCall)
{}

}
Expand Down
Loading

0 comments on commit 67d4065

Please sign in to comment.