Skip to content

Commit

Permalink
fix + testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
afkbyte committed Sep 23, 2024
1 parent 4e61a1b commit 2a25292
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 8 deletions.
2 changes: 1 addition & 1 deletion contracts/lib/eigenlayer-middleware
Submodule eigenlayer-middleware updated 62 files
+3 −0 .gitmodules
+3 −29 LICENSE
+10 −24 README.md
+ audits/Dedaub - Middleware Audit - Final - Feb'24.pdf
+2 −2 docs/README.md
+1 −1 docs/ServiceManagerBase.md
+1 −1 docs/experimental/AVS-Guide.md
+0 −1 foundry.toml
+1 −0 lib/ds-test
+1 −1 lib/eigenlayer-contracts
+1 −1 lib/forge-std
+4 −8 src/BLSApkRegistry.sol
+62 −116 src/BLSSignatureChecker.sol
+0 −175 src/EjectionManager.sol
+1 −5 src/IndexRegistry.sol
+0 −33 src/OperatorStateRetriever.sol
+145 −274 src/RegistryCoordinator.sol
+1 −6 src/RegistryCoordinatorStorage.sol
+28 −252 src/ServiceManagerBase.sol
+0 −55 src/ServiceManagerBaseStorage.sol
+3 −3 src/ServiceManagerRouter.sol
+10 −22 src/StakeRegistry.sol
+3 −24 src/interfaces/IECDSAStakeRegistryEventsAndErrors.sol
+0 −55 src/interfaces/IEjectionManager.sol
+40 −16 src/interfaces/IServiceManager.sol
+0 −61 src/interfaces/IServiceManagerUI.sol
+0 −61 src/libraries/LibMergeSort.sol
+0 −27 src/libraries/SignatureCheckerLib.sol
+0 −283 src/unaudited/ECDSAServiceManagerBase.sol
+75 −204 src/unaudited/ECDSAStakeRegistry.sol
+3 −10 src/unaudited/ECDSAStakeRegistryStorage.sol
+10 −14 src/unaudited/examples/ECDSAStakeRegistryPermissioned.sol
+0 −69 test/events/IServiceManagerBaseEvents.sol
+1 −1 test/ffi/BLSPubKeyCompendiumFFI.t.sol
+0 −68 test/harnesses/AVSDirectoryHarness.sol
+1 −6 test/integration/CoreRegistration.t.sol
+78 −134 test/integration/IntegrationDeployer.t.sol
+1 −1 test/integration/TimeMachine.t.sol
+2 −4 test/integration/User.t.sol
+3 −4 test/integration/mocks/BeaconChainOracleMock.t.sol
+2 −144 test/mocks/AVSDirectoryMock.sol
+3 −3 test/mocks/DelegationMock.sol
+0 −29 test/mocks/ECDSAServiceManagerMock.sol
+0 −14 test/mocks/ECDSAStakeRegistryMock.sol
+0 −114 test/mocks/RewardsCoordinatorMock.sol
+3 −9 test/mocks/ServiceManagerMock.sol
+146 −368 test/unit/BLSApkRegistryUnit.t.sol
+1 −1 test/unit/BitmapUtils.t.sol
+0 −186 test/unit/ECDSAServiceManager.t.sol
+14 −60 test/unit/ECDSAStakeRegistryEqualWeightUnit.t.sol
+16 −48 test/unit/ECDSAStakeRegistryPermissionedUnit.t.sol
+105 −472 test/unit/ECDSAStakeRegistryUnit.t.sol
+0 −399 test/unit/EjectionManagerUnit.t.sol
+0 −188 test/unit/LibMergeSort.t.sol
+110 −266 test/unit/OperatorStateRetrieverUnit.t.sol
+0 −200 test/unit/RegistryCoordinatorMigration.t.sol
+0 −56 test/unit/RegistryCoordinatorUnit.t.sol
+0 −533 test/unit/ServiceManagerBase.t.sol
+0 −347 test/unit/ServiceManagerMigration.t.sol
+0 −1 test/unit/ServiceManagerRouter.t.sol
+411 −820 test/unit/StakeRegistryUnit.t.sol
+92 −124 test/utils/MockAVSDeployer.sol
23 changes: 16 additions & 7 deletions services/bls_aggregation/blsagg.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,6 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc(
signedTaskResponseDigest,
)

err := a.verifySignature(taskIndex, signedTaskResponseDigest, operatorsAvsStateDict)
signedTaskResponseDigest.SignatureVerificationErrorC <- err
if err != nil {
continue
}

// compute the taskResponseDigest using the hash function
taskResponseDigest, err := a.hashFunction(signedTaskResponseDigest.TaskResponse)
if err != nil {
Expand All @@ -350,8 +344,23 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc(
// happens..
continue
}
// after verifying signature we aggregate its sig and pubkey, and update the signed stake amount

// check if the operator has already signed for this digest
digestAggregatedOperators, ok := aggregatedOperatorsDict[taskResponseDigest]
if ok {
if digestAggregatedOperators.signersOperatorIdsSet[signedTaskResponseDigest.OperatorId] {
signedTaskResponseDigest.SignatureVerificationErrorC <- fmt.Errorf("duplicate signature from operator %x for task %d", signedTaskResponseDigest.OperatorId, taskIndex)
continue
}
}

err = a.verifySignature(taskIndex, signedTaskResponseDigest, operatorsAvsStateDict)
signedTaskResponseDigest.SignatureVerificationErrorC <- err
if err != nil {
continue
}

// after verifying signature we aggregate its sig and pubkey, and update the signed stake amount
if !ok {
// first operator to sign on this digest
digestAggregatedOperators = aggregatedOperators{
Expand Down
95 changes: 95 additions & 0 deletions services/bls_aggregation/blsagg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,101 @@ func TestBlsAgg(t *testing.T) {
}
})

t.Run("1 quorum 2 operators operator 1 double sign", func(t *testing.T) {
testOperator1 := types.TestOperator{
OperatorId: types.OperatorId{1},
StakePerQuorum: map[types.QuorumNum]types.StakeAmount{0: big.NewInt(100)},
BlsKeypair: newBlsKeyPairPanics("0x1"),
}
testOperator2 := types.TestOperator{
OperatorId: types.OperatorId{2},
StakePerQuorum: map[types.QuorumNum]types.StakeAmount{0: big.NewInt(100)},
BlsKeypair: newBlsKeyPairPanics("0x2"),
}

blockNum := uint32(1)
taskIndex := types.TaskIndex(0)
quorumNumbers := types.QuorumNums{0}
quorumThresholdPercentages := []types.QuorumThresholdPercentage{100}
taskResponse := mockTaskResponse{123}

fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(
blockNum,
[]types.TestOperator{testOperator1, testOperator2},
)
logger := testutils.GetTestLogger()
blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger)

logger.Info("Initializing new task", "taskIndex", taskIndex)
err := blsAggServ.InitializeNewTask(
taskIndex,
blockNum,
quorumNumbers,
quorumThresholdPercentages,
10*time.Second, // Longer expiry time for testing
)
require.NoError(t, err)

taskResponseDigest, err := hashFunction(taskResponse)
require.NoError(t, err)

logger.Info("Processing first signature", "operatorId", testOperator1.OperatorId)
blsSigOp1 := testOperator1.BlsKeypair.SignMessage(taskResponseDigest)
err = blsAggServ.ProcessNewSignature(
context.Background(),
taskIndex,
taskResponse,
blsSigOp1,
testOperator1.OperatorId,
)
require.NoError(t, err)

logger.Info("Processing second signature (Operator 1 double sign)", "operatorId", testOperator1.OperatorId)
blsSigOp1Dup := testOperator1.BlsKeypair.SignMessage(taskResponseDigest)
err = blsAggServ.ProcessNewSignature(
context.Background(),
taskIndex,
taskResponse,
blsSigOp1Dup,
testOperator1.OperatorId,
)

if err != nil {
logger.Info("Received error from second signature", "error", err)
require.Contains(t, err.Error(), "duplicate signature")
} else {
t.Fatal("Expected an error for duplicate signature, but got nil")
}

logger.Info("Processing second signature", "operatorId", testOperator2.OperatorId)
blsSigOp2 := testOperator2.BlsKeypair.SignMessage(taskResponseDigest)
err = blsAggServ.ProcessNewSignature(
context.Background(),
taskIndex,
taskResponse,
blsSigOp2,
testOperator2.OperatorId,
)
require.NoError(t, err)

wantAggregationServiceResponse := BlsAggregationServiceResponse{
Err: nil,
TaskIndex: taskIndex,
TaskResponse: taskResponse,
TaskResponseDigest: taskResponseDigest,
NonSignersPubkeysG1: []*bls.G1Point{},
QuorumApksG1: []*bls.G1Point{testOperator1.BlsKeypair.GetPubKeyG1().
Add(testOperator2.BlsKeypair.GetPubKeyG1()),
},
SignersApkG2: testOperator1.BlsKeypair.GetPubKeyG2().
Add(testOperator2.BlsKeypair.GetPubKeyG2()),
SignersAggSigG1: testOperator1.BlsKeypair.SignMessage(taskResponseDigest).
Add(testOperator2.BlsKeypair.SignMessage(taskResponseDigest)),
}
gotAggregationServiceResponse := <-blsAggServ.aggregatedResponsesC
require.EqualValues(t, wantAggregationServiceResponse, gotAggregationServiceResponse)

})
t.Run("1 quorum 1 operator 0 signatures - task expired", func(t *testing.T) {
testOperator1 := types.TestOperator{
OperatorId: types.OperatorId{1},
Expand Down

0 comments on commit 2a25292

Please sign in to comment.