From 0953e8d4be33c50fa98ca05233faf505255509d9 Mon Sep 17 00:00:00 2001 From: kayan Date: Fri, 23 Feb 2024 17:24:37 +0800 Subject: [PATCH] other fixes --- include/evm_runtime/config_wrapper.hpp | 4 ++-- include/evm_runtime/types.hpp | 1 + src/actions.cpp | 4 ++-- src/config_wrapper.cpp | 22 +++++++++++----------- tests/gas_param_tests.cpp | 8 +------- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/include/evm_runtime/config_wrapper.hpp b/include/evm_runtime/config_wrapper.hpp index 70d3b90d..21cce268 100644 --- a/include/evm_runtime/config_wrapper.hpp +++ b/include/evm_runtime/config_wrapper.hpp @@ -42,8 +42,8 @@ struct config_wrapper { void set_fee_parameters(const fee_parameters& fee_params, bool allow_any_to_be_unspecified); - void update_gas_params(eosio::asset ram_price_mb, uint64_t minimum_gas_price); - void update_gas_params2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset, std::optional minimum_gas_price); + void update_consensus_parameters(eosio::asset ram_price_mb, uint64_t minimum_gas_price); + void update_consensus_parameters2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset, std::optional minimum_gas_price); std::pair get_consensus_param_and_maybe_promote(); diff --git a/include/evm_runtime/types.hpp b/include/evm_runtime/types.hpp index bb8cd964..67bac0e9 100644 --- a/include/evm_runtime/types.hpp +++ b/include/evm_runtime/types.hpp @@ -15,6 +15,7 @@ namespace evm_runtime { static constexpr uint32_t ninety_percent = 90'000; static constexpr uint32_t hundred_percent = 100'000; static constexpr uint64_t one_gwei = 1'000'000'000ull; + static constexpr uint64_t gas_sset_min = 2900; constexpr unsigned evm_precision = 18; constexpr eosio::name token_account(eosio::name(TOKEN_ACCOUNT_NAME)); diff --git a/src/actions.cpp b/src/actions.cpp index d83a89fa..3470fd02 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -797,7 +797,7 @@ void evm_contract::setversion(uint64_t version) { void evm_contract::updtgasparam(eosio::asset ram_price_mb, uint64_t minimum_gas_price) { require_auth(get_self()); - _config->update_gas_params(ram_price_mb, minimum_gas_price); + _config->update_consensus_parameters(ram_price_mb, minimum_gas_price); } void evm_contract::setgasparam(uint64_t gas_txnewaccount, @@ -806,7 +806,7 @@ void evm_contract::setgasparam(uint64_t gas_txnewaccount, uint64_t gas_codedeposit, uint64_t gas_sset) { require_auth(get_self()); - _config->update_gas_params2(gas_txnewaccount, + _config->update_consensus_parameters2(gas_txnewaccount, gas_newaccount, gas_txcreate, gas_codedeposit, diff --git a/src/config_wrapper.cpp b/src/config_wrapper.cpp index 0aa0160d..91401bf9 100644 --- a/src/config_wrapper.cpp +++ b/src/config_wrapper.cpp @@ -127,9 +127,9 @@ void config_wrapper::set_fee_parameters(const fee_parameters& fee_params, { if (fee_params.gas_price.has_value()) { eosio::check(*fee_params.gas_price >= one_gwei, "gas_price must >= 1Gwei"); - if (_cached_config.evm_version.has_value() && _cached_config.evm_version->cached_version >= 1) { + if (get_evm_version() >= 1) { // activate in the next evm block - this->update_gas_params2(std::optional(), /* gas_txnewaccount */ + this->update_consensus_parameters2(std::optional(), /* gas_txnewaccount */ std::optional(), /* gas_newaccount */ std::optional(), /* gas_txcreate */ std::optional(), /* gas_codedeposit */ @@ -164,7 +164,7 @@ void config_wrapper::set_fee_parameters(const fee_parameters& fee_params, set_dirty(); } -void config_wrapper::update_gas_params(eosio::asset ram_price_mb, uint64_t minimum_gas_price) { +void config_wrapper::update_consensus_parameters(eosio::asset ram_price_mb, uint64_t minimum_gas_price) { eosio::check(ram_price_mb.symbol == token_symbol, "invalid price symbol"); eosio::check(minimum_gas_price >= one_gwei, "gas_price must >= 1Gwei"); @@ -175,25 +175,25 @@ void config_wrapper::update_gas_params(eosio::asset ram_price_mb, uint64_t minim constexpr uint64_t contract_fixed_bytes = 606; constexpr uint64_t storage_slot_bytes = 346; + constexpr uint64_t max_gas_per_byte = (1ull << 43) - 1; + eosio::check(gas_per_byte_f >= 0.0, "gas_per_byte must >= 0"); - eosio::check(gas_per_byte_f * contract_fixed_bytes < (double)(0x7ffffffffffull), "gas_per_byte too big"); + eosio::check(gas_per_byte_f * contract_fixed_bytes < (double)(max_gas_per_byte), "gas_per_byte too big"); uint64_t gas_per_byte = (uint64_t)(gas_per_byte_f + 1.0); - this->update_gas_params2(account_bytes * gas_per_byte, /* gas_txnewaccount */ + this->update_consensus_parameters2(account_bytes * gas_per_byte, /* gas_txnewaccount */ account_bytes * gas_per_byte, /* gas_newaccount */ contract_fixed_bytes * gas_per_byte, /*gas_txcreate*/ gas_per_byte,/*gas_codedeposit*/ - 2900 + storage_slot_bytes * gas_per_byte,/*gas_sset*/ + gas_sset_min + storage_slot_bytes * gas_per_byte,/*gas_sset*/ minimum_gas_price /*minimum_gas_price*/ ); } -void config_wrapper::update_gas_params2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset, std::optional minimum_gas_price) +void config_wrapper::update_consensus_parameters2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset, std::optional minimum_gas_price) { - // for simplicity, ensure last (cached) evm_version >= 1, not touching promote logic - eosio::check(_cached_config.evm_version.has_value() && _cached_config.evm_version->cached_version >= 1, - "evm_version must >= 1"); + eosio::check(get_evm_version() >= 1, "evm_version must >= 1"); // should not happen eosio::check(_cached_config.consensus_parameter.has_value(), "consensus_parameter not exist"); @@ -208,7 +208,7 @@ void config_wrapper::update_gas_params2(std::optional gas_txnewaccount if (gas_txcreate.has_value()) v.gas_parameter.gas_txcreate = *gas_txcreate; if (gas_codedeposit.has_value()) v.gas_parameter.gas_codedeposit = *gas_codedeposit; if (gas_sset.has_value()) { - eosio::check(*gas_sset >= 2900, "G_sset must >= 2900"); + eosio::check(*gas_sset >= gas_sset_min, "gas_sset too small"); v.gas_parameter.gas_sset = *gas_sset; } if (minimum_gas_price.has_value()) v.minimum_gas_price = *minimum_gas_price; diff --git a/tests/gas_param_tests.cpp b/tests/gas_param_tests.cpp index b4ee7ece..590d3adf 100644 --- a/tests/gas_param_tests.cpp +++ b/tests/gas_param_tests.cpp @@ -60,12 +60,6 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try { produce_block(); produce_block(); - // require promoted evm_version larger or equal to 1 - BOOST_REQUIRE_EXCEPTION( - updtgasparam(asset(10'0000, native_symbol), 1'000'000'000, evm_account_name), - eosio_assert_message_exception, - eosio_assert_message_is("evm_version must >= 1")); - // kick of setverion, evmtx event generated { evm_eoa recipient; @@ -104,7 +98,7 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try { BOOST_REQUIRE_EXCEPTION( setgasparam(21000,21000,21000,21000,2899, evm_account_name), eosio_assert_message_exception, - eosio_assert_message_is("G_sset must >= 2900")); + eosio_assert_message_is("gas_sset too small")); updtgasparam(asset(10'0000, native_symbol), 1'000'000'000, evm_account_name);