From 0e1b7d89884162d7195070981131e5cf2e8eccc3 Mon Sep 17 00:00:00 2001 From: Lautaro Emanuel Date: Fri, 28 Jun 2024 13:42:03 -0300 Subject: [PATCH] Remove duplicated code --- aggregator/aggregator.go | 2 +- aggregator/message_blsagg.go | 25 ++++++++-------- aggregator/types/types.go | 3 +- core/types/messages/aggregation.go | 47 ------------------------------ 4 files changed, 15 insertions(+), 62 deletions(-) diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index c0b424645..2bac4753f 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -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 diff --git a/aggregator/message_blsagg.go b/aggregator/message_blsagg.go index 6101e8880..cc8e68ab8 100644 --- a/aggregator/message_blsagg.go +++ b/aggregator/message_blsagg.go @@ -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" @@ -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 { diff --git a/aggregator/types/types.go b/aggregator/types/types.go index 21499e56f..dbd0436ca 100644 --- a/aggregator/types/types.go +++ b/aggregator/types/types.go @@ -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)) diff --git a/core/types/messages/aggregation.go b/core/types/messages/aggregation.go index 59d3615bc..d37e849e5 100644 --- a/core/types/messages/aggregation.go +++ b/core/types/messages/aggregation.go @@ -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" @@ -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))