@@ -16,8 +16,11 @@ pub type Result<T> = std::result::Result<T, SigningError>;
1616#[ derive( Debug , thiserror:: Error ) ]
1717pub enum SigningError {
1818 /// Failed to build a core public key from bytes.
19- #[ error( "invalid public key length" ) ]
20- InvalidPublicKeyLength ,
19+ #[ error( "invalid public key length while {error_context}" ) ]
20+ InvalidPublicKeyLength {
21+ /// Signing helper that encountered the invalid key.
22+ error_context : & ' static str ,
23+ } ,
2124
2225 /// Failed to sign or verify with threshold BLS.
2326 #[ error( transparent) ]
@@ -65,8 +68,7 @@ pub fn sign_lock_hash(share_idx: u64, shares: &[Share], hash: &[u8]) -> Result<P
6568 let mut set = ParSignedDataSet :: new ( ) ;
6669
6770 for share in shares {
68- let pub_key = PubKey :: try_from ( share. pub_key . as_slice ( ) )
69- . map_err ( |_| SigningError :: InvalidPublicKeyLength ) ?;
71+ let pub_key = share_pubkey ( share, "signing lock hash" ) ?;
7072 let sig = BlstImpl . sign ( & share. secret_share , hash) ?;
7173
7274 set. insert (
@@ -97,7 +99,7 @@ pub fn sign_deposit_msgs(
9799
98100 for ( share, withdrawal_address) in shares. iter ( ) . zip ( withdrawal_addresses. iter ( ) ) {
99101 let eth2_pubkey = pubkey_to_eth2 ( share. pub_key ) ;
100- let pub_key = share_pubkey ( share) ?;
102+ let pub_key = share_pubkey ( share, "signing deposit message" ) ?;
101103 let withdrawal_address = pluto_eth2util:: helpers:: checksum_address ( withdrawal_address) ?;
102104
103105 let msg = deposit:: new_message ( eth2_pubkey, & withdrawal_address, amount, compounding) ?;
@@ -139,7 +141,7 @@ pub fn sign_validator_registrations(
139141
140142 for ( share, fee_recipient) in shares. iter ( ) . zip ( fee_recipients. iter ( ) ) {
141143 let eth2_pubkey = pubkey_to_eth2 ( share. pub_key ) ;
142- let pub_key = share_pubkey ( share) ?;
144+ let pub_key = share_pubkey ( share, "signing validator registration" ) ?;
143145
144146 let reg_msg = registration:: new_message (
145147 eth2_pubkey,
@@ -170,8 +172,9 @@ pub fn sign_validator_registrations(
170172 Ok ( ( set, msgs) )
171173}
172174
173- fn share_pubkey ( share : & Share ) -> Result < PubKey > {
174- PubKey :: try_from ( share. pub_key . as_slice ( ) ) . map_err ( |_| SigningError :: InvalidPublicKeyLength )
175+ fn share_pubkey ( share : & Share , error_context : & ' static str ) -> Result < PubKey > {
176+ PubKey :: try_from ( share. pub_key . as_slice ( ) )
177+ . map_err ( |_| SigningError :: InvalidPublicKeyLength { error_context } )
175178}
176179
177180#[ cfg( test) ]
0 commit comments