Skip to content

fix: enforce correct parity encoding for typed transactions#1305

Merged
klkvr merged 1 commit intomainfrom
klkvr/safety-tx-decoding
Sep 18, 2024
Merged

fix: enforce correct parity encoding for typed transactions#1305
klkvr merged 1 commit intomainfrom
klkvr/safety-tx-decoding

Conversation

@klkvr
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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();

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