Skip to content

Commit

Permalink
readd eip7702 validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Oct 8, 2024
1 parent a7f1f3f commit 73a7088
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/revm/src/handler/mainnet/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use specification::{
};
use state::Account;
use std::boxed::Box;
use transaction::{Eip1559CommonTxFields, Eip2930Tx, Eip4844Tx, Eip7702Tx, LegacyTx, Transaction};
use transaction::{
eip7702::Authorization, Eip1559CommonTxFields, Eip2930Tx, Eip4844Tx, Eip7702Tx, LegacyTx,
Transaction,
};
use wiring::{
default::{CfgEnv, EnvWiring},
result::{EVMError, EVMResultGeneric, InvalidHeader, InvalidTransaction},
Expand Down Expand Up @@ -219,6 +222,13 @@ pub fn validate_tx_env<EvmWiringT: EvmWiring, SPEC: Spec>(
if auth_list_len == 0 {
return Err(InvalidTransaction::EmptyAuthorizationList);
}

// TODO temporary here as newest EIP have removed this check.
for auth in tx.authorization_list_iter() {
if auth.is_invalid() {
return Err(InvalidTransaction::Eip7702NotSupported);
}
}
}
TransactionType::Custom => {
// custom transaction type check is not done here.
Expand Down
22 changes: 22 additions & 0 deletions crates/wiring/transaction/src/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ pub trait Authorization {

/// Returns the address that this account is delegated to.
fn address(&self) -> Address;

/// Returns true if the authorization is valid.
///
/// Temporary method needed for older EIP spec and will removed in future
/// when test get updated.
fn is_invalid(&self) -> bool;
}

// TODO move to default context
Expand All @@ -68,4 +74,20 @@ impl Authorization for RecoveredAuthorization {
fn address(&self) -> Address {
*self.inner().address()
}

fn is_invalid(&self) -> bool {
use specification::{eip2::SECP256K1N_HALF, eip7702::Parity};

// Check y_parity, Parity::Parity means that it was 0 or 1.
if !matches!(self.inner().signature().v(), Parity::Parity(_)) {
return true;
}

// Check s-value
if self.inner().signature().s() > SECP256K1N_HALF {
return true;
}

false
}
}

0 comments on commit 73a7088

Please sign in to comment.