Skip to content

Commit

Permalink
refactor compute_access_list_cost
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jan 16, 2025
1 parent f1fe3a5 commit 95cc90a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <evmone/eof.hpp>
#include <algorithm>

#include <ranges>

namespace evmone::state
{
namespace
Expand All @@ -30,12 +32,12 @@ size_t compute_tx_data_tokens(evmc_revision rev, bytes_view data) noexcept

int64_t compute_access_list_cost(const AccessList& access_list) noexcept
{
static constexpr auto storage_key_cost = 1900;
static constexpr auto address_cost = 2400;
static constexpr auto ADDRESS_COST = 2400;
static constexpr auto STORAGE_KEY_COST = 1900;

int64_t cost = 0;
for (const auto& a : access_list)
cost += address_cost + static_cast<int64_t>(a.second.size()) * storage_key_cost;
for (const auto& keys : std::views::values(access_list))
cost += ADDRESS_COST + static_cast<int64_t>(keys.size()) * STORAGE_KEY_COST;
return cost;
}

Expand Down

0 comments on commit 95cc90a

Please sign in to comment.