Skip to content

Commit

Permalink
Implement EIP-3198: BASEFEE opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed May 27, 2021
1 parent 8d6a2ba commit 86223ec
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "evmc"]
path = evmc
url = https://github.com/ethereum/evmc
url = https://github.com/torquem-ch/evmc
branch = eip-3198
2 changes: 1 addition & 1 deletion evmc
Submodule evmc updated from 53f1fe to df1c3c
3 changes: 3 additions & 0 deletions lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& ana
case OP_SELFBALANCE:
selfbalance(state);
break;
case OP_BASEFEE:
basefee(state);
break;

case OP_POP:
pop(state.stack);
Expand Down
2 changes: 2 additions & 0 deletions lib/evmone/instruction_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ constexpr inline std::array<Traits, 256> traits = []() noexcept {
table[OP_GASLIMIT] = {"GASLIMIT", 0, 1};
table[OP_CHAINID] = {"CHAINID", 0, 1};
table[OP_SELFBALANCE] = {"SELFBALANCE", 0, 1};
table[OP_BASEFEE] = {"BASEFEE", 0, 1};

table[OP_POP] = {"POP", 1, -1};
table[OP_MLOAD] = {"MLOAD", 1, 0};
Expand Down Expand Up @@ -365,6 +366,7 @@ constexpr inline std::array<int16_t, 256> gas_costs<EVMC_BERLIN> = []() noexcept
template <>
constexpr inline std::array<int16_t, 256> gas_costs<EVMC_LONDON> = []() noexcept {
auto table = gas_costs<EVMC_BERLIN>;
table[OP_BASEFEE] = 2;
return table;
}();

Expand Down
1 change: 1 addition & 0 deletions lib/evmone/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ constexpr std::array<instruction_exec_fn, 256> instruction_implementations = [](
table[OP_GASLIMIT] = op<gaslimit>;
table[OP_CHAINID] = op<chainid>;
table[OP_SELFBALANCE] = op<selfbalance>;
table[OP_BASEFEE] = op<basefee>;

table[OP_POP] = op<pop>;
table[OP_MLOAD] = op<mload>;
Expand Down
5 changes: 5 additions & 0 deletions lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ inline void gasprice(ExecutionState& state) noexcept
state.stack.push(intx::be::load<uint256>(state.host.get_tx_context().tx_gas_price));
}

inline void basefee(ExecutionState& state) noexcept
{
state.stack.push(intx::be::load<uint256>(state.host.get_tx_context().block_base_fee));
}

inline evmc_status_code extcodesize(ExecutionState& state) noexcept
{
auto& x = state.stack.top();
Expand Down

0 comments on commit 86223ec

Please sign in to comment.