2
2
* EVMC: Ethereum Client-VM Connector API
3
3
*
4
4
* @copyright
5
- * Copyright 2016-2019 The EVMC Authors.
5
+ * Copyright 2016 The EVMC Authors.
6
6
* Licensed under the Apache License, Version 2.0.
7
7
*
8
8
* @defgroup EVMC EVMC
44
44
*
45
45
* @see @ref versioning
46
46
*/
47
- EVMC_ABI_VERSION = 9
47
+ EVMC_ABI_VERSION = 10
48
48
};
49
49
50
50
@@ -89,8 +89,9 @@ enum evmc_flags
89
89
};
90
90
91
91
/**
92
- * The message describing an EVM call,
93
- * including a zero-depth calls from a transaction origin.
92
+ * The message describing an EVM call, including a zero-depth calls from a transaction origin.
93
+ *
94
+ * Most of the fields are modelled by the section 8. Message Call of the Ethereum Yellow Paper.
94
95
*/
95
96
struct evmc_message
96
97
{
@@ -103,21 +104,48 @@ struct evmc_message
103
104
*/
104
105
uint32_t flags ;
105
106
106
- /** The call depth. */
107
+ /**
108
+ * The present depth of the message call stack.
109
+ *
110
+ * Defined as `e` in the Yellow Paper.
111
+ */
107
112
int32_t depth ;
108
113
109
- /** The amount of gas for message execution. */
114
+ /**
115
+ * The amount of gas available to the message execution.
116
+ *
117
+ * Defined as `g` in the Yellow Paper.
118
+ */
110
119
int64_t gas ;
111
120
112
- /** The destination of the message. */
113
- evmc_address destination ;
121
+ /**
122
+ * The recipient of the message.
123
+ *
124
+ * This is the address of the account which storage/balance/nonce is going to be modified
125
+ * by the message execution. In case of ::EVMC_CALL, this is also the account where the
126
+ * message value evmc_message::value is going to be transferred.
127
+ * For ::EVMC_CALLCODE or ::EVMC_DELEGATECALL, this may be different from
128
+ * the evmc_message::code_address.
129
+ *
130
+ * Defined as `r` in the Yellow Paper.
131
+ */
132
+ evmc_address recipient ;
114
133
115
- /** The sender of the message. */
134
+ /**
135
+ * The sender of the message.
136
+ *
137
+ * The address of the sender of a message call defined as `s` in the Yellow Paper.
138
+ * This must be the message recipient of the message at the previous (lower) depth,
139
+ * except for the ::EVMC_DELEGATECALL where recipient is the 2 levels above the present depth.
140
+ * At the depth 0 this must be the transaction origin.
141
+ */
116
142
evmc_address sender ;
117
143
118
144
/**
119
145
* The message input data.
120
146
*
147
+ * The arbitrary length byte array of the input data of the call,
148
+ * defined as `d` in the Yellow Paper.
121
149
* This MAY be NULL.
122
150
*/
123
151
const uint8_t * input_data ;
@@ -131,30 +159,49 @@ struct evmc_message
131
159
132
160
/**
133
161
* The amount of Ether transferred with the message.
162
+ *
163
+ * This is transferred value for ::EVMC_CALL or apparent value for ::EVMC_DELEGATECALL.
164
+ * Defined as `v` or `v~` in the Yellow Paper.
134
165
*/
135
166
evmc_uint256be value ;
136
167
137
168
/**
138
169
* The optional value used in new contract address construction.
139
170
*
140
- * Ignored unless kind is EVMC_CREATE2.
171
+ * Needed only for a Host to calculate created address when kind is ::EVMC_CREATE2.
172
+ * Ignored in evmc_execute_fn().
141
173
*/
142
174
evmc_bytes32 create2_salt ;
175
+
176
+ /**
177
+ * The address of the code to be executed.
178
+ *
179
+ * For ::EVMC_CALLCODE or ::EVMC_DELEGATECALL this may be different from
180
+ * the evmc_message::recipient.
181
+ * Not required when invoking evmc_execute_fn(), only when invoking evmc_call_fn().
182
+ * Ignored if kind is ::EVMC_CREATE or ::EVMC_CREATE2.
183
+ *
184
+ * In case of ::EVMC_CAPABILITY_PRECOMPILES implementation, this fields should be inspected
185
+ * to identify the requested precompile.
186
+ *
187
+ * Defined as `c` in the Yellow Paper.
188
+ */
189
+ evmc_address code_address ;
143
190
};
144
191
145
192
146
193
/** The transaction and block data for execution. */
147
194
struct evmc_tx_context
148
195
{
149
- evmc_uint256be tx_gas_price ; /**< The transaction gas price. */
150
- evmc_address tx_origin ; /**< The transaction origin account. */
151
- evmc_address block_coinbase ; /**< The miner of the block. */
152
- int64_t block_number ; /**< The block number. */
153
- int64_t block_timestamp ; /**< The block timestamp. */
154
- int64_t block_gas_limit ; /**< The block gas limit. */
155
- evmc_uint256be block_difficulty ; /**< The block difficulty . */
156
- evmc_uint256be chain_id ; /**< The blockchain's ChainID. */
157
- evmc_uint256be block_base_fee ; /**< The block base fee per gas (EIP-1559, EIP-3198). */
196
+ evmc_uint256be tx_gas_price ; /**< The transaction gas price. */
197
+ evmc_address tx_origin ; /**< The transaction origin account. */
198
+ evmc_address block_coinbase ; /**< The miner of the block. */
199
+ int64_t block_number ; /**< The block number. */
200
+ int64_t block_timestamp ; /**< The block timestamp. */
201
+ int64_t block_gas_limit ; /**< The block gas limit. */
202
+ evmc_uint256be block_prev_randao ; /**< The block previous RANDAO (EIP-4399) . */
203
+ evmc_uint256be chain_id ; /**< The blockchain's ChainID. */
204
+ evmc_uint256be block_base_fee ; /**< The block base fee per gas (EIP-1559, EIP-3198). */
158
205
};
159
206
160
207
/**
@@ -354,6 +401,14 @@ struct evmc_result
354
401
*/
355
402
int64_t gas_left ;
356
403
404
+ /**
405
+ * The refunded gas accumulated from this execution and its sub-calls.
406
+ *
407
+ * The transaction gas refund limit is not applied.
408
+ * If evmc_result::status_code is other than ::EVMC_SUCCESS the value MUST be 0.
409
+ */
410
+ int64_t gas_refund ;
411
+
357
412
/**
358
413
* The reference to output data.
359
414
*
@@ -396,12 +451,11 @@ struct evmc_result
396
451
evmc_release_result_fn release ;
397
452
398
453
/**
399
- * The address of the contract created by create instructions .
454
+ * The address of the possibly created contract .
400
455
*
401
- * This field has valid value only if:
402
- * - it is a result of the Host method evmc_host_interface::call
403
- * - and the result describes successful contract creation
404
- * (evmc_result::status_code is ::EVMC_SUCCESS).
456
+ * The create address may be provided even though the contract creation has failed
457
+ * (evmc_result::status_code is not ::EVMC_SUCCESS). This is useful in situations
458
+ * when the address is observable, e.g. access to it remains warm.
405
459
* In all other cases the address MUST be null bytes.
406
460
*/
407
461
evmc_address create_address ;
@@ -452,40 +506,97 @@ typedef evmc_bytes32 (*evmc_get_storage_fn)(struct evmc_host_context* context,
452
506
/**
453
507
* The effect of an attempt to modify a contract storage item.
454
508
*
509
+ * See @ref storagestatus for additional information about design of this enum
510
+ * and analysis of the specification.
511
+ *
455
512
* For the purpose of explaining the meaning of each element, the following
456
513
* notation is used:
457
514
* - 0 is zero value,
458
515
* - X != 0 (X is any value other than 0),
459
- * - Y != X, Y != 0 (Y is any value other than X and 0),
460
- * - Z != Y (Z is any value other than Y),
461
- * - the "->" means the change from one value to another.
516
+ * - Y != 0, Y != X, (Y is any value other than X and 0),
517
+ * - Z != 0, Z != X, Z != X (Z is any value other than Y and X and 0),
518
+ * - the "o -> c -> v" triple describes the change status in the context of:
519
+ * - o: original value (cold value before a transaction started),
520
+ * - c: current storage value,
521
+ * - v: new storage value to be set.
522
+ *
523
+ * The order of elements follows EIPs introducing net storage gas costs:
524
+ * - EIP-2200: https://eips.ethereum.org/EIPS/eip-2200,
525
+ * - EIP-1283: https://eips.ethereum.org/EIPS/eip-1283.
462
526
*/
463
527
enum evmc_storage_status
464
528
{
465
529
/**
466
- * The value of a storage item has been left unchanged: 0 -> 0 and X -> X.
530
+ * The new/same value is assigned to the storage item without affecting the cost structure.
531
+ *
532
+ * The storage value item is either:
533
+ * - left unchanged (c == v) or
534
+ * - the dirty value (o != c) is modified again (c != v).
535
+ * This is the group of cases related to minimal gas cost of only accessing warm storage.
536
+ * 0|X -> 0 -> 0 (current value unchanged)
537
+ * 0|X|Y -> Y -> Y (current value unchanged)
538
+ * 0|X -> Y -> Z (modified previously added/modified value)
539
+ *
540
+ * This is "catch all remaining" status. I.e. if all other statuses are correctly matched
541
+ * this status should be assigned to all remaining cases.
542
+ */
543
+ EVMC_STORAGE_ASSIGNED = 0 ,
544
+
545
+ /**
546
+ * A new storage item is added by changing
547
+ * the current clean zero to a nonzero value.
548
+ * 0 -> 0 -> Z
549
+ */
550
+ EVMC_STORAGE_ADDED = 1 ,
551
+
552
+ /**
553
+ * A storage item is deleted by changing
554
+ * the current clean nonzero to the zero value.
555
+ * X -> X -> 0
556
+ */
557
+ EVMC_STORAGE_DELETED = 2 ,
558
+
559
+ /**
560
+ * A storage item is modified by changing
561
+ * the current clean nonzero to other nonzero value.
562
+ * X -> X -> Z
563
+ */
564
+ EVMC_STORAGE_MODIFIED = 3 ,
565
+
566
+ /**
567
+ * A storage item is added by changing
568
+ * the current dirty zero to a nonzero value other than the original value.
569
+ * X -> 0 -> Z
467
570
*/
468
- EVMC_STORAGE_UNCHANGED = 0 ,
571
+ EVMC_STORAGE_DELETED_ADDED = 4 ,
469
572
470
573
/**
471
- * The value of a storage item has been modified: X -> Y.
574
+ * A storage item is deleted by changing
575
+ * the current dirty nonzero to the zero value and the original value is not zero.
576
+ * X -> Y -> 0
472
577
*/
473
- EVMC_STORAGE_MODIFIED = 1 ,
578
+ EVMC_STORAGE_MODIFIED_DELETED = 5 ,
474
579
475
580
/**
476
- * A storage item has been modified after being modified before: X -> Y -> Z.
581
+ * A storage item is added by changing
582
+ * the current dirty zero to the original value.
583
+ * X -> 0 -> X
477
584
*/
478
- EVMC_STORAGE_MODIFIED_AGAIN = 2 ,
585
+ EVMC_STORAGE_DELETED_RESTORED = 6 ,
479
586
480
587
/**
481
- * A new storage item has been added: 0 -> X.
588
+ * A storage item is deleted by changing
589
+ * the current dirty nonzero to the original zero value.
590
+ * 0 -> Y -> 0
482
591
*/
483
- EVMC_STORAGE_ADDED = 3 ,
592
+ EVMC_STORAGE_ADDED_DELETED = 7 ,
484
593
485
594
/**
486
- * A storage item has been deleted: X -> 0.
595
+ * A storage item is modified by changing
596
+ * the current dirty nonzero to the original nonzero value other than the current value.
597
+ * X -> Y -> X
487
598
*/
488
- EVMC_STORAGE_DELETED = 4
599
+ EVMC_STORAGE_MODIFIED_RESTORED = 8
489
600
};
490
601
491
602
@@ -495,7 +606,7 @@ enum evmc_storage_status
495
606
* This callback function is used by a VM to update the given account storage entry.
496
607
* The VM MUST make sure that the account exists. This requirement is only a formality because
497
608
* VM implementations only modify storage of the account of the current execution context
498
- * (i.e. referenced by evmc_message::destination ).
609
+ * (i.e. referenced by evmc_message::recipient ).
499
610
*
500
611
* @param context The pointer to the Host execution context.
501
612
* @param address The address of the account.
@@ -579,8 +690,10 @@ typedef size_t (*evmc_copy_code_fn)(struct evmc_host_context* context,
579
690
* @param context The pointer to the Host execution context. See ::evmc_host_context.
580
691
* @param address The address of the contract to be selfdestructed.
581
692
* @param beneficiary The address where the remaining ETH is going to be transferred.
693
+ * @return The information if the given address has not been registered as
694
+ * selfdestructed yet. True if registered for the first time, false otherwise.
582
695
*/
583
- typedef void (* evmc_selfdestruct_fn )(struct evmc_host_context * context ,
696
+ typedef bool (* evmc_selfdestruct_fn )(struct evmc_host_context * context ,
584
697
const evmc_address * address ,
585
698
const evmc_address * beneficiary );
586
699
@@ -821,26 +934,40 @@ enum evmc_revision
821
934
/**
822
935
* The Berlin revision.
823
936
*
824
- * https://github.com/ethereum/eth1.0 -specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md
937
+ * https://github.com/ethereum/execution -specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md
825
938
*/
826
939
EVMC_BERLIN = 8 ,
827
940
828
941
/**
829
942
* The London revision.
830
943
*
831
- * https://github.com/ethereum/eth1.0 -specs/blob/master/network-upgrades/mainnet-upgrades/london.md
944
+ * https://github.com/ethereum/execution -specs/blob/master/network-upgrades/mainnet-upgrades/london.md
832
945
*/
833
946
EVMC_LONDON = 9 ,
834
947
948
+ /**
949
+ * The Paris revision (aka The Merge).
950
+ *
951
+ * https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md
952
+ */
953
+ EVMC_PARIS = 10 ,
954
+
835
955
/**
836
956
* The Shanghai revision.
837
957
*
838
- * https://github.com/ethereum/eth1.0-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md
958
+ * https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md
959
+ */
960
+ EVMC_SHANGHAI = 11 ,
961
+
962
+ /**
963
+ * The Cancun revision.
964
+ *
965
+ * The future next revision after Shanghai.
839
966
*/
840
- EVMC_SHANGHAI = 10 ,
967
+ EVMC_CANCUN = 12 ,
841
968
842
969
/** The maximum EVM revision supported. */
843
- EVMC_MAX_REVISION = EVMC_SHANGHAI ,
970
+ EVMC_MAX_REVISION = EVMC_CANCUN ,
844
971
845
972
/**
846
973
* The latest known EVM revision with finalized specification.
@@ -894,7 +1021,7 @@ enum evmc_capabilities
894
1021
895
1022
/**
896
1023
* The VM is capable of executing the precompiled contracts
897
- * defined for the range of destination addresses.
1024
+ * defined for the range of code addresses.
898
1025
*
899
1026
* The EIP-1352 (https://eips.ethereum.org/EIPS/eip-1352) specifies
900
1027
* the range 0x000...0000 - 0x000...ffff of addresses
0 commit comments