Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: EIP-7702 Add u8 validity #1824

Merged
merged 1 commit into from
Oct 17, 2024
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
23 changes: 23 additions & 0 deletions crates/primitives/src/eip7702/authorization_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down