From b78fd21288d77984b27dc7345a49387099ac8dc8 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Thu, 17 Mar 2022 10:05:20 +0100 Subject: [PATCH 1/3] Rename block_difficulty to block_prev_randao --- bindings/go/evmc/host.go | 4 ++-- bindings/rust/evmc-vm/src/container.rs | 2 +- bindings/rust/evmc-vm/src/lib.rs | 2 +- include/evmc/evmc.h | 18 +++++++++--------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bindings/go/evmc/host.go b/bindings/go/evmc/host.go index d0b987d29..78769f93c 100644 --- a/bindings/go/evmc/host.go +++ b/bindings/go/evmc/host.go @@ -74,7 +74,7 @@ type TxContext struct { Number int64 Timestamp int64 GasLimit int64 - Difficulty Hash + PrevRandao Hash ChainID Hash BaseFee Hash } @@ -173,7 +173,7 @@ func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context { C.int64_t(txContext.Number), C.int64_t(txContext.Timestamp), C.int64_t(txContext.GasLimit), - evmcBytes32(txContext.Difficulty), + evmcBytes32(txContext.PrevRandao), evmcBytes32(txContext.ChainID), evmcBytes32(txContext.BaseFee), } diff --git a/bindings/rust/evmc-vm/src/container.rs b/bindings/rust/evmc-vm/src/container.rs index 3bc5ef3fe..7c01228c1 100644 --- a/bindings/rust/evmc-vm/src/container.rs +++ b/bindings/rust/evmc-vm/src/container.rs @@ -90,7 +90,7 @@ mod tests { block_number: 0, block_timestamp: 0, block_gas_limit: 0, - block_difficulty: Uint256::default(), + block_prev_randao: Uint256::default(), chain_id: Uint256::default(), block_base_fee: Uint256::default(), } diff --git a/bindings/rust/evmc-vm/src/lib.rs b/bindings/rust/evmc-vm/src/lib.rs index 459e8e9d8..c79b4af24 100644 --- a/bindings/rust/evmc-vm/src/lib.rs +++ b/bindings/rust/evmc-vm/src/lib.rs @@ -774,7 +774,7 @@ mod tests { block_number: 42, block_timestamp: 235117, block_gas_limit: 105023, - block_difficulty: Uint256 { bytes: [0xaa; 32] }, + block_prev_randao: Uint256 { bytes: [0xaa; 32] }, chain_id: Uint256::default(), block_base_fee: Uint256::default(), } diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index 3d074f6fa..5c957b926 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -193,15 +193,15 @@ struct evmc_message /** The transaction and block data for execution. */ struct evmc_tx_context { - evmc_uint256be tx_gas_price; /**< The transaction gas price. */ - evmc_address tx_origin; /**< The transaction origin account. */ - evmc_address block_coinbase; /**< The miner of the block. */ - int64_t block_number; /**< The block number. */ - int64_t block_timestamp; /**< The block timestamp. */ - int64_t block_gas_limit; /**< The block gas limit. */ - evmc_uint256be block_difficulty; /**< The block difficulty. */ - evmc_uint256be chain_id; /**< The blockchain's ChainID. */ - evmc_uint256be block_base_fee; /**< The block base fee per gas (EIP-1559, EIP-3198). */ + evmc_uint256be tx_gas_price; /**< The transaction gas price. */ + evmc_address tx_origin; /**< The transaction origin account. */ + evmc_address block_coinbase; /**< The miner of the block. */ + int64_t block_number; /**< The block number. */ + int64_t block_timestamp; /**< The block timestamp. */ + int64_t block_gas_limit; /**< The block gas limit. */ + evmc_uint256be block_prev_randao; /**< The block previous RANDAO (EIP-4399). */ + evmc_uint256be chain_id; /**< The blockchain's ChainID. */ + evmc_uint256be block_base_fee; /**< The block base fee per gas (EIP-1559, EIP-3198). */ }; /** From db793f488335e9fa2c55ac4ac68631b155dc84d8 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Thu, 17 Mar 2022 10:15:37 +0100 Subject: [PATCH 2/3] Rename DIFFICULTY instruction to PREVRANDAO --- include/evmc/instructions.h | 2 +- lib/instructions/instruction_metrics.c | 4 +- lib/instructions/instruction_names.c | 264 ++++++++++++++++++++++++- test/unittests/instructions_test.cpp | 7 +- 4 files changed, 271 insertions(+), 6 deletions(-) diff --git a/include/evmc/instructions.h b/include/evmc/instructions.h index 505a3ce3d..1c22f848b 100644 --- a/include/evmc/instructions.h +++ b/include/evmc/instructions.h @@ -75,7 +75,7 @@ enum evmc_opcode OP_COINBASE = 0x41, OP_TIMESTAMP = 0x42, OP_NUMBER = 0x43, - OP_DIFFICULTY = 0x44, + OP_PREVRANDAO = 0x44, OP_GASLIMIT = 0x45, OP_CHAINID = 0x46, OP_SELFBALANCE = 0x47, diff --git a/lib/instructions/instruction_metrics.c b/lib/instructions/instruction_metrics.c index 3af5e928a..ea9aea96e 100644 --- a/lib/instructions/instruction_metrics.c +++ b/lib/instructions/instruction_metrics.c @@ -100,7 +100,7 @@ static struct evmc_instruction_metrics cancun_metrics[256] = { /* COINBASE = 0x41 */ {BASE, 0, 1}, /* TIMESTAMP = 0x42 */ {BASE, 0, 1}, /* NUMBER = 0x43 */ {BASE, 0, 1}, - /* DIFFICULTY = 0x44 */ {BASE, 0, 1}, + /* PREVRANDAO = 0x44 */ {BASE, 0, 1}, /* GASLIMIT = 0x45 */ {BASE, 0, 1}, /* CHAINID = 0x46 */ {BASE, 0, 1}, /* SELFBALANCE = 0x47 */ {LOW, 0, 1}, @@ -359,7 +359,7 @@ static struct evmc_instruction_metrics shanghai_metrics[256] = { /* COINBASE = 0x41 */ {BASE, 0, 1}, /* TIMESTAMP = 0x42 */ {BASE, 0, 1}, /* NUMBER = 0x43 */ {BASE, 0, 1}, - /* DIFFICULTY = 0x44 */ {BASE, 0, 1}, + /* PREVRANDAO = 0x44 */ {BASE, 0, 1}, /* GASLIMIT = 0x45 */ {BASE, 0, 1}, /* CHAINID = 0x46 */ {BASE, 0, 1}, /* SELFBALANCE = 0x47 */ {LOW, 0, 1}, diff --git a/lib/instructions/instruction_names.c b/lib/instructions/instruction_names.c index b53f375ed..64a21592d 100644 --- a/lib/instructions/instruction_names.c +++ b/lib/instructions/instruction_names.c @@ -73,7 +73,7 @@ static const char* cancun_names[256] = { /* 0x41 */ "COINBASE", /* 0x42 */ "TIMESTAMP", /* 0x43 */ "NUMBER", - /* 0x44 */ "DIFFICULTY", + /* 0x44 */ "PREVRANDAO", /* 0x45 */ "GASLIMIT", /* 0x46 */ "CHAINID", /* 0x47 */ "SELFBALANCE", @@ -332,7 +332,7 @@ static const char* shanghai_names[256] = { /* 0x41 */ "COINBASE", /* 0x42 */ "TIMESTAMP", /* 0x43 */ "NUMBER", - /* 0x44 */ "DIFFICULTY", + /* 0x44 */ "PREVRANDAO", /* 0x45 */ "GASLIMIT", /* 0x46 */ "CHAINID", /* 0x47 */ "SELFBALANCE", @@ -522,6 +522,265 @@ static const char* shanghai_names[256] = { /* 0xff */ "SELFDESTRUCT", }; +static const char* paris_names[256] = { + /* 0x00 */ "STOP", + /* 0x01 */ "ADD", + /* 0x02 */ "MUL", + /* 0x03 */ "SUB", + /* 0x04 */ "DIV", + /* 0x05 */ "SDIV", + /* 0x06 */ "MOD", + /* 0x07 */ "SMOD", + /* 0x08 */ "ADDMOD", + /* 0x09 */ "MULMOD", + /* 0x0a */ "EXP", + /* 0x0b */ "SIGNEXTEND", + /* 0x0c */ NULL, + /* 0x0d */ NULL, + /* 0x0e */ NULL, + /* 0x0f */ NULL, + /* 0x10 */ "LT", + /* 0x11 */ "GT", + /* 0x12 */ "SLT", + /* 0x13 */ "SGT", + /* 0x14 */ "EQ", + /* 0x15 */ "ISZERO", + /* 0x16 */ "AND", + /* 0x17 */ "OR", + /* 0x18 */ "XOR", + /* 0x19 */ "NOT", + /* 0x1a */ "BYTE", + /* 0x1b */ "SHL", + /* 0x1c */ "SHR", + /* 0x1d */ "SAR", + /* 0x1e */ NULL, + /* 0x1f */ NULL, + /* 0x20 */ "KECCAK256", + /* 0x21 */ NULL, + /* 0x22 */ NULL, + /* 0x23 */ NULL, + /* 0x24 */ NULL, + /* 0x25 */ NULL, + /* 0x26 */ NULL, + /* 0x27 */ NULL, + /* 0x28 */ NULL, + /* 0x29 */ NULL, + /* 0x2a */ NULL, + /* 0x2b */ NULL, + /* 0x2c */ NULL, + /* 0x2d */ NULL, + /* 0x2e */ NULL, + /* 0x2f */ NULL, + /* 0x30 */ "ADDRESS", + /* 0x31 */ "BALANCE", + /* 0x32 */ "ORIGIN", + /* 0x33 */ "CALLER", + /* 0x34 */ "CALLVALUE", + /* 0x35 */ "CALLDATALOAD", + /* 0x36 */ "CALLDATASIZE", + /* 0x37 */ "CALLDATACOPY", + /* 0x38 */ "CODESIZE", + /* 0x39 */ "CODECOPY", + /* 0x3a */ "GASPRICE", + /* 0x3b */ "EXTCODESIZE", + /* 0x3c */ "EXTCODECOPY", + /* 0x3d */ "RETURNDATASIZE", + /* 0x3e */ "RETURNDATACOPY", + /* 0x3f */ "EXTCODEHASH", + /* 0x40 */ "BLOCKHASH", + /* 0x41 */ "COINBASE", + /* 0x42 */ "TIMESTAMP", + /* 0x43 */ "NUMBER", + /* 0x44 */ "PREVRANDAO", + /* 0x45 */ "GASLIMIT", + /* 0x46 */ "CHAINID", + /* 0x47 */ "SELFBALANCE", + /* 0x48 */ "BASEFEE", + /* 0x49 */ NULL, + /* 0x4a */ NULL, + /* 0x4b */ NULL, + /* 0x4c */ NULL, + /* 0x4d */ NULL, + /* 0x4e */ NULL, + /* 0x4f */ NULL, + /* 0x50 */ "POP", + /* 0x51 */ "MLOAD", + /* 0x52 */ "MSTORE", + /* 0x53 */ "MSTORE8", + /* 0x54 */ "SLOAD", + /* 0x55 */ "SSTORE", + /* 0x56 */ "JUMP", + /* 0x57 */ "JUMPI", + /* 0x58 */ "PC", + /* 0x59 */ "MSIZE", + /* 0x5a */ "GAS", + /* 0x5b */ "JUMPDEST", + /* 0x5c */ NULL, + /* 0x5d */ NULL, + /* 0x5e */ NULL, + /* 0x5f */ NULL, + /* 0x60 */ "PUSH1", + /* 0x61 */ "PUSH2", + /* 0x62 */ "PUSH3", + /* 0x63 */ "PUSH4", + /* 0x64 */ "PUSH5", + /* 0x65 */ "PUSH6", + /* 0x66 */ "PUSH7", + /* 0x67 */ "PUSH8", + /* 0x68 */ "PUSH9", + /* 0x69 */ "PUSH10", + /* 0x6a */ "PUSH11", + /* 0x6b */ "PUSH12", + /* 0x6c */ "PUSH13", + /* 0x6d */ "PUSH14", + /* 0x6e */ "PUSH15", + /* 0x6f */ "PUSH16", + /* 0x70 */ "PUSH17", + /* 0x71 */ "PUSH18", + /* 0x72 */ "PUSH19", + /* 0x73 */ "PUSH20", + /* 0x74 */ "PUSH21", + /* 0x75 */ "PUSH22", + /* 0x76 */ "PUSH23", + /* 0x77 */ "PUSH24", + /* 0x78 */ "PUSH25", + /* 0x79 */ "PUSH26", + /* 0x7a */ "PUSH27", + /* 0x7b */ "PUSH28", + /* 0x7c */ "PUSH29", + /* 0x7d */ "PUSH30", + /* 0x7e */ "PUSH31", + /* 0x7f */ "PUSH32", + /* 0x80 */ "DUP1", + /* 0x81 */ "DUP2", + /* 0x82 */ "DUP3", + /* 0x83 */ "DUP4", + /* 0x84 */ "DUP5", + /* 0x85 */ "DUP6", + /* 0x86 */ "DUP7", + /* 0x87 */ "DUP8", + /* 0x88 */ "DUP9", + /* 0x89 */ "DUP10", + /* 0x8a */ "DUP11", + /* 0x8b */ "DUP12", + /* 0x8c */ "DUP13", + /* 0x8d */ "DUP14", + /* 0x8e */ "DUP15", + /* 0x8f */ "DUP16", + /* 0x90 */ "SWAP1", + /* 0x91 */ "SWAP2", + /* 0x92 */ "SWAP3", + /* 0x93 */ "SWAP4", + /* 0x94 */ "SWAP5", + /* 0x95 */ "SWAP6", + /* 0x96 */ "SWAP7", + /* 0x97 */ "SWAP8", + /* 0x98 */ "SWAP9", + /* 0x99 */ "SWAP10", + /* 0x9a */ "SWAP11", + /* 0x9b */ "SWAP12", + /* 0x9c */ "SWAP13", + /* 0x9d */ "SWAP14", + /* 0x9e */ "SWAP15", + /* 0x9f */ "SWAP16", + /* 0xa0 */ "LOG0", + /* 0xa1 */ "LOG1", + /* 0xa2 */ "LOG2", + /* 0xa3 */ "LOG3", + /* 0xa4 */ "LOG4", + /* 0xa5 */ NULL, + /* 0xa6 */ NULL, + /* 0xa7 */ NULL, + /* 0xa8 */ NULL, + /* 0xa9 */ NULL, + /* 0xaa */ NULL, + /* 0xab */ NULL, + /* 0xac */ NULL, + /* 0xad */ NULL, + /* 0xae */ NULL, + /* 0xaf */ NULL, + /* 0xb0 */ NULL, + /* 0xb1 */ NULL, + /* 0xb2 */ NULL, + /* 0xb3 */ NULL, + /* 0xb4 */ NULL, + /* 0xb5 */ NULL, + /* 0xb6 */ NULL, + /* 0xb7 */ NULL, + /* 0xb8 */ NULL, + /* 0xb9 */ NULL, + /* 0xba */ NULL, + /* 0xbb */ NULL, + /* 0xbc */ NULL, + /* 0xbd */ NULL, + /* 0xbe */ NULL, + /* 0xbf */ NULL, + /* 0xc0 */ NULL, + /* 0xc1 */ NULL, + /* 0xc2 */ NULL, + /* 0xc3 */ NULL, + /* 0xc4 */ NULL, + /* 0xc5 */ NULL, + /* 0xc6 */ NULL, + /* 0xc7 */ NULL, + /* 0xc8 */ NULL, + /* 0xc9 */ NULL, + /* 0xca */ NULL, + /* 0xcb */ NULL, + /* 0xcc */ NULL, + /* 0xcd */ NULL, + /* 0xce */ NULL, + /* 0xcf */ NULL, + /* 0xd0 */ NULL, + /* 0xd1 */ NULL, + /* 0xd2 */ NULL, + /* 0xd3 */ NULL, + /* 0xd4 */ NULL, + /* 0xd5 */ NULL, + /* 0xd6 */ NULL, + /* 0xd7 */ NULL, + /* 0xd8 */ NULL, + /* 0xd9 */ NULL, + /* 0xda */ NULL, + /* 0xdb */ NULL, + /* 0xdc */ NULL, + /* 0xdd */ NULL, + /* 0xde */ NULL, + /* 0xdf */ NULL, + /* 0xe0 */ NULL, + /* 0xe1 */ NULL, + /* 0xe2 */ NULL, + /* 0xe3 */ NULL, + /* 0xe4 */ NULL, + /* 0xe5 */ NULL, + /* 0xe6 */ NULL, + /* 0xe7 */ NULL, + /* 0xe8 */ NULL, + /* 0xe9 */ NULL, + /* 0xea */ NULL, + /* 0xeb */ NULL, + /* 0xec */ NULL, + /* 0xed */ NULL, + /* 0xee */ NULL, + /* 0xef */ NULL, + /* 0xf0 */ "CREATE", + /* 0xf1 */ "CALL", + /* 0xf2 */ "CALLCODE", + /* 0xf3 */ "RETURN", + /* 0xf4 */ "DELEGATECALL", + /* 0xf5 */ "CREATE2", + /* 0xf6 */ NULL, + /* 0xf7 */ NULL, + /* 0xf8 */ NULL, + /* 0xf9 */ NULL, + /* 0xfa */ "STATICCALL", + /* 0xfb */ NULL, + /* 0xfc */ NULL, + /* 0xfd */ "REVERT", + /* 0xfe */ "INVALID", + /* 0xff */ "SELFDESTRUCT", +}; + static const char* london_names[256] = { /* 0x00 */ "STOP", /* 0x01 */ "ADD", @@ -2085,6 +2344,7 @@ const char* const* evmc_get_instruction_names_table(enum evmc_revision revision) case EVMC_SHANGHAI: return shanghai_names; case EVMC_PARIS: + return paris_names; case EVMC_LONDON: return london_names; case EVMC_BERLIN: diff --git a/test/unittests/instructions_test.cpp b/test/unittests/instructions_test.cpp index c134acae5..a4216be4c 100644 --- a/test/unittests/instructions_test.cpp +++ b/test/unittests/instructions_test.cpp @@ -352,7 +352,7 @@ TEST(instructions, london_hard_fork) EXPECT_TRUE(bn[OP_BASEFEE] == nullptr); } -TEST(instructions, merge_hard_fork) +TEST(instructions, paris_hard_fork) { const auto p = evmc_get_instruction_metrics_table(EVMC_PARIS); const auto l = evmc_get_instruction_metrics_table(EVMC_LONDON); @@ -362,8 +362,13 @@ TEST(instructions, merge_hard_fork) for (int op = 0x00; op <= 0xff; ++op) { EXPECT_EQ(p[op], l[op]) << op; + if (op == OP_PREVRANDAO) + continue; EXPECT_STREQ(pn[op], ln[op]) << op; } + + EXPECT_EQ(pn[OP_PREVRANDAO], std::string{"PREVRANDAO"}); + EXPECT_EQ(ln[OP_PREVRANDAO], std::string{"DIFFICULTY"}); } TEST(instructions, shanghai_hard_fork) From e78e20d3710f086a01cb959f7acad144319b6f62 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Thu, 17 Mar 2022 10:21:30 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8fe64017..a71b0b7bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,9 @@ and this project adheres to [Semantic Versioning]. [#620](https://github.com/ethereum/evmc/pull/620) [#621](https://github.com/ethereum/evmc/pull/621) [#632](https://github.com/ethereum/evmc/pull/632) +- According to [EIP-4399](https://eips.ethereum.org/EIPS/eip-4399), + `block_difficulty` field was renamed to `block_prev_randao`, and `DIFFICULTY` opcode to `PREVRANDAO`. + [#635](https://github.com/ethereum/evmc/pull/635) ## [9.0.0] — 2021-06-30