Skip to content

Commit

Permalink
Use signature for SignedAggregateAttestationAndProof (#5605)
Browse files Browse the repository at this point in the history
* Use right signature

* Minor refactor and a regression test

* Use proper DomainRequest for mock

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
terencechain and prylabs-bulldozer[bot] authored Apr 24, 2020
1 parent 3ac15e3 commit 07f6894
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
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)
}
}

0 comments on commit 07f6894

Please sign in to comment.