Skip to content

Commit

Permalink
fix issue #187
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhihua81 committed Apr 8, 2024
1 parent a85583b commit 91acc2c
Showing 1 changed file with 15 additions and 49 deletions.
64 changes: 15 additions & 49 deletions services/bls_aggregation/blsagg.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,25 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc(

if checkIfStakeThresholdsMet(digestAggregatedOperators.signersTotalStakePerQuorum, totalStakePerQuorum, quorumThresholdPercentagesMap) {
nonSignersOperatorIds := []types.OperatorId{}
nonSignersG1Pubkeys := []*bls.G1Point{}

for operatorId, operator := range operatorsAvsStateDict {
for operatorId := range operatorsAvsStateDict {
if _, operatorSigned := digestAggregatedOperators.signersOperatorIdsSet[operatorId]; !operatorSigned {
nonSignersOperatorIds = append(nonSignersOperatorIds, operatorId)
nonSignersG1Pubkeys = append(nonSignersG1Pubkeys, operator.Pubkeys.G1Pubkey)
}
}

// the contract requires a sorted nonSignersOperatorIds
sort.SliceStable(nonSignersOperatorIds, func(i, j int) bool {
iOprInt := new(big.Int).SetBytes(nonSignersOperatorIds[i][:])
jOprInt := new(big.Int).SetBytes(nonSignersOperatorIds[j][:])
return iOprInt.Cmp(jOprInt) == -1
})

nonSignersG1Pubkeys := []*bls.G1Point{}
for _, operatorId := range nonSignersOperatorIds {
operator := operatorsAvsStateDict[operatorId]
nonSignersG1Pubkeys = append(nonSignersG1Pubkeys, operator.Pubkeys.G1Pubkey)
}

indices, err := a.avsRegistryService.GetCheckSignaturesIndices(&bind.CallOpts{}, taskCreatedBlock, quorumNumbers, nonSignersOperatorIds)
if err != nil {
a.aggregatedResponsesC <- BlsAggregationServiceResponse{
Expand All @@ -305,14 +316,6 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc(
TotalStakeIndices: indices.TotalStakeIndices,
NonSignerStakeIndices: indices.NonSignerStakeIndices,
}

blsAggregationServiceResponse.NonSignersPubkeysG1,
blsAggregationServiceResponse.NonSignerQuorumBitmapIndices =
sortByOprId(
blsAggregationServiceResponse.NonSignersPubkeysG1,
blsAggregationServiceResponse.NonSignerQuorumBitmapIndices,
)

a.aggregatedResponsesC <- blsAggregationServiceResponse
return
}
Expand All @@ -326,43 +329,6 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc(

}

type Wrapper struct {
pubkeyG1 *bls.G1Point
quorumBitmapIndex uint32
}

// note for caller, this method assumes quorumBitmapIndices & stakeIndices both have same length with pubkeysG1
// will return original arrays if the lengths are not match
func sortByOprId(pubkeysG1 []*bls.G1Point, quorumBitmapIndices []uint32) (
retPubkeysG1 []*bls.G1Point, retQuorumBitmapIndices []uint32,
) {
if len(pubkeysG1) != len(quorumBitmapIndices) || len(pubkeysG1) == 0 || len(pubkeysG1) == 1 {
return pubkeysG1, quorumBitmapIndices
}

var wrappers []*Wrapper
for i := range pubkeysG1 {
wrappers = append(wrappers, &Wrapper{
pubkeyG1: pubkeysG1[i],
quorumBitmapIndex: quorumBitmapIndices[i],
})
}
sort.SliceStable(wrappers, func(i, j int) bool {
iOpr := types.OperatorIdFromPubkey(wrappers[i].pubkeyG1)
jOpr := types.OperatorIdFromPubkey(wrappers[j].pubkeyG1)
iOprInt := new(big.Int).SetBytes(iOpr[:])
jOprInt := new(big.Int).SetBytes(jOpr[:])
return iOprInt.Cmp(jOprInt) == -1
})

for i := range wrappers {
retPubkeysG1 = append(retPubkeysG1, wrappers[i].pubkeyG1)
retQuorumBitmapIndices = append(retQuorumBitmapIndices, wrappers[i].quorumBitmapIndex)
}

return
}

// closeTaskGoroutine is run when the goroutine processing taskIndex's task responses ends (for whatever reason)
// it deletes the response channel for taskIndex from a.taskChans
// so that the main thread knows that this task goroutine is no longer running
Expand Down

0 comments on commit 91acc2c

Please sign in to comment.