-
Notifications
You must be signed in to change notification settings - Fork 151
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
refactor: remove Signature
generic
#719
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot, for the exact reasons you described
Instead, we now convert signature into k256::Signature during recovery.
this makes sense, we then can do different recovery even
type Error = k256::ecdsa::Error; | ||
|
||
fn try_from(value: Signature) -> Result<Self, Self::Error> { | ||
Self::from_scalars(value.r.to_be_bytes(), value.s.to_be_bytes()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recovery becomes more expensive because this is not a free conversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth looking into easier ways to construct the scalars without going through big endian bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think k256 Signature allows instantiation without going through bytes
Given that signature fields are not public, should we consider adding this to it:
#[cfg(feature = "k256")]
signature: Option<k256::ecdsa::Signature>,
which will be set to None
if invalid signature is instantiated, and recovery will just fail if its None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think k256 Signature allows instantiation without going through bytes
it doesn't
I think we should be okay with this overhead. this only affects the alloy sig -> k256 signature conversion and most common is decoding this from rlp
and getting rid of the additional footprint is more impactful, at least from reth pov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Motivation
Currently it is impossible to construct an invalid signature, because
k256
feature requires it to contain a validk256::Signature
. This makes it impossible to decode and store invalid signatures.For example, we require this in reth to keep deposit transaction signatures: https://github.com/paradigmxyz/reth/blob/42dc5eea1685385b835edd03029640609f4c4ab4/crates/primitives/src/transaction/signature.rs#L200
Solution
Remove generic from
Signature
. Instead, we now convert signature intok256::Signature
during recovery.PR Checklist