Transaction encoding is made a bit more verbose as signature.v() is now encoded and accounted in length separately
Validation/adjustments of signature parity value are removed
Legacy transaction decoding now handles decoding of parity manually by decoding it into u64 and extracting chain_id when possible. Encoding manually encodes chain_id into boolean parity as per EIP-155 spec.
sign_transaction_with_chain_id macro no more adjusts the signature. as long as signer signed the correct payload with chain_id we are fine with parity being boolean, and legacy transaction encoding methods will figure out how to encode it into integer
signed_legacy_serde module is added which should be used for serialization of Signed<TxLegacy> to respect the specification requiring parity being serialized as EIP-155 compliant v key.
This is not perfect from our pov because we now have more boilerplate logic for parity encoding. However, this makes encoding API safer without any changes to it.
One limitation here is that Signed<TxLegacy> on its own would be serialized incorrectly with yParity key. We can't implement serialize directly on individual Signed<_> types because this would make it impossible to implement serde for Signed<_> with custom transaction. For now I've added with = "signed_legacy_serde" to envelope legacy variants which should ensure that enveloped transactions are always (de)serialized correctly
Motivation
Integrates signature from https://github.com/alloy-rs/core/pull/776
Depends on https://github.com/alloy-rs/eips/pull/12 and https://github.com/alloy-rs/core/pull/796, needs minor releases for core and eips
Solution
Changes in this PR:
signature.v()
is now encoded and accounted in length separatelyu64
and extracting chain_id when possible. Encoding manually encodes chain_id into boolean parity as per EIP-155 spec.sign_transaction_with_chain_id
macro no more adjusts the signature. as long as signer signed the correct payload with chain_id we are fine with parity being boolean, and legacy transaction encoding methods will figure out how to encode it into integersigned_legacy_serde
module is added which should be used for serialization ofSigned<TxLegacy>
to respect the specification requiring parity being serialized as EIP-155 compliantv
key.This is not perfect from our pov because we now have more boilerplate logic for parity encoding. However, this makes encoding API safer without any changes to it.
One limitation here is that
Signed<TxLegacy>
on its own would be serialized incorrectly withyParity
key. We can't implement serialize directly on individualSigned<_>
types because this would make it impossible to implement serde forSigned<_>
with custom transaction. For now I've addedwith = "signed_legacy_serde"
to envelope legacy variants which should ensure that enveloped transactions are always (de)serialized correctlyPR Checklist