15 "Address types size mismatch");
17 "Address types alignment mismatch");
26 return *
reinterpret_cast<Address*
>(&_addr);
30 static_assert(
alignof(
h256) ==
alignof(
evm_uint256be),
"Hash types alignment mismatch");
39 return fromBigEndian<u256>(_n.
bytes);
54 auto &env = *
reinterpret_cast<ExtVMFace*
>(_opaqueEnv);
58 o_result->address = toEvmC(env.myAddress);
61 o_result->address = toEvmC(env.caller);
64 o_result->address = toEvmC(env.origin);
67 o_result->uint256be = toEvmC(env.gasPrice);
70 o_result->address = toEvmC(env.envInfo().author());
73 o_result->uint256be = toEvmC(env.envInfo().difficulty());
76 o_result->int64 = env.envInfo().gasLimit();
80 o_result->int64 =
static_cast<int64_t
>(env.envInfo().number());
84 o_result->int64 =
static_cast<int64_t
>(env.envInfo().timestamp());
88 auto addr = fromEvmC(_arg->address);
89 auto &
code = env.codeAt(addr);
90 o_result->data =
code.data();
91 o_result->data_size =
code.size();
96 auto addr = fromEvmC(_arg->address);
97 o_result->int64 = env.codeSizeAt(addr);
102 auto addr = fromEvmC(_arg->address);
103 o_result->uint256be = toEvmC(env.balance(addr));
107 o_result->uint256be = toEvmC(env.blockHash(_arg->int64));
111 auto key = asUint(_arg->uint256be);
112 o_result->uint256be = toEvmC(env.store(key));
117 auto addr = fromEvmC(_arg->address);
118 o_result->int64 = env.exists(addr);
122 o_result->int64 = env.depth;
134 auto &env = *
reinterpret_cast<ExtVMFace*
>(_opaqueEnv);
139 auto index = asUint(_arg1->uint256be);
140 auto value = asUint(_arg2->uint256be);
141 if (value == 0 && env.store(index) != 0)
142 env.sub.refunds += env.evmSchedule().sstoreRefundGas;
144 env.setStore(index, value);
149 size_t numTopics = _arg2->data_size /
sizeof(
h256);
150 h256 const* pTopics =
reinterpret_cast<h256 const*
>(_arg2->data);
151 env.log({pTopics, pTopics + numTopics}, {_arg1->data, _arg1->data_size});
156 env.suicide(fromEvmC(_arg1->address));
167 uint8_t
const* _inputData,
169 uint8_t* _outputData,
173 assert(_gas >= 0 &&
"Invalid gas value");
174 auto &env = *
reinterpret_cast<ExtVMFace*
>(_opaqueEnv);
175 auto value = asUint(*_value);
180 assert(_outputSize == 20);
182 auto addr = env.create(value, gas, input, {});
183 auto gasLeft =
static_cast<decltype(_gas)
>(gas);
187 gasLeft |= EVM_CALL_FAILURE;
191 CallParameters params;
194 params.valueTransfer = _kind ==
EVM_DELEGATECALL ? 0 : params.apparentValue;
195 params.senderAddress = _kind ==
EVM_DELEGATECALL ? env.caller : env.myAddress;
196 params.codeAddress = fromEvmC(*_address);
197 params.receiveAddress = _kind ==
EVM_CALL ? params.codeAddress : env.myAddress;
201 auto output = env.call(params);
202 auto gasLeft =
static_cast<int64_t
>(params.gas);
205 output->copyTo({_outputData, _outputSize});
208 gasLeft |= EVM_CALL_FAILURE;
221 m_instance = factory.create(_queryFn, _updateFn, _callFn);
229 EVM(EVM
const&) =
delete;
230 EVM& operator=(EVM) =
delete;
245 Result(Result&& _other):
249 _other.m_result.
release =
nullptr;
252 Result(Result
const&) =
delete;
253 Result& operator=(Result
const&) =
delete;
260 int64_t gasLeft()
const 275 Result execute(ExtVMFace& _ext, int64_t gas)
277 auto env =
reinterpret_cast<evm_env*
>(&_ext);
281 _ext.code.size(), gas, _ext.data.data(), _ext.data.size(),
294 m_instance, _mode, toEvmC(_codeHash), _code.data(), _code.size()
306 static EVM jit(evm_query, evm_update, evm_call);
314 auto rejected =
false;
322 cwarn <<
"Execution rejected by EVM JIT (gas limit: " << io_gas <<
"), executing with interpreter";
326 auto gas =
static_cast<int64_t
>(io_gas);
327 auto r = getJit().execute(_ext, gas);
333 io_gas = r.gasLeft();
334 auto output = r.output();
336 return {output.toVector(), 0, output.size()};
350 return getJit().isCodeReady(_mode, _codeHash);
355 getJit().compile(_mode, _code, _codeHash);
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
uint8_t bytes[32]
The 32 bytes of the big-endian integer or hash.
owning_bytes_ref exec(u256 &io_gas, ExtVMFace &_ext, OnOpFunc const &_onOp) overridefinal
VM implementation.
evm_get_code_status_fn get_code_status
Optional pointer to function returning a status of a code.
u256 const & timestamp() const
Big-endian 256-bit integer.
uint8_t const * output_data
The reference to output data.
h160 Address
An Ethereum address: 20 bytes.
Current block difficulty for DIFFICULTY.
EnvInfo const & envInfo() const
Get the execution environment information.
int64_t gas_left
The amount of gas left after the execution.
Current block number for NUMBER.
assert(len-trim+(2 *lenIndices)<=WIDTH)
static void compile(evm_mode _mode, bytesConstRef _code, h256 _codeHash)
evm_release_result_fn release
The pointer to the result release implementation.
static std::unique_ptr< VMFace > create()
Creates a VM instance of global kind (controlled by setKind() function).
Execution finished with success.
u256 const & number() const
evm_prepare_code_fn prepare_code
Optional pointer to function compiling a code.
Transaction gas price for GASPRICE.
The code has been compiled and is available in memory.
Address of the contract for ADDRESS.
Request CREATE. Semantic of some params changes.
Message sender address for CALLER.
Ran out of gas executing code of the transaction.
evm_update_key
The update callback key.
Variant type to represent possible types of values used in EVM.
EXPORT struct evm_factory evmjit_get_factory(void)
Get EVMJIT instance.
enum evm_result_code code
The execution result code.
size_t output_size
The size of the output data.
Current block timestamp for TIMESTAMP.
Balance of a given address for BALANCE.
evm_destroy_fn destroy
Pointer to function destroying the EVM instance.
Transaction origin address for ORIGIN.
Big-endian 160-bit hash suitable for keeping an Ethereum address.
vector_ref< byte const > bytesConstRef
evm_call_kind
The kind of call-like instruction.
Current block miner address for COINBASE.
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VM *, ExtVMFace const *)> OnOpFunc
Block hash of by block number for BLOCKHASH.
Check if an account exists.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
evm_mode
EVM compatibility mode aka chain mode.
Request DELEGATECALL. The value param ignored.
Code by an address for EXTCODECOPY.
evm_execute_fn execute
Pointer to function executing a code by the EVM instance.
The EVM code execution result.
evm_result_code
The execution result code.
Interface and null implementation of the class for specifying VM externalities.
Storage value of a given key for SLOAD.
static bool isCodeReady(evm_mode _mode, h256 _codeHash)
Reference to a slice of buffer that also owns the buffer.
void(* evm_update_fn)(struct evm_env *env, enum evm_update_key key, const union evm_variant *arg1, const union evm_variant *arg2)
Update callback function.
void * memcpy(void *a, const void *b, size_t c)
Mark contract as selfdestructed and set beneficiary address.
Code size by an address for EXTCODESIZE.
evm_instance * m_instance
The VM instance created with m_interface.create().
static evm_mode scheduleToMode(EVMSchedule const &_schedule)
void(* evm_query_fn)(union evm_variant *result, struct evm_env *env, enum evm_query_key key, const union evm_variant *arg)
Query callback function.
Current block gas limit for GASLIMIT.
evm_query_key
The query callback key.
int64_t(* evm_call_fn)(struct evm_env *env, enum evm_call_kind kind, int64_t gas, const struct evm_uint160be *address, const struct evm_uint256be *value, uint8_t const *input, size_t input_size, uint8_t *output, size_t output_size)
Pointer to the callback function supporting EVM calls.