From ccc52420e27a56abb2e58e8fbd26f1cb15b4c93f Mon Sep 17 00:00:00 2001 From: kayan Date: Tue, 16 Apr 2024 16:12:37 +0800 Subject: [PATCH 1/2] use base_fee_per_gas --- include/evm_runtime/types.hpp | 5 +++-- silkworm | 2 +- src/actions.cpp | 18 +++++++++++++++--- tests/basic_evm_tester.hpp | 3 ++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/evm_runtime/types.hpp b/include/evm_runtime/types.hpp index 67bac0e9..686bcaef 100644 --- a/include/evm_runtime/types.hpp +++ b/include/evm_runtime/types.hpp @@ -90,8 +90,9 @@ namespace evm_runtime { struct evmtx_v0 { uint64_t eos_evm_version; bytes rlptx; - - EOSLIB_SERIALIZE(evmtx_v0, (eos_evm_version)(rlptx)); + uint64_t base_fee_per_gas; + + EOSLIB_SERIALIZE(evmtx_v0, (eos_evm_version)(rlptx)(base_fee_per_gas)); }; using evmtx_type = std::variant; diff --git a/silkworm b/silkworm index b9554f89..1ab2f704 160000 --- a/silkworm +++ b/silkworm @@ -1 +1 @@ -Subproject commit b9554f894184fa09408170bb9ee0ae3febb10ced +Subproject commit 1ab2f704ada69250cd36535dacf32130636cfeda diff --git a/src/actions.cpp b/src/actions.cpp index ce0a5d58..d55508fc 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -329,8 +329,14 @@ void evm_contract::exec(const exec_input& input, const std::optionalget_genesis_time().sec_since_epoch()); Block block; + + auto evm_version = _config->get_evm_version(); + std::optional base_fee_per_gas; + if (evm_version >= 1) { + base_fee_per_gas = _config->get_gas_price(); + } eosevm::prepare_block_header(block.header, bm, get_self().value, - bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), _config->get_evm_version()); + bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), evm_version, base_fee_per_gas); evm_runtime::state state{get_self(), get_self(), true}; IntraBlockState ibstate{state}; @@ -448,8 +454,14 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const eosevm::block_mapping bm(_config->get_genesis_time().sec_since_epoch()); Block block; + + std::optional base_fee_per_gas; + if (current_version >= 1) { + base_fee_per_gas = _config->get_gas_price(); + } + eosevm::prepare_block_header(block.header, bm, get_self().value, - bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), current_version); + bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), current_version, base_fee_per_gas); silkworm::protocol::TrustRuleSet engine{*found_chain_config->second}; @@ -490,7 +502,7 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const } if (current_version >= 1) { - auto event = evmtx_type{evmtx_v0{current_version, txn.get_rlptx()}}; + auto event = evmtx_type{evmtx_v0{current_version, txn.get_rlptx(), *base_fee_per_gas}}; action(std::vector{}, get_self(), "evmtx"_n, event) .send(); } diff --git a/tests/basic_evm_tester.hpp b/tests/basic_evm_tester.hpp index f6184476..a4d60a56 100644 --- a/tests/basic_evm_tester.hpp +++ b/tests/basic_evm_tester.hpp @@ -52,6 +52,7 @@ namespace evm_test { struct evmtx_v0 { uint64_t eos_evm_version; bytes rlptx; + uint64_t base_fee_per_gas; }; using evmtx_type = std::variant; @@ -195,7 +196,7 @@ FC_REFLECT(evm_test::message_receiver, (account)(handler)(min_fee)(flags)); FC_REFLECT(evm_test::bridge_message_v0, (receiver)(sender)(timestamp)(value)(data)); FC_REFLECT(evm_test::gcstore, (id)(storage_id)); FC_REFLECT(evm_test::account_code, (id)(ref_count)(code)(code_hash)); -FC_REFLECT(evm_test::evmtx_v0, (eos_evm_version)(rlptx)); +FC_REFLECT(evm_test::evmtx_v0, (eos_evm_version)(rlptx)(base_fee_per_gas)); namespace evm_test { class evm_eoa From c3e0f5cfaee45bb536e576e6b706f25a8803d3f6 Mon Sep 17 00:00:00 2001 From: kayan Date: Wed, 17 Apr 2024 15:31:45 +0800 Subject: [PATCH 2/2] enhance version test --- tests/version_tests.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/version_tests.cpp b/tests/version_tests.cpp index e1f8e579..87d14cb6 100644 --- a/tests/version_tests.cpp +++ b/tests/version_tests.cpp @@ -110,7 +110,16 @@ BOOST_FIXTURE_TEST_CASE(set_version, version_tester) try { // Fund evm1 address with 100 EOS (this will NOT trigger an update of the evm version) evm_eoa evm1; const int64_t to_bridge = 1000000; - transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x()); + auto trace0 = transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x()); + BOOST_CHECK_EQUAL(trace0->action_traces.size(), 4); + BOOST_REQUIRE(trace0->action_traces[0].act.account == token_account_name); + BOOST_REQUIRE(trace0->action_traces[0].act.name == "transfer"_n); + BOOST_REQUIRE(trace0->action_traces[1].act.account == token_account_name); + BOOST_REQUIRE(trace0->action_traces[1].act.name == "transfer"_n); + BOOST_REQUIRE(trace0->action_traces[2].act.account == token_account_name); + BOOST_REQUIRE(trace0->action_traces[2].act.name == "transfer"_n); + BOOST_REQUIRE(trace0->action_traces[3].act.account == evm_account_name); + BOOST_REQUIRE(trace0->action_traces[3].act.name == "pushtx"_n); config = get_config(); BOOST_CHECK_EQUAL(config.evm_version.has_value(), true); @@ -127,13 +136,31 @@ BOOST_FIXTURE_TEST_CASE(set_version, version_tester) try { } // Fund evm1 address with 100 more EOS (this will trigger an update of the evm version) - transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x()); + auto trace = transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x()); config = get_config(); BOOST_CHECK_EQUAL(config.evm_version.has_value(), true); BOOST_CHECK_EQUAL(config.evm_version.value().cached_version, 1); BOOST_CHECK_EQUAL(config.evm_version.value().pending_version.has_value(), false); + BOOST_CHECK_EQUAL(trace->action_traces.size(), 4); + BOOST_REQUIRE(trace->action_traces[0].act.account == token_account_name); + BOOST_REQUIRE(trace->action_traces[0].act.name == "transfer"_n); + BOOST_REQUIRE(trace->action_traces[1].act.account == token_account_name); + BOOST_REQUIRE(trace->action_traces[1].act.name == "transfer"_n); + BOOST_REQUIRE(trace->action_traces[2].act.account == token_account_name); + BOOST_REQUIRE(trace->action_traces[2].act.name == "transfer"_n); + BOOST_REQUIRE(trace->action_traces[3].act.account == evm_account_name); + BOOST_REQUIRE(trace->action_traces[3].act.name == "evmtx"_n); + + auto evmtx_v = fc::raw::unpack( + trace->action_traces[3].act.data.data(), trace->action_traces[3].act.data.size()); + BOOST_REQUIRE(std::holds_alternative(evmtx_v)); + + const auto &evmtx = std::get(evmtx_v); + BOOST_CHECK_EQUAL(evmtx.eos_evm_version, 1); + BOOST_CHECK_EQUAL(evmtx.base_fee_per_gas, config.gas_price); + } FC_LOG_AND_RETHROW() BOOST_FIXTURE_TEST_CASE(traces_in_different_eosevm_version, version_tester) try {