Skip to content

Commit

Permalink
Remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
emlautarom1 committed Jun 28, 2024
1 parent 56abc17 commit 0e1b7d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 62 deletions.
2 changes: 1 addition & 1 deletion aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (agg *Aggregator) sendAggregatedResponseToContract(blsAggServiceResp types.
taskResponse := agg.taskResponses[blsAggServiceResp.TaskIndex][blsAggServiceResp.TaskResponseDigest]
agg.taskResponsesLock.RUnlock()

aggregation, err := types.NewMessageBlsAggregationFromTaskServiceResponse(uint64(task.TaskCreatedBlock), blsAggServiceResp)
aggregation, err := types.NewMessageBlsAggregationFromServiceResponse(uint64(task.TaskCreatedBlock), blsAggServiceResp)
if err != nil {
agg.logger.Error("Aggregator failed to format aggregation", "err", err)
return
Expand Down
25 changes: 13 additions & 12 deletions aggregator/message_blsagg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/services/avsregistry"
blsagg "github.com/Layr-Labs/eigensdk-go/services/bls_aggregation"
eigentypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"

Expand Down Expand Up @@ -428,18 +427,20 @@ func (mbas *MessageBlsAggregatorService) getMessageBlsAggregationResponse(messag
}
}

aggregation, err := messages.NewMessageBlsAggregationFromServiceResponse(
aggregation, err := types.NewMessageBlsAggregationFromServiceResponse(
validationInfo.ethBlockNumber,
blsagg.BlsAggregationServiceResponse{
TaskResponseDigest: messageDigest,
NonSignersPubkeysG1: getG1PubkeysOfNonSigners(digestAggregatedOperators.signersOperatorIdsSet, validationInfo.operatorsAvsStateDict),
QuorumApksG1: validationInfo.quorumApksG1,
SignersApkG2: digestAggregatedOperators.signersApkG2,
SignersAggSigG1: digestAggregatedOperators.signersAggSigG1,
NonSignerQuorumBitmapIndices: indices.NonSignerQuorumBitmapIndices,
QuorumApkIndices: indices.QuorumApkIndices,
TotalStakeIndices: indices.TotalStakeIndices,
NonSignerStakeIndices: indices.NonSignerStakeIndices,
types.TaskBlsAggregationServiceResponse{
TaskResponseDigest: messageDigest,
TaskBlsAggregation: messages.TaskBlsAggregation{
NonSignersPubkeysG1: getG1PubkeysOfNonSigners(digestAggregatedOperators.signersOperatorIdsSet, validationInfo.operatorsAvsStateDict),
QuorumApksG1: validationInfo.quorumApksG1,
SignersApkG2: digestAggregatedOperators.signersApkG2,
SignersAggSigG1: digestAggregatedOperators.signersAggSigG1,
NonSignerQuorumBitmapIndices: indices.NonSignerQuorumBitmapIndices,
QuorumApkIndices: indices.QuorumApkIndices,
TotalStakeIndices: indices.TotalStakeIndices,
NonSignerStakeIndices: indices.NonSignerStakeIndices,
},
},
)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions aggregator/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ type GetCheckpointMessagesResponse struct {
CheckpointMessages messages.CheckpointMessages
}

// TODO: Deduplicate from `messages.NewMessageBlsAggregationFromServiceResponse`
func NewMessageBlsAggregationFromTaskServiceResponse(ethBlockNumber uint64, resp TaskBlsAggregationServiceResponse) (messages.MessageBlsAggregation, error) {
func NewMessageBlsAggregationFromServiceResponse(ethBlockNumber uint64, resp TaskBlsAggregationServiceResponse) (messages.MessageBlsAggregation, error) {
nonSignersPubkeyHashes := make([][32]byte, 0, len(resp.NonSignersPubkeysG1))
for _, pubkey := range resp.NonSignersPubkeysG1 {
hash, err := core.HashBNG1Point(core.ConvertToBN254G1Point(pubkey))
Expand Down
47 changes: 0 additions & 47 deletions core/types/messages/aggregation.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package messages

import (
"bytes"
"sort"

"github.com/Layr-Labs/eigensdk-go/crypto/bls"
blsagg "github.com/Layr-Labs/eigensdk-go/services/bls_aggregation"

registryrollup "github.com/NethermindEth/near-sffl/contracts/bindings/SFFLRegistryRollup"
taskmanager "github.com/NethermindEth/near-sffl/contracts/bindings/SFFLTaskManager"
Expand Down Expand Up @@ -37,49 +33,6 @@ type MessageBlsAggregation struct {
NonSignerStakeIndices [][]uint32
}

func NewMessageBlsAggregationFromServiceResponse(ethBlockNumber uint64, resp blsagg.BlsAggregationServiceResponse) (MessageBlsAggregation, error) {
nonSignersPubkeyHashes := make([][32]byte, 0, len(resp.NonSignersPubkeysG1))
for _, pubkey := range resp.NonSignersPubkeysG1 {
hash, err := core.HashBNG1Point(core.ConvertToBN254G1Point(pubkey))
if err != nil {
return MessageBlsAggregation{}, err
}

nonSignersPubkeyHashes = append(nonSignersPubkeyHashes, hash)
}

nonSignersPubkeys := append([]*bls.G1Point{}, resp.NonSignersPubkeysG1...)
nonSignerQuorumBitmapIndices := append([]uint32{}, resp.NonSignerQuorumBitmapIndices...)

nonSignerStakeIndices := make([][]uint32, 0, len(resp.NonSignerStakeIndices))
for _, nonSignerStakeIndex := range resp.NonSignerStakeIndices {
nonSignerStakeIndices = append(nonSignerStakeIndices, append([]uint32{}, nonSignerStakeIndex...))
}

sortByPubkeyHash := func(arr any) {
sort.Slice(arr, func(i, j int) bool {
return bytes.Compare(nonSignersPubkeyHashes[i][:], nonSignersPubkeyHashes[j][:]) == -1
})
}

sortByPubkeyHash(nonSignersPubkeys)
sortByPubkeyHash(nonSignerStakeIndices)
sortByPubkeyHash(nonSignerQuorumBitmapIndices)

return MessageBlsAggregation{
EthBlockNumber: uint64(ethBlockNumber),
MessageDigest: resp.TaskResponseDigest,
NonSignersPubkeysG1: nonSignersPubkeys,
QuorumApksG1: resp.QuorumApksG1,
SignersApkG2: resp.SignersApkG2,
SignersAggSigG1: resp.SignersAggSigG1,
NonSignerQuorumBitmapIndices: nonSignerQuorumBitmapIndices,
QuorumApkIndices: resp.QuorumApkIndices,
TotalStakeIndices: resp.TotalStakeIndices,
NonSignerStakeIndices: nonSignerStakeIndices,
}, nil
}

func (msg MessageBlsAggregation) ExtractBindingMainnet() taskmanager.IBLSSignatureCheckerNonSignerStakesAndSignature {
nonSignersPubkeys := make([]taskmanager.BN254G1Point, 0, len(msg.NonSignersPubkeysG1))
quorumApks := make([]taskmanager.BN254G1Point, 0, len(msg.QuorumApksG1))
Expand Down

0 comments on commit 0e1b7d8

Please sign in to comment.