@@ -180,10 +180,10 @@ func (h *DecryptionKeysHandler) MessagePrototypes() []p2pmsg.Message {
180
180
return []p2pmsg.Message {& p2pmsg.DecryptionKeys {}}
181
181
}
182
182
183
- func validateSignerIndices (extra * p2pmsg.DecryptionKeys_Gnosis , n int ) (pubsub.ValidationResult , error ) {
184
- for i , signerIndex := range extra .Gnosis . SignerIndices {
183
+ func validateSignerIndices (extra * p2pmsg.GnosisDecryptionKeysExtra , n int ) (pubsub.ValidationResult , error ) {
184
+ for i , signerIndex := range extra .SignerIndices {
185
185
if i >= 1 {
186
- prevSignerIndex := extra .Gnosis . SignerIndices [i - 1 ]
186
+ prevSignerIndex := extra .SignerIndices [i - 1 ]
187
187
if signerIndex == prevSignerIndex {
188
188
return pubsub .ValidationReject , errors .New ("duplicate signer index found" )
189
189
}
@@ -198,8 +198,7 @@ func validateSignerIndices(extra *p2pmsg.DecryptionKeys_Gnosis, n int) (pubsub.V
198
198
return pubsub .ValidationAccept , nil
199
199
}
200
200
201
- func (h * DecryptionKeysHandler ) ValidateMessage (ctx context.Context , msg p2pmsg.Message ) (pubsub.ValidationResult , error ) {
202
- keys := msg .(* p2pmsg.DecryptionKeys )
201
+ func ValidateDecryptionKeysBasic (keys * p2pmsg.DecryptionKeys ) (pubsub.ValidationResult , error ) {
203
202
extra , ok := keys .Extra .(* p2pmsg.DecryptionKeys_Gnosis )
204
203
if ! ok {
205
204
return pubsub .ValidationReject , errors .Errorf ("unexpected extra type %T, expected Gnosis" , keys .Extra )
@@ -218,21 +217,23 @@ func (h *DecryptionKeysHandler) ValidateMessage(ctx context.Context, msg p2pmsg.
218
217
return pubsub .ValidationReject , errors .New ("msg does not contain any keys" )
219
218
}
220
219
221
- obsKeyperDB := obskeyperdatabase .New (h .dbpool )
222
- keyperSet , err := obsKeyperDB .GetKeyperSetByKeyperConfigIndex (ctx , int64 (keys .Eon ))
223
- if err != nil {
224
- return pubsub .ValidationReject , errors .Wrapf (err , "failed to get keyper set from database for eon %d" , keys .Eon )
225
- }
220
+ return pubsub .ValidationAccept , nil
221
+ }
226
222
227
- if int32 (len (extra .Gnosis .SignerIndices )) != keyperSet .Threshold {
228
- return pubsub .ValidationReject , errors .Errorf ("expected %d signers, got %d" , keyperSet .Threshold , len (extra .Gnosis .SignerIndices ))
223
+ func ValidateDecryptionKeysSignatures (
224
+ keys * p2pmsg.DecryptionKeys ,
225
+ extra * p2pmsg.GnosisDecryptionKeysExtra ,
226
+ keyperSet * obskeyperdatabase.KeyperSet ,
227
+ ) (pubsub.ValidationResult , error ) {
228
+ if int32 (len (extra .SignerIndices )) != keyperSet .Threshold {
229
+ return pubsub .ValidationReject , errors .Errorf ("expected %d signers, got %d" , keyperSet .Threshold , len (extra .SignerIndices ))
229
230
}
230
231
231
232
res , err := validateSignerIndices (extra , len (keyperSet .Keypers ))
232
233
if res != pubsub .ValidationAccept {
233
234
return res , err
234
235
}
235
- signers , err := keyperSet .GetSubset (extra .Gnosis . SignerIndices )
236
+ signers , err := keyperSet .GetSubset (extra .SignerIndices )
236
237
if err != nil {
237
238
return pubsub .ValidationReject , err
238
239
}
@@ -245,15 +246,15 @@ func (h *DecryptionKeysHandler) ValidateMessage(ctx context.Context, msg p2pmsg.
245
246
slotDecryptionSignatureData , err := gnosisssztypes .NewSlotDecryptionSignatureData (
246
247
keys .InstanceID ,
247
248
keys .Eon ,
248
- extra .Gnosis . Slot ,
249
- extra .Gnosis . TxPointer ,
249
+ extra .Slot ,
250
+ extra .TxPointer ,
250
251
identityPreimages ,
251
252
)
252
253
if err != nil {
253
254
return pubsub .ValidationReject , errors .Wrap (err , "failed to create slot decryption signature data object" )
254
255
}
255
- for signatureIndex := 0 ; signatureIndex < len (extra .Gnosis . Signatures ); signatureIndex ++ {
256
- signature := extra .Gnosis . Signatures [signatureIndex ]
256
+ for signatureIndex := 0 ; signatureIndex < len (extra .Signatures ); signatureIndex ++ {
257
+ signature := extra .Signatures [signatureIndex ]
257
258
signer := signers [signatureIndex ]
258
259
signatureValid , err := slotDecryptionSignatureData .CheckSignature (signature , signer )
259
260
if err != nil {
@@ -267,6 +268,30 @@ func (h *DecryptionKeysHandler) ValidateMessage(ctx context.Context, msg p2pmsg.
267
268
return pubsub .ValidationAccept , nil
268
269
}
269
270
271
+ func (h * DecryptionKeysHandler ) ValidateMessage (ctx context.Context , msg p2pmsg.Message ) (pubsub.ValidationResult , error ) {
272
+ keys := msg .(* p2pmsg.DecryptionKeys )
273
+
274
+ res , err := ValidateDecryptionKeysBasic (keys )
275
+ if res != pubsub .ValidationAccept || err != nil {
276
+ return res , err
277
+ }
278
+
279
+ extra := keys .Extra .(* p2pmsg.DecryptionKeys_Gnosis ).Gnosis
280
+
281
+ obsKeyperDB := obskeyperdatabase .New (h .dbpool )
282
+ keyperSet , err := obsKeyperDB .GetKeyperSetByKeyperConfigIndex (ctx , int64 (keys .Eon ))
283
+ if err != nil {
284
+ return pubsub .ValidationReject , errors .Wrapf (err , "failed to get keyper set from database for eon %d" , keys .Eon )
285
+ }
286
+
287
+ res , err = ValidateDecryptionKeysSignatures (keys , extra , & keyperSet )
288
+ if res != pubsub .ValidationAccept || err != nil {
289
+ return res , err
290
+ }
291
+
292
+ return pubsub .ValidationAccept , nil
293
+ }
294
+
270
295
func (h * DecryptionKeysHandler ) HandleMessage (ctx context.Context , msg p2pmsg.Message ) ([]p2pmsg.Message , error ) {
271
296
keys := msg .(* p2pmsg.DecryptionKeys )
272
297
extra := keys .Extra .(* p2pmsg.DecryptionKeys_Gnosis ).Gnosis
0 commit comments