mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 16:08:26 -05:00
Return Error For Batch Verifier (#9766)
* fix it * make err check happy * radek's review Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -49,7 +49,7 @@ func (s *Service) verifierRoutine() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) validateWithBatchVerifier(ctx context.Context, message string, set *bls.SignatureSet) pubsub.ValidationResult {
|
||||
func (s *Service) validateWithBatchVerifier(ctx context.Context, message string, set *bls.SignatureSet) (pubsub.ValidationResult, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "sync.validateWithBatchVerifier")
|
||||
defer span.End()
|
||||
|
||||
@@ -65,17 +65,17 @@ func (s *Service) validateWithBatchVerifier(ctx context.Context, message string,
|
||||
log.WithError(resErr).Tracef("Could not perform batch verification of %s", message)
|
||||
verified, err := set.Verify()
|
||||
if err != nil {
|
||||
log.WithError(err).Debugf("Could not verify %s", message)
|
||||
tracing.AnnotateError(span, err)
|
||||
return pubsub.ValidationReject
|
||||
verErr := errors.Wrapf(err, "Could not verify %s", message)
|
||||
tracing.AnnotateError(span, verErr)
|
||||
return pubsub.ValidationReject, verErr
|
||||
}
|
||||
if !verified {
|
||||
log.Debugf("Verification of %s failed", message)
|
||||
tracing.AnnotateError(span, err)
|
||||
return pubsub.ValidationReject
|
||||
verErr := errors.Errorf("Verification of %s failed", message)
|
||||
tracing.AnnotateError(span, verErr)
|
||||
return pubsub.ValidationReject, verErr
|
||||
}
|
||||
}
|
||||
return pubsub.ValidationAccept
|
||||
return pubsub.ValidationAccept, nil
|
||||
}
|
||||
|
||||
func verifyBatch(verifierBatch []*signatureVerifier) {
|
||||
|
||||
@@ -71,9 +71,13 @@ func TestValidateWithBatchVerifier(t *testing.T) {
|
||||
for _, st := range tt.preFilledSets {
|
||||
svc.signatureChan <- &signatureVerifier{set: st, resChan: make(chan error, 10)}
|
||||
}
|
||||
if got := svc.validateWithBatchVerifier(context.Background(), tt.message, tt.set); got != tt.want {
|
||||
got, err := svc.validateWithBatchVerifier(context.Background(), tt.message, tt.set)
|
||||
if got != tt.want {
|
||||
t.Errorf("validateWithBatchVerifier() = %v, want %v", got, tt.want)
|
||||
}
|
||||
if err != nil && tt.want == pubsub.ValidationAccept {
|
||||
t.Errorf("Wanted no error but received: %v", err)
|
||||
}
|
||||
cancel()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func (s *Service) validateAggregatedAtt(ctx context.Context, signed *ethpb.Signe
|
||||
set.Join(selectionSigSet).Join(aggregatorSigSet).Join(attSigSet)
|
||||
|
||||
if features.Get().EnableBatchVerification {
|
||||
return s.validateWithBatchVerifier(ctx, "aggregate", set), nil
|
||||
return s.validateWithBatchVerifier(ctx, "aggregate", set)
|
||||
}
|
||||
valid, err := set.Verify()
|
||||
if err != nil {
|
||||
|
||||
@@ -224,7 +224,7 @@ func (s *Service) validateUnaggregatedAttWithState(ctx context.Context, a *eth.A
|
||||
tracing.AnnotateError(span, err)
|
||||
return pubsub.ValidationReject, err
|
||||
}
|
||||
return s.validateWithBatchVerifier(ctx, "attestation", set), nil
|
||||
return s.validateWithBatchVerifier(ctx, "attestation", set)
|
||||
}
|
||||
if err := blocks.VerifyAttestationSignature(ctx, bs, a); err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
|
||||
@@ -248,7 +248,7 @@ func (s *Service) rejectInvalidSyncCommitteeSignature(m *ethpb.SyncCommitteeMess
|
||||
PublicKeys: []bls.PublicKey{pKey},
|
||||
Signatures: [][]byte{m.Signature},
|
||||
}
|
||||
return s.validateWithBatchVerifier(ctx, "sync committee message", set), nil
|
||||
return s.validateWithBatchVerifier(ctx, "sync committee message", set)
|
||||
}
|
||||
|
||||
// We reject a malformed signature from bytes according to the p2p specification.
|
||||
|
||||
@@ -218,7 +218,7 @@ func (s *Service) rejectInvalidContributionSignature(m *ethpb.SignedContribution
|
||||
PublicKeys: []bls.PublicKey{publicKey},
|
||||
Signatures: [][]byte{m.Signature},
|
||||
}
|
||||
return s.validateWithBatchVerifier(ctx, "sync contribution signature", set), nil
|
||||
return s.validateWithBatchVerifier(ctx, "sync contribution signature", set)
|
||||
}
|
||||
|
||||
if err := signing.VerifySigningRoot(m.Message, pubkey[:], m.Signature, d); err != nil {
|
||||
@@ -282,7 +282,7 @@ func (s *Service) rejectInvalidSyncAggregateSignature(m *ethpb.SignedContributio
|
||||
PublicKeys: []bls.PublicKey{aggKey},
|
||||
Signatures: [][]byte{m.Message.Contribution.Signature},
|
||||
}
|
||||
return s.validateWithBatchVerifier(ctx, "sync contribution aggregate signature", set), nil
|
||||
return s.validateWithBatchVerifier(ctx, "sync contribution aggregate signature", set)
|
||||
}
|
||||
sig, err := bls.SignatureFromBytes(m.Message.Contribution.Signature)
|
||||
if err != nil {
|
||||
@@ -343,7 +343,10 @@ func (s *Service) verifySyncSelectionData(ctx context.Context, m *ethpb.Contribu
|
||||
PublicKeys: []bls.PublicKey{publicKey},
|
||||
Signatures: [][]byte{m.SelectionProof},
|
||||
}
|
||||
valid := s.validateWithBatchVerifier(ctx, "sync contribution selection signature", set)
|
||||
valid, err := s.validateWithBatchVerifier(ctx, "sync contribution selection signature", set)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if valid != pubsub.ValidationAccept {
|
||||
return errors.New("invalid sync selection proof provided")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user