From 916e84a67a902711d7a32f68a5168d69fb6ed6d3 Mon Sep 17 00:00:00 2001 From: Giulio rebuffo Date: Mon, 28 Oct 2024 14:15:42 +0100 Subject: [PATCH] Fix bls attestations test again (#12513) This time it does not use goroutines --- cl/cltypes/bls_to_execution_change.go | 1 + .../network/services/batch_signature_verification.go | 4 +++- .../services/bls_to_execution_change_service.go | 4 ++++ .../services/bls_to_execution_change_service_test.go | 11 ++++++----- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cl/cltypes/bls_to_execution_change.go b/cl/cltypes/bls_to_execution_change.go index fea594a84f3..ca6a87f7d9a 100644 --- a/cl/cltypes/bls_to_execution_change.go +++ b/cl/cltypes/bls_to_execution_change.go @@ -63,6 +63,7 @@ func (*BLSToExecutionChange) Static() bool { type SignedBLSToExecutionChangeWithGossipData struct { SignedBLSToExecutionChange *SignedBLSToExecutionChange GossipData *sentinel.GossipData + ImmediateVerification bool } type SignedBLSToExecutionChange struct { diff --git a/cl/phase1/network/services/batch_signature_verification.go b/cl/phase1/network/services/batch_signature_verification.go index 5178f3ee0ed..da315a3186e 100644 --- a/cl/phase1/network/services/batch_signature_verification.go +++ b/cl/phase1/network/services/batch_signature_verification.go @@ -29,6 +29,8 @@ type BatchSignatureVerifier struct { ctx context.Context } +var ErrInvalidBlsSignature = errors.New("invalid bls signature") + // each AggregateVerification request has sentinel.SentinelClient and *sentinel.GossipData // to make sure that we can validate it separately and in case of failure we ban corresponding // GossipData.Peer or simply run F and publish GossipData in case signature verification succeeds. @@ -181,7 +183,7 @@ func (b *BatchSignatureVerifier) runBatchVerification(signatures [][]byte, signR monitor.ObserveBatchVerificationThroughput(time.Since(start), len(signatures)) if !valid { - return errors.New("batch invalid signature") + return ErrInvalidBlsSignature } return nil diff --git a/cl/phase1/network/services/bls_to_execution_change_service.go b/cl/phase1/network/services/bls_to_execution_change_service.go index fd12a9dabef..35bbba6ebc6 100644 --- a/cl/phase1/network/services/bls_to_execution_change_service.go +++ b/cl/phase1/network/services/bls_to_execution_change_service.go @@ -136,6 +136,10 @@ func (s *blsToExecutionChangeService) ProcessMessage(ctx context.Context, subnet }, } + if msg.ImmediateVerification { + return s.batchSignatureVerifier.ImmediateVerification(aggregateVerificationData) + } + // push the signatures to verify asynchronously and run final functions after that. s.batchSignatureVerifier.AsyncVerifyBlsToExecutionChange(aggregateVerificationData) diff --git a/cl/phase1/network/services/bls_to_execution_change_service_test.go b/cl/phase1/network/services/bls_to_execution_change_service_test.go index becf3807829..ee0fc6fac76 100644 --- a/cl/phase1/network/services/bls_to_execution_change_service_test.go +++ b/cl/phase1/network/services/bls_to_execution_change_service_test.go @@ -85,7 +85,8 @@ func (t *blsToExecutionChangeTestSuite) TestProcessMessage() { }, Signature: [96]byte{1, 2, 3}, }, - GossipData: nil, + GossipData: nil, + ImmediateVerification: true, } tests := []struct { @@ -179,7 +180,7 @@ func (t *blsToExecutionChangeTestSuite) TestProcessMessage() { t.gomockCtrl.RecordCall(t.mockFuncs, "BlsVerifyMultipleSignatures", gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil).Times(2) }, msg: mockMsg, - specificErr: ErrIgnore, + specificErr: ErrInvalidBlsSignature, wantErr: true, }, { @@ -206,9 +207,9 @@ func (t *blsToExecutionChangeTestSuite) TestProcessMessage() { mockStateMutator.EXPECT().SetWithdrawalCredentialForValidatorAtIndex(int(mockMsg.SignedBLSToExecutionChange.Message.ValidatorIndex), mockNewWc).Times(1) t.gomockCtrl.RecordCall(t.mockFuncs, "BlsVerifyMultipleSignatures", gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil).Times(1) }, - msg: mockMsg, - specificErr: ErrIgnore, - wantErr: true, + msg: mockMsg, + // specificErr: ErrInvalidBlsSignature, + // wantErr: true, }, }