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

Fix gas price used in evm_contract::call_ #783

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions include/evm_runtime/evm_contract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class [[eosio::contract]] evm_contract : public contract

void process_tx(const runtime_config& rc, eosio::name miner, const transaction& tx, std::optional<uint64_t> min_inclusion_price);
void dispatch_tx(const runtime_config& rc, const transaction& tx);

uint64_t get_gas_price(uint64_t version);
};

} // namespace evm_runtime
Expand Down
43 changes: 24 additions & 19 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,8 @@ void evm_contract::exec(const exec_input& input, const std::optional<exec_callba
auto evm_version = _config->get_evm_version();

std::optional<uint64_t> base_fee_per_gas;
auto gas_prices = _config->get_gas_prices();
if (evm_version >= 1) {
if( evm_version >= 3) {
base_fee_per_gas = gas_prices.get_base_price();
} else {
base_fee_per_gas = _config->get_gas_price();
}
base_fee_per_gas = get_gas_price(evm_version);
}

eosevm::prepare_block_header(block.header, bm, get_self().value,
Expand Down Expand Up @@ -481,13 +476,8 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
Block block;

std::optional<uint64_t> base_fee_per_gas;
auto gas_prices = _config->get_gas_prices();
if (current_version >= 1) {
if( current_version >= 3) {
base_fee_per_gas = gas_prices.get_base_price();
} else {
base_fee_per_gas = _config->get_gas_price();
}
base_fee_per_gas = get_gas_price(current_version);
}

eosevm::prepare_block_header(block.header, bm, get_self().value,
Expand All @@ -512,9 +502,10 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
eosio::check(inclusion_price >= (min_inclusion_price.has_value() ? *min_inclusion_price : 0), "inclusion price must >= min_inclusion_price");
} else { // old behavior
check(tx.max_priority_fee_per_gas == tx.max_fee_per_gas, "max_priority_fee_per_gas must be equal to max_fee_per_gas");
check(tx.max_fee_per_gas >= _config->get_gas_price(), "gas price is too low");
check(tx.max_fee_per_gas >= get_gas_price(current_version), "gas price is too low");
}

auto gas_prices = _config->get_gas_prices();
auto gp = silkworm::gas_prices_t{gas_prices.overhead_price, gas_prices.storage_price};
silkworm::ExecutionProcessor ep{block, engine, state, *found_chain_config->second, gp};

Expand Down Expand Up @@ -659,7 +650,8 @@ void evm_contract::handle_account_transfer(const eosio::asset& quantity, const s
}

void evm_contract::handle_evm_transfer(eosio::asset quantity, const std::string& memo) {
if(_config->get_evm_version() >= 1) _config->process_price_queue();
auto current_version = _config->get_evm_version();
if(current_version >= 1) _config->process_price_queue();
//move all incoming quantity in to the contract's balance. the evm bridge trx will "pull" from this balance
balances balance_table(get_self(), get_self().value);
balance_table.modify(balance_table.get(get_self().value), eosio::same_payer, [&](balance& b){
Expand Down Expand Up @@ -690,11 +682,13 @@ void evm_contract::handle_evm_transfer(eosio::asset quantity, const std::string&
return gas_limit;
};

auto txn_price = get_gas_price(current_version);

Transaction txn;
txn.type = TransactionType::kLegacy;
txn.nonce = get_and_increment_nonce(get_self());
txn.max_priority_fee_per_gas = _config->get_gas_price();
txn.max_fee_per_gas = _config->get_gas_price();
txn.max_priority_fee_per_gas = txn_price;
txn.max_fee_per_gas = txn_price;
txn.to = to_evmc_address(*address_bytes);
txn.gas_limit = calculate_gas_limit(*txn.to);
txn.value = value;
Expand Down Expand Up @@ -752,13 +746,16 @@ bool evm_contract::gc(uint32_t max) {
}

void evm_contract::call_(const runtime_config& rc, intx::uint256 s, const bytes& to, intx::uint256 value, const bytes& data, uint64_t gas_limit, uint64_t nonce) {
if(_config->get_evm_version() >= 1) _config->process_price_queue();
auto current_version = _config->get_evm_version();
if(current_version >= 1) _config->process_price_queue();

auto txn_price = get_gas_price(current_version);

Transaction txn;
txn.type = TransactionType::kLegacy;
txn.nonce = nonce;
txn.max_priority_fee_per_gas = _config->get_gas_price();
txn.max_fee_per_gas = _config->get_gas_price();
txn.max_priority_fee_per_gas = txn_price;
txn.max_fee_per_gas = txn_price;
txn.gas_limit = gas_limit;
txn.value = value;
txn.data = Bytes{(const uint8_t*)data.data(), data.size()};
Expand Down Expand Up @@ -930,4 +927,12 @@ void evm_contract::setgaslimit(uint64_t ingress_gas_limit) {
_config->set_ingress_gas_limit(ingress_gas_limit);
}

uint64_t evm_contract::get_gas_price(uint64_t evm_version) {
if( evm_version >= 3) {
auto gas_prices = _config->get_gas_prices();
return gas_prices.get_base_price();
}
return _config->get_gas_price();
}

} //evm_runtime
Loading