mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
Guard against no attesters within committee in VerifyAttestationNoVerifySignature (#15169)
* Guard against no attesters within committee in `VerifyAttestationNoVerifySignature` * changelog fragment
This commit is contained in:
@@ -106,7 +106,7 @@ func VerifyAttestationNoVerifySignature(
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c := helpers.SlotCommitteeCount(activeValidatorCount)
|
||||
committeeCount := helpers.SlotCommitteeCount(activeValidatorCount)
|
||||
|
||||
var indexedAtt ethpb.IndexedAtt
|
||||
|
||||
@@ -115,13 +115,14 @@ func VerifyAttestationNoVerifySignature(
|
||||
return errors.New("committee index must be 0 post-Electra")
|
||||
}
|
||||
|
||||
aggBits := att.GetAggregationBits()
|
||||
committeeIndices := att.CommitteeBitsVal().BitIndices()
|
||||
committees := make([][]primitives.ValidatorIndex, len(committeeIndices))
|
||||
participantsCount := 0
|
||||
var err error
|
||||
for i, ci := range committeeIndices {
|
||||
if uint64(ci) >= c {
|
||||
return fmt.Errorf("committee index %d >= committee count %d", ci, c)
|
||||
if uint64(ci) >= committeeCount {
|
||||
return fmt.Errorf("committee index %d >= committee count %d", ci, committeeCount)
|
||||
}
|
||||
committees[i], err = helpers.BeaconCommitteeFromState(ctx, beaconState, att.GetData().Slot, primitives.CommitteeIndex(ci))
|
||||
if err != nil {
|
||||
@@ -129,16 +130,32 @@ func VerifyAttestationNoVerifySignature(
|
||||
}
|
||||
participantsCount += len(committees[i])
|
||||
}
|
||||
if att.GetAggregationBits().Len() != uint64(participantsCount) {
|
||||
if aggBits.Len() != uint64(participantsCount) {
|
||||
return fmt.Errorf("aggregation bits count %d is different than participant count %d", att.GetAggregationBits().Len(), participantsCount)
|
||||
}
|
||||
|
||||
committeeOffset := 0
|
||||
for ci, c := range committees {
|
||||
attesterFound := false
|
||||
for i := range c {
|
||||
if aggBits.BitAt(uint64(committeeOffset + i)) {
|
||||
attesterFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !attesterFound {
|
||||
return fmt.Errorf("no attesting indices found for committee index %d", ci)
|
||||
}
|
||||
committeeOffset += len(c)
|
||||
}
|
||||
|
||||
indexedAtt, err = attestation.ConvertToIndexed(ctx, att, committees...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if uint64(att.GetData().CommitteeIndex) >= c {
|
||||
return fmt.Errorf("committee index %d >= committee count %d", att.GetData().CommitteeIndex, c)
|
||||
if uint64(att.GetData().CommitteeIndex) >= committeeCount {
|
||||
return fmt.Errorf("committee index %d >= committee count %d", att.GetData().CommitteeIndex, committeeCount)
|
||||
}
|
||||
|
||||
// Verify attesting indices are correct.
|
||||
|
||||
@@ -296,6 +296,22 @@ func TestVerifyAttestationNoVerifySignature_Electra(t *testing.T) {
|
||||
err = blocks.VerifyAttestationNoVerifySignature(context.TODO(), beaconState, att)
|
||||
assert.ErrorContains(t, "aggregation bits count 123 is different than participant count 3", err)
|
||||
})
|
||||
t.Run("no attester in committee", func(t *testing.T) {
|
||||
aggBits := bitfield.NewBitlist(3)
|
||||
committeeBits := bitfield.NewBitvector64()
|
||||
committeeBits.SetBitAt(0, true)
|
||||
att := ðpb.AttestationElectra{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
CommitteeBits: committeeBits,
|
||||
}
|
||||
att.Signature = zeroSig[:]
|
||||
err = blocks.VerifyAttestationNoVerifySignature(context.TODO(), beaconState, att)
|
||||
assert.ErrorContains(t, "no attesting indices found for committee index 0", err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestConvertToIndexed_OK(t *testing.T) {
|
||||
|
||||
3
changelog/radek_electra-committee-assertion.md
Normal file
3
changelog/radek_electra-committee-assertion.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Fixed
|
||||
|
||||
- Guard against no attesters within committee in `VerifyAttestationNoVerifySignature`.
|
||||
@@ -111,7 +111,7 @@ func AttestingIndices(att ethpb.Att, committees ...[]primitives.ValidatorIndex)
|
||||
|
||||
attesters := make([]uint64, 0, aggBits.Count())
|
||||
committeeOffset := 0
|
||||
for _, c := range committees {
|
||||
for ci, c := range committees {
|
||||
committeeAttesters := make([]uint64, 0, len(c))
|
||||
for i, vi := range c {
|
||||
if aggBits.BitAt(uint64(committeeOffset + i)) {
|
||||
@@ -119,7 +119,7 @@ func AttestingIndices(att ethpb.Att, committees ...[]primitives.ValidatorIndex)
|
||||
}
|
||||
}
|
||||
if len(committeeAttesters) == 0 {
|
||||
return nil, fmt.Errorf("no attesting indices found in committee %v", c)
|
||||
return nil, fmt.Errorf("no attesting indices found for committee index %d", ci)
|
||||
}
|
||||
attesters = append(attesters, committeeAttesters...)
|
||||
committeeOffset += len(c)
|
||||
|
||||
@@ -81,6 +81,14 @@ func TestAttestingIndices(t *testing.T) {
|
||||
},
|
||||
want: []uint64{0, 1},
|
||||
},
|
||||
{
|
||||
name: "Electra - No attester in committee",
|
||||
args: args{
|
||||
att: ð.AttestationElectra{AggregationBits: bitfield.Bitlist{0b11100}},
|
||||
committees: [][]primitives.ValidatorIndex{{0, 1}, {0, 1}},
|
||||
},
|
||||
err: "no attesting indices found for committee index 0",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user