@@ -57,21 +57,46 @@ pub enum AggregateError {
5757 context : & ' static str ,
5858 } ,
5959
60+ /// Local share data contained an invalid validator pubkey.
61+ #[ error( "invalid pubkey in local share" ) ]
62+ InvalidLocalSharePubKey ,
63+
6064 /// Partial signatures referenced a missing public share.
6165 #[ error( "invalid pubshare" ) ]
6266 InvalidPubshare ,
6367
6468 /// Partial signature verification failed for deposit data.
65- #[ error( "invalid deposit data partial signature from peer" ) ]
66- InvalidDepositPartialSignature ,
69+ #[ error( "invalid deposit data partial signature from peer {share_idx} for pubkey {pub_key}" ) ]
70+ InvalidDepositPartialSignature {
71+ /// Peer share index.
72+ share_idx : u64 ,
73+ /// Validator pubkey.
74+ pub_key : String ,
75+ } ,
6776
6877 /// Partial signature verification failed for validator registrations.
69- #[ error( "invalid validator registration partial signature from peer" ) ]
70- InvalidValidatorRegistrationPartialSignature ,
78+ #[ error(
79+ "invalid validator registration partial signature from peer {share_idx} for pubkey {pub_key}"
80+ ) ]
81+ InvalidValidatorRegistrationPartialSignature {
82+ /// Peer share index.
83+ share_idx : u64 ,
84+ /// Validator pubkey.
85+ pub_key : String ,
86+ } ,
7187
7288 /// Partial signature verification failed for lock hash.
73- #[ error( "invalid lock hash partial signature from peer: {0}" ) ]
74- InvalidLockHashPartialSignature ( pluto_crypto:: types:: Error ) ,
89+ #[ error(
90+ "invalid lock hash partial signature from peer {share_idx} for pubkey {pub_key}: {source}"
91+ ) ]
92+ InvalidLockHashPartialSignature {
93+ /// Peer share index.
94+ share_idx : u64 ,
95+ /// Validator pubkey.
96+ pub_key : String ,
97+ /// Verification error.
98+ source : pluto_crypto:: types:: Error ,
99+ } ,
75100
76101 /// Aggregate signature verification failed for deposit data.
77102 #[ error( "invalid deposit data aggregated signature: {0}" ) ]
@@ -108,6 +133,7 @@ pub fn agg_lock_hash_sig(
108133 let mut pubkeys = Vec :: new ( ) ;
109134
110135 for ( pub_key, partials) in data {
136+ let pub_key_hex = hex_pubkey ( pub_key) ;
111137 let share = shares
112138 . get ( pub_key)
113139 . ok_or ( AggregateError :: InvalidPubKeyFromPeer {
@@ -121,9 +147,13 @@ pub fn agg_lock_hash_sig(
121147 . get ( & partial. share_idx )
122148 . ok_or ( AggregateError :: InvalidPubshare ) ?;
123149
124- BlstImpl
125- . verify ( pubshare, hash, & sig)
126- . map_err ( AggregateError :: InvalidLockHashPartialSignature ) ?;
150+ BlstImpl . verify ( pubshare, hash, & sig) . map_err ( |source| {
151+ AggregateError :: InvalidLockHashPartialSignature {
152+ share_idx : partial. share_idx ,
153+ pub_key : pub_key_hex. clone ( ) ,
154+ source,
155+ }
156+ } ) ?;
127157
128158 sigs. push ( sig) ;
129159 pubkeys. push ( * pubshare) ;
@@ -144,6 +174,7 @@ pub fn agg_deposit_data(
144174 let mut res = Vec :: with_capacity ( data. len ( ) ) ;
145175
146176 for ( pub_key, partials) in data {
177+ let pub_key_hex = hex_pubkey ( pub_key) ;
147178 let msg = msgs
148179 . get ( pub_key)
149180 . ok_or ( AggregateError :: DepositMessageNotFound ) ?;
@@ -154,8 +185,11 @@ pub fn agg_deposit_data(
154185 context : "deposit data" ,
155186 } ) ?;
156187 let partial_sigs =
157- verify_threshold_partials ( partials, & share. public_shares , & sig_root, || {
158- AggregateError :: InvalidDepositPartialSignature
188+ verify_threshold_partials ( partials, & share. public_shares , & sig_root, |share_idx| {
189+ AggregateError :: InvalidDepositPartialSignature {
190+ share_idx,
191+ pub_key : pub_key_hex. clone ( ) ,
192+ }
159193 } ) ?;
160194
161195 let agg_sig = BlstImpl . threshold_aggregate ( & partial_sigs) ?;
@@ -188,6 +222,7 @@ pub fn agg_validator_registrations(
188222 let mut res = Vec :: with_capacity ( data. len ( ) ) ;
189223
190224 for ( pub_key, partials) in data {
225+ let pub_key_hex = hex_pubkey ( pub_key) ;
191226 let msg = msgs
192227 . get ( pub_key)
193228 . ok_or ( AggregateError :: ValidatorRegistrationNotFound ) ?;
@@ -199,8 +234,11 @@ pub fn agg_validator_registrations(
199234 context : "validator registrations" ,
200235 } ) ?;
201236 let partial_sigs =
202- verify_threshold_partials ( partials, & share. public_shares , & sig_root, || {
203- AggregateError :: InvalidValidatorRegistrationPartialSignature
237+ verify_threshold_partials ( partials, & share. public_shares , & sig_root, |share_idx| {
238+ AggregateError :: InvalidValidatorRegistrationPartialSignature {
239+ share_idx,
240+ pub_key : pub_key_hex. clone ( ) ,
241+ }
204242 } ) ?;
205243
206244 let agg_sig = BlstImpl . threshold_aggregate ( & partial_sigs) ?;
@@ -231,16 +269,17 @@ fn shares_by_pubkey(shares: &[Share]) -> Result<HashMap<PubKey, &Share>> {
231269 shares
232270 . iter ( )
233271 . map ( |share| {
234- let pub_key = PubKey :: try_from ( share. pub_key . as_slice ( ) ) . map_err ( |_| {
235- AggregateError :: InvalidPubKeyFromPeer {
236- context : "local share" ,
237- }
238- } ) ?;
272+ let pub_key = PubKey :: try_from ( share. pub_key . as_slice ( ) )
273+ . map_err ( |_| AggregateError :: InvalidLocalSharePubKey ) ?;
239274 Ok ( ( pub_key, share) )
240275 } )
241276 . collect ( )
242277}
243278
279+ fn hex_pubkey ( pub_key : & PubKey ) -> String {
280+ hex:: encode ( pub_key. as_ref ( ) )
281+ }
282+
244283fn extract_partial_signature ( partial : & ParSignedData ) -> Result < Signature > {
245284 let sig = partial. signed_data . signature ( ) ?;
246285 Ok ( signature_from_bytes ( sig. as_ref ( ) ) ?)
@@ -250,7 +289,7 @@ fn verify_threshold_partials(
250289 partials : & [ ParSignedData ] ,
251290 public_shares : & HashMap < u64 , PublicKey > ,
252291 message : & [ u8 ] ,
253- invalid_signature_error : fn ( ) -> AggregateError ,
292+ invalid_signature_error : impl Fn ( u64 ) -> AggregateError ,
254293) -> Result < HashMap < u8 , Signature > > {
255294 let mut res = HashMap :: with_capacity ( partials. len ( ) ) ;
256295
@@ -262,7 +301,7 @@ fn verify_threshold_partials(
262301
263302 BlstImpl
264303 . verify ( pubshare, message, & sig)
265- . map_err ( |_| invalid_signature_error ( ) ) ?;
304+ . map_err ( |_| invalid_signature_error ( partial . share_idx ) ) ?;
266305
267306 res. insert ( u8:: try_from ( partial. share_idx ) ?, sig) ;
268307 }
@@ -418,7 +457,7 @@ mod tests {
418457
419458 assert ! ( matches!(
420459 err,
421- AggregateError :: InvalidDepositPartialSignature
460+ AggregateError :: InvalidDepositPartialSignature { share_idx : 3 , .. }
422461 ) ) ;
423462 }
424463
@@ -453,7 +492,7 @@ mod tests {
453492
454493 assert ! ( matches!(
455494 err,
456- AggregateError :: InvalidLockHashPartialSignature ( _ )
495+ AggregateError :: InvalidLockHashPartialSignature { share_idx : 3 , .. }
457496 ) ) ;
458497 }
459498
0 commit comments