diff --git a/lib/evmone/execution_state.hpp b/lib/evmone/execution_state.hpp index 9635882..abf42ba 100644 --- a/lib/evmone/execution_state.hpp +++ b/lib/evmone/execution_state.hpp @@ -145,6 +145,19 @@ struct gas_parameters { uint64_t G_codedeposit = 200; uint64_t G_sset = 20000; + static gas_parameters apply_discount_factor(const intx::uint256& inclusion_price, const uint64_t base_fee_per_gas, const uint64_t storage_price, const evmone::gas_parameters& g) { + //storage_gas_discount_factor = (storage_price)/(base_price + inclusion_price) + const intx::uint256 num(storage_price); + const intx::uint256 den(intx::uint256(base_fee_per_gas) + intx::uint256(inclusion_price)); + gas_parameters out; + out.G_txnewaccount = static_cast((num*g.G_txnewaccount)/den); + out.G_newaccount = static_cast((num*g.G_newaccount)/den); + out.G_txcreate = static_cast((num*g.G_txcreate)/den); + out.G_codedeposit = static_cast((num*g.G_codedeposit)/den); + out.G_sset = static_cast((num*g.G_sset)/den); + return out; + }; + const storage_cost_t& get_storage_cost(uint64_t version) { if(!storage_cost.has_value()) { storage_cost = generate_storage_cost_table(version); @@ -162,7 +175,7 @@ struct gas_parameters { storage_cost_t st; if( version >= 3) { int64_t cpu_gas_to_change_slot = reset - warm_access; //cpu cost of adding or removing or mutating a slot in the db - int64_t storage_gas_to_add_slot = set - reset; //storage cost of adding a new slot into the db + int64_t storage_gas_to_add_slot = set; //storage cost of adding a new slot into the db st[EVMC_STORAGE_ASSIGNED] = { 0, 0}; st[EVMC_STORAGE_ADDED] = { cpu_gas_to_change_slot, storage_gas_to_add_slot}; @@ -223,8 +236,8 @@ struct gas_state_t { int64_t apply_storage_gas_delta(int64_t storage_gas_delta){ if (eos_evm_version_ >= 3) { int64_t d = storage_gas_delta - storage_gas_refund_; - storage_gas_refund_ = std::max(-d, 0l); - const auto gas_consumed = std::max(d, 0l); + storage_gas_refund_ = std::max(-d, decltype(d){0}); + const auto gas_consumed = std::max(d, decltype(d){0}); storage_gas_consumed_ += gas_consumed; return gas_consumed; } @@ -234,8 +247,8 @@ struct gas_state_t { int64_t apply_speculative_cpu_gas_delta(int64_t cpu_gas_delta) { if (eos_evm_version_ >= 3) { int64_t d = cpu_gas_delta - cpu_gas_refund_; - cpu_gas_refund_ = std::max(-d, 0l); - const auto gas_consumed = std::max(d, 0l); + cpu_gas_refund_ = std::max(-d, decltype(d){0}); + const auto gas_consumed = std::max(d, decltype(d){0}); speculative_cpu_gas_consumed_ += gas_consumed; return gas_consumed; } @@ -262,13 +275,13 @@ struct gas_state_t { int64_t collapse() { const auto s = std::min(storage_gas_consumed_, storage_gas_refund_); const auto x = storage_gas_consumed_ - storage_gas_refund_; - storage_gas_consumed_ = std::max(x, 0l); - storage_gas_refund_ = std::max(-x, 0l); + storage_gas_consumed_ = std::max(x, decltype(x){0}); + storage_gas_refund_ = std::max(-x, decltype(x){0}); const auto c = std::min(speculative_cpu_gas_consumed_, cpu_gas_refund_); const auto y = speculative_cpu_gas_consumed_ - cpu_gas_refund_; - speculative_cpu_gas_consumed_ = std::max(y, 0l); - cpu_gas_refund_ = std::max(-y, 0l); + speculative_cpu_gas_consumed_ = std::max(y, decltype(y){0}); + cpu_gas_refund_ = std::max(-y, decltype(y){0}); return s + c; }