From bb1c30f2bd20ca9d1ace80673efb05f077f924ed Mon Sep 17 00:00:00 2001 From: Iaroslav Mazur Date: Sat, 30 Dec 2023 14:35:39 +0100 Subject: [PATCH] refactor(interpreter): simplify the logic of calc.new_cost() --- crates/interpreter/src/gas/calc.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/interpreter/src/gas/calc.rs b/crates/interpreter/src/gas/calc.rs index 6a55c39f..9e7a2f19 100644 --- a/crates/interpreter/src/gas/calc.rs +++ b/crates/interpreter/src/gas/calc.rs @@ -285,22 +285,16 @@ fn xfer_cost(is_call_or_callcode: bool, transfers_value: bool) -> u64 { #[inline] fn new_cost(is_call_or_staticcall: bool, is_new: bool, transfers_value: bool) -> u64 { - if is_call_or_staticcall { - // EIP-161: State trie clearing (invariant-preserving alternative) - if SPEC::enabled(SPURIOUS_DRAGON) { - if transfers_value && is_new { - NEWACCOUNT - } else { - 0 - } - } else if is_new { - NEWACCOUNT - } else { - 0 - } - } else { - 0 + if !is_call_or_staticcall || !is_new { + return 0; } + + // EIP-161: State trie clearing (invariant-preserving alternative) + if SPEC::enabled(SPURIOUS_DRAGON) && !transfers_value { + return 0; + } + + NEWACCOUNT } #[inline]