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

Upgrade EVMC to version 7.0.0 #5810

Merged
merged 2 commits into from
Nov 12, 2019
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
2 changes: 1 addition & 1 deletion evmc
56 changes: 26 additions & 30 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ void delete_output(const evmc_result* result)
delete[] result->output_data;
}

evmc_result execute(evmc_vm* _instance, evmc_host_context* _context, evmc_revision _rev,
const evmc_message* _msg, uint8_t const* _code, size_t _codeSize) noexcept
evmc_result execute(evmc_vm* _instance, const evmc_host_interface* _host,
evmc_host_context* _context, evmc_revision _rev, const evmc_message* _msg, uint8_t const* _code,
size_t _codeSize) noexcept
{
(void)_instance;
std::unique_ptr<dev::eth::VM> vm{new dev::eth::VM};
Expand All @@ -35,7 +36,7 @@ evmc_result execute(evmc_vm* _instance, evmc_host_context* _context, evmc_revisi

try
{
output = vm->exec(_context, _rev, _msg, _code, _codeSize);
output = vm->exec(_host, _context, _rev, _msg, _code, _codeSize);
result.status_code = EVMC_SUCCESS;
result.gas_left = vm->m_io_gas;
}
Expand Down Expand Up @@ -100,7 +101,7 @@ evmc_result execute(evmc_vm* _instance, evmc_host_context* _context, evmc_revisi
}
} // namespace

extern "C" evmc_vm* evmc_create_interpreter() noexcept
extern "C" evmc_vm* evmc_create_aleth_interpreter() noexcept
{
// TODO: Allow creating multiple instances with different configurations.
static evmc_vm s_vm{
Expand Down Expand Up @@ -238,7 +239,7 @@ void VM::fetchInstruction()
evmc_tx_context const& VM::getTxContext()
{
if (!m_tx_context)
m_tx_context.emplace(m_context->host->get_tx_context(m_context));
m_tx_context.emplace(m_host->get_tx_context(m_context));
return m_tx_context.value();
}

Expand All @@ -247,9 +248,10 @@ evmc_tx_context const& VM::getTxContext()
//
// interpreter entry point

owning_bytes_ref VM::exec(evmc_host_context* _context, evmc_revision _rev, const evmc_message* _msg,
uint8_t const* _code, size_t _codeSize)
owning_bytes_ref VM::exec(const evmc_host_interface* _host, evmc_host_context* _context,
evmc_revision _rev, const evmc_message* _msg, uint8_t const* _code, size_t _codeSize)
{
m_host = _host;
m_context = _context;
m_rev = _rev;
m_metrics = &s_metrics[m_rev];
Expand Down Expand Up @@ -364,15 +366,15 @@ void VM::interpretCases()
if (m_rev >= EVMC_TANGERINE_WHISTLE)
{
if (m_rev == EVMC_TANGERINE_WHISTLE ||
fromEvmC(m_context->host->get_balance(m_context, &m_message->destination)) > 0)
fromEvmC(m_host->get_balance(m_context, &m_message->destination)) > 0)
{
if (!m_context->host->account_exists(m_context, &destination))
if (!m_host->account_exists(m_context, &destination))
m_runGas += VMSchedule::callNewAccount;
}
}

updateIOGas();
m_context->host->selfdestruct(m_context, &m_message->destination, &destination);
m_host->selfdestruct(m_context, &m_message->destination, &destination);
m_bounce = nullptr;
}
BREAK
Expand Down Expand Up @@ -449,8 +451,7 @@ void VM::interpretCases()
uint8_t const* data = m_mem.data() + size_t(m_SP[0]);
size_t dataSize = size_t(m_SP[1]);

m_context->host->emit_log(
m_context, &m_message->destination, data, dataSize, nullptr, 0);
m_host->emit_log(m_context, &m_message->destination, data, dataSize, nullptr, 0);
}
NEXT

Expand All @@ -469,8 +470,7 @@ void VM::interpretCases()
evmc_uint256be topics[] = {toEvmC(m_SP[2])};
size_t numTopics = sizeof(topics) / sizeof(topics[0]);

m_context->host->emit_log(
m_context, &m_message->destination, data, dataSize, topics, numTopics);
m_host->emit_log(m_context, &m_message->destination, data, dataSize, topics, numTopics);
}
NEXT

Expand All @@ -489,8 +489,7 @@ void VM::interpretCases()
evmc_uint256be topics[] = {toEvmC(m_SP[2]), toEvmC(m_SP[3])};
size_t numTopics = sizeof(topics) / sizeof(topics[0]);

m_context->host->emit_log(
m_context, &m_message->destination, data, dataSize, topics, numTopics);
m_host->emit_log(m_context, &m_message->destination, data, dataSize, topics, numTopics);
}
NEXT

Expand All @@ -509,8 +508,7 @@ void VM::interpretCases()
evmc_uint256be topics[] = {toEvmC(m_SP[2]), toEvmC(m_SP[3]), toEvmC(m_SP[4])};
size_t numTopics = sizeof(topics) / sizeof(topics[0]);

m_context->host->emit_log(
m_context, &m_message->destination, data, dataSize, topics, numTopics);
m_host->emit_log(m_context, &m_message->destination, data, dataSize, topics, numTopics);
}
NEXT

Expand All @@ -530,8 +528,7 @@ void VM::interpretCases()
toEvmC(m_SP[2]), toEvmC(m_SP[3]), toEvmC(m_SP[4]), toEvmC(m_SP[5])};
size_t numTopics = sizeof(topics) / sizeof(topics[0]);

m_context->host->emit_log(
m_context, &m_message->destination, data, dataSize, topics, numTopics);
m_host->emit_log(m_context, &m_message->destination, data, dataSize, topics, numTopics);
}
NEXT

Expand Down Expand Up @@ -893,7 +890,7 @@ void VM::interpretCases()
updateIOGas();

evmc_address address = toEvmC(asAddress(m_SP[0]));
m_SPP[0] = fromEvmC(m_context->host->get_balance(m_context, &address));
m_SPP[0] = fromEvmC(m_host->get_balance(m_context, &address));
}
NEXT

Expand Down Expand Up @@ -976,7 +973,7 @@ void VM::interpretCases()

evmc_address address = toEvmC(asAddress(m_SP[0]));

m_SPP[0] = m_context->host->get_code_size(m_context, &address);
m_SPP[0] = m_host->get_code_size(m_context, &address);
}
NEXT

Expand Down Expand Up @@ -1018,7 +1015,7 @@ void VM::interpretCases()
updateIOGas();

evmc_address address = toEvmC(asAddress(m_SP[0]));
m_SPP[0] = fromEvmC(m_context->host->get_code_hash(m_context, &address));
m_SPP[0] = fromEvmC(m_host->get_code_hash(m_context, &address));
}
NEXT

Expand Down Expand Up @@ -1049,8 +1046,8 @@ void VM::interpretCases()
m_SP[2] > codeOffsetMax ? codeOffsetMax : static_cast<size_t>(m_SP[2]);
size_t size = static_cast<size_t>(copyMemSize);

size_t numCopied = m_context->host->copy_code(
m_context, &address, codeOffset, &m_mem[memoryOffset], size);
size_t numCopied =
m_host->copy_code(m_context, &address, codeOffset, &m_mem[memoryOffset], size);

std::fill_n(&m_mem[memoryOffset + numCopied], size - numCopied, 0);
}
Expand All @@ -1077,7 +1074,7 @@ void VM::interpretCases()

if (number < blockNumber && number >= std::max(int64_t(256), blockNumber) - 256)
{
m_SPP[0] = fromEvmC(m_context->host->get_block_hash(m_context, int64_t(number)));
m_SPP[0] = fromEvmC(m_host->get_block_hash(m_context, int64_t(number)));
}
else
m_SPP[0] = 0;
Expand Down Expand Up @@ -1152,7 +1149,7 @@ void VM::interpretCases()

updateIOGas();

m_SPP[0] = fromEvmC(m_context->host->get_balance(m_context, &m_message->destination));
m_SPP[0] = fromEvmC(m_host->get_balance(m_context, &m_message->destination));
}
NEXT

Expand Down Expand Up @@ -1351,8 +1348,7 @@ void VM::interpretCases()
updateIOGas();

evmc_uint256be key = toEvmC(m_SP[0]);
m_SPP[0] =
fromEvmC(m_context->host->get_storage(m_context, &m_message->destination, &key));
m_SPP[0] = fromEvmC(m_host->get_storage(m_context, &m_message->destination, &key));
}
NEXT

Expand All @@ -1368,7 +1364,7 @@ void VM::interpretCases()
evmc_uint256be const key = toEvmC(m_SP[0]);
evmc_uint256be const value = toEvmC(m_SP[1]);
auto const status =
m_context->host->set_storage(m_context, &m_message->destination, &key, &value);
m_host->set_storage(m_context, &m_message->destination, &key, &value);

switch(status)
{
Expand Down
5 changes: 3 additions & 2 deletions libaleth-interpreter/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ class VM

VM() = default;

owning_bytes_ref exec(evmc_host_context* _context, evmc_revision _rev, const evmc_message* _msg,
uint8_t const* _code, size_t _codeSize);
owning_bytes_ref exec(const evmc_host_interface* _host, evmc_host_context* _context,
evmc_revision _rev, const evmc_message* _msg, uint8_t const* _code, size_t _codeSize);

uint64_t m_io_gas = 0;
private:
const evmc_host_interface* m_host = nullptr;
evmc_host_context* m_context = nullptr;
evmc_revision m_rev = EVMC_FRONTIER;
std::array<evmc_instruction_metrics, 256>* m_metrics = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions libaleth-interpreter/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void VM::caseCreate()
// Clear the return data buffer. This will not free the memory.
m_returnData.clear();

u256 const balance = fromEvmC(m_context->host->get_balance(m_context, &m_message->destination));
u256 const balance = fromEvmC(m_host->get_balance(m_context, &m_message->destination));
if (balance >= endowment && m_message->depth < 1024)
{
evmc_message msg = {};
Expand All @@ -139,7 +139,7 @@ void VM::caseCreate()
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 = m_context->host->call(m_context, &msg);
evmc_result result = m_host->call(m_context, &msg);

if (result.status_code == EVMC_SUCCESS)
m_SPP[0] = fromAddress(fromEvmC(result.create_address));
Expand Down Expand Up @@ -169,7 +169,7 @@ void VM::caseCall()
bytesRef output;
if (caseCallSetup(msg, output))
{
evmc_result result = m_context->host->call(m_context, &msg);
evmc_result result = m_host->call(m_context, &msg);

m_returnData.assign(result.output_data, result.output_data + result.output_size);
bytesConstRef{&m_returnData}.copyTo(output);
Expand Down Expand Up @@ -215,7 +215,7 @@ bool VM::caseCallSetup(evmc_message& o_msg, bytesRef& o_output)
evmc_address destination = toEvmC(asAddress(m_SP[1]));

if (m_OP == Instruction::CALL && (m_SP[2] > 0 || m_rev < EVMC_SPURIOUS_DRAGON) &&
!m_context->host->account_exists(m_context, &destination))
!m_host->account_exists(m_context, &destination))
{
m_runGas += VMSchedule::callNewAccount;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ bool VM::caseCallSetup(evmc_message& o_msg, bytesRef& o_output)
o_msg.gas += VMSchedule::callStipend;
{
u256 const balance =
fromEvmC(m_context->host->get_balance(m_context, &m_message->destination));
fromEvmC(m_host->get_balance(m_context, &m_message->destination));
balanceOk = balance >= value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libaleth-interpreter/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
extern "C" {
#endif

EVMC_EXPORT struct evmc_vm* evmc_create_interpreter() EVMC_NOEXCEPT;
EVMC_EXPORT struct evmc_vm* evmc_create_aleth_interpreter() EVMC_NOEXCEPT;

#if __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion libevm/VMFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ VMPtr VMFactory::create(VMKind _kind)
switch (_kind)
{
case VMKind::Interpreter:
return {new EVMC{evmc_create_interpreter()}, default_delete};
return {new EVMC{evmc_create_aleth_interpreter()}, default_delete};
case VMKind::DLL:
assert(g_evmcDll != nullptr);
// Return "fake" owning pointer to global EVMC DLL VM.
Expand Down
10 changes: 5 additions & 5 deletions test/unittests/libevm/VMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class LegacyVMCreate2TestFixture: public Create2TestFixture
class AlethInterpreterCreate2TestFixture: public Create2TestFixture
{
public:
AlethInterpreterCreate2TestFixture(): Create2TestFixture{new EVMC{evmc_create_interpreter()}} {}
AlethInterpreterCreate2TestFixture(): Create2TestFixture{new EVMC{evmc_create_aleth_interpreter()}} {}
};

class ExtcodehashTestFixture : public TestOutputHelperFixture
Expand Down Expand Up @@ -376,7 +376,7 @@ class AlethInterpreterExtcodehashTestFixture : public ExtcodehashTestFixture
{
public:
AlethInterpreterExtcodehashTestFixture()
: ExtcodehashTestFixture{new EVMC{evmc_create_interpreter()}}
: ExtcodehashTestFixture{new EVMC{evmc_create_aleth_interpreter()}}
{}
};

Expand Down Expand Up @@ -546,7 +546,7 @@ class LegacyVMSstoreTestFixture : public SstoreTestFixture
class AlethInterpreterSstoreTestFixture : public SstoreTestFixture
{
public:
AlethInterpreterSstoreTestFixture() : SstoreTestFixture{new EVMC{evmc_create_interpreter()}} {}
AlethInterpreterSstoreTestFixture() : SstoreTestFixture{new EVMC{evmc_create_aleth_interpreter()}} {}
};

class ChainIDTestFixture : public TestOutputHelperFixture
Expand Down Expand Up @@ -630,7 +630,7 @@ class LegacyVMChainIDTestFixture : public ChainIDTestFixture
class AlethInterpreterChainIDTestFixture : public ChainIDTestFixture
{
public:
AlethInterpreterChainIDTestFixture() : ChainIDTestFixture{new EVMC{evmc_create_interpreter()}}
AlethInterpreterChainIDTestFixture() : ChainIDTestFixture{new EVMC{evmc_create_aleth_interpreter()}}
{}
};

Expand Down Expand Up @@ -749,7 +749,7 @@ class LegacyVMBalanceFixture : public BalanceFixture
class AlethInterpreterBalanceFixture : public BalanceFixture
{
public:
AlethInterpreterBalanceFixture() : BalanceFixture{new EVMC{evmc_create_interpreter()}} {}
AlethInterpreterBalanceFixture() : BalanceFixture{new EVMC{evmc_create_aleth_interpreter()}} {}
};
} // namespace

Expand Down