diff --git a/validator/client/validator_aggregate.go b/validator/client/validator_aggregate.go index c83140b995d8..c90ce75cb395 100644 --- a/validator/client/validator_aggregate.go +++ b/validator/client/validator_aggregate.go @@ -96,21 +96,14 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot uint64, pu return } - d, err := v.domainData(ctx, helpers.SlotToEpoch(res.AggregateAndProof.Aggregate.Data.Slot), params.BeaconConfig().DomainAggregateAndProof[:]) + sig, err := v.aggregateAndProofSig(ctx, pubKey, res.AggregateAndProof) if err != nil { - log.Errorf("Could not get domain data to sign aggregate and proof: %v", err) - return + log.Errorf("Could not sign aggregate and proof: %v", err) } - signedRoot, err := helpers.ComputeSigningRoot(res.AggregateAndProof, d.SignatureDomain) - if err != nil { - log.Errorf("Could not compute sign root for aggregate and proof: %v", err) - return - } - _, err = v.validatorClient.SubmitSignedAggregateSelectionProof(ctx, ðpb.SignedAggregateSubmitRequest{ SignedAggregateAndProof: ðpb.SignedAggregateAttestationAndProof{ Message: res.AggregateAndProof, - Signature: signedRoot[:], + Signature: sig, }, }) if err != nil { @@ -165,6 +158,25 @@ func (v *validator) waitToSlotTwoThirds(ctx context.Context, slot uint64) { time.Sleep(roughtime.Until(finalTime)) } +// This returns the signature of validator signing over aggregate and +// proof object. +func (v *validator) aggregateAndProofSig(ctx context.Context, pubKey [48]byte, agg *ethpb.AggregateAttestationAndProof) ([]byte, error) { + d, err := v.domainData(ctx, helpers.SlotToEpoch(agg.Aggregate.Data.Slot), params.BeaconConfig().DomainAggregateAndProof[:]) + if err != nil { + return nil, err + } + signedRoot, err := helpers.ComputeSigningRoot(agg, d.SignatureDomain) + if err != nil { + return nil, err + } + sig, err := v.keyManager.Sign(pubKey, signedRoot) + if err != nil { + return nil, err + } + + return sig.Marshal(), nil +} + func (v *validator) addIndicesToLog(duty *ethpb.DutiesResponse_Duty) error { v.attLogsLock.Lock() defer v.attLogsLock.Unlock() diff --git a/validator/client/validator_aggregate_test.go b/validator/client/validator_aggregate_test.go index 9a33eb3e9887..d9707aebb6e9 100644 --- a/validator/client/validator_aggregate_test.go +++ b/validator/client/validator_aggregate_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" + "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/testutil" @@ -78,3 +79,26 @@ func TestWaitForSlotTwoThird_WaitCorrectly(t *testing.T) { t.Errorf("Wanted %d time for slot two third but got %d", twoThirdTime, currentTime) } } + +func TestAggregateAndProofSignature_CanSignValidSignature(t *testing.T) { + validator, m, finish := setup(t) + defer finish() + + m.validatorClient.EXPECT().DomainData( + gomock.Any(), // ctx + ðpb.DomainRequest{Epoch: 0, Domain: params.BeaconConfig().DomainAggregateAndProof[:]}, + ).Return(ðpb.DomainResponse{}, nil /*err*/) + + agg := ðpb.AggregateAttestationAndProof{ + AggregatorIndex: 0, + Aggregate: ðpb.Attestation{Data: ðpb.AttestationData{}}, + SelectionProof: nil, + } + sig, err := validator.aggregateAndProofSig(context.Background(), validatorPubKey, agg) + if err != nil { + t.Fatal(err) + } + if _, err := bls.SignatureFromBytes(sig); err != nil { + t.Fatal(err) + } +}