Fabcoin Core  0.16.2
P2P Digital Currency
evm.h
Go to the documentation of this file.
1 #ifndef EVM_H
16 #define EVM_H
17 
18 #include <stdint.h> // Definition of int64_t, uint64_t.
19 #include <stddef.h> // Definition of size_t.
20 
21 #if __cplusplus
22 extern "C" {
23 #endif
24 
25 // BEGIN Python CFFI declarations
26 
28 enum { EVM_ABI_VERSION = 0 };
29 
36 struct evm_uint256be {
38  uint8_t bytes[32];
39 };
40 
42 struct evm_uint160be {
44  uint8_t bytes[20];
45 };
46 
56 };
57 
58 struct evm_result;
59 
68 typedef void (*evm_release_result_fn)(struct evm_result const* result);
69 
71 struct evm_result {
74 
78  int64_t gas_left;
79 
82  uint8_t const* output_data;
83 
85  size_t output_size;
86 
93 
97 
99  char const* error_message;
100 
104 
106 };
107 
110  EVM_SLOAD = 0,
122  EVM_BALANCE = 12,
126 };
127 
128 
131 struct evm_env;
132 
138 union evm_variant {
140  int64_t int64;
141 
143  struct evm_uint256be uint256be;
144 
145  struct {
148  uint8_t address_padding[12];
149 
152  };
153 
155  struct {
157  uint8_t const* data;
158 
160  size_t data_size;
161  };
162 };
163 
232 typedef void (*evm_query_fn)(union evm_variant* result,
233  struct evm_env* env,
234  enum evm_query_key key,
235  const union evm_variant* arg);
236 
240  EVM_LOG = 1,
242 };
244 
245 
271 typedef void (*evm_update_fn)(struct evm_env* env,
272  enum evm_update_key key,
273  const union evm_variant* arg1,
274  const union evm_variant* arg2);
275 
278  EVM_CALL = 0,
282 };
283 
285 static const int64_t EVM_CALL_FAILURE = 0x8000000000000000;
286 
308 typedef int64_t (*evm_call_fn)(
309  struct evm_env* env,
310  enum evm_call_kind kind,
311  int64_t gas,
312  const struct evm_uint160be* address,
313  const struct evm_uint256be* value,
314  uint8_t const* input,
315  size_t input_size,
316  uint8_t* output,
317  size_t output_size);
318 
319 
320 struct evm_instance;
321 
331 typedef struct evm_instance* (*evm_create_fn)(evm_query_fn query_fn,
332  evm_update_fn update_fn,
333  evm_call_fn call_fn);
334 
338 typedef void (*evm_destroy_fn)(struct evm_instance* evm);
339 
340 
352 typedef int (*evm_set_option_fn)(struct evm_instance* evm,
353  char const* name,
354  char const* value);
355 
356 
359 enum evm_mode {
364 };
365 
366 
386 typedef struct evm_result (*evm_execute_fn)(struct evm_instance* instance,
387  struct evm_env* env,
388  enum evm_mode mode,
389  struct evm_uint256be code_hash,
390  uint8_t const* code,
391  size_t code_size,
392  int64_t gas,
393  uint8_t const* input,
394  size_t input_size,
395  struct evm_uint256be value);
396 
397 
402 
405 
408 };
409 
410 
412 typedef enum evm_code_status
414  enum evm_mode mode,
415  struct evm_uint256be code_hash);
416 
420 typedef void (*evm_prepare_code_fn)(struct evm_instance* instance,
421  enum evm_mode mode,
422  struct evm_uint256be code_hash,
423  uint8_t const* code,
424  size_t code_size);
425 
429 struct evm_instance {
432 
435 
440 
445 
450 };
451 
455 struct evm_factory {
461 
464 };
465 
466 // END Python CFFI declarations
467 
476 
477 
478 #if __cplusplus
479 }
480 #endif
481 
482 #endif // EVM_H
483 
uint8_t bytes[32]
The 32 bytes of the big-endian integer or hash.
Definition: evm.h:38
void(* evm_prepare_code_fn)(struct evm_instance *instance, enum evm_mode mode, struct evm_uint256be code_hash, uint8_t const *code, size_t code_size)
Request preparation of the code for faster execution.
Definition: evm.h:420
evm_get_code_status_fn get_code_status
Optional pointer to function returning a status of a code.
Definition: evm.h:439
Big-endian 256-bit integer.
Definition: evm.h:36
char const * error_message
The error message explaining the result code.
Definition: evm.h:99
Update storage entry.
Definition: evm.h:239
uint8_t const * output_data
The reference to output data.
Definition: evm.h:82
evm_mode mode
Definition: SmartVM.cpp:47
Current block difficulty for DIFFICULTY.
Definition: evm.h:116
int64_t gas_left
The amount of gas left after the execution.
Definition: evm.h:78
Current block number for NUMBER.
Definition: evm.h:118
evm_release_result_fn release
The pointer to the result release implementation.
Definition: evm.h:92
Execution finished with success.
Definition: evm.h:49
uint8_t const * data
Pointer to the data.
Definition: evm.h:157
evm_prepare_code_fn prepare_code
Optional pointer to function compiling a code.
Definition: evm.h:444
int(* evm_set_option_fn)(struct evm_instance *evm, char const *name, char const *value)
Configures the EVM instance.
Definition: evm.h:352
Transaction gas price for GASPRICE.
Definition: evm.h:114
bytes code
Definition: SmartVM.cpp:45
struct evm_instance *(* evm_create_fn)(evm_query_fn query_fn, evm_update_fn update_fn, evm_call_fn call_fn)
Forward declaration.
Definition: evm.h:331
The code has been compiled and is available in memory.
Definition: evm.h:404
evm_code_status
Status of a code in VM. Useful for JIT-like implementations.
Definition: evm.h:399
int64_t int64
A host-endian 64-bit integer.
Definition: evm.h:140
struct evm_factory examplevm_get_factory(void)
Example of a function creating uninitialized instance of an example VM.
Definition: examplevm.c:72
evm_set_option_fn set_option
Optional pointer to function modifying VM&#39;s options.
Definition: evm.h:449
Address of the contract for ADDRESS.
Definition: evm.h:111
evm_create_fn create
Pointer to function creating and initializing the EVM instance.
Definition: evm.h:463
Request CREATE. Semantic of some params changes.
Definition: evm.h:281
Message sender address for CALLER.
Definition: evm.h:112
evm_update_key
The update callback key.
Definition: evm.h:238
Variant type to represent possible types of values used in EVM.
Definition: evm.h:138
The EVM instance factory.
Definition: evm.h:455
Current call depth.
Definition: evm.h:125
Request CALLCODE.
Definition: evm.h:280
size_t output_size
The size of the output data.
Definition: evm.h:85
Current block timestamp for TIMESTAMP.
Definition: evm.h:119
Balance of a given address for BALANCE.
Definition: evm.h:122
const char * name
Definition: rest.cpp:36
void * internal_memory
The pointer to EVM-owned memory.
Definition: evm.h:103
evm_destroy_fn destroy
Pointer to function destroying the EVM instance.
Definition: evm.h:431
Request CALL.
Definition: evm.h:278
Transaction origin address for ORIGIN.
Definition: evm.h:113
Big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evm.h:42
int abi_version
EVM-C ABI version implemented by the EVM factory and instance.
Definition: evm.h:460
The EVM instance.
Definition: evm.h:429
evm_call_kind
The kind of call-like instruction.
Definition: evm.h:277
Current block miner address for COINBASE.
Definition: evm.h:115
Block hash of by block number for BLOCKHASH.
Definition: evm.h:123
Check if an account exists.
Definition: evm.h:124
evm_mode
EVM compatibility mode aka chain mode.
Definition: evm.h:359
Request DELEGATECALL. The value param ignored.
Definition: evm.h:279
Code by an address for EXTCODECOPY.
Definition: evm.h:120
The compiled version of the code is available in on-disk cache.
Definition: evm.h:407
evm_execute_fn execute
Pointer to function executing a code by the EVM instance.
Definition: evm.h:434
void(* evm_destroy_fn)(struct evm_instance *evm)
Destroys the EVM instance.
Definition: evm.h:338
The EVM code execution result.
Definition: evm.h:71
enum evm_code_status(* evm_get_code_status_fn)(struct evm_instance *instance, enum evm_mode mode, struct evm_uint256be code_hash)
Get information the status of the code in the VM.
Definition: evm.h:413
evm_result_code
The execution result code.
Definition: evm.h:48
struct evm_result(* evm_execute_fn)(struct evm_instance *instance, struct evm_env *env, enum evm_mode mode, struct evm_uint256be code_hash, uint8_t const *code, size_t code_size, int64_t gas, uint8_t const *input, size_t input_size, struct evm_uint256be value)
Generates and executes machine code for given EVM bytecode.
Definition: evm.h:386
Storage value of a given key for SLOAD.
Definition: evm.h:110
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.
Definition: evm.h:271
Mark contract as selfdestructed and set beneficiary address.
Definition: evm.h:241
Code size by an address for EXTCODESIZE.
Definition: evm.h:121
Log.
Definition: evm.h:240
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.
Definition: evm.h:232
Current block gas limit for GASLIMIT.
Definition: evm.h:117
The code is uknown to the VM.
Definition: evm.h:401
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
size_t data_size
Size of the referenced memory/data.
Definition: evm.h:160
void(* evm_release_result_fn)(struct evm_result const *result)
Forward declaration.
Definition: evm.h:68
evm_query_key
The query callback key.
Definition: evm.h:109
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.
Definition: evm.h:308
Generic execution failure.
Definition: evm.h:50