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 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
14 changes: 12 additions & 2 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ evmc_result execute(evmc_instance* _instance, evmc_context* _context, evmc_revis
result.gas_left = vm->m_io_gas;
output = ex.output(); // This moves the output from the exception!
}
catch (dev::eth::BadInstruction const&)
{
result.status_code = EVMC_UNDEFINED_INSTRUCTION;
}
catch (dev::eth::DisallowedStateChange const&)
{
result.status_code = EVMC_STATIC_MODE_VIOLATION;
}
catch (dev::eth::VMException const&)
{
result.status_code = EVMC_FAILURE;
Expand Down Expand Up @@ -272,8 +280,10 @@ void VM::interpretCases()
CASE(CREATE2)
{
ON_OP();
// TODO: Bring back support for CREATE2.
throwBadInstruction();
if (m_rev < EVMC_CONSTANTINOPLE)
throwBadInstruction();
if (m_message->flags & EVMC_STATIC)
throwDisallowedStateChange();

m_bounce = &VM::caseCreate;
}
Expand Down
24 changes: 8 additions & 16 deletions libaleth-interpreter/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,13 @@ void VM::caseCreate()
m_runGas = VMSchedule::createGas;

// Collect arguments.
u256 endowment = m_SP[0];
u256 salt;
u256 initOff;
u256 initSize;
u256 const endowment = m_SP[0];
u256 const initOff = m_SP[1];
u256 const initSize = m_SP[2];

if (m_OP == Instruction::CREATE)
{
initOff = m_SP[1];
initSize = m_SP[2];
}
else
{
salt = m_SP[1];
initOff = m_SP[2];
initSize = m_SP[3];
}
u256 salt;
if (m_OP == Instruction::CREATE2)
salt = m_SP[3];

updateMem(memNeed(initOff, initSize));
updateIOGas();
Expand All @@ -149,9 +140,10 @@ void VM::caseCreate()

msg.input_data = &m_mem[off];
msg.input_size = size;
msg.create2_salt = toEvmC(salt);
msg.sender = m_message->destination;
msg.depth = m_message->depth + 1;
msg.kind = EVMC_CREATE; // FIXME: In EVM-C move the kind to the top.
msg.kind = m_OP == Instruction::CREATE ? EVMC_CREATE : EVMC_CREATE2; // FIXME: In EVMC move the kind to the top.
msg.value = toEvmC(endowment);

evmc_result result;
Expand Down
4 changes: 2 additions & 2 deletions libaleth-interpreter/VMConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ namespace eth
&&CALLCODE, \
&&RETURN, \
&&DELEGATECALL, \
&&INVALID, \
&&CREATE2, \
&&INVALID, \
&&INVALID, \
&&INVALID, \
&&INVALID, \
&&STATICCALL, \
&&CREATE2, \
&&INVALID, \
&&INVALID, \
&&REVERT, \
&&INVALID, \
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
Loading