Skip to content

Commit

Permalink
Merge pull request #451 from ethereum/eip-4399
Browse files Browse the repository at this point in the history
Rename DIFFICULTY -> PREVRANDAO
  • Loading branch information
chfast authored Mar 29, 2022
2 parents 0e11c21 + 9da9dd3 commit b9e5c4a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,9 @@ inline void number(StackTop stack, ExecutionState& state) noexcept
stack.push(static_cast<uint64_t>(state.get_tx_context().block_number));
}

inline void difficulty(StackTop stack, ExecutionState& state) noexcept
inline void prevrandao(StackTop stack, ExecutionState& state) noexcept
{
stack.push(intx::be::load<uint256>(state.get_tx_context().block_difficulty));
stack.push(intx::be::load<uint256>(state.get_tx_context().block_prev_randao));
}

inline void gaslimit(StackTop stack, ExecutionState& state) noexcept
Expand Down
4 changes: 2 additions & 2 deletions lib/evmone/instructions_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ constexpr inline GasCostTable gas_costs = []() noexcept {
table[EVMC_FRONTIER][OP_COINBASE] = 2;
table[EVMC_FRONTIER][OP_TIMESTAMP] = 2;
table[EVMC_FRONTIER][OP_NUMBER] = 2;
table[EVMC_FRONTIER][OP_DIFFICULTY] = 2;
table[EVMC_FRONTIER][OP_PREVRANDAO] = 2;
table[EVMC_FRONTIER][OP_GASLIMIT] = 2;
table[EVMC_FRONTIER][OP_POP] = 2;
table[EVMC_FRONTIER][OP_MLOAD] = 3;
Expand Down Expand Up @@ -265,7 +265,7 @@ constexpr inline std::array<Traits, 256> traits = []() noexcept {
table[OP_COINBASE] = {"COINBASE", 0, 1, EVMC_FRONTIER};
table[OP_TIMESTAMP] = {"TIMESTAMP", 0, 1, EVMC_FRONTIER};
table[OP_NUMBER] = {"NUMBER", 0, 1, EVMC_FRONTIER};
table[OP_DIFFICULTY] = {"DIFFICULTY", 0, 1, EVMC_FRONTIER};
table[OP_PREVRANDAO] = {"PREVRANDAO", 0, 1, EVMC_FRONTIER};
table[OP_GASLIMIT] = {"GASLIMIT", 0, 1, EVMC_FRONTIER};
table[OP_CHAINID] = {"CHAINID", 0, 1, EVMC_ISTANBUL};
table[OP_SELFBALANCE] = {"SELFBALANCE", 0, 1, EVMC_ISTANBUL};
Expand Down
2 changes: 1 addition & 1 deletion lib/evmone/instructions_xmacro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
X(OP_COINBASE, coinbase) \
X(OP_TIMESTAMP, timestamp) \
X(OP_NUMBER, number) \
X(OP_DIFFICULTY, difficulty) \
X(OP_PREVRANDAO, prevrandao) \
X(OP_GASLIMIT, gaslimit) \
X(OP_CHAINID, chainid) \
X(OP_SELFBALANCE, selfbalance) \
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/evm_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ TEST_P(evm, tx_context)
host.tx_context.chain_id.bytes[28] = 0xaa;
host.tx_context.block_coinbase.bytes[1] = 0xcc;
host.tx_context.tx_origin.bytes[2] = 0x55;
host.tx_context.block_difficulty.bytes[1] = 0xdd;
host.tx_context.block_prev_randao.bytes[1] = 0xdd;
host.tx_context.tx_gas_price.bytes[2] = 0x66;

auto const code = bytecode{} + OP_TIMESTAMP + OP_COINBASE + OP_OR + OP_GASPRICE + OP_OR +
OP_NUMBER + OP_OR + OP_DIFFICULTY + OP_OR + OP_GASLIMIT + OP_OR + OP_ORIGIN +
OP_NUMBER + OP_OR + OP_PREVRANDAO + OP_OR + OP_GASLIMIT + OP_OR + OP_ORIGIN +
OP_OR + OP_CHAINID + OP_OR + ret_top();
execute(52, code);
EXPECT_EQ(result.status_code, EVMC_SUCCESS);
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/evm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,13 @@ TEST_P(evm, return_empty_buffer_at_offset_0)

TEST_P(evm, return_empty_buffer_at_high_offset)
{
host.tx_context.block_difficulty =
host.tx_context.block_prev_randao =
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1_bytes32;

execute(push(0) + OP_DIFFICULTY + OP_RETURN);
execute(push(0) + OP_PREVRANDAO + OP_RETURN);
EXPECT_STATUS(EVMC_SUCCESS);

execute(push(0) + OP_DIFFICULTY + OP_REVERT);
execute(push(0) + OP_PREVRANDAO + OP_REVERT);
EXPECT_STATUS(EVMC_REVERT);
}

Expand Down

0 comments on commit b9e5c4a

Please sign in to comment.