Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 8eeb892

Browse files
authored
Merge pull request #635 from torquem-ch/eip-4399
EIP-4399: Supplant DIFFICULTY opcode with PREVRANDAO
2 parents 1e48d38 + e78e20d commit 8eeb892

File tree

9 files changed

+287
-19
lines changed

9 files changed

+287
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ and this project adheres to [Semantic Versioning].
4343
[#620](https://github.com/ethereum/evmc/pull/620)
4444
[#621](https://github.com/ethereum/evmc/pull/621)
4545
[#632](https://github.com/ethereum/evmc/pull/632)
46+
- According to [EIP-4399](https://eips.ethereum.org/EIPS/eip-4399),
47+
`block_difficulty` field was renamed to `block_prev_randao`, and `DIFFICULTY` opcode to `PREVRANDAO`.
48+
[#635](https://github.com/ethereum/evmc/pull/635)
4649

4750
## [9.0.0] — 2021-06-30
4851

bindings/go/evmc/host.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type TxContext struct {
7474
Number int64
7575
Timestamp int64
7676
GasLimit int64
77-
Difficulty Hash
77+
PrevRandao Hash
7878
ChainID Hash
7979
BaseFee Hash
8080
}
@@ -173,7 +173,7 @@ func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context {
173173
C.int64_t(txContext.Number),
174174
C.int64_t(txContext.Timestamp),
175175
C.int64_t(txContext.GasLimit),
176-
evmcBytes32(txContext.Difficulty),
176+
evmcBytes32(txContext.PrevRandao),
177177
evmcBytes32(txContext.ChainID),
178178
evmcBytes32(txContext.BaseFee),
179179
}

bindings/rust/evmc-vm/src/container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ mod tests {
9090
block_number: 0,
9191
block_timestamp: 0,
9292
block_gas_limit: 0,
93-
block_difficulty: Uint256::default(),
93+
block_prev_randao: Uint256::default(),
9494
chain_id: Uint256::default(),
9595
block_base_fee: Uint256::default(),
9696
}

bindings/rust/evmc-vm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ mod tests {
774774
block_number: 42,
775775
block_timestamp: 235117,
776776
block_gas_limit: 105023,
777-
block_difficulty: Uint256 { bytes: [0xaa; 32] },
777+
block_prev_randao: Uint256 { bytes: [0xaa; 32] },
778778
chain_id: Uint256::default(),
779779
block_base_fee: Uint256::default(),
780780
}

include/evmc/evmc.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ struct evmc_message
193193
/** The transaction and block data for execution. */
194194
struct evmc_tx_context
195195
{
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_difficulty; /**< The block difficulty. */
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). */
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). */
205205
};
206206

207207
/**

include/evmc/instructions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ enum evmc_opcode
7575
OP_COINBASE = 0x41,
7676
OP_TIMESTAMP = 0x42,
7777
OP_NUMBER = 0x43,
78-
OP_DIFFICULTY = 0x44,
78+
OP_PREVRANDAO = 0x44,
7979
OP_GASLIMIT = 0x45,
8080
OP_CHAINID = 0x46,
8181
OP_SELFBALANCE = 0x47,

lib/instructions/instruction_metrics.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static struct evmc_instruction_metrics cancun_metrics[256] = {
100100
/* COINBASE = 0x41 */ {BASE, 0, 1},
101101
/* TIMESTAMP = 0x42 */ {BASE, 0, 1},
102102
/* NUMBER = 0x43 */ {BASE, 0, 1},
103-
/* DIFFICULTY = 0x44 */ {BASE, 0, 1},
103+
/* PREVRANDAO = 0x44 */ {BASE, 0, 1},
104104
/* GASLIMIT = 0x45 */ {BASE, 0, 1},
105105
/* CHAINID = 0x46 */ {BASE, 0, 1},
106106
/* SELFBALANCE = 0x47 */ {LOW, 0, 1},
@@ -359,7 +359,7 @@ static struct evmc_instruction_metrics shanghai_metrics[256] = {
359359
/* COINBASE = 0x41 */ {BASE, 0, 1},
360360
/* TIMESTAMP = 0x42 */ {BASE, 0, 1},
361361
/* NUMBER = 0x43 */ {BASE, 0, 1},
362-
/* DIFFICULTY = 0x44 */ {BASE, 0, 1},
362+
/* PREVRANDAO = 0x44 */ {BASE, 0, 1},
363363
/* GASLIMIT = 0x45 */ {BASE, 0, 1},
364364
/* CHAINID = 0x46 */ {BASE, 0, 1},
365365
/* SELFBALANCE = 0x47 */ {LOW, 0, 1},

lib/instructions/instruction_names.c

Lines changed: 262 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static const char* cancun_names[256] = {
7373
/* 0x41 */ "COINBASE",
7474
/* 0x42 */ "TIMESTAMP",
7575
/* 0x43 */ "NUMBER",
76-
/* 0x44 */ "DIFFICULTY",
76+
/* 0x44 */ "PREVRANDAO",
7777
/* 0x45 */ "GASLIMIT",
7878
/* 0x46 */ "CHAINID",
7979
/* 0x47 */ "SELFBALANCE",
@@ -332,7 +332,7 @@ static const char* shanghai_names[256] = {
332332
/* 0x41 */ "COINBASE",
333333
/* 0x42 */ "TIMESTAMP",
334334
/* 0x43 */ "NUMBER",
335-
/* 0x44 */ "DIFFICULTY",
335+
/* 0x44 */ "PREVRANDAO",
336336
/* 0x45 */ "GASLIMIT",
337337
/* 0x46 */ "CHAINID",
338338
/* 0x47 */ "SELFBALANCE",
@@ -522,6 +522,265 @@ static const char* shanghai_names[256] = {
522522
/* 0xff */ "SELFDESTRUCT",
523523
};
524524

525+
static const char* paris_names[256] = {
526+
/* 0x00 */ "STOP",
527+
/* 0x01 */ "ADD",
528+
/* 0x02 */ "MUL",
529+
/* 0x03 */ "SUB",
530+
/* 0x04 */ "DIV",
531+
/* 0x05 */ "SDIV",
532+
/* 0x06 */ "MOD",
533+
/* 0x07 */ "SMOD",
534+
/* 0x08 */ "ADDMOD",
535+
/* 0x09 */ "MULMOD",
536+
/* 0x0a */ "EXP",
537+
/* 0x0b */ "SIGNEXTEND",
538+
/* 0x0c */ NULL,
539+
/* 0x0d */ NULL,
540+
/* 0x0e */ NULL,
541+
/* 0x0f */ NULL,
542+
/* 0x10 */ "LT",
543+
/* 0x11 */ "GT",
544+
/* 0x12 */ "SLT",
545+
/* 0x13 */ "SGT",
546+
/* 0x14 */ "EQ",
547+
/* 0x15 */ "ISZERO",
548+
/* 0x16 */ "AND",
549+
/* 0x17 */ "OR",
550+
/* 0x18 */ "XOR",
551+
/* 0x19 */ "NOT",
552+
/* 0x1a */ "BYTE",
553+
/* 0x1b */ "SHL",
554+
/* 0x1c */ "SHR",
555+
/* 0x1d */ "SAR",
556+
/* 0x1e */ NULL,
557+
/* 0x1f */ NULL,
558+
/* 0x20 */ "KECCAK256",
559+
/* 0x21 */ NULL,
560+
/* 0x22 */ NULL,
561+
/* 0x23 */ NULL,
562+
/* 0x24 */ NULL,
563+
/* 0x25 */ NULL,
564+
/* 0x26 */ NULL,
565+
/* 0x27 */ NULL,
566+
/* 0x28 */ NULL,
567+
/* 0x29 */ NULL,
568+
/* 0x2a */ NULL,
569+
/* 0x2b */ NULL,
570+
/* 0x2c */ NULL,
571+
/* 0x2d */ NULL,
572+
/* 0x2e */ NULL,
573+
/* 0x2f */ NULL,
574+
/* 0x30 */ "ADDRESS",
575+
/* 0x31 */ "BALANCE",
576+
/* 0x32 */ "ORIGIN",
577+
/* 0x33 */ "CALLER",
578+
/* 0x34 */ "CALLVALUE",
579+
/* 0x35 */ "CALLDATALOAD",
580+
/* 0x36 */ "CALLDATASIZE",
581+
/* 0x37 */ "CALLDATACOPY",
582+
/* 0x38 */ "CODESIZE",
583+
/* 0x39 */ "CODECOPY",
584+
/* 0x3a */ "GASPRICE",
585+
/* 0x3b */ "EXTCODESIZE",
586+
/* 0x3c */ "EXTCODECOPY",
587+
/* 0x3d */ "RETURNDATASIZE",
588+
/* 0x3e */ "RETURNDATACOPY",
589+
/* 0x3f */ "EXTCODEHASH",
590+
/* 0x40 */ "BLOCKHASH",
591+
/* 0x41 */ "COINBASE",
592+
/* 0x42 */ "TIMESTAMP",
593+
/* 0x43 */ "NUMBER",
594+
/* 0x44 */ "PREVRANDAO",
595+
/* 0x45 */ "GASLIMIT",
596+
/* 0x46 */ "CHAINID",
597+
/* 0x47 */ "SELFBALANCE",
598+
/* 0x48 */ "BASEFEE",
599+
/* 0x49 */ NULL,
600+
/* 0x4a */ NULL,
601+
/* 0x4b */ NULL,
602+
/* 0x4c */ NULL,
603+
/* 0x4d */ NULL,
604+
/* 0x4e */ NULL,
605+
/* 0x4f */ NULL,
606+
/* 0x50 */ "POP",
607+
/* 0x51 */ "MLOAD",
608+
/* 0x52 */ "MSTORE",
609+
/* 0x53 */ "MSTORE8",
610+
/* 0x54 */ "SLOAD",
611+
/* 0x55 */ "SSTORE",
612+
/* 0x56 */ "JUMP",
613+
/* 0x57 */ "JUMPI",
614+
/* 0x58 */ "PC",
615+
/* 0x59 */ "MSIZE",
616+
/* 0x5a */ "GAS",
617+
/* 0x5b */ "JUMPDEST",
618+
/* 0x5c */ NULL,
619+
/* 0x5d */ NULL,
620+
/* 0x5e */ NULL,
621+
/* 0x5f */ NULL,
622+
/* 0x60 */ "PUSH1",
623+
/* 0x61 */ "PUSH2",
624+
/* 0x62 */ "PUSH3",
625+
/* 0x63 */ "PUSH4",
626+
/* 0x64 */ "PUSH5",
627+
/* 0x65 */ "PUSH6",
628+
/* 0x66 */ "PUSH7",
629+
/* 0x67 */ "PUSH8",
630+
/* 0x68 */ "PUSH9",
631+
/* 0x69 */ "PUSH10",
632+
/* 0x6a */ "PUSH11",
633+
/* 0x6b */ "PUSH12",
634+
/* 0x6c */ "PUSH13",
635+
/* 0x6d */ "PUSH14",
636+
/* 0x6e */ "PUSH15",
637+
/* 0x6f */ "PUSH16",
638+
/* 0x70 */ "PUSH17",
639+
/* 0x71 */ "PUSH18",
640+
/* 0x72 */ "PUSH19",
641+
/* 0x73 */ "PUSH20",
642+
/* 0x74 */ "PUSH21",
643+
/* 0x75 */ "PUSH22",
644+
/* 0x76 */ "PUSH23",
645+
/* 0x77 */ "PUSH24",
646+
/* 0x78 */ "PUSH25",
647+
/* 0x79 */ "PUSH26",
648+
/* 0x7a */ "PUSH27",
649+
/* 0x7b */ "PUSH28",
650+
/* 0x7c */ "PUSH29",
651+
/* 0x7d */ "PUSH30",
652+
/* 0x7e */ "PUSH31",
653+
/* 0x7f */ "PUSH32",
654+
/* 0x80 */ "DUP1",
655+
/* 0x81 */ "DUP2",
656+
/* 0x82 */ "DUP3",
657+
/* 0x83 */ "DUP4",
658+
/* 0x84 */ "DUP5",
659+
/* 0x85 */ "DUP6",
660+
/* 0x86 */ "DUP7",
661+
/* 0x87 */ "DUP8",
662+
/* 0x88 */ "DUP9",
663+
/* 0x89 */ "DUP10",
664+
/* 0x8a */ "DUP11",
665+
/* 0x8b */ "DUP12",
666+
/* 0x8c */ "DUP13",
667+
/* 0x8d */ "DUP14",
668+
/* 0x8e */ "DUP15",
669+
/* 0x8f */ "DUP16",
670+
/* 0x90 */ "SWAP1",
671+
/* 0x91 */ "SWAP2",
672+
/* 0x92 */ "SWAP3",
673+
/* 0x93 */ "SWAP4",
674+
/* 0x94 */ "SWAP5",
675+
/* 0x95 */ "SWAP6",
676+
/* 0x96 */ "SWAP7",
677+
/* 0x97 */ "SWAP8",
678+
/* 0x98 */ "SWAP9",
679+
/* 0x99 */ "SWAP10",
680+
/* 0x9a */ "SWAP11",
681+
/* 0x9b */ "SWAP12",
682+
/* 0x9c */ "SWAP13",
683+
/* 0x9d */ "SWAP14",
684+
/* 0x9e */ "SWAP15",
685+
/* 0x9f */ "SWAP16",
686+
/* 0xa0 */ "LOG0",
687+
/* 0xa1 */ "LOG1",
688+
/* 0xa2 */ "LOG2",
689+
/* 0xa3 */ "LOG3",
690+
/* 0xa4 */ "LOG4",
691+
/* 0xa5 */ NULL,
692+
/* 0xa6 */ NULL,
693+
/* 0xa7 */ NULL,
694+
/* 0xa8 */ NULL,
695+
/* 0xa9 */ NULL,
696+
/* 0xaa */ NULL,
697+
/* 0xab */ NULL,
698+
/* 0xac */ NULL,
699+
/* 0xad */ NULL,
700+
/* 0xae */ NULL,
701+
/* 0xaf */ NULL,
702+
/* 0xb0 */ NULL,
703+
/* 0xb1 */ NULL,
704+
/* 0xb2 */ NULL,
705+
/* 0xb3 */ NULL,
706+
/* 0xb4 */ NULL,
707+
/* 0xb5 */ NULL,
708+
/* 0xb6 */ NULL,
709+
/* 0xb7 */ NULL,
710+
/* 0xb8 */ NULL,
711+
/* 0xb9 */ NULL,
712+
/* 0xba */ NULL,
713+
/* 0xbb */ NULL,
714+
/* 0xbc */ NULL,
715+
/* 0xbd */ NULL,
716+
/* 0xbe */ NULL,
717+
/* 0xbf */ NULL,
718+
/* 0xc0 */ NULL,
719+
/* 0xc1 */ NULL,
720+
/* 0xc2 */ NULL,
721+
/* 0xc3 */ NULL,
722+
/* 0xc4 */ NULL,
723+
/* 0xc5 */ NULL,
724+
/* 0xc6 */ NULL,
725+
/* 0xc7 */ NULL,
726+
/* 0xc8 */ NULL,
727+
/* 0xc9 */ NULL,
728+
/* 0xca */ NULL,
729+
/* 0xcb */ NULL,
730+
/* 0xcc */ NULL,
731+
/* 0xcd */ NULL,
732+
/* 0xce */ NULL,
733+
/* 0xcf */ NULL,
734+
/* 0xd0 */ NULL,
735+
/* 0xd1 */ NULL,
736+
/* 0xd2 */ NULL,
737+
/* 0xd3 */ NULL,
738+
/* 0xd4 */ NULL,
739+
/* 0xd5 */ NULL,
740+
/* 0xd6 */ NULL,
741+
/* 0xd7 */ NULL,
742+
/* 0xd8 */ NULL,
743+
/* 0xd9 */ NULL,
744+
/* 0xda */ NULL,
745+
/* 0xdb */ NULL,
746+
/* 0xdc */ NULL,
747+
/* 0xdd */ NULL,
748+
/* 0xde */ NULL,
749+
/* 0xdf */ NULL,
750+
/* 0xe0 */ NULL,
751+
/* 0xe1 */ NULL,
752+
/* 0xe2 */ NULL,
753+
/* 0xe3 */ NULL,
754+
/* 0xe4 */ NULL,
755+
/* 0xe5 */ NULL,
756+
/* 0xe6 */ NULL,
757+
/* 0xe7 */ NULL,
758+
/* 0xe8 */ NULL,
759+
/* 0xe9 */ NULL,
760+
/* 0xea */ NULL,
761+
/* 0xeb */ NULL,
762+
/* 0xec */ NULL,
763+
/* 0xed */ NULL,
764+
/* 0xee */ NULL,
765+
/* 0xef */ NULL,
766+
/* 0xf0 */ "CREATE",
767+
/* 0xf1 */ "CALL",
768+
/* 0xf2 */ "CALLCODE",
769+
/* 0xf3 */ "RETURN",
770+
/* 0xf4 */ "DELEGATECALL",
771+
/* 0xf5 */ "CREATE2",
772+
/* 0xf6 */ NULL,
773+
/* 0xf7 */ NULL,
774+
/* 0xf8 */ NULL,
775+
/* 0xf9 */ NULL,
776+
/* 0xfa */ "STATICCALL",
777+
/* 0xfb */ NULL,
778+
/* 0xfc */ NULL,
779+
/* 0xfd */ "REVERT",
780+
/* 0xfe */ "INVALID",
781+
/* 0xff */ "SELFDESTRUCT",
782+
};
783+
525784
static const char* london_names[256] = {
526785
/* 0x00 */ "STOP",
527786
/* 0x01 */ "ADD",
@@ -2085,6 +2344,7 @@ const char* const* evmc_get_instruction_names_table(enum evmc_revision revision)
20852344
case EVMC_SHANGHAI:
20862345
return shanghai_names;
20872346
case EVMC_PARIS:
2347+
return paris_names;
20882348
case EVMC_LONDON:
20892349
return london_names;
20902350
case EVMC_BERLIN:

0 commit comments

Comments
 (0)