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

fix: enforce correct parity encoding for typed transactions #1305

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Sep 18, 2024

Motivation

Enforces that we only accept 0 or 1 as parity for typed transactions, and only 27, 28 or 35.. for legacy transactions

ref paradigmxyz/reth#10758

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@klkvr
Copy link
Member Author

klkvr commented Sep 18, 2024

Wondering if we should consider introducing parity generic on signature? this might end up hacky, but likely can be done in a nice way with some helper traits

@klkvr
Copy link
Member Author

klkvr commented Sep 18, 2024

eg we could do

trait SignableTransaction {
    type Signature;
    ...
}

struct Signed<Unsigned: SignableTransaction> {
    tx: Unsigned,
    signature: Unsigned::Signature,
}

impl SignableTransaction for TxLegacy {
    type Signature = primitives::Signature<LegacyParity>;
    ...
}

impl SignableTransaction for TxLegacy {
    // default generic would be a simple bool
    type Signature = primitives::Signature;
    ...
}

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we def need to enforce this on decoding, but I think we have a problem an encoding where it would be possible to use an incorrect signature, right?

so making the sig tx specific makes sense, if we can make the ergonomics right, because dealing with these things manually is a pita

@klkvr
Copy link
Member Author

klkvr commented Sep 18, 2024

we def need to enforce this on decoding, but I think we have a problem an encoding where it would be possible to use an incorrect signature, right?

yeah, we enforce correct parity in into_signed right now:

// Drop any v chain id value to ensure the signature format is correct at the time of
// combination for an EIP-1559 transaction. V should indicate the y-parity of the
// signature.
let signature = signature.with_parity_bool();

@klkvr klkvr merged commit 2f65d0b into main Sep 18, 2024
26 checks passed
@klkvr klkvr deleted the klkvr/safety-tx-decoding branch September 18, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants