EVMC
evmc.h
Go to the documentation of this file.
1
11#ifndef EVMC_H
12#define EVMC_H
13
14#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 6)
21#define EVMC_DEPRECATED __attribute__((deprecated))
22#else
23#define EVMC_DEPRECATED
24#endif
25
26
27#include <stdbool.h> /* Definition of bool, true and false. */
28#include <stddef.h> /* Definition of size_t. */
29#include <stdint.h> /* Definition of int64_t, uint64_t. */
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/* BEGIN Python CFFI declarations */
36
37enum
38{
48};
49
50
56typedef struct evmc_bytes32
57{
59 uint8_t bytes[32];
61
66
68typedef struct evmc_address
69{
71 uint8_t bytes[20];
73
76{
82 EVMC_CREATE2 = 4
83};
84
87{
88 EVMC_STATIC = 1
89};
90
97{
100
105 uint32_t flags;
106
112 int32_t depth;
113
119 int64_t gas;
120
133
143
151 const uint8_t* input_data;
152
159
167
175
190};
191
192
195{
199 int64_t block_number;
207};
208
214struct evmc_host_context;
215
225typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_host_context* context);
226
239typedef evmc_bytes32 (*evmc_get_block_hash_fn)(struct evmc_host_context* context, int64_t number);
240
262{
265
268
276
279
289
292
298
301
304
311
314
317
324
330
336
341
347
350
353
366
370
371/* Forward declaration. */
372struct evmc_result;
373
390typedef void (*evmc_release_result_fn)(const struct evmc_result* result);
391
394{
397
404 int64_t gas_left;
405
412 int64_t gas_refund;
413
426 const uint8_t* output_data;
427
434
455
465
477 uint8_t padding[4];
478};
479
480
490typedef bool (*evmc_account_exists_fn)(struct evmc_host_context* context,
491 const evmc_address* address);
492
505 const evmc_address* address,
506 const evmc_bytes32* key);
507
521 const evmc_address* address,
522 const evmc_bytes32* key);
523
524
547{
563
570
577
584
591
598
605
612
620
621
636typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_host_context* context,
637 const evmc_address* address,
638 const evmc_bytes32* key,
639 const evmc_bytes32* value);
640
655typedef void (*evmc_set_transient_storage_fn)(struct evmc_host_context* context,
656 const evmc_address* address,
657 const evmc_bytes32* key,
658 const evmc_bytes32* value);
659
670 const evmc_address* address);
671
682typedef size_t (*evmc_get_code_size_fn)(struct evmc_host_context* context,
683 const evmc_address* address);
684
697 const evmc_address* address);
698
716typedef size_t (*evmc_copy_code_fn)(struct evmc_host_context* context,
717 const evmc_address* address,
718 size_t code_offset,
719 uint8_t* buffer_data,
720 size_t buffer_size);
721
734typedef bool (*evmc_selfdestruct_fn)(struct evmc_host_context* context,
735 const evmc_address* address,
736 const evmc_address* beneficiary);
737
751typedef void (*evmc_emit_log_fn)(struct evmc_host_context* context,
752 const evmc_address* address,
753 const uint8_t* data,
754 size_t data_size,
755 const evmc_bytes32 topics[],
756 size_t topics_count);
757
762{
767
773
785typedef enum evmc_access_status (*evmc_access_account_fn)(struct evmc_host_context* context,
786 const evmc_address* address);
787
800typedef enum evmc_access_status (*evmc_access_storage_fn)(struct evmc_host_context* context,
801 const evmc_address* address,
802 const evmc_bytes32* key);
803
811typedef struct evmc_result (*evmc_call_fn)(struct evmc_host_context* context,
812 const struct evmc_message* msg);
813
823{
826
829
832
835
838
841
844
847
850
853
856
859
862
865
868
871};
872
873
874/* Forward declaration. */
875struct evmc_vm;
876
882typedef void (*evmc_destroy_fn)(struct evmc_vm* vm);
883
888{
889 EVMC_SET_OPTION_SUCCESS = 0,
890 EVMC_SET_OPTION_INVALID_NAME = 1,
891 EVMC_SET_OPTION_INVALID_VALUE = 2
892};
893
907typedef enum evmc_set_option_result (*evmc_set_option_fn)(struct evmc_vm* vm,
908 char const* name,
909 char const* value);
910
911
919{
926
933
940
947
954
961
970
977
984
991
998
1005
1013
1020
1023
1031
1032
1051typedef struct evmc_result (*evmc_execute_fn)(struct evmc_vm* vm,
1052 const struct evmc_host_interface* host,
1053 struct evmc_host_context* context,
1054 enum evmc_revision rev,
1055 const struct evmc_message* msg,
1056 uint8_t const* code,
1057 size_t code_size);
1058
1063{
1068
1073
1084 EVMC_CAPABILITY_PRECOMPILES = (1u << 2)
1086
1093
1104
1105
1112{
1119 const int abi_version;
1120
1127 const char* name;
1128
1135 const char* version;
1136
1143
1150
1162
1169};
1170
1171/* END Python CFFI declarations */
1172
1173#ifdef EVMC_DOCUMENTATION
1189struct evmc_vm* evmc_create_example_vm(void);
1190#endif
1191
1192#ifdef __cplusplus
1193}
1194#endif
1195
1196#endif
evmc_flags
The flags for evmc_message.
Definition: evmc.h:87
bool(* evmc_selfdestruct_fn)(struct evmc_host_context *context, const evmc_address *address, const evmc_address *beneficiary)
Selfdestruct callback function.
Definition: evmc.h:734
void(* evmc_destroy_fn)(struct evmc_vm *vm)
Destroys the VM instance.
Definition: evmc.h:882
struct evmc_bytes32 evmc_uint256be
The alias for evmc_bytes32 to represent a big-endian 256-bit integer.
Definition: evmc.h:65
evmc_set_option_result
Possible outcomes of evmc_set_option.
Definition: evmc.h:888
void(* evmc_release_result_fn)(const struct evmc_result *result)
Releases resources assigned to an execution result.
Definition: evmc.h:390
size_t(* evmc_get_code_size_fn)(struct evmc_host_context *context, const evmc_address *address)
Get code size callback function.
Definition: evmc.h:682
evmc_capabilities
Possible capabilities of a VM.
Definition: evmc.h:1063
struct evmc_vm * evmc_create_example_vm(void)
Example of a function creating an instance of an example EVM implementation.
Definition: example_vm.cpp:392
evmc_status_code
The execution status code.
Definition: evmc.h:262
bool(* evmc_account_exists_fn)(struct evmc_host_context *context, const evmc_address *address)
Check account existence callback function.
Definition: evmc.h:490
evmc_uint256be(* evmc_get_balance_fn)(struct evmc_host_context *context, const evmc_address *address)
Get balance callback function.
Definition: evmc.h:669
struct evmc_result(* evmc_call_fn)(struct evmc_host_context *context, const struct evmc_message *msg)
Pointer to the callback function supporting EVM calls.
Definition: evmc.h:811
enum evmc_set_option_result(* evmc_set_option_fn)(struct evmc_vm *vm, char const *name, char const *value)
Configures the VM instance.
Definition: evmc.h:907
uint32_t evmc_capabilities_flagset
Alias for unsigned integer representing a set of bit flags of EVMC capabilities.
Definition: evmc.h:1092
evmc_bytes32(* evmc_get_code_hash_fn)(struct evmc_host_context *context, const evmc_address *address)
Get code hash callback function.
Definition: evmc.h:696
evmc_bytes32(* evmc_get_storage_fn)(struct evmc_host_context *context, const evmc_address *address, const evmc_bytes32 *key)
Get storage callback function.
Definition: evmc.h:504
struct evmc_tx_context(* evmc_get_tx_context_fn)(struct evmc_host_context *context)
Get transaction context callback function.
Definition: evmc.h:225
size_t(* evmc_copy_code_fn)(struct evmc_host_context *context, const evmc_address *address, size_t code_offset, uint8_t *buffer_data, size_t buffer_size)
Copy code callback function.
Definition: evmc.h:716
enum evmc_access_status(* evmc_access_account_fn)(struct evmc_host_context *context, const evmc_address *address)
Access account callback function.
Definition: evmc.h:785
evmc_bytes32(* evmc_get_block_hash_fn)(struct evmc_host_context *context, int64_t number)
Get block hash callback function.
Definition: evmc.h:239
evmc_capabilities_flagset(* evmc_get_capabilities_fn)(struct evmc_vm *vm)
Return the supported capabilities of the VM instance.
Definition: evmc.h:1103
evmc_access_status
Access status per EIP-2929: Gas cost increases for state access opcodes.
Definition: evmc.h:762
void(* evmc_emit_log_fn)(struct evmc_host_context *context, const evmc_address *address, const uint8_t *data, size_t data_size, const evmc_bytes32 topics[], size_t topics_count)
Log callback function.
Definition: evmc.h:751
evmc_call_kind
The kind of call-like instruction.
Definition: evmc.h:76
enum evmc_access_status(* evmc_access_storage_fn)(struct evmc_host_context *context, const evmc_address *address, const evmc_bytes32 *key)
Access storage callback function.
Definition: evmc.h:800
evmc_storage_status
The effect of an attempt to modify a contract storage item.
Definition: evmc.h:547
void(* evmc_set_transient_storage_fn)(struct evmc_host_context *context, const evmc_address *address, const evmc_bytes32 *key, const evmc_bytes32 *value)
Set transient storage callback function.
Definition: evmc.h:655
evmc_revision
EVM revision.
Definition: evmc.h:919
struct evmc_result(* evmc_execute_fn)(struct evmc_vm *vm, const struct evmc_host_interface *host, struct evmc_host_context *context, enum evmc_revision rev, const struct evmc_message *msg, uint8_t const *code, size_t code_size)
Executes the given code using the input from the message.
Definition: evmc.h:1051
enum evmc_storage_status(* evmc_set_storage_fn)(struct evmc_host_context *context, const evmc_address *address, const evmc_bytes32 *key, const evmc_bytes32 *value)
Set storage callback function.
Definition: evmc.h:636
evmc_bytes32(* evmc_get_transient_storage_fn)(struct evmc_host_context *context, const evmc_address *address, const evmc_bytes32 *key)
Get transient storage callback function.
Definition: evmc.h:520
@ EVMC_ABI_VERSION
The EVMC ABI version number of the interface declared in this file.
Definition: evmc.h:47
@ EVMC_STATIC
Static call mode.
Definition: evmc.h:88
@ EVMC_CAPABILITY_EVM1
The VM is capable of executing EVM1 bytecode.
Definition: evmc.h:1067
@ EVMC_CAPABILITY_PRECOMPILES
The VM is capable of executing the precompiled contracts defined for the range of code addresses.
Definition: evmc.h:1084
@ EVMC_CAPABILITY_EWASM
The VM is capable of executing ewasm bytecode.
Definition: evmc.h:1072
@ EVMC_INSUFFICIENT_BALANCE
The caller does not have enough funds for value transfer.
Definition: evmc.h:349
@ EVMC_ARGUMENT_OUT_OF_RANGE
An argument to a state accessing method has a value outside of the accepted range of values.
Definition: evmc.h:335
@ EVMC_INVALID_MEMORY_ACCESS
Tried to read outside memory bounds.
Definition: evmc.h:310
@ EVMC_REJECTED
The execution of the given code and/or message has been rejected by the EVM implementation.
Definition: evmc.h:365
@ EVMC_UNDEFINED_INSTRUCTION
An undefined instruction has been encountered.
Definition: evmc.h:291
@ EVMC_SUCCESS
Execution finished with success.
Definition: evmc.h:264
@ EVMC_OUT_OF_MEMORY
The VM failed to allocate the amount of memory needed for execution.
Definition: evmc.h:368
@ EVMC_STACK_UNDERFLOW
Execution of an opcode has required more items on the EVM stack.
Definition: evmc.h:300
@ EVMC_BAD_JUMP_DESTINATION
Execution has violated the jump destination restrictions.
Definition: evmc.h:303
@ EVMC_INVALID_INSTRUCTION
The designated INVALID instruction has been hit during execution.
Definition: evmc.h:288
@ EVMC_STATIC_MODE_VIOLATION
Tried to execute an operation which is restricted in static mode.
Definition: evmc.h:316
@ EVMC_WASM_TRAP
A WebAssembly trap has been hit during execution.
Definition: evmc.h:346
@ EVMC_PRECOMPILE_FAILURE
A call to a precompiled or system contract has ended with a failure.
Definition: evmc.h:323
@ EVMC_INTERNAL_ERROR
EVM implementation generic internal error.
Definition: evmc.h:352
@ EVMC_OUT_OF_GAS
The execution has run out of gas.
Definition: evmc.h:278
@ EVMC_CONTRACT_VALIDATION_FAILURE
Contract validation has failed (e.g.
Definition: evmc.h:329
@ EVMC_CALL_DEPTH_EXCEEDED
Call depth has exceeded the limit (if any)
Definition: evmc.h:313
@ EVMC_WASM_UNREACHABLE_INSTRUCTION
A WebAssembly unreachable instruction has been hit during execution.
Definition: evmc.h:340
@ EVMC_STACK_OVERFLOW
The execution has attempted to put more items on the EVM stack than the specified limit.
Definition: evmc.h:297
@ EVMC_FAILURE
Generic execution failure.
Definition: evmc.h:267
@ EVMC_REVERT
Execution terminated with REVERT opcode.
Definition: evmc.h:275
@ EVMC_ACCESS_COLD
The entry hasn't been accessed before – it's the first access.
Definition: evmc.h:766
@ EVMC_ACCESS_WARM
The entry is already in accessed_addresses or accessed_storage_keys.
Definition: evmc.h:771
@ EVMC_CREATE
Request CREATE.
Definition: evmc.h:81
@ EVMC_DELEGATECALL
Request DELEGATECALL.
Definition: evmc.h:78
@ EVMC_CREATE2
Request CREATE2.
Definition: evmc.h:82
@ EVMC_CALL
Request CALL.
Definition: evmc.h:77
@ EVMC_CALLCODE
Request CALLCODE.
Definition: evmc.h:80
@ EVMC_STORAGE_ADDED_DELETED
A storage item is deleted by changing the current dirty nonzero to the original zero value.
Definition: evmc.h:611
@ EVMC_STORAGE_MODIFIED_RESTORED
A storage item is modified by changing the current dirty nonzero to the original nonzero value other ...
Definition: evmc.h:618
@ EVMC_STORAGE_DELETED_RESTORED
A storage item is added by changing the current dirty zero to the original value.
Definition: evmc.h:604
@ EVMC_STORAGE_ADDED
A new storage item is added by changing the current clean zero to a nonzero value.
Definition: evmc.h:569
@ EVMC_STORAGE_MODIFIED_DELETED
A storage item is deleted by changing the current dirty nonzero to the zero value and the original va...
Definition: evmc.h:597
@ EVMC_STORAGE_ASSIGNED
The new/same value is assigned to the storage item without affecting the cost structure.
Definition: evmc.h:562
@ EVMC_STORAGE_DELETED
A storage item is deleted by changing the current clean nonzero to the zero value.
Definition: evmc.h:576
@ EVMC_STORAGE_DELETED_ADDED
A storage item is added by changing the current dirty zero to a nonzero value other than the original...
Definition: evmc.h:590
@ EVMC_STORAGE_MODIFIED
A storage item is modified by changing the current clean nonzero to other nonzero value.
Definition: evmc.h:583
@ EVMC_HOMESTEAD
The Homestead revision.
Definition: evmc.h:932
@ EVMC_LATEST_STABLE_REVISION
The latest known EVM revision with finalized specification.
Definition: evmc.h:1029
@ EVMC_PRAGUE
The Prague revision.
Definition: evmc.h:1019
@ EVMC_ISTANBUL
The Istanbul revision.
Definition: evmc.h:976
@ EVMC_FRONTIER
The Frontier revision.
Definition: evmc.h:925
@ EVMC_PETERSBURG
The Petersburg revision.
Definition: evmc.h:969
@ EVMC_CONSTANTINOPLE
The Constantinople revision.
Definition: evmc.h:960
@ EVMC_TANGERINE_WHISTLE
The Tangerine Whistle revision.
Definition: evmc.h:939
@ EVMC_MAX_REVISION
The maximum EVM revision supported.
Definition: evmc.h:1022
@ EVMC_SPURIOUS_DRAGON
The Spurious Dragon revision.
Definition: evmc.h:946
@ EVMC_BYZANTIUM
The Byzantium revision.
Definition: evmc.h:953
@ EVMC_CANCUN
The Cancun revision.
Definition: evmc.h:1012
@ EVMC_SHANGHAI
The Shanghai revision.
Definition: evmc.h:1004
@ EVMC_LONDON
The London revision.
Definition: evmc.h:990
@ EVMC_PARIS
The Paris revision (aka The Merge).
Definition: evmc.h:997
@ EVMC_BERLIN
The Berlin revision.
Definition: evmc.h:983
Big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.h:69
uint8_t bytes[20]
The 20 bytes of the hash.
Definition: evmc.h:71
The fixed size array of 32 bytes.
Definition: evmc.h:57
uint8_t bytes[32]
The 32 bytes.
Definition: evmc.h:59
The opaque data type representing the Host execution context.
The Host interface.
Definition: evmc.h:823
evmc_get_code_hash_fn get_code_hash
Get code hash callback function.
Definition: evmc.h:840
evmc_call_fn call
Call callback function.
Definition: evmc.h:849
evmc_selfdestruct_fn selfdestruct
Selfdestruct callback function.
Definition: evmc.h:846
evmc_get_storage_fn get_storage
Get storage callback function.
Definition: evmc.h:828
evmc_copy_code_fn copy_code
Copy code callback function.
Definition: evmc.h:843
evmc_get_code_size_fn get_code_size
Get code size callback function.
Definition: evmc.h:837
evmc_get_transient_storage_fn get_transient_storage
Get transient storage callback function.
Definition: evmc.h:867
evmc_set_transient_storage_fn set_transient_storage
Set transient storage callback function.
Definition: evmc.h:870
evmc_get_block_hash_fn get_block_hash
Get block hash callback function.
Definition: evmc.h:855
evmc_emit_log_fn emit_log
Emit log callback function.
Definition: evmc.h:858
evmc_account_exists_fn account_exists
Check account existence callback function.
Definition: evmc.h:825
evmc_access_account_fn access_account
Access account callback function.
Definition: evmc.h:861
evmc_get_balance_fn get_balance
Get balance callback function.
Definition: evmc.h:834
evmc_set_storage_fn set_storage
Set storage callback function.
Definition: evmc.h:831
evmc_get_tx_context_fn get_tx_context
Get transaction context callback function.
Definition: evmc.h:852
evmc_access_storage_fn access_storage
Access storage callback function.
Definition: evmc.h:864
The message describing an EVM call, including a zero-depth calls from a transaction origin.
Definition: evmc.h:97
const uint8_t * input_data
The message input data.
Definition: evmc.h:151
evmc_bytes32 create2_salt
The optional value used in new contract address construction.
Definition: evmc.h:174
size_t input_size
The size of the message input data.
Definition: evmc.h:158
evmc_address recipient
The recipient of the message.
Definition: evmc.h:132
enum evmc_call_kind kind
The kind of the call.
Definition: evmc.h:99
int32_t depth
The present depth of the message call stack.
Definition: evmc.h:112
uint32_t flags
Additional flags modifying the call execution behavior.
Definition: evmc.h:105
evmc_address code_address
The address of the code to be executed.
Definition: evmc.h:189
evmc_uint256be value
The amount of Ether transferred with the message.
Definition: evmc.h:166
evmc_address sender
The sender of the message.
Definition: evmc.h:142
int64_t gas
The amount of gas available to the message execution.
Definition: evmc.h:119
The EVM code execution result.
Definition: evmc.h:394
const uint8_t * output_data
The reference to output data.
Definition: evmc.h:426
enum evmc_status_code status_code
The execution status code.
Definition: evmc.h:396
evmc_release_result_fn release
The method releasing all resources associated with the result object.
Definition: evmc.h:454
int64_t gas_refund
The refunded gas accumulated from this execution and its sub-calls.
Definition: evmc.h:412
size_t output_size
The size of the output data.
Definition: evmc.h:433
uint8_t padding[4]
Reserved data that MAY be used by a evmc_result object creator.
Definition: evmc.h:477
evmc_address create_address
The address of the possibly created contract.
Definition: evmc.h:464
int64_t gas_left
The amount of gas left after the execution.
Definition: evmc.h:404
The transaction and block data for execution.
Definition: evmc.h:195
evmc_address tx_origin
The transaction origin account.
Definition: evmc.h:197
evmc_uint256be block_base_fee
The block base fee per gas (EIP-1559, EIP-3198).
Definition: evmc.h:204
int64_t block_number
The block number.
Definition: evmc.h:199
int64_t block_timestamp
The block timestamp.
Definition: evmc.h:200
const evmc_bytes32 * blob_hashes
The array of blob hashes (EIP-4844).
Definition: evmc.h:205
evmc_uint256be tx_gas_price
The transaction gas price.
Definition: evmc.h:196
size_t blob_hashes_count
The number of blob hashes (EIP-4844).
Definition: evmc.h:206
evmc_uint256be chain_id
The blockchain's ChainID.
Definition: evmc.h:203
evmc_uint256be block_prev_randao
The block previous RANDAO (EIP-4399).
Definition: evmc.h:202
evmc_address block_coinbase
The miner of the block.
Definition: evmc.h:198
int64_t block_gas_limit
The block gas limit.
Definition: evmc.h:201
The VM instance.
Definition: evmc.h:1112
evmc_set_option_fn set_option
Optional pointer to function modifying VM's options.
Definition: evmc.h:1168
evmc_get_capabilities_fn get_capabilities
A method returning capabilities supported by the VM instance.
Definition: evmc.h:1161
evmc_execute_fn execute
Pointer to function executing a code by the VM instance.
Definition: evmc.h:1149
const char * name
The name of the EVMC VM implementation.
Definition: evmc.h:1127
evmc_destroy_fn destroy
Pointer to function destroying the VM instance.
Definition: evmc.h:1142
const int abi_version
EVMC ABI version implemented by the VM instance.
Definition: evmc.h:1119
const char * version
The version of the EVMC VM implementation, e.g.
Definition: evmc.h:1135