11use crate :: proto;
22use alloy_primitives:: { Address , BlockHash , Bloom , TxHash , B256 , B64 , U256 } ;
3- use eyre:: { eyre , OptionExt } ;
3+ use eyre:: OptionExt ;
44use reth:: primitives:: Block ;
55use std:: sync:: Arc ;
66
@@ -142,7 +142,7 @@ impl TryFrom<&reth::primitives::TransactionSigned> for proto::Transaction {
142142 let signature = proto:: Signature {
143143 r : transaction. signature ( ) . r ( ) . to_le_bytes_vec ( ) ,
144144 s : transaction. signature ( ) . s ( ) . to_le_bytes_vec ( ) ,
145- y_parity : transaction. signature ( ) . v ( ) ,
145+ y_parity : transaction. signature ( ) . v ( ) as u8 as u32 ,
146146 } ;
147147 let transaction = match & transaction. clone ( ) . into_typed_transaction ( ) {
148148 reth:: primitives:: Transaction :: Legacy ( alloy_consensus:: TxLegacy {
@@ -242,27 +242,21 @@ impl TryFrom<&reth::primitives::TransactionSigned> for proto::Transaction {
242242 authorization_list,
243243 input,
244244 } ) => {
245- // Map over the authorization_list and collect into a Result<Vec<_>, _>
246245 let authorization_list: Vec < proto:: AuthorizationListItem > = authorization_list
247246 . iter ( )
248- . map ( |authorization| -> Result < proto:: AuthorizationListItem , eyre:: Error > {
249- let signature =
250- authorization. signature ( ) . map_err ( |_| eyre ! ( "signature missing" ) ) ?;
251-
252- Ok ( proto:: AuthorizationListItem {
253- authorization : Some ( proto:: Authorization {
254- chain_id : authorization. chain_id ( ) . to_le_bytes_vec ( ) ,
255- address : authorization. address ( ) . to_vec ( ) ,
256- nonce : authorization. nonce ( ) ,
257- } ) ,
258- signature : Some ( proto:: Signature {
259- r : signature. r ( ) . to_le_bytes_vec ( ) ,
260- s : signature. s ( ) . to_le_bytes_vec ( ) ,
261- y_parity : signature. v ( ) ,
262- } ) ,
263- } )
247+ . map ( |authorization| proto:: AuthorizationListItem {
248+ authorization : Some ( proto:: Authorization {
249+ chain_id : authorization. chain_id ( ) . to_le_bytes_vec ( ) ,
250+ address : authorization. address ( ) . to_vec ( ) ,
251+ nonce : authorization. nonce ( ) ,
252+ } ) ,
253+ signature : Some ( proto:: Signature {
254+ r : authorization. r ( ) . to_le_bytes_vec ( ) ,
255+ s : authorization. s ( ) . to_le_bytes_vec ( ) ,
256+ y_parity : authorization. y_parity ( ) as u32 ,
257+ } ) ,
264258 } )
265- . collect :: < Result < Vec < _ > , _ > > ( ) ? ;
259+ . collect :: < Vec < _ > > ( ) ;
266260
267261 proto:: transaction:: Transaction :: Eip7702 ( proto:: TransactionEip7702 {
268262 chain_id : * chain_id,
@@ -628,10 +622,15 @@ impl TryFrom<&proto::Transaction> for reth::primitives::TransactionSigned {
628622 fn try_from ( transaction : & proto:: Transaction ) -> Result < Self , Self :: Error > {
629623 let hash = TxHash :: try_from ( transaction. hash . as_slice ( ) ) ?;
630624 let signature = transaction. signature . as_ref ( ) . ok_or_eyre ( "no signature" ) ?;
625+ if signature. y_parity > 1 {
626+ return Err ( eyre:: eyre!( alloy_primitives:: SignatureError :: InvalidParity (
627+ signature. y_parity as u64
628+ ) ) ) ;
629+ }
631630 let signature = alloy_primitives:: Signature :: new (
632631 U256 :: try_from_le_slice ( signature. r . as_slice ( ) ) . ok_or_eyre ( "failed to parse r" ) ?,
633632 U256 :: try_from_le_slice ( signature. s . as_slice ( ) ) . ok_or_eyre ( "failed to parse s" ) ?,
634- signature. y_parity ,
633+ signature. y_parity == 1 ,
635634 ) ;
636635
637636 let transaction = match transaction. transaction . as_ref ( ) . ok_or_eyre ( "no transaction" ) ? {
@@ -774,13 +773,12 @@ impl TryFrom<&proto::Transaction> for reth::primitives::TransactionSigned {
774773 . map ( |authorization| {
775774 let signature =
776775 authorization. signature . as_ref ( ) . ok_or_eyre ( "no signature" ) ?;
777- let signature = alloy_primitives:: Signature :: new (
778- U256 :: try_from_le_slice ( signature. r . as_slice ( ) )
779- . ok_or_eyre ( "failed to parse r" ) ?,
780- U256 :: try_from_le_slice ( signature. s . as_slice ( ) )
781- . ok_or_eyre ( "failed to parse s" ) ?,
782- signature. y_parity ,
783- ) ;
776+
777+ let r = U256 :: try_from_le_slice ( signature. r . as_slice ( ) )
778+ . ok_or_eyre ( "failed to parse r" ) ?;
779+ let s = U256 :: try_from_le_slice ( signature. s . as_slice ( ) )
780+ . ok_or_eyre ( "failed to parse s" ) ?;
781+ let y_parity = signature. y_parity as u8 ;
784782
785783 let authorization =
786784 authorization. authorization . as_ref ( ) . ok_or_eyre ( "no authorization" ) ?;
@@ -792,13 +790,18 @@ impl TryFrom<&proto::Transaction> for reth::primitives::TransactionSigned {
792790 . try_into ( )
793791 . map_err ( |_| eyre:: eyre!( "chain_id must be exactly 8 bytes" ) ) ?,
794792 ) ;
795-
796- Ok ( alloy_eips:: eip7702:: Authorization {
793+ let authorization = alloy_eips:: eip7702:: Authorization {
797794 chain_id,
798795 address : Address :: try_from ( authorization. address . as_slice ( ) ) ?,
799796 nonce : authorization. nonce ,
800- }
801- . into_signed ( signature) )
797+ } ;
798+
799+ Ok ( alloy_eips:: eip7702:: SignedAuthorization :: new_unchecked (
800+ authorization,
801+ y_parity,
802+ r,
803+ s,
804+ ) )
802805 } )
803806 . collect :: < eyre:: Result < Vec < _ > > > ( ) ?,
804807 input : input. to_vec ( ) . into ( ) ,
0 commit comments