Skip to content

Commit 12062b0

Browse files
authored
chore: re-use num_words in gas::cost_per_word (#1371)
1 parent 3e089f3 commit 12062b0

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

crates/interpreter/src/gas/calc.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
use revm_primitives::Bytes;
2-
31
use super::constants::*;
42
use crate::{
5-
primitives::{
6-
Address, SpecId,
7-
SpecId::{BERLIN, SPURIOUS_DRAGON, TANGERINE},
8-
U256,
9-
},
3+
num_words,
4+
primitives::{Address, Bytes, SpecId, U256},
105
SelfDestructResult,
116
};
127
use std::vec::Vec;
@@ -155,7 +150,7 @@ pub const fn keccak256_cost(len: u64) -> Option<u64> {
155150
/// Calculate the cost of buffer per word.
156151
#[inline]
157152
pub const fn cost_per_word(len: u64, multiple: u64) -> Option<u64> {
158-
multiple.checked_mul(len.div_ceil(32))
153+
multiple.checked_mul(num_words(len))
159154
}
160155

161156
/// EIP-3860: Limit and meter initcode
@@ -302,9 +297,9 @@ pub const fn call_cost(
302297
new_account_accounting: bool,
303298
) -> u64 {
304299
// Account access.
305-
let mut gas = if spec_id.is_enabled_in(BERLIN) {
300+
let mut gas = if spec_id.is_enabled_in(SpecId::BERLIN) {
306301
warm_cold_cost(is_cold)
307-
} else if spec_id.is_enabled_in(TANGERINE) {
302+
} else if spec_id.is_enabled_in(SpecId::TANGERINE) {
308303
// EIP-150: Gas cost changes for IO-heavy operations
309304
700
310305
} else {
@@ -319,7 +314,7 @@ pub const fn call_cost(
319314
// new account cost
320315
if new_account_accounting {
321316
// EIP-161: State trie clearing (invariant-preserving alternative)
322-
if spec_id.is_enabled_in(SPURIOUS_DRAGON) {
317+
if spec_id.is_enabled_in(SpecId::SPURIOUS_DRAGON) {
323318
// account only if there is value transferred.
324319
if transfers_value {
325320
gas += NEWACCOUNT;

0 commit comments

Comments
 (0)