From 35842288e5d29f0902334e3e704b3082da0afa59 Mon Sep 17 00:00:00 2001 From: rakita Date: Thu, 17 Oct 2024 12:00:26 +0200 Subject: [PATCH] feat: EIP-7702 Add u8 validity --- .../src/eip7702/authorization_list.rs | 23 +++++++++++++++++++ crates/primitives/src/env.rs | 3 +++ 2 files changed, 26 insertions(+) diff --git a/crates/primitives/src/eip7702/authorization_list.rs b/crates/primitives/src/eip7702/authorization_list.rs index f4f7680c5e..7304c1206f 100644 --- a/crates/primitives/src/eip7702/authorization_list.rs +++ b/crates/primitives/src/eip7702/authorization_list.rs @@ -36,6 +36,29 @@ impl AuthorizationList { } } + /// Validate the authorization list. + pub fn is_valid(&self) -> Result<(), InvalidAuthorization> { + let validate = |auth: &SignedAuthorization| -> Result<(), InvalidAuthorization> { + // Check y_parity + if let Parity::Eip155(parity) = auth.signature().v() { + if parity > u8::MAX as u64 { + return Err(InvalidAuthorization::InvalidYParity); + } + } + Ok(()) + }; + + match self { + Self::Signed(signed) => signed.iter().try_for_each(validate)?, + Self::Recovered(recovered) => recovered + .iter() + .map(|recovered| &recovered.inner) + .try_for_each(validate)?, + }; + + Ok(()) + } + /// Return empty authorization list. pub fn empty() -> Self { Self::Recovered(Vec::new()) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index e0d856df98..e3f79411ba 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -202,6 +202,9 @@ impl Env { return Err(InvalidTransaction::EmptyAuthorizationList); } + // Validate the authorization item signature `v` to be less than u8::MAX. + auth_list.is_valid()?; + // Check if other fields are unset. if self.tx.max_fee_per_blob_gas.is_some() || !self.tx.blob_hashes.is_empty() { return Err(InvalidTransaction::AuthorizationListInvalidFields);