Skip to content

Commit

Permalink
chore: re-use num_words in gas::cost_per_word (bluealloy#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored May 2, 2024
1 parent 3e089f3 commit 12062b0
Showing 1 changed file with 6 additions and 11 deletions.
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

0 comments on commit 12062b0

Please sign in to comment.