From d8e422c9ffc13ecc71e0a1387e6299ab9385abc6 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Fri, 10 Jun 2022 20:23:44 +0530 Subject: [PATCH] Remove checks for equivocatory blocks --- lib/babe/errors.go | 3 -- lib/babe/verify.go | 29 ------------------ lib/babe/verify_integration_test.go | 47 ----------------------------- lib/babe/verify_test.go | 39 ------------------------ 4 files changed, 118 deletions(-) diff --git a/lib/babe/errors.go b/lib/babe/errors.go index 527a0a8915..521007187b 100644 --- a/lib/babe/errors.go +++ b/lib/babe/errors.go @@ -33,9 +33,6 @@ var ( // ErrBadSignature is returned when a seal is invalid ErrBadSignature = errors.New("could not verify signature") - // ErrProducerEquivocated is returned when a block producer has produced conflicting blocks - ErrProducerEquivocated = errors.New("block producer equivocated") - // ErrNotAuthorized is returned when the node is not authorized to produce a block ErrNotAuthorized = errors.New("not authorized to produce block") diff --git a/lib/babe/verify.go b/lib/babe/verify.go index add58392a4..d4b01d26b0 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -340,35 +340,6 @@ func (b *verifier) verifyAuthorshipRight(header *types.Header) error { return ErrBadSignature } - // check if the producer has equivocated, ie. have they produced a conflicting block? - hashes := b.blockState.GetAllBlocksAtDepth(header.ParentHash) - - for _, hash := range hashes { - currentHeader, err := b.blockState.GetHeader(hash) - if err != nil { - continue - } - - currentBlockProducerIndex, err := getAuthorityIndex(currentHeader) - if err != nil { - continue - } - - var existingBlockProducerIndex uint32 - switch d := babePreDigest.(type) { - case types.BabePrimaryPreDigest: - existingBlockProducerIndex = d.AuthorityIndex - case types.BabeSecondaryVRFPreDigest: - existingBlockProducerIndex = d.AuthorityIndex - case types.BabeSecondaryPlainPreDigest: - existingBlockProducerIndex = d.AuthorityIndex - } - - if currentBlockProducerIndex == existingBlockProducerIndex && hash != header.Hash() { - return ErrProducerEquivocated - } - } - return nil } diff --git a/lib/babe/verify_integration_test.go b/lib/babe/verify_integration_test.go index 48cdd864da..5e298ecfcc 100644 --- a/lib/babe/verify_integration_test.go +++ b/lib/babe/verify_integration_test.go @@ -386,53 +386,6 @@ func TestVerifyAuthorshipRight(t *testing.T) { require.NoError(t, err) } -func TestVerifyAuthorshipRight_Equivocation(t *testing.T) { - kp, err := sr25519.GenerateKeypair() - require.NoError(t, err) - - cfg := &ServiceConfig{ - Keypair: kp, - } - - babeService := createTestService(t, cfg) - epochData, err := babeService.initiateEpoch(testEpochIndex) - require.NoError(t, err) - - epochData.threshold = maxThreshold - epochData.authorities = []types.Authority{ - { - Key: kp.Public().(*sr25519.PublicKey), - }, - } - - // create and add first block - block := createTestBlock(t, babeService, genesisHeader, [][]byte{}, 1, testEpochIndex, epochData) - block.Header.Hash() - - err = babeService.blockState.AddBlock(block) - require.NoError(t, err) - - verifier, err := newVerifier(babeService.blockState, testEpochIndex, &verifierInfo{ - authorities: epochData.authorities, - threshold: epochData.threshold, - randomness: epochData.randomness, - }) - require.NoError(t, err) - - err = verifier.verifyAuthorshipRight(&block.Header) - require.NoError(t, err) - - // create new block - block2 := createTestBlock(t, babeService, genesisHeader, [][]byte{}, 1, testEpochIndex, epochData) - block2.Header.Hash() - - err = babeService.blockState.AddBlock(block2) - require.NoError(t, err) - - err = verifier.verifyAuthorshipRight(&block2.Header) - require.Equal(t, ErrProducerEquivocated, err) -} - func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { /* * Setup the services: StateService, DigestHandler, EpochState diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index f6c106ca7c..739584f03f 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -612,27 +612,6 @@ func Test_verifier_verifyAuthorshipRight(t *testing.T) { //// Case 8: Get header error babeVerifier6 := newTestVerifier(t, kp, mockBlockStateErr, scale.MaxUint128, false) - // Case 9: Equivocate case primary - babeVerifier7 := newTestVerifier(t, kp, mockBlockStateEquiv1, scale.MaxUint128, false) - - // Case 10: Equivocate case secondary plain - babeSecPlainPrd2, err := testBabeSecondaryPlainPreDigest.ToPreRuntimeDigest() - assert.NoError(t, err) - header8 := newTestHeader(t, *babeSecPlainPrd2) - - hash2 := encodeAndHashHeader(t, header8) - signAndAddSeal(t, kp, header8, hash2[:]) - babeVerifier8 := newTestVerifier(t, kp, mockBlockStateEquiv2, scale.MaxUint128, true) - - // Case 11: equivocation case secondary VRF - encVrfDigest := newEncodedBabeDigest(t, testBabeSecondaryVRFPreDigest) - assert.NoError(t, err) - header9 := newTestHeader(t, *types.NewBABEPreRuntimeDigest(encVrfDigest)) - - hash3 := encodeAndHashHeader(t, header9) - signAndAddSeal(t, kp, header9, hash3[:]) - babeVerifier9 := newTestVerifier(t, kp, mockBlockStateEquiv3, scale.MaxUint128, true) - tests := []struct { name string verifier verifier @@ -697,24 +676,6 @@ func Test_verifier_verifyAuthorshipRight(t *testing.T) { verifier: *babeVerifier6, header: header7, }, - { - name: "equivocate - primary", - verifier: *babeVerifier7, - header: header7, - expErr: ErrProducerEquivocated, - }, - { - name: "equivocate - secondary plain", - verifier: *babeVerifier8, - header: header8, - expErr: ErrProducerEquivocated, - }, - { - name: "equivocate - secondary vrf", - verifier: *babeVerifier9, - header: header9, - expErr: ErrProducerEquivocated, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {