Skip to content

Commit

Permalink
Merge pull request #692 from eosnetworkfoundation/elmato/use-gas-para…
Browse files Browse the repository at this point in the history
…meters

Use active gas parameters in ExecutionState
  • Loading branch information
elmato authored Mar 22, 2024
2 parents 3cc42ee + 587589b commit d232ace
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/evm_runtime/config_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct config_wrapper {
void update_consensus_parameters(eosio::asset ram_price_mb, uint64_t minimum_gas_price);
void update_consensus_parameters2(std::optional<uint64_t> gas_txnewaccount, std::optional<uint64_t> gas_newaccount, std::optional<uint64_t> gas_txcreate, std::optional<uint64_t> gas_codedeposit, std::optional<uint64_t> gas_sset, std::optional<uint64_t> minimum_gas_price);

const consensus_parameter_data_type& get_consensus_param();
std::pair<const consensus_parameter_data_type &, bool> get_consensus_param_and_maybe_promote();

private:
Expand Down
2 changes: 1 addition & 1 deletion silkworm
Submodule silkworm updated 78 files
+6 −3 CMakeLists.txt
+5 −1 cmake/conan.cmake
+12 −0 cmake/profiles/linux_arm_gcc_11_debug
+12 −0 cmake/profiles/linux_arm_gcc_11_release
+1 −1 cmd/dev/check_changes.cpp
+1 −1 cmd/dev/scan_txs.cpp
+2 −2 cmd/state-transition/state_transition.cpp
+3 −3 cmd/test/ethereum.cpp
+38 −0 eosevm/CMakeLists.txt
+85 −0 eosevm/consensus_parameters.cpp
+58 −0 eosevm/consensus_parameters.hpp
+12 −5 silkworm/core/chain/config.cpp
+1 −0 silkworm/core/chain/config.hpp
+6 −0 silkworm/core/common/test_util.hpp
+41 −13 silkworm/core/execution/evm.cpp
+18 −1 silkworm/core/execution/evm.hpp
+77 −12 silkworm/core/execution/evm_test.cpp
+2 −2 silkworm/core/execution/execution.hpp
+2 −2 silkworm/core/execution/execution_test.cpp
+3 −3 silkworm/core/execution/processor.cpp
+1 −1 silkworm/core/execution/processor.hpp
+7 −9 silkworm/core/execution/processor_test.cpp
+3 −1 silkworm/core/protocol/base_rule_set.cpp
+3 −3 silkworm/core/protocol/blockchain.cpp
+2 −1 silkworm/core/protocol/blockchain.hpp
+2 −2 silkworm/core/protocol/intrinsic_gas.cpp
+2 −3 silkworm/core/protocol/intrinsic_gas.hpp
+18 −2 silkworm/core/protocol/intrinsic_gas_test.cpp
+5 −4 silkworm/core/protocol/validation.cpp
+4 −2 silkworm/core/protocol/validation.hpp
+16 −16 silkworm/core/protocol/validation_test.cpp
+28 −1 silkworm/core/types/block.cpp
+5 −0 silkworm/core/types/block.hpp
+2 −0 silkworm/core/types/block_test.cpp
+1 −0 silkworm/node/CMakeLists.txt
+53 −0 silkworm/node/db/access_layer.cpp
+20 −0 silkworm/node/db/access_layer.hpp
+104 −3 silkworm/node/db/access_layer_test.cpp
+8 −0 silkworm/node/db/tables.hpp
+27 −0 silkworm/node/db/util.cpp
+11 −0 silkworm/node/db/util.hpp
+8 −1 silkworm/node/db/util_test.cpp
+3 −3 silkworm/node/stagedsync/stages/_test.cpp
+20 −0 silkworm/node/stagedsync/stages/stage.cpp
+5 −0 silkworm/node/stagedsync/stages/stage.hpp
+5 −3 silkworm/node/stagedsync/stages/stage_bodies.cpp
+1 −1 silkworm/node/stagedsync/stages/stage_bodies.hpp
+2 −2 silkworm/node/stagedsync/stages/stage_bodies_test.cpp
+3 −1 silkworm/node/stagedsync/stages/stage_execution.cpp
+3 −3 silkworm/node/stagedsync/stages/stage_history_index_test.cpp
+26 −0 silkworm/silkrpc/commands/debug_api_test.cpp
+20 −6 silkworm/silkrpc/commands/eth_api.cpp
+1 −0 silkworm/silkrpc/commands/eth_api.hpp
+7 −0 silkworm/silkrpc/commands/ots_api.cpp
+1 −1 silkworm/silkrpc/common/util.cpp
+2 −2 silkworm/silkrpc/common/util_test.cpp
+26 −0 silkworm/silkrpc/core/account_dumper_test.cpp
+26 −0 silkworm/silkrpc/core/account_walker_test.cpp
+7 −4 silkworm/silkrpc/core/estimate_gas_oracle.cpp
+1 −1 silkworm/silkrpc/core/estimate_gas_oracle.hpp
+15 −15 silkworm/silkrpc/core/estimate_gas_oracle_test.cpp
+10 −5 silkworm/silkrpc/core/evm_executor.cpp
+4 −2 silkworm/silkrpc/core/evm_executor.hpp
+26 −0 silkworm/silkrpc/core/gas_parameters.cpp
+18 −0 silkworm/silkrpc/core/gas_parameters.hpp
+14 −4 silkworm/silkrpc/core/rawdb/chain.cpp
+2 −0 silkworm/silkrpc/core/rawdb/chain.hpp
+26 −0 silkworm/silkrpc/core/storage_walker_test.cpp
+4 −0 silkworm/silkrpc/ethdb/cursor.hpp
+32 −0 silkworm/silkrpc/ethdb/file/local_cursor.cpp
+4 −0 silkworm/silkrpc/ethdb/file/local_cursor.hpp
+24 −0 silkworm/silkrpc/ethdb/kv/remote_cursor.cpp
+4 −0 silkworm/silkrpc/ethdb/kv/remote_cursor.hpp
+16 −0 silkworm/silkrpc/json/block.cpp
+4 −0 silkworm/silkrpc/test/mock_cursor.hpp
+1 −1 silkworm/silkrpc/test/mock_estimate_gas_oracle.hpp
+1 −1 silkworm/silkrpc/types/block.hpp
+1 −1 third_party/evmone
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ target_compile_options(evm_runtime PUBLIC --no-missing-ricardian-clause)
if (WITH_LARGE_STACK)
target_link_options(evm_runtime PUBLIC --stack-size=50000000)
else()
target_link_options(evm_runtime PUBLIC --stack-size=36000)
target_link_options(evm_runtime PUBLIC --stack-size=35248)
endif()
31 changes: 28 additions & 3 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ Receipt evm_contract::execute_tx(const runtime_config& rc, eosio::name miner, Bl
}

ValidationResult r = silkworm::protocol::pre_validate_transaction(tx, ep.evm().revision(), ep.evm().config().chain_id,
ep.evm().block().header.base_fee_per_gas, ep.evm().block().header.data_gas_price());
ep.evm().block().header.base_fee_per_gas, ep.evm().block().header.data_gas_price(),
ep.evm().get_eos_evm_version(), ep.evm().get_gas_params());

check_result( r, tx, "pre_validate_transaction error" );
r = silkworm::protocol::validate_transaction(tx, ep.state(), ep.available_gas());
check_result( r, tx, "validate_transaction error" );
Expand Down Expand Up @@ -333,7 +335,19 @@ void evm_contract::exec(const exec_input& input, const std::optional<exec_callba
evm_runtime::state state{get_self(), get_self(), true};
IntraBlockState ibstate{state};

EVM evm{block, ibstate, *found_chain_config.value().second};
const auto& consensus_param = _config->get_consensus_param();

auto gas_params = std::visit([&](const auto &v) {
return evmone::gas_parameters(
v.gas_parameter.gas_txnewaccount,
v.gas_parameter.gas_newaccount,
v.gas_parameter.gas_txcreate,
v.gas_parameter.gas_codedeposit,
v.gas_parameter.gas_sset
);
}, consensus_param);

EVM evm{block, ibstate, *found_chain_config.value().second, gas_params};

Transaction txn;
txn.to = to_address(input.to);
Expand Down Expand Up @@ -440,7 +454,18 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
silkworm::protocol::TrustRuleSet engine{*found_chain_config->second};

evm_runtime::state state{get_self(), get_self(), false, false};
silkworm::ExecutionProcessor ep{block, engine, state, *found_chain_config->second};

auto gas_params = std::visit([&](const auto &v) {
return evmone::gas_parameters(
v.gas_parameter.gas_txnewaccount,
v.gas_parameter.gas_newaccount,
v.gas_parameter.gas_txcreate,
v.gas_parameter.gas_codedeposit,
v.gas_parameter.gas_sset
);
}, gas_param_pair.first);

silkworm::ExecutionProcessor ep{block, engine, state, *found_chain_config->second, gas_params};

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");
Expand Down
6 changes: 6 additions & 0 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ void config_wrapper::update_consensus_parameters2(std::optional<uint64_t> gas_tx
set_dirty();
}

const consensus_parameter_data_type& config_wrapper::get_consensus_param() {
// should not happen
eosio::check(_cached_config.consensus_parameter.has_value(), "consensus_parameter not exist");
return _cached_config.consensus_parameter->get_consensus_param(_cached_config.genesis_time, get_current_time());
}

std::pair<const consensus_parameter_data_type &, bool> config_wrapper::get_consensus_param_and_maybe_promote() {

// should not happen
Expand Down
2 changes: 1 addition & 1 deletion src/test_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace silkworm;

evm_runtime::test::engine engine{evm_runtime::test::kTestNetwork};
evm_runtime::state state{get_self(), get_self()};
silkworm::ExecutionProcessor ep{block, engine, state, evm_runtime::test::kTestNetwork};
silkworm::ExecutionProcessor ep{block, engine, state, evm_runtime::test::kTestNetwork, {}};

if(orlptx) {
Transaction tx;
Expand Down
18 changes: 18 additions & 0 deletions tests/basic_evm_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,24 @@ std::optional<account_object> basic_evm_tester::find_account_by_id(uint64_t id)
return convert_to_account_object(row);
}

intx::uint128 basic_evm_tester::tx_data_cost(const silkworm::Transaction& txn) const {
intx::uint128 gas{0};

const intx::uint128 data_len{txn.data.length()};
if (data_len == 0) {
return gas;
}

const intx::uint128 non_zero_bytes{as_range::count_if(txn.data, [](uint8_t c) { return c != 0; })};
const intx::uint128 nonZeroGas{silkworm::protocol::fee::kGTxDataNonZeroIstanbul};
gas += non_zero_bytes * nonZeroGas;
const intx::uint128 zero_bytes{data_len - non_zero_bytes};
gas += zero_bytes * silkworm::protocol::fee::kGTxDataZero;

return gas;
}


bool basic_evm_tester::scan_account_storage(uint64_t account_id, std::function<bool(storage_slot)> visitor) const
{
static constexpr eosio::chain::name storage_table_name = "storage"_n;
Expand Down
3 changes: 3 additions & 0 deletions tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <silkworm/core/rlp/encode.hpp>
#include <silkworm/core/common/util.hpp>
#include <silkworm/core/execution/address.hpp>
#include <silkworm/core/protocol/param.hpp>

#include <secp256k1.h>

Expand Down Expand Up @@ -467,6 +468,8 @@ class basic_evm_tester : public evm_validating_tester
bool scan_gcstore(std::function<bool(gcstore)> visitor) const;
bool scan_account_code(std::function<bool(account_code)> visitor) const;
void scan_balances(std::function<bool(evm_test::vault_balance_row)> visitor) const;

intx::uint128 tx_data_cost(const silkworm::Transaction& txn) const;
};

inline constexpr intx::uint256 operator"" _wei(const char* s) { return intx::from_string<intx::uint256>(s); }
Expand Down
Loading

0 comments on commit d232ace

Please sign in to comment.