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{
84};
85
88{
89 EVMC_STATIC = 1
90};
91
98{
101
106 uint32_t flags;
107
113 int32_t depth;
114
120 int64_t gas;
121
134
144
152 const uint8_t* input_data;
153
160
168
177
192
196 const uint8_t* code;
197
201 size_t code_size;
202};
203
205typedef struct evmc_tx_initcode
206{
208 const uint8_t* code;
209 size_t code_size;
211
214{
218 int64_t block_number;
229};
230
236struct evmc_host_context;
237
247typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_host_context* context);
248
261typedef evmc_bytes32 (*evmc_get_block_hash_fn)(struct evmc_host_context* context, int64_t number);
262
284{
287
290
298
301
311
314
320
323
326
333
336
339
346
352
358
363
369
372
375
388
392
393/* Forward declaration. */
394struct evmc_result;
395
412typedef void (*evmc_release_result_fn)(const struct evmc_result* result);
413
416{
419
426 int64_t gas_left;
427
434 int64_t gas_refund;
435
448 const uint8_t* output_data;
449
456
477
487
499 uint8_t padding[4];
500};
501
502
512typedef bool (*evmc_account_exists_fn)(struct evmc_host_context* context,
513 const evmc_address* address);
514
527 const evmc_address* address,
528 const evmc_bytes32* key);
529
543 const evmc_address* address,
544 const evmc_bytes32* key);
545
546
569{
585
592
599
606
613
620
627
634
642
643
658typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_host_context* context,
659 const evmc_address* address,
660 const evmc_bytes32* key,
661 const evmc_bytes32* value);
662
677typedef void (*evmc_set_transient_storage_fn)(struct evmc_host_context* context,
678 const evmc_address* address,
679 const evmc_bytes32* key,
680 const evmc_bytes32* value);
681
692 const evmc_address* address);
693
704typedef size_t (*evmc_get_code_size_fn)(struct evmc_host_context* context,
705 const evmc_address* address);
706
719 const evmc_address* address);
720
738typedef size_t (*evmc_copy_code_fn)(struct evmc_host_context* context,
739 const evmc_address* address,
740 size_t code_offset,
741 uint8_t* buffer_data,
742 size_t buffer_size);
743
756typedef bool (*evmc_selfdestruct_fn)(struct evmc_host_context* context,
757 const evmc_address* address,
758 const evmc_address* beneficiary);
759
773typedef void (*evmc_emit_log_fn)(struct evmc_host_context* context,
774 const evmc_address* address,
775 const uint8_t* data,
776 size_t data_size,
777 const evmc_bytes32 topics[],
778 size_t topics_count);
779
784{
789
795
807typedef enum evmc_access_status (*evmc_access_account_fn)(struct evmc_host_context* context,
808 const evmc_address* address);
809
822typedef enum evmc_access_status (*evmc_access_storage_fn)(struct evmc_host_context* context,
823 const evmc_address* address,
824 const evmc_bytes32* key);
825
833typedef struct evmc_result (*evmc_call_fn)(struct evmc_host_context* context,
834 const struct evmc_message* msg);
835
845{
848
851
854
857
860
863
866
869
872
875
878
881
884
887
890
893};
894
895
896/* Forward declaration. */
897struct evmc_vm;
898
904typedef void (*evmc_destroy_fn)(struct evmc_vm* vm);
905
910{
911 EVMC_SET_OPTION_SUCCESS = 0,
912 EVMC_SET_OPTION_INVALID_NAME = 1,
913 EVMC_SET_OPTION_INVALID_VALUE = 2
914};
915
929typedef enum evmc_set_option_result (*evmc_set_option_fn)(struct evmc_vm* vm,
930 char const* name,
931 char const* value);
932
933
941{
948
955
962
969
976
983
992
999
1006
1013
1020
1027
1035
1042
1045
1053
1054
1073typedef struct evmc_result (*evmc_execute_fn)(struct evmc_vm* vm,
1074 const struct evmc_host_interface* host,
1075 struct evmc_host_context* context,
1076 enum evmc_revision rev,
1077 const struct evmc_message* msg,
1078 uint8_t const* code,
1079 size_t code_size);
1080
1085{
1090
1095
1106 EVMC_CAPABILITY_PRECOMPILES = (1u << 2)
1108
1115
1126
1127
1134{
1141 const int abi_version;
1142
1149 const char* name;
1150
1157 const char* version;
1158
1165
1172
1184
1191};
1192
1193/* END Python CFFI declarations */
1194
1195#ifdef EVMC_DOCUMENTATION
1211struct evmc_vm* evmc_create_example_vm(void);
1212#endif
1213
1214#ifdef __cplusplus
1215}
1216#endif
1217
1218#endif
evmc_flags
The flags for evmc_message.
Definition: evmc.h:88
bool(* evmc_selfdestruct_fn)(struct evmc_host_context *context, const evmc_address *address, const evmc_address *beneficiary)
Selfdestruct callback function.
Definition: evmc.h:756
void(* evmc_destroy_fn)(struct evmc_vm *vm)
Destroys the VM instance.
Definition: evmc.h:904
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:910
void(* evmc_release_result_fn)(const struct evmc_result *result)
Releases resources assigned to an execution result.
Definition: evmc.h:412
size_t(* evmc_get_code_size_fn)(struct evmc_host_context *context, const evmc_address *address)
Get code size callback function.
Definition: evmc.h:704
evmc_capabilities
Possible capabilities of a VM.
Definition: evmc.h:1085
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:284
bool(* evmc_account_exists_fn)(struct evmc_host_context *context, const evmc_address *address)
Check account existence callback function.
Definition: evmc.h:512
evmc_uint256be(* evmc_get_balance_fn)(struct evmc_host_context *context, const evmc_address *address)
Get balance callback function.
Definition: evmc.h:691
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:833
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:929
uint32_t evmc_capabilities_flagset
Alias for unsigned integer representing a set of bit flags of EVMC capabilities.
Definition: evmc.h:1114
evmc_bytes32(* evmc_get_code_hash_fn)(struct evmc_host_context *context, const evmc_address *address)
Get code hash callback function.
Definition: evmc.h:718
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:526
struct evmc_tx_context(* evmc_get_tx_context_fn)(struct evmc_host_context *context)
Get transaction context callback function.
Definition: evmc.h:247
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:738
enum evmc_access_status(* evmc_access_account_fn)(struct evmc_host_context *context, const evmc_address *address)
Access account callback function.
Definition: evmc.h:807
evmc_bytes32(* evmc_get_block_hash_fn)(struct evmc_host_context *context, int64_t number)
Get block hash callback function.
Definition: evmc.h:261
evmc_capabilities_flagset(* evmc_get_capabilities_fn)(struct evmc_vm *vm)
Return the supported capabilities of the VM instance.
Definition: evmc.h:1125
evmc_access_status
Access status per EIP-2929: Gas cost increases for state access opcodes.
Definition: evmc.h:784
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:773
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:822
evmc_storage_status
The effect of an attempt to modify a contract storage item.
Definition: evmc.h:569
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:677
evmc_revision
EVM revision.
Definition: evmc.h:941
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:1073
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:658
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:542
@ 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:89
@ EVMC_CAPABILITY_EVM1
The VM is capable of executing EVM1 bytecode.
Definition: evmc.h:1089
@ EVMC_CAPABILITY_PRECOMPILES
The VM is capable of executing the precompiled contracts defined for the range of code addresses.
Definition: evmc.h:1106
@ EVMC_CAPABILITY_EWASM
The VM is capable of executing ewasm bytecode.
Definition: evmc.h:1094
@ EVMC_INSUFFICIENT_BALANCE
The caller does not have enough funds for value transfer.
Definition: evmc.h:371
@ 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:357
@ EVMC_INVALID_MEMORY_ACCESS
Tried to read outside memory bounds.
Definition: evmc.h:332
@ EVMC_REJECTED
The execution of the given code and/or message has been rejected by the EVM implementation.
Definition: evmc.h:387
@ EVMC_UNDEFINED_INSTRUCTION
An undefined instruction has been encountered.
Definition: evmc.h:313
@ EVMC_SUCCESS
Execution finished with success.
Definition: evmc.h:286
@ EVMC_OUT_OF_MEMORY
The VM failed to allocate the amount of memory needed for execution.
Definition: evmc.h:390
@ EVMC_STACK_UNDERFLOW
Execution of an opcode has required more items on the EVM stack.
Definition: evmc.h:322
@ EVMC_BAD_JUMP_DESTINATION
Execution has violated the jump destination restrictions.
Definition: evmc.h:325
@ EVMC_INVALID_INSTRUCTION
The designated INVALID instruction has been hit during execution.
Definition: evmc.h:310
@ EVMC_STATIC_MODE_VIOLATION
Tried to execute an operation which is restricted in static mode.
Definition: evmc.h:338
@ EVMC_WASM_TRAP
A WebAssembly trap has been hit during execution.
Definition: evmc.h:368
@ EVMC_PRECOMPILE_FAILURE
A call to a precompiled or system contract has ended with a failure.
Definition: evmc.h:345
@ EVMC_INTERNAL_ERROR
EVM implementation generic internal error.
Definition: evmc.h:374
@ EVMC_OUT_OF_GAS
The execution has run out of gas.
Definition: evmc.h:300
@ EVMC_CONTRACT_VALIDATION_FAILURE
Contract validation has failed (e.g.
Definition: evmc.h:351
@ EVMC_CALL_DEPTH_EXCEEDED
Call depth has exceeded the limit (if any)
Definition: evmc.h:335
@ EVMC_WASM_UNREACHABLE_INSTRUCTION
A WebAssembly unreachable instruction has been hit during execution.
Definition: evmc.h:362
@ EVMC_STACK_OVERFLOW
The execution has attempted to put more items on the EVM stack than the specified limit.
Definition: evmc.h:319
@ EVMC_FAILURE
Generic execution failure.
Definition: evmc.h:289
@ EVMC_REVERT
Execution terminated with REVERT opcode.
Definition: evmc.h:297
@ EVMC_ACCESS_COLD
The entry hasn't been accessed before – it's the first access.
Definition: evmc.h:788
@ EVMC_ACCESS_WARM
The entry is already in accessed_addresses or accessed_storage_keys.
Definition: evmc.h:793
@ EVMC_CREATE
Request CREATE.
Definition: evmc.h:81
@ EVMC_EOFCREATE
Request EOFCREATE.
Definition: evmc.h:83
@ 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:633
@ EVMC_STORAGE_MODIFIED_RESTORED
A storage item is modified by changing the current dirty nonzero to the original nonzero value other ...
Definition: evmc.h:640
@ EVMC_STORAGE_DELETED_RESTORED
A storage item is added by changing the current dirty zero to the original value.
Definition: evmc.h:626
@ EVMC_STORAGE_ADDED
A new storage item is added by changing the current clean zero to a nonzero value.
Definition: evmc.h:591
@ 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:619
@ EVMC_STORAGE_ASSIGNED
The new/same value is assigned to the storage item without affecting the cost structure.
Definition: evmc.h:584
@ EVMC_STORAGE_DELETED
A storage item is deleted by changing the current clean nonzero to the zero value.
Definition: evmc.h:598
@ 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:612
@ EVMC_STORAGE_MODIFIED
A storage item is modified by changing the current clean nonzero to other nonzero value.
Definition: evmc.h:605
@ EVMC_HOMESTEAD
The Homestead revision.
Definition: evmc.h:954
@ EVMC_LATEST_STABLE_REVISION
The latest known EVM revision with finalized specification.
Definition: evmc.h:1051
@ EVMC_PRAGUE
The Prague revision.
Definition: evmc.h:1041
@ EVMC_ISTANBUL
The Istanbul revision.
Definition: evmc.h:998
@ EVMC_FRONTIER
The Frontier revision.
Definition: evmc.h:947
@ EVMC_PETERSBURG
The Petersburg revision.
Definition: evmc.h:991
@ EVMC_CONSTANTINOPLE
The Constantinople revision.
Definition: evmc.h:982
@ EVMC_TANGERINE_WHISTLE
The Tangerine Whistle revision.
Definition: evmc.h:961
@ EVMC_MAX_REVISION
The maximum EVM revision supported.
Definition: evmc.h:1044
@ EVMC_SPURIOUS_DRAGON
The Spurious Dragon revision.
Definition: evmc.h:968
@ EVMC_BYZANTIUM
The Byzantium revision.
Definition: evmc.h:975
@ EVMC_CANCUN
The Cancun revision.
Definition: evmc.h:1034
@ EVMC_SHANGHAI
The Shanghai revision.
Definition: evmc.h:1026
@ EVMC_LONDON
The London revision.
Definition: evmc.h:1012
@ EVMC_PARIS
The Paris revision (aka The Merge).
Definition: evmc.h:1019
@ EVMC_BERLIN
The Berlin revision.
Definition: evmc.h:1005
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:845
evmc_get_code_hash_fn get_code_hash
Get code hash callback function.
Definition: evmc.h:862
evmc_call_fn call
Call callback function.
Definition: evmc.h:871
evmc_selfdestruct_fn selfdestruct
Selfdestruct callback function.
Definition: evmc.h:868
evmc_get_storage_fn get_storage
Get storage callback function.
Definition: evmc.h:850
evmc_copy_code_fn copy_code
Copy code callback function.
Definition: evmc.h:865
evmc_get_code_size_fn get_code_size
Get code size callback function.
Definition: evmc.h:859
evmc_get_transient_storage_fn get_transient_storage
Get transient storage callback function.
Definition: evmc.h:889
evmc_set_transient_storage_fn set_transient_storage
Set transient storage callback function.
Definition: evmc.h:892
evmc_get_block_hash_fn get_block_hash
Get block hash callback function.
Definition: evmc.h:877
evmc_emit_log_fn emit_log
Emit log callback function.
Definition: evmc.h:880
evmc_account_exists_fn account_exists
Check account existence callback function.
Definition: evmc.h:847
evmc_access_account_fn access_account
Access account callback function.
Definition: evmc.h:883
evmc_get_balance_fn get_balance
Get balance callback function.
Definition: evmc.h:856
evmc_set_storage_fn set_storage
Set storage callback function.
Definition: evmc.h:853
evmc_get_tx_context_fn get_tx_context
Get transaction context callback function.
Definition: evmc.h:874
evmc_access_storage_fn access_storage
Access storage callback function.
Definition: evmc.h:886
The message describing an EVM call, including a zero-depth calls from a transaction origin.
Definition: evmc.h:98
const uint8_t * input_data
The message input data.
Definition: evmc.h:152
evmc_bytes32 create2_salt
The optional value used in new contract address construction.
Definition: evmc.h:176
const uint8_t * code
The code to be executed.
Definition: evmc.h:196
size_t input_size
The size of the message input data.
Definition: evmc.h:159
evmc_address recipient
The recipient of the message.
Definition: evmc.h:133
enum evmc_call_kind kind
The kind of the call.
Definition: evmc.h:100
int32_t depth
The present depth of the message call stack.
Definition: evmc.h:113
uint32_t flags
Additional flags modifying the call execution behavior.
Definition: evmc.h:106
evmc_address code_address
The address of the code to be executed.
Definition: evmc.h:191
size_t code_size
The length of the code to be executed.
Definition: evmc.h:201
evmc_uint256be value
The amount of Ether transferred with the message.
Definition: evmc.h:167
evmc_address sender
The sender of the message.
Definition: evmc.h:143
int64_t gas
The amount of gas available to the message execution.
Definition: evmc.h:120
The EVM code execution result.
Definition: evmc.h:416
const uint8_t * output_data
The reference to output data.
Definition: evmc.h:448
enum evmc_status_code status_code
The execution status code.
Definition: evmc.h:418
evmc_release_result_fn release
The method releasing all resources associated with the result object.
Definition: evmc.h:476
int64_t gas_refund
The refunded gas accumulated from this execution and its sub-calls.
Definition: evmc.h:434
size_t output_size
The size of the output data.
Definition: evmc.h:455
uint8_t padding[4]
Reserved data that MAY be used by a evmc_result object creator.
Definition: evmc.h:499
evmc_address create_address
The address of the possibly created contract.
Definition: evmc.h:486
int64_t gas_left
The amount of gas left after the execution.
Definition: evmc.h:426
The transaction and block data for execution.
Definition: evmc.h:214
size_t initcodes_count
The number of transaction initcodes (TXCREATE).
Definition: evmc.h:228
evmc_address tx_origin
The transaction origin account.
Definition: evmc.h:216
evmc_uint256be block_base_fee
The block base fee per gas (EIP-1559, EIP-3198).
Definition: evmc.h:223
int64_t block_number
The block number.
Definition: evmc.h:218
int64_t block_timestamp
The block timestamp.
Definition: evmc.h:219
const evmc_bytes32 * blob_hashes
The array of blob hashes (EIP-4844).
Definition: evmc.h:225
evmc_uint256be tx_gas_price
The transaction gas price.
Definition: evmc.h:215
const evmc_tx_initcode * initcodes
The array of transaction initcodes (TXCREATE).
Definition: evmc.h:227
size_t blob_hashes_count
The number of blob hashes (EIP-4844).
Definition: evmc.h:226
evmc_uint256be chain_id
The blockchain's ChainID.
Definition: evmc.h:222
evmc_uint256be block_prev_randao
The block previous RANDAO (EIP-4399).
Definition: evmc.h:221
evmc_address block_coinbase
The miner of the block.
Definition: evmc.h:217
evmc_uint256be blob_base_fee
The blob base fee (EIP-7516).
Definition: evmc.h:224
int64_t block_gas_limit
The block gas limit.
Definition: evmc.h:220
The hashed initcode used for TXCREATE instruction.
Definition: evmc.h:206
size_t code_size
The length of the code.
Definition: evmc.h:209
evmc_bytes32 hash
The initcode hash.
Definition: evmc.h:207
const uint8_t * code
The code.
Definition: evmc.h:208
The VM instance.
Definition: evmc.h:1134
evmc_set_option_fn set_option
Optional pointer to function modifying VM's options.
Definition: evmc.h:1190
evmc_get_capabilities_fn get_capabilities
A method returning capabilities supported by the VM instance.
Definition: evmc.h:1183
evmc_execute_fn execute
Pointer to function executing a code by the VM instance.
Definition: evmc.h:1171
const char * name
The name of the EVMC VM implementation.
Definition: evmc.h:1149
evmc_destroy_fn destroy
Pointer to function destroying the VM instance.
Definition: evmc.h:1164
const int abi_version
EVMC ABI version implemented by the VM instance.
Definition: evmc.h:1141
const char * version
The version of the EVMC VM implementation, e.g.
Definition: evmc.h:1157