Skip to content

Commit

Permalink
Update gas floor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Jan 16, 2025
1 parent eac82bc commit 95fcbf4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
21 changes: 8 additions & 13 deletions evm-tests/jsontests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub mod eip7623 {

/// Calculate the transaction cost floor as specified in EIP-7623.
#[must_use]
pub fn calc_tx_floor_cost(tokens_in_calldata: u64) -> u64 {
pub const fn calc_tx_floor_cost(tokens_in_calldata: u64) -> u64 {
tokens_in_calldata * TOTAL_COST_FLOOR_PER_TOKEN + 21_000
}
}
Expand Down Expand Up @@ -466,7 +466,7 @@ pub mod transaction {

if *spec >= ForkSpec::Prague {
// EIP-7623 validation
let floor_gas = eip7623::calc_tx_floor_cost(eip7623::get_tokens_in_calldata(&*tx.data));
let floor_gas = eip7623::calc_tx_floor_cost(eip7623::get_tokens_in_calldata(&tx.data));
if floor_gas > tx.gas_limit.into() {
return Err(InvalidTxReason::GasFloorMoreThanGasLimit);
}
Expand All @@ -483,22 +483,17 @@ pub mod transaction {
// Other validation step inside EVM transact logic.
for auth in test_tx.authorization_list.iter() {
// 1. Verify the chain id is either 0 or the chain’s current ID.
let mut is_valid = if auth.chain_id.0 > U256::from(u64::MAX) {
false
} else {
auth.chain_id.0 == U256::from(0) || auth.chain_id.0 == vicinity.chain_id
};
// 3. `authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s]`
let mut is_valid = auth.chain_id.0 <= U256::from(u64::MAX)
&& (auth.chain_id.0 == U256::from(0) || auth.chain_id.0 == vicinity.chain_id);

// 3. `authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s]`
// Validate the signature, as in tests it is possible to have invalid signatures values.
let v = auth.v.0 .0;
if !(v[0] < u64::from(u8::MAX) && v[1..4].iter().all(|&elem| elem == 0)) {
is_valid = false;
}
// Value `v` shouldn't be greater then 1
if v[0] > 1 {
let v = auth.v.0;
if v > U256::from(1) {
is_valid = false;
}

// EIP-2 validation
if auth.s.0 > eip7702::SECP256K1N_HALF {
is_valid = false;
Expand Down
10 changes: 5 additions & 5 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
/// 9. Increase the `nonce` of `authority` by one.
///
/// It means, that steps 1,3 of spec must be passed before calling this function:
/// 1 Verify the chain id is either 0 or the chain’s current ID.
/// 1. Verify the chain id is either 0 or the chain’s current ID.
/// 3. `authority = ecrecover(...)`
///
/// See: [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702#behavior)
Expand Down Expand Up @@ -994,13 +994,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
// 8. Set the code of authority to be `0xef0100 || address`. This is a delegation designation.
// * As a special case, if address is 0x0000000000000000000000000000000000000000 do not write the designation.
// Clear the account’s code.
let mut delegation_clearing = false;
if authority.address.is_zero() {
delegation_clearing = true;
let delegation_clearing = if authority.address.is_zero() {
state.set_code(authority.authority, Vec::new());
true
} else {
state.set_code(authority.authority, authority.delegation_code());
}
false
};
// 9. Increase the nonce of authority by one.
state.inc_nonce(authority.authority)?;

Expand Down

0 comments on commit 95fcbf4

Please sign in to comment.