Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/handler/src/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ where
exec_result: &mut Self::ExecResult,
init_and_floor_gas: handler_interface::InitialAndFloorGas,
) {
let gas_result = exec_result.gas_mut();
if gas_result.spent() < init_and_floor_gas.floor_gas {
let _ = gas_result.record_cost(init_and_floor_gas.floor_gas - gas_result.spent());
let gas = exec_result.gas_mut();
// EIP-7623: Increase calldata cost
// spend at least a gas_floor amount of gas.
if gas.spent_sub_refunded() < init_and_floor_gas.floor_gas {
gas.set_spent(init_and_floor_gas.floor_gas);
// clear refund
gas.set_refund(0);
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/interpreter/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ impl Gas {
self.limit - self.remaining
}

/// Returns the total amount of gas spent, minus the refunded gas.
#[inline]
pub const fn spent_sub_refunded(&self) -> u64 {
self.spent().saturating_sub(self.refunded as u64)
}

/// Returns the amount of gas remaining.
#[inline]
pub const fn remaining(&self) -> u64 {
Expand Down Expand Up @@ -119,6 +125,12 @@ impl Gas {
self.refunded = refund;
}

/// Set a spent value. This overrides the current spent value.
#[inline]
pub fn set_spent(&mut self, spent: u64) {
self.remaining = self.limit.saturating_sub(spent);
}

/// Records an explicit cost.
///
/// Returns `false` if the gas limit is exceeded.
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ where
let mut exec_result = exec.last_frame_result(context, frame_result)?;

let post_exec = self.handler.post_execution();
// Check gas floor
post_exec.eip7623_check_gas_floor(context, &mut exec_result, init_and_floor_gas);
// Calculate final refund and add EIP-7702 refund to gas.
post_exec.refund(context, &mut exec_result, eip7702_gas_refund);
// Check gas floor
post_exec.eip7623_check_gas_floor(context, &mut exec_result, init_and_floor_gas);
// Reimburse the caller
post_exec.reimburse_caller(context, &mut exec_result)?;
// Reward beneficiary
Expand Down
13 changes: 8 additions & 5 deletions crates/statetest-types/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use revm::{
primitives::{Address, Bytes, HashMap, B256},
state::AccountInfo,
};
use revm::primitives::{Address, Bytes, HashMap, B256};
use serde::Deserialize;

use crate::transaction::TxPartIndices;
use crate::{transaction::TxPartIndices, AccountInfo};

/// State test indexed state result deserialization.
#[derive(Debug, PartialEq, Eq, Deserialize)]
Expand All @@ -23,6 +20,12 @@ pub struct Test {
/// Logs root
pub logs: B256,

/// Output state.
///
/// Note: Not used.
#[serde(default)]
state: HashMap<Address, AccountInfo>,

/// Tx bytes
pub txbytes: Option<Bytes>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,30 @@
"data": 0,
"gas": 0,
"value": 0
},
"state": {
"0x0000000000000000000000000000000000001000": {
"nonce": "0x01",
"balance": "0x04",
"code": "0x5854505854",
"storage": {}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x2cd931",
"code": "0x",
"storage": {}
}
}
}
]
},
"_info": {
"hash": "0x398e2b06c420d105024fdaf2cb8d718dca2263da0a1c71b97119cc3bf156a611",
"hash": "0x813518336344739b9f7d43d8bead1ec6bb7f6bd22c3abdb95ba468734b8ddd82",
"comment": "`execution-spec-tests` generated test",
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
"description": "Test function documentation:\n\n Test type 1 transaction.",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/berlin/eip2930_access_list/test_acl.py#L15",
"description": "Test function documentation:\nTest type 1 transaction.",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/berlin/eip2930_access_list/test_acl.py#L19",
"fixture_format": "state_test",
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2930.md",
"reference-spec-version": "c9db53a936c5c9cbe2db32ba0d1b86c4c6e73534"
Expand Down
Loading