Skip to content

Commit

Permalink
Caplin: Fix aggregate quality (#12583)
Browse files Browse the repository at this point in the history
Basically we had wrong behaviour is overlapping bits. last bit on are
length and shall not be counted. also decreased batched chunk size
  • Loading branch information
Giulio2002 authored Nov 15, 2024
1 parent 2b2180c commit adfdcbd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cl/aggregation/pool_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (p *aggregationPoolImpl) AddAttestation(inAtt *solid.Attestation) error {
return nil
}

if utils.IsOverlappingBitlist(att.AggregationBits.Bytes(), inAtt.AggregationBits.Bytes()) {
if utils.IsOverlappingSSZBitlist(att.AggregationBits.Bytes(), inAtt.AggregationBits.Bytes()) {
// the on bit is already set, so ignore
return ErrIsSuperset
}
Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/handler/block_production.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ func (a *ApiHandler) findBestAttestationsForBlockProduction(
candidateAggregationBits := candidate.AggregationBits.Bytes()
for _, curAtt := range hashToAtts[dataRoot] {
currAggregationBitsBytes := curAtt.AggregationBits.Bytes()
if !utils.IsOverlappingBitlist(currAggregationBitsBytes, candidateAggregationBits) {
if !utils.IsOverlappingSSZBitlist(currAggregationBitsBytes, candidateAggregationBits) {
// merge signatures
candidateSig := candidate.Signature
curSig := curAtt.Signature
Expand Down
3 changes: 1 addition & 2 deletions cl/phase1/network/services/batch_signature_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
batchSignatureVerificationThreshold = 300
batchSignatureVerificationThreshold = 50
reservedSize = 512
)

Expand Down Expand Up @@ -154,7 +154,6 @@ func (b *BatchSignatureVerifier) processSignatureVerification(aggregateVerificat
if b.sentinel != nil && v.GossipData != nil {
if _, err := b.sentinel.PublishGossip(b.ctx, v.GossipData); err != nil {
log.Debug("failed to publish gossip", "err", err)
return err
}
}
}
Expand Down
30 changes: 28 additions & 2 deletions cl/utils/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,42 @@ func IsNonStrictSupersetBitlist(a, b []byte) bool {
return true
}

func IsOverlappingBitlist(a, b []byte) bool {
// IsOverlappingSSZBitlist checks if bitlist 'a' and bitlist 'b' have any overlapping bits
// However, it ignores the last bits in the last byte.
func IsOverlappingSSZBitlist(a, b []byte) bool {
length := min(len(a), len(b))
for i := range length {

if a[i]&b[i] != 0 {
return true
if i != length-1 {
return true
}
var foundOverlap bool
// check the overlap bit by bit
for j := 0; j < 8; j++ {
if (a[i]>>j)&(b[i]>>j)&1 == 1 {
if foundOverlap {
return true
}
foundOverlap = true
}
}
}
}
return false

}

// func IsOverlappingBitlist(a, b []byte) bool {
// length := min(len(a), len(b))
// for i := range length {
// if a[i]&b[i] != 0 {
// return true
// }
// }
// return false
// }

func BitsOnCount(b []byte) int {
count := 0
for _, v := range b {
Expand Down

0 comments on commit adfdcbd

Please sign in to comment.