Skip to content

Commit

Permalink
Fix bls aggregation for multiple quorums (#394)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomás Grüner <[email protected]>
  • Loading branch information
TomasArrachea and MegaRedHand authored Feb 19, 2025
1 parent d323b0f commit 01368ec
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 72 deletions.
70 changes: 39 additions & 31 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Each version will have a separate `Breaking Changes` section as well. To describe in how to upgrade from one version to another if needed

## [Unreleased]
### Added

### Added 🎉

### Changed
* fix: change requested pr url in changelog's workflow by @maximopalopoli in <https://github.com/Layr-Labs/eigensdk-go/pull/575>

* Fixed BLS aggregation for multiple quorums by @TomasArrachea in [#394](https://github.com/Layr-Labs/eigensdk-go/pull/394)
* fix: change requested pr url in changelog's workflow by @maximopalopoli in [#575](https://github.com/Layr-Labs/eigensdk-go/pull/575)

### Breaking changes

Expand All @@ -22,20 +26,20 @@ Each version will have a separate `Breaking Changes` section as well. To describ
```go
// BEFORE
blsAggServ.ProcessNewSignature(
context.Background(),
taskIndex,
taskResponse,
blsSigOp1,
testOperator1.OperatorId,
)
context.Background(),
taskIndex,
taskResponse,
blsSigOp1,
testOperator1.OperatorId,
)

// AFTER
taskSignature := NewTaskSignature(taskIndex, taskResponse, blsSig, testOperator1.OperatorId)

blsAggServ.ProcessNewSignature(
context.Background(),
taskSignature,
)
context.Background(),
taskSignature,
)
```

* refactor: update interface on `bls aggregation` in [#485](https://github.com/Layr-Labs/eigensdk-go/pull/485).
Expand All @@ -47,12 +51,12 @@ Each version will have a separate `Breaking Changes` section as well. To describ
blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger)
blsAggServ.InitializeNewTask(
taskIndex,
blockNum,
quorumNumbers,
quorumThresholdPercentages,
tasksTimeToExpiry,
)
taskIndex,
blockNum,
quorumNumbers,
quorumThresholdPercentages,
tasksTimeToExpiry,
)
// AFTER
blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger)
Expand All @@ -67,25 +71,29 @@ Each version will have a separate `Breaking Changes` section as well. To describ
// BEFORE
blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger)
err = blsAggServ.InitializeNewTaskWithWindow(
taskIndex,
blockNum,
quorumNumbers,
quorumThresholdPercentages,
timeToExpiry,
windowDuration,
)
taskIndex,
blockNum,
quorumNumbers,
quorumThresholdPercentages,
timeToExpiry,
windowDuration,
)
// AFTER
blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger)
metadata := NewTaskMetadata(
taskIndex,
blockNum,
quorumNumbers,
quorumThresholdPercentages,
tasksTimeToExpiry,
).WithWindowDuration(windowDuration)
taskIndex,
blockNum,
quorumNumbers,
quorumThresholdPercentages,
tasksTimeToExpiry,
).WithWindowDuration(windowDuration)
blsAggServ.InitializeNewTask(metadata)
```

### Removed

------------

Changes made in the v0.1.X versions weren't tracked by this changelog.
21 changes: 16 additions & 5 deletions services/bls_aggregation/blsagg.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,22 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc(
// after verifying signature we aggregate its sig and pubkey, and update the signed stake amount
if !ok {
// first operator to sign on this digest
signersApkG2 := bls.NewZeroG2Point()
signersAggSigG1 := bls.NewZeroSignature()
// for each quorum the operator has stake in, the signature is aggregated
// see
// https://github.com/Layr-Labs/eigenlayer-middleware/blob/7d49b5181b09198ed275783453aa082bb3766990/src/BLSSignatureChecker.sol#L161-L168
for range operatorsAvsStateDict[signedTaskResponseDigest.OperatorId].StakePerQuorum {
signersApkG2 = signersApkG2.Add(
operatorsAvsStateDict[signedTaskResponseDigest.OperatorId].OperatorInfo.Pubkeys.G2Pubkey,
)
signersAggSigG1 = signersAggSigG1.Add(signedTaskResponseDigest.BlsSignature)
}
digestAggregatedOperators = aggregatedOperators{
// we've already verified that the operator is part of the task's quorum, so we don't need checks
// here
signersApkG2: bls.NewZeroG2Point().
Add(operatorsAvsStateDict[signedTaskResponseDigest.OperatorId].OperatorInfo.Pubkeys.G2Pubkey),
signersAggSigG1: signedTaskResponseDigest.BlsSignature,
signersApkG2: signersApkG2,
signersAggSigG1: signersAggSigG1,
signersOperatorIdsSet: map[types.OperatorId]bool{signedTaskResponseDigest.OperatorId: true},
signersTotalStakePerQuorum: cloneStakePerQuorumMap(
operatorsAvsStateDict[signedTaskResponseDigest.OperatorId].StakePerQuorum,
Expand All @@ -484,10 +494,11 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc(
"taskIndex", metadata.taskIndex,
"taskResponseDigest", taskResponseDigest)

digestAggregatedOperators.signersAggSigG1.Add(signedTaskResponseDigest.BlsSignature)
digestAggregatedOperators.signersApkG2.Add(operatorsAvsStateDict[signedTaskResponseDigest.OperatorId].OperatorInfo.Pubkeys.G2Pubkey)
digestAggregatedOperators.signersOperatorIdsSet[signedTaskResponseDigest.OperatorId] = true
// for each quorum the operator has stake in, the signature is aggregated
for quorumNum, stake := range operatorsAvsStateDict[signedTaskResponseDigest.OperatorId].StakePerQuorum {
digestAggregatedOperators.signersAggSigG1.Add(signedTaskResponseDigest.BlsSignature)
digestAggregatedOperators.signersApkG2.Add(operatorsAvsStateDict[signedTaskResponseDigest.OperatorId].OperatorInfo.Pubkeys.G2Pubkey)
if _, ok := digestAggregatedOperators.signersTotalStakePerQuorum[quorumNum]; !ok {
// if we haven't seen this quorum before, initialize its signed stake to 0
// possible if previous operators who sent us signatures were not part of this quorum
Expand Down
Loading

0 comments on commit 01368ec

Please sign in to comment.