prevent OR on bitlists of different length (#4209)

* prevent OR on bitlists of different length
* prevent OR on bitlists of different length
This commit is contained in:
Preston Van Loon
2019-12-06 06:33:40 -08:00
committed by prylabs-bulldozer[bot]
parent dc0b8fad4f
commit cae24068d4
2 changed files with 13 additions and 0 deletions

View File

@@ -28,6 +28,9 @@ func NewContainerFromAttestations(atts []*ethpb.Attestation) *AttestationContain
func (ac *AttestationContainer) Contains(att *ethpb.Attestation) bool {
all := bitfield.NewBitlist(att.AggregationBits.Len())
for _, sp := range ac.SignaturePairs {
if all.Len() != sp.AggregationBits.Len() {
continue
}
all = all.Or(sp.AggregationBits)
}
return all.Contains(att.AggregationBits)

View File

@@ -63,6 +63,16 @@ func TestAttestationContainer_Contains(t *testing.T) {
contains: bitfield.Bitlist{0b01000000, 0b1},
want: false,
},
{
input: []bitfield.Bitlist{
{0b10000001, 0b1},
{0b10000010, 0b1},
{0b10000100, 0b1},
{0b10010001, 0b1},
},
contains: bitfield.Bitlist{0b10000000, 0b10}, // Different length.
want: false,
},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {