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

[1.0->main] merge changes removing the 1gwei gas price limit #768

Merged
merged 5 commits into from
Sep 4, 2024
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
1 change: 1 addition & 0 deletions include/evm_runtime/config_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct config_wrapper {
void clear_dirty();

eosio::time_point get_current_time()const;
bool check_gas_overflow(uint64_t gas_txcreate, uint64_t gas_codedeposit) const; // return true if pass

bool _dirty = false;
bool _exists = false;
Expand Down
33 changes: 25 additions & 8 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <evm_runtime/tables.hpp>
#include <silkworm/core/protocol/param.hpp>
#include <evm_runtime/config_wrapper.hpp>

namespace evm_runtime {
Expand Down Expand Up @@ -232,10 +233,7 @@ void config_wrapper::set_fee_parameters(const fee_parameters& fee_params,
bool allow_any_to_be_unspecified)
{
if (fee_params.gas_price.has_value()) {
eosio::check(*fee_params.gas_price >= one_gwei, "gas_price must >= 1Gwei");
auto current_version = get_evm_version_and_maybe_promote();
if( current_version >= 1 ) {
eosio::check(current_version < 3, "can't set gas_price");
if(get_evm_version() >= 1) {
enqueue_gas_price(*fee_params.gas_price);
} else {
set_gas_price(*fee_params.gas_price);
Expand Down Expand Up @@ -270,23 +268,31 @@ void config_wrapper::update_consensus_parameters(eosio::asset ram_price_mb, uint
eosio::check(get_evm_version() < 3, "unable to set params");

//TODO: should we allow to call this when version>=3
constexpr char too_big_str[] = "gas_per_byte too big";
eosio::check(ram_price_mb.symbol == get_token_symbol(), "invalid price symbol");
eosio::check(gas_price >= one_gwei, "gas_price must >= 1Gwei");
eosio::check(gas_price > 0, "zero gas price is not allowed");

auto miner_cut = get_evm_version() >= 1 ? 0 : _cached_config.miner_cut;

eosio::check(miner_cut < hundred_percent, "100% miner cut is not allowed");

constexpr uint64_t overflow_limit = (1ull << 63) - 1;

eosio::check((double)overflow_limit/get_minimum_natively_representable() > ram_price_mb.amount / (1024.0 * 1024.0), too_big_str);

double gas_per_byte_f = (ram_price_mb.amount / (1024.0 * 1024.0) * get_minimum_natively_representable()) / (gas_price * static_cast<double>(hundred_percent - miner_cut) / hundred_percent);

constexpr uint64_t account_bytes = 347;
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)(max_gas_per_byte), "gas_per_byte too big");

uint64_t gas_per_byte = (uint64_t)(gas_per_byte_f + 1.0);

eosio::check((double)overflow_limit/gas_per_byte > contract_fixed_bytes, too_big_str);
eosio::check(check_gas_overflow(gas_per_byte * contract_fixed_bytes, gas_per_byte), too_big_str);

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*/
Expand Down Expand Up @@ -378,4 +384,15 @@ uint64_t config_wrapper::get_minimum_natively_representable() const {
return pow10_const(evm_precision - _cached_config.ingress_bridge_fee.symbol.precision());
}

bool config_wrapper::check_gas_overflow(uint64_t gas_txcreate, uint64_t gas_codedeposit) const {
// We use 2^63 - 1 instead of 2^64 - 1 for some margin.
constexpr uint64_t overflow_limit = (1ull << 63) - 1;

if (overflow_limit / gas_txcreate < silkworm::protocol::kMaxCodeSize)
return false;
if (overflow_limit - silkworm::protocol::kMaxCodeSize * gas_txcreate < gas_codedeposit)
return false;
return true;
}

} //namespace evm_runtime
10 changes: 0 additions & 10 deletions tests/gas_fee_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ try {
BOOST_CHECK_EQUAL(conf2.miner_cut, 90'000);
BOOST_CHECK_EQUAL(conf2.ingress_bridge_fee, conf1.ingress_bridge_fee);



BOOST_REQUIRE_EXCEPTION(setfeeparams({.gas_price = 0}),
eosio_assert_message_exception,
eosio_assert_message_is("gas_price must >= 1Gwei"));

BOOST_REQUIRE_EXCEPTION(setfeeparams({.gas_price = 999'999'999}),
eosio_assert_message_exception,
eosio_assert_message_is("gas_price must >= 1Gwei"));

// Change only gas_price to 1Gwei
setfeeparams({.gas_price = 1'000'000'000});

Expand Down
18 changes: 12 additions & 6 deletions tests/gas_param_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try {
eosio_assert_message_exception,
eosio_assert_message_is("evm_version must >= 1"));

// zero gas price
BOOST_REQUIRE_EXCEPTION(
updtgasparam(asset(10'0000, native_symbol), 0, evm_account_name),
eosio_assert_message_exception,
eosio_assert_message_is("zero gas price is not allowed"));

// fee too high
BOOST_REQUIRE_EXCEPTION(
updtgasparam(asset((1ull << 62) - 1, native_symbol), 1'000'000'000, evm_account_name),
eosio_assert_message_exception,
eosio_assert_message_is("gas_per_byte too big"));

setversion(1, evm_account_name);

produce_block();
Expand All @@ -88,12 +100,6 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try {
BOOST_ASSERT(trace->action_traces.size() >= 2 && trace->action_traces[1].act.name == "evmtx"_n);
}

// require miniumum gas at least 1 gwei
BOOST_REQUIRE_EXCEPTION(
updtgasparam(asset(10'0000, native_symbol), 999'999'999, evm_account_name),
eosio_assert_message_exception,
eosio_assert_message_is("gas_price must >= 1Gwei"));

// invalid symbol in ram_price_mb paramerter
BOOST_REQUIRE_EXCEPTION(
updtgasparam(asset(10'0000, symbol::from_string("0,EOS")), 1'000'000'000, evm_account_name),
Expand Down