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

chore: re-use num_words in gas::cost_per_word #1371

Merged
merged 1 commit into from
May 2, 2024
Merged
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
17 changes: 6 additions & 11 deletions crates/interpreter/src/gas/calc.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use revm_primitives::Bytes;

use super::constants::*;
use crate::{
primitives::{
Address, SpecId,
SpecId::{BERLIN, SPURIOUS_DRAGON, TANGERINE},
U256,
},
num_words,
primitives::{Address, Bytes, SpecId, U256},
SelfDestructResult,
};
use std::vec::Vec;
Expand Down Expand Up @@ -155,7 +150,7 @@ pub const fn keccak256_cost(len: u64) -> Option<u64> {
/// Calculate the cost of buffer per word.
#[inline]
pub const fn cost_per_word(len: u64, multiple: u64) -> Option<u64> {
multiple.checked_mul(len.div_ceil(32))
multiple.checked_mul(num_words(len))
}

/// EIP-3860: Limit and meter initcode
Expand Down Expand Up @@ -302,9 +297,9 @@ pub const fn call_cost(
new_account_accounting: bool,
) -> u64 {
// Account access.
let mut gas = if spec_id.is_enabled_in(BERLIN) {
let mut gas = if spec_id.is_enabled_in(SpecId::BERLIN) {
warm_cold_cost(is_cold)
} else if spec_id.is_enabled_in(TANGERINE) {
} else if spec_id.is_enabled_in(SpecId::TANGERINE) {
// EIP-150: Gas cost changes for IO-heavy operations
700
} else {
Expand All @@ -319,7 +314,7 @@ pub const fn call_cost(
// new account cost
if new_account_accounting {
// EIP-161: State trie clearing (invariant-preserving alternative)
if spec_id.is_enabled_in(SPURIOUS_DRAGON) {
if spec_id.is_enabled_in(SpecId::SPURIOUS_DRAGON) {
// account only if there is value transferred.
if transfers_value {
gas += NEWACCOUNT;
Expand Down
Loading