From 3098302551c7229e460933edf260997ceebd3036 Mon Sep 17 00:00:00 2001 From: rakita Date: Tue, 27 Aug 2024 19:57:21 +0200 Subject: [PATCH] fix refund cnt --- bins/revme/src/cmd/statetest/models/mod.rs | 4 +--- crates/interpreter/src/gas/constants.rs | 1 - crates/interpreter/src/instructions/contract.rs | 2 ++ .../src/instructions/contract/call_helpers.rs | 4 +++- crates/interpreter/src/instructions/host.rs | 2 +- crates/revm/src/handler/mainnet/pre_execution.rs | 10 +++++----- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bins/revme/src/cmd/statetest/models/mod.rs b/bins/revme/src/cmd/statetest/models/mod.rs index f56f3d9928..f3a5786dff 100644 --- a/bins/revme/src/cmd/statetest/models/mod.rs +++ b/bins/revme/src/cmd/statetest/models/mod.rs @@ -6,9 +6,7 @@ use deserializer::*; pub use eip7702::TxEip7702; pub use spec::SpecName; -use revm::primitives::{ - AccessList, Address, AuthorizationList, Bytes, HashMap, B256, U256, -}; +use revm::primitives::{AccessList, Address, AuthorizationList, Bytes, HashMap, B256, U256}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; diff --git a/crates/interpreter/src/gas/constants.rs b/crates/interpreter/src/gas/constants.rs index 93f1422202..a9dcb0a537 100644 --- a/crates/interpreter/src/gas/constants.rs +++ b/crates/interpreter/src/gas/constants.rs @@ -47,7 +47,6 @@ pub const COLD_ACCOUNT_ACCESS_COST: u64 = 2600; pub const WARM_STORAGE_READ_COST: u64 = 100; pub const WARM_SSTORE_RESET: u64 = SSTORE_RESET - COLD_SLOAD_COST; - /// EIP-3860 : Limit and meter initcode pub const INITCODE_WORD_COST: u64 = 2; diff --git a/crates/interpreter/src/instructions/contract.rs b/crates/interpreter/src/instructions/contract.rs index 281e147582..8d929d86ec 100644 --- a/crates/interpreter/src/instructions/contract.rs +++ b/crates/interpreter/src/instructions/contract.rs @@ -429,6 +429,8 @@ pub fn call(interpreter: &mut Interpreter, host: & gas_limit = gas_limit.saturating_add(gas::CALL_STIPEND); } + println!("gas_limit (with stipend): {}", gas_limit); + // Call host to interact with target contract interpreter.next_action = InterpreterAction::Call { inputs: Box::new(CallInputs { diff --git a/crates/interpreter/src/instructions/contract/call_helpers.rs b/crates/interpreter/src/instructions/contract/call_helpers.rs index 7d758dc05b..1cdd58d82a 100644 --- a/crates/interpreter/src/instructions/contract/call_helpers.rs +++ b/crates/interpreter/src/instructions/contract/call_helpers.rs @@ -50,7 +50,7 @@ pub fn calc_call_gas( local_gas_limit: u64, ) -> Option { let call_cost = gas::call_cost(SPEC::SPEC_ID, has_transfer, account_load); - + println!("call_cost: {}", call_cost); gas!(interpreter, call_cost, None); // EIP-150: Gas cost changes for IO-heavy operations @@ -64,5 +64,7 @@ pub fn calc_call_gas( local_gas_limit }; + println!("gas_limit: {}", gas_limit); + Some(gas_limit) } diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 6263d9ca8b..612cbac5c1 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -2,7 +2,7 @@ use crate::{ gas::{self, warm_cold_cost, warm_cold_cost_with_delegation}, interpreter::Interpreter, primitives::{Bytes, Log, LogData, Spec, SpecId::*, B256, U256}, - Host, InstructionResult, + Host, InstructionResult, }; use core::cmp::min; use std::vec::Vec; diff --git a/crates/revm/src/handler/mainnet/pre_execution.rs b/crates/revm/src/handler/mainnet/pre_execution.rs index 19ea3467ed..60933ef44f 100644 --- a/crates/revm/src/handler/mainnet/pre_execution.rs +++ b/crates/revm/src/handler/mainnet/pre_execution.rs @@ -112,7 +112,7 @@ pub fn apply_eip7702_auth_list( return Ok(0); }; - let mut created_accounts_cnt = 0; + let mut refunded_accounts = 0; for authorization in authorization_list.recovered_iter() { // 1. recover authority and authorized addresses. // authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s] @@ -149,8 +149,8 @@ pub fn apply_eip7702_auth_list( } // 6. Refund the sender PER_EMPTY_ACCOUNT_COST - PER_AUTH_BASE_COST gas if authority exists in the trie. - if authority_acc.is_empty() { - created_accounts_cnt += 1; + if !authority_acc.is_empty() { + refunded_accounts += 1; } // 7. Set the code of authority to be 0xef0100 || address. This is a delegation designation. @@ -163,8 +163,8 @@ pub fn apply_eip7702_auth_list( authority_acc.mark_touch(); } - let existing_accounts = authorization_list.len() as u64 - created_accounts_cnt; let refunded_gas = - existing_accounts * (eip7702::PER_EMPTY_ACCOUNT_COST - eip7702::PER_AUTH_BASE_COST); + refunded_accounts * (eip7702::PER_EMPTY_ACCOUNT_COST - eip7702::PER_AUTH_BASE_COST); + Ok(refunded_gas) }