Skip to content

Commit

Permalink
Use correct domain to verify aggregate selection (#5604)
Browse files Browse the repository at this point in the history
* Use domain selection proof
* Merge refs/heads/master into selection-domain
* Merge branch 'master' of github.com:prysmaticlabs/prysm into selection-domain
* Fixed all the tests
* Merge branch 'selection-domain' of github.com:prysmaticlabs/prysm into selection-domain
  • Loading branch information
terencechain authored Apr 24, 2020
1 parent ffdf248 commit 3ac15e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
14 changes: 9 additions & 5 deletions beacon-chain/sync/pending_attestations_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
if err != nil {
t.Error(err)
}
domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
attesterDomain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
hashTreeRoot, err := helpers.ComputeSigningRoot(att.Data, domain)
hashTreeRoot, err := helpers.ComputeSigningRoot(att.Data, attesterDomain)
if err != nil {
t.Error(err)
}
Expand All @@ -165,7 +165,11 @@ func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
}
att.Signature = bls.AggregateSignatures(sigs).Marshal()[:]

slotRoot, err := helpers.ComputeSigningRoot(att.Data.Slot, domain)
selectionDomain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainSelectionProof, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
slotRoot, err := helpers.ComputeSigningRoot(att.Data.Slot, selectionDomain)
if err != nil {
t.Fatal(err)
}
Expand All @@ -175,11 +179,11 @@ func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
Aggregate: att,
AggregatorIndex: 33,
}
domain, err = helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainAggregateAndProof, beaconState.GenesisValidatorRoot())
attesterDomain, err = helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainAggregateAndProof, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
signingRoot, err := helpers.ComputeSigningRoot(aggregateAndProof, domain)
signingRoot, err := helpers.ComputeSigningRoot(aggregateAndProof, attesterDomain)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/sync/validate_aggregate_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func validateSelection(ctx context.Context, s *stateTrie.BeaconState, data *ethp
return fmt.Errorf("validator is not an aggregator for slot %d", data.Slot)
}

domain, err := helpers.Domain(s.Fork(), helpers.SlotToEpoch(data.Slot), params.BeaconConfig().DomainBeaconAttester, s.GenesisValidatorRoot())
domain, err := helpers.Domain(s.Fork(), helpers.SlotToEpoch(data.Slot), params.BeaconConfig().DomainSelectionProof, s.GenesisValidatorRoot())
if err != nil {
return err
}
Expand Down
30 changes: 19 additions & 11 deletions beacon-chain/sync/validate_aggregate_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestVerifySelection_CanVerify(t *testing.T) {
beaconState, privKeys := testutil.DeterministicGenesisState(t, validators)

data := &ethpb.AttestationData{}
domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainSelectionProof, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -382,11 +382,11 @@ func TestValidateAggregateAndProofWithNewStateMgmt_CanValidate(t *testing.T) {
if err != nil {
t.Error(err)
}
domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
attesterDomain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
hashTreeRoot, err := helpers.ComputeSigningRoot(att.Data, domain)
hashTreeRoot, err := helpers.ComputeSigningRoot(att.Data, attesterDomain)
if err != nil {
t.Error(err)
}
Expand All @@ -397,7 +397,11 @@ func TestValidateAggregateAndProofWithNewStateMgmt_CanValidate(t *testing.T) {
}
att.Signature = bls.AggregateSignatures(sigs).Marshal()[:]

slotRoot, err := helpers.ComputeSigningRoot(att.Data.Slot, domain)
selectionDomain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainSelectionProof, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
slotRoot, err := helpers.ComputeSigningRoot(att.Data.Slot, selectionDomain)
if err != nil {
t.Fatal(err)
}
Expand All @@ -410,11 +414,11 @@ func TestValidateAggregateAndProofWithNewStateMgmt_CanValidate(t *testing.T) {
}
signedAggregateAndProof := &ethpb.SignedAggregateAttestationAndProof{Message: aggregateAndProof}

domain, err = helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainAggregateAndProof, beaconState.GenesisValidatorRoot())
attesterDomain, err = helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainAggregateAndProof, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
signingRoot, err := helpers.ComputeSigningRoot(signedAggregateAndProof.Message, domain)
signingRoot, err := helpers.ComputeSigningRoot(signedAggregateAndProof.Message, attesterDomain)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -503,11 +507,11 @@ func TestVerifyIndexInCommittee_SeenAggregatorSlot(t *testing.T) {
t.Error(err)
}
attestingIndices := attestationutil.AttestingIndices(att.AggregationBits, committee)
domain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
attesterDomain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
hashTreeRoot, err := helpers.ComputeSigningRoot(att.Data, domain)
hashTreeRoot, err := helpers.ComputeSigningRoot(att.Data, attesterDomain)
if err != nil {
t.Error(err)
}
Expand All @@ -518,7 +522,11 @@ func TestVerifyIndexInCommittee_SeenAggregatorSlot(t *testing.T) {
}
att.Signature = bls.AggregateSignatures(sigs).Marshal()[:]

slotRoot, err := helpers.ComputeSigningRoot(att.Data.Slot, domain)
selectionDomain, err := helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainSelectionProof, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
slotRoot, err := helpers.ComputeSigningRoot(att.Data.Slot, selectionDomain)
if err != nil {
t.Fatal(err)
}
Expand All @@ -531,11 +539,11 @@ func TestVerifyIndexInCommittee_SeenAggregatorSlot(t *testing.T) {
}
signedAggregateAndProof := &ethpb.SignedAggregateAttestationAndProof{Message: aggregateAndProof}

domain, err = helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainAggregateAndProof, beaconState.GenesisValidatorRoot())
attesterDomain, err = helpers.Domain(beaconState.Fork(), 0, params.BeaconConfig().DomainAggregateAndProof, beaconState.GenesisValidatorRoot())
if err != nil {
t.Fatal(err)
}
signingRoot, err := helpers.ComputeSigningRoot(signedAggregateAndProof.Message, domain)
signingRoot, err := helpers.ComputeSigningRoot(signedAggregateAndProof.Message, attesterDomain)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit 3ac15e3

Please sign in to comment.