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{
91};
92
99{
102
107 uint32_t flags;
108
114 int32_t depth;
115
121 int64_t gas;
122
135
145
153 const uint8_t* input_data;
154
161
169
178
193
197 const uint8_t* code;
198
202 size_t code_size;
203};
204
206typedef struct evmc_tx_initcode
207{
209 const uint8_t* code;
210 size_t code_size;
212
215{
219 int64_t block_number;
230};
231
237struct evmc_host_context;
238
248typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_host_context* context);
249
262typedef evmc_bytes32 (*evmc_get_block_hash_fn)(struct evmc_host_context* context, int64_t number);
263
285{
288
291
299
302
312
315
321
324
327
334
337
340
347
353
359
364
370
373
376
389
393
394/* Forward declaration. */
395struct evmc_result;
396
413typedef void (*evmc_release_result_fn)(const struct evmc_result* result);
414
417{
420
427 int64_t gas_left;
428
435 int64_t gas_refund;
436
449 const uint8_t* output_data;
450
457
478
488
500 uint8_t padding[4];
501};
502
503
513typedef bool (*evmc_account_exists_fn)(struct evmc_host_context* context,
514 const evmc_address* address);
515
528 const evmc_address* address,
529 const evmc_bytes32* key);
530
544 const evmc_address* address,
545 const evmc_bytes32* key);
546
547
570{
586
593
600
607
614
621
628
635
643
644
659typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_host_context* context,
660 const evmc_address* address,
661 const evmc_bytes32* key,
662 const evmc_bytes32* value);
663
678typedef void (*evmc_set_transient_storage_fn)(struct evmc_host_context* context,
679 const evmc_address* address,
680 const evmc_bytes32* key,
681 const evmc_bytes32* value);
682
693 const evmc_address* address);
694
705typedef size_t (*evmc_get_code_size_fn)(struct evmc_host_context* context,
706 const evmc_address* address);
707
720 const evmc_address* address);
721
739typedef size_t (*evmc_copy_code_fn)(struct evmc_host_context* context,
740 const evmc_address* address,
741 size_t code_offset,
742 uint8_t* buffer_data,
743 size_t buffer_size);
744
757typedef bool (*evmc_selfdestruct_fn)(struct evmc_host_context* context,
758 const evmc_address* address,
759 const evmc_address* beneficiary);
760
774typedef void (*evmc_emit_log_fn)(struct evmc_host_context* context,
775 const evmc_address* address,
776 const uint8_t* data,
777 size_t data_size,
778 const evmc_bytes32 topics[],
779 size_t topics_count);
780
785{
790
796
808typedef enum evmc_access_status (*evmc_access_account_fn)(struct evmc_host_context* context,
809 const evmc_address* address);
810
823typedef enum evmc_access_status (*evmc_access_storage_fn)(struct evmc_host_context* context,
824 const evmc_address* address,
825 const evmc_bytes32* key);
826
834typedef struct evmc_result (*evmc_call_fn)(struct evmc_host_context* context,
835 const struct evmc_message* msg);
836
846{
849
852
855
858
861
864
867
870
873
876
879
882
885
888
891
894};
895
896
897/* Forward declaration. */
898struct evmc_vm;
899
905typedef void (*evmc_destroy_fn)(struct evmc_vm* vm);
906
911{
912 EVMC_SET_OPTION_SUCCESS = 0,
913 EVMC_SET_OPTION_INVALID_NAME = 1,
914 EVMC_SET_OPTION_INVALID_VALUE = 2
915};
916
930typedef enum evmc_set_option_result (*evmc_set_option_fn)(struct evmc_vm* vm,
931 char const* name,
932 char const* value);
933
934
942{
949
956
963
970
977
984
993
1000
1007
1014
1021
1028
1035
1042
1049
1055
1058
1066
1067
1086typedef struct evmc_result (*evmc_execute_fn)(struct evmc_vm* vm,
1087 const struct evmc_host_interface* host,
1088 struct evmc_host_context* context,
1089 enum evmc_revision rev,
1090 const struct evmc_message* msg,
1091 uint8_t const* code,
1092 size_t code_size);
1093
1098{
1103
1108
1119 EVMC_CAPABILITY_PRECOMPILES = (1u << 2)
1121
1128
1139
1140
1147{
1154 const int abi_version;
1155
1162 const char* name;
1163
1170 const char* version;
1171
1178
1185
1197
1204};
1205
1206/* END Python CFFI declarations */
1207
1208#ifdef EVMC_DOCUMENTATION
1224struct evmc_vm* evmc_create_example_vm(void);
1225#endif
1226
1227#ifdef __cplusplus
1228}
1229#endif
1230
1231#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:757
void(* evmc_destroy_fn)(struct evmc_vm *vm)
Destroys the VM instance.
Definition: evmc.h:905
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:911
void(* evmc_release_result_fn)(const struct evmc_result *result)
Releases resources assigned to an execution result.
Definition: evmc.h:413
size_t(* evmc_get_code_size_fn)(struct evmc_host_context *context, const evmc_address *address)
Get code size callback function.
Definition: evmc.h:705
evmc_capabilities
Possible capabilities of a VM.
Definition: evmc.h:1098
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:285
bool(* evmc_account_exists_fn)(struct evmc_host_context *context, const evmc_address *address)
Check account existence callback function.
Definition: evmc.h:513
evmc_uint256be(* evmc_get_balance_fn)(struct evmc_host_context *context, const evmc_address *address)
Get balance callback function.
Definition: evmc.h:692
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:834
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:930
uint32_t evmc_capabilities_flagset
Alias for unsigned integer representing a set of bit flags of EVMC capabilities.
Definition: evmc.h:1127
evmc_bytes32(* evmc_get_code_hash_fn)(struct evmc_host_context *context, const evmc_address *address)
Get code hash callback function.
Definition: evmc.h:719
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:527
struct evmc_tx_context(* evmc_get_tx_context_fn)(struct evmc_host_context *context)
Get transaction context callback function.
Definition: evmc.h:248
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:739
enum evmc_access_status(* evmc_access_account_fn)(struct evmc_host_context *context, const evmc_address *address)
Access account callback function.
Definition: evmc.h:808
evmc_bytes32(* evmc_get_block_hash_fn)(struct evmc_host_context *context, int64_t number)
Get block hash callback function.
Definition: evmc.h:262
evmc_capabilities_flagset(* evmc_get_capabilities_fn)(struct evmc_vm *vm)
Return the supported capabilities of the VM instance.
Definition: evmc.h:1138
evmc_access_status
Access status per EIP-2929: Gas cost increases for state access opcodes.
Definition: evmc.h:785
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:774
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:823
evmc_storage_status
The effect of an attempt to modify a contract storage item.
Definition: evmc.h:570
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:678
evmc_revision
EVM revision.
Definition: evmc.h:942
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:1086
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:659
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:543
@ 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_DELEGATED
Delegated call mode (EIP-7702).
Definition: evmc.h:90
@ EVMC_CAPABILITY_EVM1
The VM is capable of executing EVM1 bytecode.
Definition: evmc.h:1102
@ EVMC_CAPABILITY_PRECOMPILES
The VM is capable of executing the precompiled contracts defined for the range of code addresses.
Definition: evmc.h:1119
@ EVMC_CAPABILITY_EWASM
The VM is capable of executing ewasm bytecode.
Definition: evmc.h:1107
@ EVMC_INSUFFICIENT_BALANCE
The caller does not have enough funds for value transfer.
Definition: evmc.h:372
@ 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:358
@ EVMC_INVALID_MEMORY_ACCESS
Tried to read outside memory bounds.
Definition: evmc.h:333
@ EVMC_REJECTED
The execution of the given code and/or message has been rejected by the EVM implementation.
Definition: evmc.h:388
@ EVMC_UNDEFINED_INSTRUCTION
An undefined instruction has been encountered.
Definition: evmc.h:314
@ EVMC_SUCCESS
Execution finished with success.
Definition: evmc.h:287
@ EVMC_OUT_OF_MEMORY
The VM failed to allocate the amount of memory needed for execution.
Definition: evmc.h:391
@ EVMC_STACK_UNDERFLOW
Execution of an opcode has required more items on the EVM stack.
Definition: evmc.h:323
@ EVMC_BAD_JUMP_DESTINATION
Execution has violated the jump destination restrictions.
Definition: evmc.h:326
@ EVMC_INVALID_INSTRUCTION
The designated INVALID instruction has been hit during execution.
Definition: evmc.h:311
@ EVMC_STATIC_MODE_VIOLATION
Tried to execute an operation which is restricted in static mode.
Definition: evmc.h:339
@ EVMC_WASM_TRAP
A WebAssembly trap has been hit during execution.
Definition: evmc.h:369
@ EVMC_PRECOMPILE_FAILURE
A call to a precompiled or system contract has ended with a failure.
Definition: evmc.h:346
@ EVMC_INTERNAL_ERROR
EVM implementation generic internal error.
Definition: evmc.h:375
@ EVMC_OUT_OF_GAS
The execution has run out of gas.
Definition: evmc.h:301
@ EVMC_CONTRACT_VALIDATION_FAILURE
Contract validation has failed (e.g.
Definition: evmc.h:352
@ EVMC_CALL_DEPTH_EXCEEDED
Call depth has exceeded the limit (if any)
Definition: evmc.h:336
@ EVMC_WASM_UNREACHABLE_INSTRUCTION
A WebAssembly unreachable instruction has been hit during execution.
Definition: evmc.h:363
@ EVMC_STACK_OVERFLOW
The execution has attempted to put more items on the EVM stack than the specified limit.
Definition: evmc.h:320
@ EVMC_FAILURE
Generic execution failure.
Definition: evmc.h:290
@ EVMC_REVERT
Execution terminated with REVERT opcode.
Definition: evmc.h:298
@ EVMC_ACCESS_COLD
The entry hasn't been accessed before – it's the first access.
Definition: evmc.h:789
@ EVMC_ACCESS_WARM
The entry is already in accessed_addresses or accessed_storage_keys.
Definition: evmc.h:794
@ 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:634
@ EVMC_STORAGE_MODIFIED_RESTORED
A storage item is modified by changing the current dirty nonzero to the original nonzero value other ...
Definition: evmc.h:641
@ EVMC_STORAGE_DELETED_RESTORED
A storage item is added by changing the current dirty zero to the original value.
Definition: evmc.h:627
@ EVMC_STORAGE_ADDED
A new storage item is added by changing the current clean zero to a nonzero value.
Definition: evmc.h:592
@ 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:620
@ EVMC_STORAGE_ASSIGNED
The new/same value is assigned to the storage item without affecting the cost structure.
Definition: evmc.h:585
@ EVMC_STORAGE_DELETED
A storage item is deleted by changing the current clean nonzero to the zero value.
Definition: evmc.h:599
@ 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:613
@ EVMC_STORAGE_MODIFIED
A storage item is modified by changing the current clean nonzero to other nonzero value.
Definition: evmc.h:606
@ EVMC_OSAKA
The Osaka / Fusaka revision.
Definition: evmc.h:1048
@ EVMC_HOMESTEAD
The Homestead revision.
Definition: evmc.h:955
@ EVMC_LATEST_STABLE_REVISION
The latest known EVM revision with finalized specification.
Definition: evmc.h:1064
@ EVMC_PRAGUE
The Prague / Pectra revision.
Definition: evmc.h:1041
@ EVMC_ISTANBUL
The Istanbul revision.
Definition: evmc.h:999
@ EVMC_FRONTIER
The Frontier revision.
Definition: evmc.h:948
@ EVMC_PETERSBURG
The Petersburg revision.
Definition: evmc.h:992
@ EVMC_EXPERIMENTAL
The unspecified EVM revision used for EVM implementations to expose experimental features.
Definition: evmc.h:1054
@ EVMC_CONSTANTINOPLE
The Constantinople revision.
Definition: evmc.h:983
@ EVMC_TANGERINE_WHISTLE
The Tangerine Whistle revision.
Definition: evmc.h:962
@ EVMC_MAX_REVISION
The maximum EVM revision supported.
Definition: evmc.h:1057
@ EVMC_SPURIOUS_DRAGON
The Spurious Dragon revision.
Definition: evmc.h:969
@ EVMC_BYZANTIUM
The Byzantium revision.
Definition: evmc.h:976
@ EVMC_CANCUN
The Cancun revision.
Definition: evmc.h:1034
@ EVMC_SHANGHAI
The Shanghai revision.
Definition: evmc.h:1027
@ EVMC_LONDON
The London revision.
Definition: evmc.h:1013
@ EVMC_PARIS
The Paris revision (aka The Merge).
Definition: evmc.h:1020
@ EVMC_BERLIN
The Berlin revision.
Definition: evmc.h:1006
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:846
evmc_get_code_hash_fn get_code_hash
Get code hash callback function.
Definition: evmc.h:863
evmc_call_fn call
Call callback function.
Definition: evmc.h:872
evmc_selfdestruct_fn selfdestruct
Selfdestruct callback function.
Definition: evmc.h:869
evmc_get_storage_fn get_storage
Get storage callback function.
Definition: evmc.h:851
evmc_copy_code_fn copy_code
Copy code callback function.
Definition: evmc.h:866
evmc_get_code_size_fn get_code_size
Get code size callback function.
Definition: evmc.h:860
evmc_get_transient_storage_fn get_transient_storage
Get transient storage callback function.
Definition: evmc.h:890
evmc_set_transient_storage_fn set_transient_storage
Set transient storage callback function.
Definition: evmc.h:893
evmc_get_block_hash_fn get_block_hash
Get block hash callback function.
Definition: evmc.h:878
evmc_emit_log_fn emit_log
Emit log callback function.
Definition: evmc.h:881
evmc_account_exists_fn account_exists
Check account existence callback function.
Definition: evmc.h:848
evmc_access_account_fn access_account
Access account callback function.
Definition: evmc.h:884
evmc_get_balance_fn get_balance
Get balance callback function.
Definition: evmc.h:857
evmc_set_storage_fn set_storage
Set storage callback function.
Definition: evmc.h:854
evmc_get_tx_context_fn get_tx_context
Get transaction context callback function.
Definition: evmc.h:875
evmc_access_storage_fn access_storage
Access storage callback function.
Definition: evmc.h:887
The message describing an EVM call, including a zero-depth calls from a transaction origin.
Definition: evmc.h:99
const uint8_t * input_data
The message input data.
Definition: evmc.h:153
evmc_bytes32 create2_salt
The optional value used in new contract address construction.
Definition: evmc.h:177
const uint8_t * code
The code to be executed.
Definition: evmc.h:197
size_t input_size
The size of the message input data.
Definition: evmc.h:160
evmc_address recipient
The recipient of the message.
Definition: evmc.h:134
enum evmc_call_kind kind
The kind of the call.
Definition: evmc.h:101
int32_t depth
The present depth of the message call stack.
Definition: evmc.h:114
uint32_t flags
Additional flags modifying the call execution behavior.
Definition: evmc.h:107
evmc_address code_address
The address of the code to be executed.
Definition: evmc.h:192
size_t code_size
The length of the code to be executed.
Definition: evmc.h:202
evmc_uint256be value
The amount of Ether transferred with the message.
Definition: evmc.h:168
evmc_address sender
The sender of the message.
Definition: evmc.h:144
int64_t gas
The amount of gas available to the message execution.
Definition: evmc.h:121
The EVM code execution result.
Definition: evmc.h:417
const uint8_t * output_data
The reference to output data.
Definition: evmc.h:449
enum evmc_status_code status_code
The execution status code.
Definition: evmc.h:419
evmc_release_result_fn release
The method releasing all resources associated with the result object.
Definition: evmc.h:477
int64_t gas_refund
The refunded gas accumulated from this execution and its sub-calls.
Definition: evmc.h:435
size_t output_size
The size of the output data.
Definition: evmc.h:456
uint8_t padding[4]
Reserved data that MAY be used by a evmc_result object creator.
Definition: evmc.h:500
evmc_address create_address
The address of the possibly created contract.
Definition: evmc.h:487
int64_t gas_left
The amount of gas left after the execution.
Definition: evmc.h:427
The transaction and block data for execution.
Definition: evmc.h:215
size_t initcodes_count
The number of transaction initcodes (TXCREATE).
Definition: evmc.h:229
evmc_address tx_origin
The transaction origin account.
Definition: evmc.h:217
evmc_uint256be block_base_fee
The block base fee per gas (EIP-1559, EIP-3198).
Definition: evmc.h:224
int64_t block_number
The block number.
Definition: evmc.h:219
int64_t block_timestamp
The block timestamp.
Definition: evmc.h:220
const evmc_bytes32 * blob_hashes
The array of blob hashes (EIP-4844).
Definition: evmc.h:226
evmc_uint256be tx_gas_price
The transaction gas price.
Definition: evmc.h:216
const evmc_tx_initcode * initcodes
The array of transaction initcodes (TXCREATE).
Definition: evmc.h:228
size_t blob_hashes_count
The number of blob hashes (EIP-4844).
Definition: evmc.h:227
evmc_uint256be chain_id
The blockchain's ChainID.
Definition: evmc.h:223
evmc_uint256be block_prev_randao
The block previous RANDAO (EIP-4399).
Definition: evmc.h:222
evmc_address block_coinbase
The miner of the block.
Definition: evmc.h:218
evmc_uint256be blob_base_fee
The blob base fee (EIP-7516).
Definition: evmc.h:225
int64_t block_gas_limit
The block gas limit.
Definition: evmc.h:221
The hashed initcode used for TXCREATE instruction.
Definition: evmc.h:207
size_t code_size
The length of the code.
Definition: evmc.h:210
evmc_bytes32 hash
The initcode hash.
Definition: evmc.h:208
const uint8_t * code
The code.
Definition: evmc.h:209
The VM instance.
Definition: evmc.h:1147
evmc_set_option_fn set_option
Optional pointer to function modifying VM's options.
Definition: evmc.h:1203
evmc_get_capabilities_fn get_capabilities
A method returning capabilities supported by the VM instance.
Definition: evmc.h:1196
evmc_execute_fn execute
Pointer to function executing a code by the VM instance.
Definition: evmc.h:1184
const char * name
The name of the EVMC VM implementation.
Definition: evmc.h:1162
evmc_destroy_fn destroy
Pointer to function destroying the VM instance.
Definition: evmc.h:1177
const int abi_version
EVMC ABI version implemented by the VM instance.
Definition: evmc.h:1154
const char * version
The version of the EVMC VM implementation, e.g.
Definition: evmc.h:1170