Skip to content

Commit

Permalink
Remove checks for equivocatory blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansagathiya committed Jun 10, 2022
1 parent 8582cb2 commit d8e422c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 118 deletions.
3 changes: 0 additions & 3 deletions lib/babe/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
29 changes: 0 additions & 29 deletions lib/babe/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
47 changes: 0 additions & 47 deletions lib/babe/verify_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 0 additions & 39 deletions lib/babe/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d8e422c

Please sign in to comment.