From f63ab1e136aa4cd51c83be8c9afcb4e6f7915325 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 6 Dec 2019 10:21:57 -0800 Subject: [PATCH] Remove formatting error for signature fail to verify (#4211) * Remove formatting error for sig * Update beacon-chain/core/blocks/block_operations.go Co-Authored-By: Ivan Martinez * Merge branch 'master' into sig-error-log --- beacon-chain/core/blocks/block_operations.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/beacon-chain/core/blocks/block_operations.go b/beacon-chain/core/blocks/block_operations.go index 2139d8fac..9a6024573 100644 --- a/beacon-chain/core/blocks/block_operations.go +++ b/beacon-chain/core/blocks/block_operations.go @@ -32,6 +32,10 @@ var log = logrus.WithField("prefix", "blocks") var eth1DataCache = cache.NewEth1DataVoteCache() +// ErrSigFailedToVerify returns when a signature of a block object(ie attestation, slashing, exit... etc) +// failed to verify. +var ErrSigFailedToVerify = errors.New("signature did not verify") + func verifySigningRoot(obj interface{}, pub []byte, signature []byte, domain uint64) error { publicKey, err := bls.PublicKeyFromBytes(pub) if err != nil { @@ -46,7 +50,7 @@ func verifySigningRoot(obj interface{}, pub []byte, signature []byte, domain uin return errors.Wrap(err, "could not get signing root") } if !sig.Verify(root[:], publicKey, domain) { - return fmt.Errorf("signature did not verify") + return ErrSigFailedToVerify } return nil } @@ -61,7 +65,7 @@ func verifySignature(signedData []byte, pub []byte, signature []byte, domain uin return errors.Wrap(err, "could not convert bytes to signature") } if !sig.Verify(signedData, publicKey, domain) { - return fmt.Errorf("signature did not verify: %v", fmt.Sprintf("%#x", bytesutil.Trunc(signature))) + return ErrSigFailedToVerify } return nil } @@ -177,8 +181,7 @@ func ProcessBlockHeader( currentEpoch := helpers.CurrentEpoch(beaconState) domain := helpers.Domain(beaconState.Fork, currentEpoch, params.BeaconConfig().DomainBeaconProposer) if err := verifySigningRoot(block, proposer.PublicKey, block.Signature, domain); err != nil { - sig := fmt.Sprintf("%#x", bytesutil.Trunc(block.Signature)) - return nil, errors.Wrapf(err, "could not verify block signature %v", sig) + return nil, ErrSigFailedToVerify } return beaconState, nil @@ -809,8 +812,7 @@ func VerifyIndexedAttestation(ctx context.Context, beaconState *pb.BeaconState, hasVotes := len(custodyBit0Indices) > 0 || len(custodyBit1Indices) > 0 if hasVotes && !sig.VerifyAggregate(pubkeys, msgs, domain) { - return fmt.Errorf("attestation aggregation signature did not verify %v", - fmt.Sprintf("%#x", bytesutil.Trunc(indexedAtt.Signature))) + return ErrSigFailedToVerify } return nil } @@ -1053,8 +1055,7 @@ func VerifyExit(beaconState *pb.BeaconState, exit *ethpb.VoluntaryExit) error { } domain := helpers.Domain(beaconState.Fork, exit.Epoch, params.BeaconConfig().DomainVoluntaryExit) if err := verifySigningRoot(exit, validator.PublicKey, exit.Signature, domain); err != nil { - sig := fmt.Sprintf("%#x", bytesutil.Trunc(exit.Signature)) - return errors.Wrapf(err, "could not verify voluntary exit signature %v", sig) + return ErrSigFailedToVerify } return nil }