-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: migrate to alloy TxLegacy #9593
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.
amazing work so far!
@@ -1172,7 +1176,8 @@ impl TransactionSigned { | |||
/// only `true`. | |||
pub(crate) fn payload_len_inner(&self) -> usize { | |||
match &self.transaction { | |||
Transaction::Legacy(legacy_tx) => legacy_tx.payload_len_with_signature(&self.signature), | |||
Transaction::Legacy(legacy_tx) => legacy_tx | |||
.encoded_len_with_signature(&self.signature.as_alloy_signature(legacy_tx.chain_id)), |
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.
maybe worth exploring if we can phase out the reth-prim signature type?
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.
That would be interesting, but can it be done in a followup?
@mattsse the test Should as_alloy_signature() returns a Result and also update the callers to also returns a Result? Or maybe it's time to migrate to alloy signature per your comment above: #9593 (comment), but it wouldn't be possible to create invalid signatures anymore. |
can you elaborate? unclear what fails, the default alloy
I think with |
@mattsse Unfortunately alloy-primitives "k256" feature is enabled due to this in alloy-signer: https://github.com/alloy-rs/alloy/blob/423a4c53c1bffdfb2acca2daee60215194f7711d/crates/signer/Cargo.toml#L22C7-L22C18 And also this in revm-primitives: https://github.com/leruaa/revm/blob/1adc908dfa924a9cd5673b526ecbaaec7298d60f/crates/primitives/Cargo.toml#L25 |
To add a bit of context: The issue with the test test_sending_invalid_transactions is that it create an invalid signature here: reth/crates/net/network/tests/it/txgossip.rs Line 132 in 4a19161
Deeper in the code this signature is converted to an alloy I fixed I think the main issue here is that the So I think we need to update alloy-primitives to never remove @mattsse wdyt? I hope to have been clear :) |
yeah, tbh I find this behaviour in alloy-primitives a bit strange because this obfuscates things. but maybe you can use a type alias for this here for now? we also need to change these functions so they accept any |
Unfortunately we can't use a type alias because |
this is kinda stupid lol let's change that we also need an infallible constructor for I find this type a bit strange... |
@leruaa just checking in, is this now only blocked by a new alloy release? |
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.
this is a pretty huge unlock and should unblock further alloy changes.
ptal at the codec things @joshieDo
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, tried locally with no issues
sweet, blocking this to go in after tmrw's release really nice work @leruaa this unblocks us from migrating the other variants aswell |
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.
alright, let's finally do this.
tysm for kickstarting this.
only have two more qs
#[test] | ||
fn test_payload_len_with_eip155_chain_id() { | ||
// Select 1 as an arbitrary nonzero value for R and S, as v() always returns 0 for (0, 0). | ||
let signature = Signature { r: U256::from(1), s: U256::from(1), odd_y_parity: false }; | ||
|
||
assert_eq!(3, signature.payload_len_with_eip155_chain_id(None)); | ||
assert_eq!(3, signature.payload_len_with_eip155_chain_id(Some(1))); | ||
assert_eq!(4, signature.payload_len_with_eip155_chain_id(Some(47))); | ||
} |
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.
why was this test removed?
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.
The corresponding method payload_len_with_eip155_chain_id() has been removed.
#[test] | ||
fn test_encode_and_decode_with_eip155_chain_id() { |
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.
same
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.
encode_with_eip155_chain_id() has also been removed
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.
sorry I have to ask more questions because I'm a bit lost with the signature types
also would appreciate a closer look by @Rjected
alloy_primitives::Parity::NonEip155(self.odd_y_parity) | ||
} |
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.
hmm unsure if this is correct.
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.
This was to reflect the "else" case here:
reth/crates/primitives/src/transaction/signature.rs
Lines 88 to 103 in ae8ce20
pub fn v(&self, chain_id: Option<u64>) -> u64 { | |
if let Some(chain_id) = chain_id { | |
// EIP-155: v = {0, 1} + CHAIN_ID * 2 + 35 | |
self.odd_y_parity as u64 + chain_id * 2 + 35 | |
} else { | |
#[cfg(feature = "optimism")] | |
// pre bedrock system transactions were sent from the zero address as legacy | |
// transactions with an empty signature | |
// | |
// NOTE: this is very hacky and only relevant for op-mainnet pre bedrock | |
if *self == Self::optimism_deposit_tx_signature() { | |
return 0 | |
} | |
self.odd_y_parity as u64 + 27 | |
} | |
} |
/// Returns a signature with the given chain ID applied to the `v` value. | ||
pub(crate) fn as_signature_with_eip155_parity( | ||
&self, | ||
chain_id: Option<u64>, | ||
) -> SignatureWithParity { | ||
let parity = match chain_id { | ||
Some(chain_id) => EncodableSignature::v(self).with_chain_id(chain_id), | ||
None => EncodableSignature::v(self), | ||
}; | ||
|
||
SignatureWithParity::new(self.r(), self.s(), parity) |
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.
why do we need this?
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 did that to encode the tx + signature the exact same way as before, in encode_with_signature()
:
reth/crates/primitives/src/transaction/legacy.rs
Lines 94 to 101 in ae8ce20
pub(crate) fn encode_with_signature(&self, signature: &Signature, out: &mut dyn bytes::BufMut) { | |
let payload_length = | |
self.fields_len() + signature.payload_len_with_eip155_chain_id(self.chain_id); | |
let header = Header { list: true, payload_length }; | |
header.encode(out); | |
self.encode_fields(out); | |
signature.encode_with_eip155_chain_id(out, self.chain_id); | |
} |
So I needed a way to carry the chain_id.
I realize this is not taken into account anymore: reth/crates/primitives/src/transaction/signature.rs Lines 93 to 100 in ae8ce20
Let me add a commit |
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, let's send it this finally @klkvr
Cf #9484