Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EIP-3198: BASEFEE opcode #333

Merged
merged 4 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ commands:
steps:
- restore_cache:
name: "Restore Silkworm cache"
key: &silkworm-cache-key silkworm-20210413
key: &silkworm-cache-key silkworm-eip-3198-20210529
- run:
name: "Check Silkworm cache"
command: |
Expand All @@ -38,8 +38,8 @@ commands:
working_directory: ~/silkworm/src
command: |
[ "$SILKWORM_BUILD" = true ] || exit 0
git clone --no-checkout --single-branch https://github.com/torquem-ch/silkworm.git .
git checkout 3388d3ef7ba37ca440707a96a7d2886989073a59
git clone --no-checkout --single-branch https://github.com/torquem-ch/silkworm.git . --branch eip-3198
git checkout 07a4b7ab2849dc759249b204a455e309ab096412
git submodule update --init --recursive --depth=1 --progress
- run:
name: "Configure Silkworm"
Expand Down
2 changes: 1 addition & 1 deletion evmc
Submodule evmc updated 47 files
+1 −1 .bumpversion.cfg
+11 −0 CHANGELOG.md
+7 −2 CMakeLists.txt
+2 −0 bindings/go/evmc/host.go
+1 −1 bindings/java/java/src/test/java/org/ethereum/evmc/TestHostContext.java
+1 −1 bindings/rust/evmc-declare-tests/Cargo.toml
+2 −2 bindings/rust/evmc-declare/Cargo.toml
+1 −1 bindings/rust/evmc-sys/Cargo.toml
+2 −2 bindings/rust/evmc-vm/Cargo.toml
+1 −0 bindings/rust/evmc-vm/src/container.rs
+1 −0 bindings/rust/evmc-vm/src/lib.rs
+5 −5 circle.yml
+1 −1 docs/EVMC.md
+1 −1 examples/example-rust-vm/Cargo.toml
+1 −1 examples/example-rust-vm/src/lib.rs
+1 −1 go.mod
+2 −1 include/evmc/evmc.h
+33 −0 include/evmc/evmc.hpp
+80 −0 include/evmc/helpers.h
+1 −0 include/evmc/hex.hpp
+1 −0 include/evmc/instructions.h
+3 −5 include/evmc/tooling.hpp
+3 −2 lib/CMakeLists.txt
+1 −1 lib/hex/CMakeLists.txt
+2 −2 lib/instructions/CMakeLists.txt
+260 −0 lib/instructions/instruction_metrics.c
+260 −0 lib/instructions/instruction_names.c
+2 −2 lib/loader/CMakeLists.txt
+1 −1 lib/mocked_host/CMakeLists.txt
+18 −0 lib/tooling/CMakeLists.txt
+120 −0 lib/tooling/run.cpp
+1 −1 test/compilation/CMakeLists.txt
+1 −1 test/gomod/README
+1 −1 test/gomod/use_evmc_test.go
+3 −4 test/unittests/CMakeLists.txt
+144 −0 test/unittests/cpp_test.cpp
+11 −0 test/unittests/instructions_test.cpp
+50 −14 test/unittests/tooling_test.cpp
+0 −2 tools/CMakeLists.txt
+0 −9 tools/commands/CMakeLists.txt
+0 −88 tools/commands/run.cpp
+2 −4 tools/evmc/CMakeLists.txt
+6 −2 tools/evmc/main.cpp
+0 −9 tools/utils/CMakeLists.txt
+0 −126 tools/utils/utils.cpp
+0 −20 tools/utils/utils.hpp
+0 −1 tools/vmtester/CMakeLists.txt
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
1 change: 1 addition & 0 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_executable(evmone-unittests
evm_test.cpp
evm_calls_test.cpp
evm_eip2929_test.cpp
evm_eip3198_basefee_test.cpp
evm_state_test.cpp
evm_other_test.cpp
evmone_test.cpp
Expand Down
34 changes: 34 additions & 0 deletions test/unittests/evm_eip3198_basefee_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2021 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

/// This file contains EVM unit tests for EIP-3198 "BASEFEE opcode"
/// https://eips.ethereum.org/EIPS/eip-3198

#include "evm_fixture.hpp"

using namespace evmc::literals;
using evmone::test::evm;

TEST_P(evm, basefee_pre_london)
{
rev = EVMC_BERLIN;
const auto code = bytecode{OP_BASEFEE};

execute(code);
EXPECT_STATUS(EVMC_UNDEFINED_INSTRUCTION);
}

TEST_P(evm, basefee_nominal_case)
{
// https://eips.ethereum.org/EIPS/eip-3198#nominal-case
rev = EVMC_LONDON;
host.tx_context.block_base_fee = evmc::bytes32{7};

execute(bytecode{} + OP_BASEFEE + OP_STOP);
EXPECT_GAS_USED(EVMC_SUCCESS, 2);

execute(bytecode{} + OP_BASEFEE + ret_top());
EXPECT_GAS_USED(EVMC_SUCCESS, 17);
EXPECT_OUTPUT_INT(7);
}