Skip to content

Commit

Permalink
fix refund cnt
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Aug 27, 2024
1 parent 61b3567 commit 3098302
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
4 changes: 1 addition & 3 deletions bins/revme/src/cmd/statetest/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion crates/interpreter/src/gas/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ pub fn call<H: Host + ?Sized, SPEC: Spec>(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 {
Expand Down
4 changes: 3 additions & 1 deletion crates/interpreter/src/instructions/contract/call_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn calc_call_gas<SPEC: Spec>(
local_gas_limit: u64,
) -> Option<u64> {
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
Expand All @@ -64,5 +64,7 @@ pub fn calc_call_gas<SPEC: Spec>(
local_gas_limit
};

println!("gas_limit: {}", gas_limit);

Some(gas_limit)
}
2 changes: 1 addition & 1 deletion crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions crates/revm/src/handler/mainnet/pre_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn apply_eip7702_auth_list<SPEC: Spec, EXT, DB: Database>(
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]
Expand Down Expand Up @@ -149,8 +149,8 @@ pub fn apply_eip7702_auth_list<SPEC: Spec, EXT, DB: Database>(
}

// 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.
Expand All @@ -163,8 +163,8 @@ pub fn apply_eip7702_auth_list<SPEC: Spec, EXT, DB: Database>(
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)
}

0 comments on commit 3098302

Please sign in to comment.