Skip to content
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

Use signature for SignedAggregateAttestationAndProof #5605

Merged
merged 10 commits into from
Apr 24, 2020
32 changes: 22 additions & 10 deletions validator/client/validator_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &ethpb.SignedAggregateSubmitRequest{
SignedAggregateAndProof: &ethpb.SignedAggregateAttestationAndProof{
Message: res.AggregateAndProof,
Signature: signedRoot[:],
Signature: sig,
},
})
if err != nil {
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 24 additions & 0 deletions validator/client/validator_aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
&ethpb.DomainRequest{Epoch: 0, Domain: params.BeaconConfig().DomainAggregateAndProof[:]},
).Return(&ethpb.DomainResponse{}, nil /*err*/)

agg := &ethpb.AggregateAttestationAndProof{
AggregatorIndex: 0,
Aggregate: &ethpb.Attestation{Data: &ethpb.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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a sig verify or something for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sufficient. We just want to verify that it's a "valid" BLS signature which was where the regression is. As we previously use signing root instead of signature (different byte lengths)

}