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

CREATE2 implementation in aleth-interpreter #5125

Merged
merged 6 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 4 additions & 16 deletions libaleth-interpreter/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,12 @@ void VM::caseCreate()
auto off = static_cast<size_t>(initOff);
auto size = static_cast<size_t>(initSize);

bytes saltAndInputData;
if (m_OP == Instruction::CREATE)
{
msg.input_data = &m_mem[off];
msg.input_size = size;
msg.kind = EVMC_CREATE; // FIXME: In EVM-C move the kind to the top.
}
else
{
assert(m_OP == Instruction::CREATE2);
// Pass salt data through EVMC as 32-byte prefix in evmc_message::input_data
saltAndInputData = toBigEndian(salt) + bytesConstRef(&m_mem[off], size);
msg.input_data = saltAndInputData.data();
msg.input_size = saltAndInputData.size();
msg.kind = EVMC_CREATE2;
}
msg.input_data = &m_mem[off];
msg.input_size = size;
msg.salt = toEvmC(salt);
msg.sender = m_message->destination;
msg.depth = m_message->depth + 1;
msg.kind = m_OP == Instruction::CREATE ? EVMC_CREATE : EVMC_CREATE2; // FIXME: In EVM-C move the kind to the top.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"EVM-C" -> "EMVC" :)

msg.value = toEvmC(endowment);

evmc_result result;
Expand Down
2 changes: 1 addition & 1 deletion libevm/EVMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class EVM
uint32_t flags = _ext.staticCall ? EVMC_STATIC : 0;
assert(flags != EVMC_STATIC || kind == EVMC_CALL); // STATIC implies a CALL.
evmc_message msg = {toEvmC(_ext.myAddress), toEvmC(_ext.caller), toEvmC(_ext.value),
_ext.data.data(), _ext.data.size(), toEvmC(_ext.codeHash), gas,
_ext.data.data(), _ext.data.size(), toEvmC(_ext.codeHash), toEvmC(0x0_cppui256), 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())};
Expand Down
19 changes: 4 additions & 15 deletions libevm/ExtVMFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,13 @@ void create(evmc_result* o_result, ExtVMFace& _env, evmc_message const* _msg) no
{
u256 gas = _msg->gas;
u256 value = fromEvmC(_msg->value);
bytesConstRef init = {_msg->input_data, _msg->input_size};
u256 salt = fromEvmC(_msg->salt);
Instruction opcode = _msg->kind == EVMC_CREATE ? Instruction::CREATE : Instruction::CREATE2;

// ExtVM::create takes the sender address from .myAddress.
assert(fromEvmC(_msg->sender) == _env.myAddress);

bytesConstRef init;
u256 salt;
Instruction opcode = Instruction::CREATE;
if (_msg->kind == EVMC_CREATE)
init = {_msg->input_data, _msg->input_size};
else
{
assert(_msg->kind == EVMC_CREATE2);
// Salt data is passsed as 32-byte prefix in evmc_message::input_data
assert(_msg->input_size >= 32);
init = {_msg->input_data + 32, _msg->input_size - 32};
opcode = Instruction::CREATE2;
salt = fromBigEndian<u256>(bytesConstRef{_msg->input_data, 32});
}

CreateResult result = _env.create(value, gas, init, opcode, salt, {});
o_result->status_code = result.status;
o_result->gas_left = static_cast<int64_t>(gas);
Expand Down