mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Fix evmcc compilation - provide fake runtime data
This commit is contained in:
parent
e3ccc03fde
commit
5f4c1c7466
3 changed files with 46 additions and 42 deletions
|
|
@ -171,28 +171,33 @@ int main(int argc, char** argv)
|
|||
|
||||
if (options.count("interpret"))
|
||||
{
|
||||
eth::jit::ExecutionEngine engine;
|
||||
u256 gas = initialGas;
|
||||
using namespace eth::jit;
|
||||
|
||||
// Create fake ExtVM interface
|
||||
eth::ExtVMFace ext;
|
||||
ext.myAddress = Address(1122334455667788);
|
||||
ext.caller = Address(0xfacefacefaceface);
|
||||
ext.origin = Address(101010101010101010);
|
||||
ext.value = 0xabcd;
|
||||
ext.gasPrice = 1002;
|
||||
ext.previousBlock.hash = u256(1003);
|
||||
ext.currentBlock.coinbaseAddress = Address(1004);
|
||||
ext.currentBlock.timestamp = 1005;
|
||||
ext.currentBlock.number = 1006;
|
||||
ext.currentBlock.difficulty = 1007;
|
||||
ext.currentBlock.gasLimit = 1008;
|
||||
ext.data = std::string("Hello the Beautiful World of Ethereum!");
|
||||
ext.code = { 0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf };
|
||||
ExecutionEngine engine;
|
||||
eth::jit::u256 gas = initialGas;
|
||||
|
||||
// Create random runtime data
|
||||
RuntimeData data;
|
||||
data.set(RuntimeData::Gas, gas);
|
||||
data.set(RuntimeData::Address, (u160)Address(1122334455667788));
|
||||
data.set(RuntimeData::Caller, (u160)Address(0xfacefacefaceface));
|
||||
data.set(RuntimeData::Origin, (u160)Address(101010101010101010));
|
||||
data.set(RuntimeData::CallValue, 0xabcd);
|
||||
data.set(RuntimeData::CallDataSize, 3);
|
||||
data.set(RuntimeData::GasPrice, 1003);
|
||||
data.set(RuntimeData::PrevHash, 1003);
|
||||
data.set(RuntimeData::CoinBase, (u160)Address(101010101010101015));
|
||||
data.set(RuntimeData::TimeStamp, 1005);
|
||||
data.set(RuntimeData::Number, 1006);
|
||||
data.set(RuntimeData::Difficulty, 16);
|
||||
data.set(RuntimeData::GasLimit, 1008);
|
||||
data.set(RuntimeData::CodeSize, bytecode.size());
|
||||
data.callData = (uint8_t*)"abc";
|
||||
data.code = bytecode.data();
|
||||
|
||||
// BROKEN: env_* functions must be implemented & RuntimeData struct created
|
||||
auto result = engine.run(std::move(module), gas, ext);
|
||||
return result;
|
||||
auto result = engine.run(std::move(module), &data, nullptr);
|
||||
return static_cast<int>(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,26 +13,23 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
|
|||
{
|
||||
using namespace jit;
|
||||
|
||||
RuntimeData data{{},nullptr,nullptr};
|
||||
|
||||
#define set(INDEX, VALUE) data.elems[INDEX] = eth2llvm(VALUE)
|
||||
set(RuntimeData::Gas, m_gas);
|
||||
set(RuntimeData::Address, fromAddress(_ext.myAddress));
|
||||
set(RuntimeData::Caller, fromAddress(_ext.caller));
|
||||
set(RuntimeData::Origin, fromAddress(_ext.origin));
|
||||
set(RuntimeData::CallValue, _ext.value);
|
||||
set(RuntimeData::CallDataSize, _ext.data.size());
|
||||
set(RuntimeData::GasPrice, _ext.gasPrice);
|
||||
set(RuntimeData::PrevHash, _ext.previousBlock.hash);
|
||||
set(RuntimeData::CoinBase, fromAddress(_ext.currentBlock.coinbaseAddress));
|
||||
set(RuntimeData::TimeStamp, _ext.currentBlock.timestamp);
|
||||
set(RuntimeData::Number, _ext.currentBlock.number);
|
||||
set(RuntimeData::Difficulty, _ext.currentBlock.difficulty);
|
||||
set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
|
||||
set(RuntimeData::CodeSize, _ext.code.size()); // TODO: Use constant
|
||||
RuntimeData data;
|
||||
data.set(RuntimeData::Gas, m_gas);
|
||||
data.set(RuntimeData::Address, fromAddress(_ext.myAddress));
|
||||
data.set(RuntimeData::Caller, fromAddress(_ext.caller));
|
||||
data.set(RuntimeData::Origin, fromAddress(_ext.origin));
|
||||
data.set(RuntimeData::CallValue, _ext.value);
|
||||
data.set(RuntimeData::CallDataSize, _ext.data.size());
|
||||
data.set(RuntimeData::GasPrice, _ext.gasPrice);
|
||||
data.set(RuntimeData::PrevHash, _ext.previousBlock.hash);
|
||||
data.set(RuntimeData::CoinBase, fromAddress(_ext.currentBlock.coinbaseAddress));
|
||||
data.set(RuntimeData::TimeStamp, _ext.currentBlock.timestamp);
|
||||
data.set(RuntimeData::Number, _ext.currentBlock.number);
|
||||
data.set(RuntimeData::Difficulty, _ext.currentBlock.difficulty);
|
||||
data.set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
|
||||
data.set(RuntimeData::CodeSize, _ext.code.size());
|
||||
data.callData = _ext.data.data();
|
||||
data.code = _ext.code.data();
|
||||
#undef set
|
||||
|
||||
ExecutionEngine engine;
|
||||
auto env = reinterpret_cast<Env*>(&_ext);
|
||||
|
|
@ -62,7 +59,7 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
|
|||
|
||||
namespace
|
||||
{
|
||||
// MSVS linker ignores export symbols in Env.cpp if nothing point at least one of them
|
||||
// MSVS linker ignores export symbols in Env.cpp if nothing points at least one of them
|
||||
extern "C" void env_sload();
|
||||
void linkerWorkaround()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
namespace dev
|
||||
|
|
@ -35,9 +35,11 @@ struct RuntimeData
|
|||
ReturnDataSize = CallDataSize
|
||||
};
|
||||
|
||||
i256 elems[_size];
|
||||
byte const* callData;
|
||||
byte const* code;
|
||||
i256 elems[_size] = {};
|
||||
byte const* callData = nullptr;
|
||||
byte const* code = nullptr;
|
||||
|
||||
void set(Index _index, u256 _value) { elems[_index] = eth2llvm(_value); }
|
||||
};
|
||||
|
||||
/// VM Environment (ExtVM) opaque type
|
||||
|
|
|
|||
Loading…
Reference in a new issue