-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mark invalid encrypted shares as 'invalid' #1151
Changes from 8 commits
4719016
35a8e1e
f6ba656
157f3fc
d1babcf
ef3d9bb
b9cdf34
a4d7418
deb4f61
d035b92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,12 +179,12 @@ func (eh *EventHandler) handleValidatorAdded(txn basedb.Txn, event *contract.Con | |
} | ||
|
||
validatorShare := eh.nodeStorage.Shares().Get(txn, event.PublicKey) | ||
var malformedEventError *MalformedEventError | ||
|
||
if validatorShare == nil { | ||
createdShare, err := eh.handleShareCreation(txn, event, sharePublicKeys, encryptedKeys) | ||
if err != nil { | ||
var malformedEventError *MalformedEventError | ||
if errors.As(err, &malformedEventError) { | ||
if errors.As(err, &malformedEventError) && malformedEventError != nil && !malformedEventError.IsInvalidEncryptedShare { | ||
logger.Warn("malformed event", zap.Error(err)) | ||
|
||
return nil, err | ||
|
@@ -209,7 +209,7 @@ func (eh *EventHandler) handleValidatorAdded(txn basedb.Txn, event *contract.Con | |
} | ||
|
||
isOperatorShare := validatorShare.BelongsToOperator(eh.operatorData.GetOperatorData().ID) | ||
if isOperatorShare { | ||
if isOperatorShare && !validatorShare.Invalid { | ||
eh.metrics.ValidatorInactive(event.PublicKey) | ||
ownShare = validatorShare | ||
logger = logger.With(zap.Bool("own_validator", isOperatorShare)) | ||
|
@@ -233,11 +233,21 @@ func (eh *EventHandler) handleShareCreation( | |
sharePublicKeys, | ||
encryptedKeys, | ||
) | ||
|
||
var malformedEventError *MalformedEventError = nil | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("could not extract validator share from event: %w", err) | ||
if errors.As(err, &malformedEventError) && | ||
malformedEventError.IsInvalidEncryptedShare && | ||
share.BelongsToOperator(eh.operatorData.GetOperatorData().ID) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this error can't ever happen if this is not your validator, because you only try to decrypt your own shares, so maybe this check is redundant? |
||
|
||
share.Metadata.Invalid = true | ||
} else { | ||
return nil, fmt.Errorf("could not extract validator share from event: %w", err) | ||
} | ||
Comment on lines
+240
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets invert the condition to return if it's not the error we want, otherwise we continue with setting the invalid flag. |
||
} | ||
|
||
if share.BelongsToOperator(eh.operatorData.GetOperatorData().ID) { | ||
if malformedEventError == nil && share.BelongsToOperator(eh.operatorData.GetOperatorData().ID) { | ||
if shareSecret == nil { | ||
return nil, errors.New("could not decode shareSecret") | ||
} | ||
|
@@ -253,7 +263,11 @@ func (eh *EventHandler) handleShareCreation( | |
return nil, fmt.Errorf("could not save validator share: %w", err) | ||
} | ||
|
||
return share, nil | ||
if malformedEventError == nil { | ||
return share, nil | ||
} | ||
|
||
return share, malformedEventError | ||
} | ||
|
||
func validatorAddedEventToShare( | ||
|
@@ -301,18 +315,21 @@ func validatorAddedEventToShare( | |
shareSecret = &bls.SecretKey{} | ||
decryptedSharePrivateKey, err := rsaencryption.DecodeKey(operatorPrivateKey, encryptedKeys[i]) | ||
if err != nil { | ||
return nil, nil, &MalformedEventError{ | ||
Err: fmt.Errorf("could not decrypt share private key: %w", err), | ||
return &validatorShare, nil, &MalformedEventError{ | ||
Err: fmt.Errorf("could not decrypt share private key: %w", err), | ||
IsInvalidEncryptedShare: true, | ||
} | ||
} | ||
if err = shareSecret.SetHexString(string(decryptedSharePrivateKey)); err != nil { | ||
return nil, nil, &MalformedEventError{ | ||
Err: fmt.Errorf("could not set decrypted share private key: %w", err), | ||
return &validatorShare, nil, &MalformedEventError{ | ||
Err: fmt.Errorf("could not set decrypted share private key: %w", err), | ||
IsInvalidEncryptedShare: true, | ||
} | ||
} | ||
if !bytes.Equal(shareSecret.GetPublicKey().Serialize(), validatorShare.SharePubKey) { | ||
return nil, nil, &MalformedEventError{ | ||
Err: errors.New("share private key does not match public key"), | ||
return &validatorShare, nil, &MalformedEventError{ | ||
Err: fmt.Errorf("share private key does not match public key"), | ||
IsInvalidEncryptedShare: true, | ||
} | ||
Comment on lines
+318
to
333
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please try to instead of returning malformed error, instead to just set the Invalid flag on the share and return no error? with this you'd be able to just ask if the share is invalid rather than if there was a malformedError |
||
} | ||
} | ||
|
@@ -321,6 +338,7 @@ func validatorAddedEventToShare( | |
validatorShare.DomainType = ssvtypes.GetDefaultDomain() | ||
validatorShare.Committee = committee | ||
validatorShare.Graffiti = []byte("ssv.network") | ||
validatorShare.Metadata.Invalid = false | ||
|
||
return &validatorShare, shareSecret, nil | ||
} | ||
|
@@ -520,7 +538,8 @@ func (eh *EventHandler) processClusterEvent( | |
|
||
// MalformedEventError is returned when event is malformed | ||
type MalformedEventError struct { | ||
Err error | ||
Err error | ||
IsInvalidEncryptedShare bool | ||
} | ||
|
||
func (e *MalformedEventError) Error() string { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -686,6 +686,10 @@ func (c *controller) onShareStart(share *ssvtypes.SSVShare) (bool, error) { | |
c.logger.Warn("skipping validator until it becomes active", fields.PubKey(share.ValidatorPubKey)) | ||
return false, nil | ||
} | ||
if share.Invalid { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can add it to the filter above in |
||
c.logger.Warn("skipping validator with invalid share", fields.PubKey(share.ValidatorPubKey)) | ||
return false, nil | ||
} | ||
|
||
if err := c.setShareFeeRecipient(share, c.recipientsStorage.GetRecipientData); err != nil { | ||
return false, fmt.Errorf("could not set share fee recipient: %w", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,5 @@ type Metadata struct { | |
BeaconMetadata *beaconprotocol.ValidatorMetadata | ||
OwnerAddress common.Address | ||
Liquidated bool | ||
Invalid bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can rename this to otherwise one might assume that something else in the event may have been invalid (such as invalid nonce) |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= nil
is redundant