From c8b46b553abf2955e61373d7c27fc10d73272ad3 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Tue, 19 Oct 2021 16:11:09 -0400 Subject: [PATCH 01/12] add check for types.ConfigData.SecondarySlots --- dot/types/babe.go | 2 +- lib/babe/verify.go | 57 +++++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/dot/types/babe.go b/dot/types/babe.go index 9a6d81de79..0ff21cd74f 100644 --- a/dot/types/babe.go +++ b/dot/types/babe.go @@ -95,7 +95,7 @@ func (d *EpochDataRaw) ToEpochData() (*EpochData, error) { type ConfigData struct { C1 uint64 C2 uint64 - SecondarySlots byte // TODO: this is unused, will need to update BABE verifier to use this (#1863) + SecondarySlots byte } // GetSlotFromHeader returns the BABE slot from the given header diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 4453c2d802..108ccdd027 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -32,9 +32,10 @@ import ( // verifierInfo contains the information needed to verify blocks // it remains the same for an epoch type verifierInfo struct { - authorities []types.Authority - randomness Randomness - threshold *common.Uint128 + authorities []types.Authority + randomness Randomness + threshold *common.Uint128 + secondarySlots bool } // onDisabledInfo contains information about an authority that's been disabled at a certain @@ -225,9 +226,10 @@ func (v *VerificationManager) getVerifierInfo(epoch uint64) (*verifierInfo, erro } return &verifierInfo{ - authorities: epochData.Authorities, - randomness: epochData.Randomness, - threshold: threshold, + authorities: epochData.Authorities, + randomness: epochData.Randomness, + threshold: threshold, + secondarySlots: configData.SecondarySlots > 0, }, nil } @@ -248,11 +250,12 @@ func (v *VerificationManager) getConfigData(epoch uint64) (*types.ConfigData, er // verifier is a BABE verifier for a specific authority set, randomness, and threshold type verifier struct { - blockState BlockState - epoch uint64 - authorities []types.Authority - randomness Randomness - threshold *common.Uint128 + blockState BlockState + epoch uint64 + authorities []types.Authority + randomness Randomness + threshold *common.Uint128 + secondarySlots bool } // newVerifier returns a Verifier for the epoch described by the given descriptor @@ -262,11 +265,12 @@ func newVerifier(blockState BlockState, epoch uint64, info *verifierInfo) (*veri } return &verifier{ - blockState: blockState, - epoch: epoch, - authorities: info.authorities, - randomness: info.randomness, - threshold: info.threshold, + blockState: blockState, + epoch: epoch, + authorities: info.authorities, + randomness: info.randomness, + threshold: info.threshold, + secondarySlots: info.secondarySlots, }, nil } @@ -384,17 +388,24 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (types case *types.BabePrimaryPreDigest: ok, err = b.verifyPrimarySlotWinner(d.AuthorityIndex(), d.SlotNumber(), d.VrfOutput(), d.VrfProof()) case *types.BabeSecondaryVRFPreDigest: - pub := b.authorities[d.AuthorityIndex()].Key - var pk *sr25519.PublicKey - pk, err = sr25519.NewPublicKey(pub.Encode()) - if err != nil { - return nil, err + if b.secondarySlots { + pub := b.authorities[d.AuthorityIndex()].Key + var pk *sr25519.PublicKey + pk, err = sr25519.NewPublicKey(pub.Encode()) + if err != nil { + return nil, err + } + + ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) + } else { + ok = true } - ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) case *types.BabeSecondaryPlainPreDigest: ok = true - err = verifySecondarySlotPlain(d.AuthorityIndex(), d.SlotNumber(), len(b.authorities), b.randomness) + if b.secondarySlots { + err = verifySecondarySlotPlain(d.AuthorityIndex(), d.SlotNumber(), len(b.authorities), b.randomness) + } } // verify that they are the slot winner From 7d6f8cd0c01550e2a1c80c7af7c199fcfbe5b492 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Fri, 22 Oct 2021 17:15:52 -0400 Subject: [PATCH 02/12] Update lib/babe/verify.go Co-authored-by: Quentin McGaw --- lib/babe/verify.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 108ccdd027..ded4100b7c 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -388,17 +388,18 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (types case *types.BabePrimaryPreDigest: ok, err = b.verifyPrimarySlotWinner(d.AuthorityIndex(), d.SlotNumber(), d.VrfOutput(), d.VrfProof()) case *types.BabeSecondaryVRFPreDigest: - if b.secondarySlots { - pub := b.authorities[d.AuthorityIndex()].Key - var pk *sr25519.PublicKey - pk, err = sr25519.NewPublicKey(pub.Encode()) - if err != nil { - return nil, err - } - - ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) - } else { + if !b.secondarySlots { ok = true + break + } + pub := b.authorities[d.AuthorityIndex()].Key + var pk *sr25519.PublicKey + pk, err = sr25519.NewPublicKey(pub.Encode()) + if err != nil { + return nil, err + } + + ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) } case *types.BabeSecondaryPlainPreDigest: From d25c78134e5e8f4a5a1bf00fc9b75fbc08f2e469 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 25 Oct 2021 15:10:07 -0400 Subject: [PATCH 03/12] update ok = false if !b.secondarySlots --- lib/babe/verify.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index ded4100b7c..7c00e309e9 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -389,18 +389,17 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (types ok, err = b.verifyPrimarySlotWinner(d.AuthorityIndex(), d.SlotNumber(), d.VrfOutput(), d.VrfProof()) case *types.BabeSecondaryVRFPreDigest: if !b.secondarySlots { - ok = true + ok = false break } pub := b.authorities[d.AuthorityIndex()].Key - var pk *sr25519.PublicKey - pk, err = sr25519.NewPublicKey(pub.Encode()) + + pk, err := sr25519.NewPublicKey(pub.Encode()) // nolint if err != nil { return nil, err } - ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) - } + ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) // nolint case *types.BabeSecondaryPlainPreDigest: ok = true From 4ef465224216cee1d12644b67ee9b3d3e77e67f5 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Wed, 27 Oct 2021 14:56:43 -0400 Subject: [PATCH 04/12] stub test for secondary verification --- lib/babe/verify_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index 4a4c0730e3..420ab3786c 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -162,6 +162,25 @@ func TestVerificationManager_VerifyBlock_Ok(t *testing.T) { require.NoError(t, err) } +func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { + babeService := createTestService(t, nil) + rt, err := babeService.blockState.GetRuntime(nil) + require.NoError(t, err) + + cfg, err := rt.BabeConfiguration() + require.NoError(t, err) + + cfg.GenesisAuthorities = types.AuthoritiesToRaw(babeService.epochData.authorities) + cfg.C1 = 1 + cfg.C2 = 1 + + vm := newTestVerificationManager(t, cfg) + + block, _ := createTestBlock(t, babeService, genesisHeader, [][]byte{}, 1, testEpochIndex) + err = vm.VerifyBlock(&block.Header) + require.NoError(t, err) +} + func TestVerificationManager_VerifyBlock_MultipleEpochs(t *testing.T) { babeService := createTestService(t, nil) rt, err := babeService.blockState.GetRuntime(nil) From ee0900d444c553f425270c3c9d1176cb5dc1ec34 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Wed, 27 Oct 2021 16:45:28 -0400 Subject: [PATCH 05/12] add test to verify secondary digest --- lib/babe/verify_test.go | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index 420ab3786c..d53e837fc6 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -18,7 +18,9 @@ package babe import ( "errors" + "github.com/ChainSafe/gossamer/lib/common" "io/ioutil" + "math/big" "os" "testing" "time" @@ -173,12 +175,46 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { cfg.GenesisAuthorities = types.AuthoritiesToRaw(babeService.epochData.authorities) cfg.C1 = 1 cfg.C2 = 1 + cfg.SecondarySlots = 0 vm := newTestVerificationManager(t, cfg) - block, _ := createTestBlock(t, babeService, genesisHeader, [][]byte{}, 1, testEpochIndex) - err = vm.VerifyBlock(&block.Header) + kp, err := sr25519.GenerateKeypair() + require.NoError(t, err) + + dig := createSecondaryVRFPreDigest(t, kp, 0, uint64(0), uint64(0), Randomness{}) + + // create pre-digest + preDigest := &types.PreRuntimeDigest{ + ConsensusEngineID: types.BabeEngineID, + Data: dig.Encode(), + } + + // create new block header + number := big.NewInt(1) + digest := types.NewDigest() + err = digest.Add(*preDigest) + require.NoError(t, err) + + // create seal and add to digest + seal := &types.SealDigest{ + ConsensusEngineID: types.BabeEngineID, + Data: []byte{0}, + } require.NoError(t, err) + + err = digest.Add(*seal) + require.NoError(t, err) + + header, err := types.NewHeader(common.EmptyHash, common.EmptyHash, common.EmptyHash, number, digest) + require.NoError(t, err) + + block := types.Block{ + Header: *header, + Body: nil, + } + err = vm.VerifyBlock(&block.Header) + require.EqualError(t, err, "failed to verify pre-runtime digest: could not verify slot claim VRF proof") } func TestVerificationManager_VerifyBlock_MultipleEpochs(t *testing.T) { From b6930bb4365dc9c705da602e62a49717034f32b5 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Fri, 29 Oct 2021 14:01:33 -0400 Subject: [PATCH 06/12] address PR comments --- lib/babe/verify.go | 9 ++++++--- lib/babe/verify_test.go | 16 +++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 2090e23ff3..7272fed978 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -427,10 +427,13 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) // nolint case *types.BabeSecondaryPlainPreDigest: - ok = true - if b.secondarySlots { - err = verifySecondarySlotPlain(d.AuthorityIndex, d.SlotNumber, len(b.authorities), b.randomness) + if !b.secondarySlots { + ok = false + break } + + ok = true + err = verifySecondarySlotPlain(d.AuthorityIndex, d.SlotNumber, len(b.authorities), b.randomness) } // verify that they are the slot winner diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index 3d4265e3ac..ccbd549cf3 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -18,21 +18,20 @@ package babe import ( "errors" - "github.com/ChainSafe/gossamer/lib/common" "io/ioutil" "math/big" "os" "testing" "time" - "github.com/ChainSafe/gossamer/lib/genesis" - "github.com/stretchr/testify/require" - "github.com/ChainSafe/gossamer/dot/state" "github.com/ChainSafe/gossamer/dot/types" + "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/crypto/sr25519" - + "github.com/ChainSafe/gossamer/lib/genesis" + "github.com/ChainSafe/gossamer/pkg/scale" log "github.com/ChainSafe/log15" + "github.com/stretchr/testify/require" ) func newTestVerificationManager(t *testing.T, genCfg *types.BabeConfiguration) *VerificationManager { @@ -184,10 +183,13 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { dig := createSecondaryVRFPreDigest(t, kp, 0, uint64(0), uint64(0), Randomness{}) + digEnc, err := scale.Marshal(dig) + require.NoError(t, err) + // create pre-digest preDigest := &types.PreRuntimeDigest{ ConsensusEngineID: types.BabeEngineID, - Data: dig.Encode(), + Data: digEnc, } // create new block header @@ -206,7 +208,7 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { err = digest.Add(*seal) require.NoError(t, err) - header, err := types.NewHeader(common.EmptyHash, common.EmptyHash, common.EmptyHash, number, digest) + header, err := types.NewHeader(common.Hash{}, common.Hash{}, common.Hash{}, number, digest) require.NoError(t, err) block := types.Block{ From 83a4591889db9704094a99fd646c0335a521ebb1 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Fri, 29 Oct 2021 14:06:03 -0400 Subject: [PATCH 07/12] add err check --- lib/babe/verify.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 7272fed978..1f3adabd1a 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -425,6 +425,9 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale } ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) // nolint + if err != nil { + return nil, err + } case *types.BabeSecondaryPlainPreDigest: if !b.secondarySlots { From ac41b7ac912bec5e882a9cba3716cc9c6022591e Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 1 Nov 2021 15:45:40 -0400 Subject: [PATCH 08/12] update pointers to fix tests --- lib/babe/verify.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 1f3adabd1a..58bc059888 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -410,9 +410,9 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale ) switch d := babePreDigest.(type) { - case *types.BabePrimaryPreDigest: + case types.BabePrimaryPreDigest: ok, err = b.verifyPrimarySlotWinner(d.AuthorityIndex, d.SlotNumber, d.VRFOutput, d.VRFProof) - case *types.BabeSecondaryVRFPreDigest: + case types.BabeSecondaryVRFPreDigest: if !b.secondarySlots { ok = false break @@ -424,12 +424,12 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale return nil, err } - ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) // nolint + ok, err = verifySecondarySlotVRF(&d, pk, b.epoch, len(b.authorities), b.randomness) // nolint if err != nil { return nil, err } - case *types.BabeSecondaryPlainPreDigest: + case types.BabeSecondaryPlainPreDigest: if !b.secondarySlots { ok = false break From b4f4fad397dd9b7fd63fd88db04040f00da75878 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 1 Nov 2021 17:22:34 -0400 Subject: [PATCH 09/12] add tests for decoding --- lib/babe/verify.go | 2 +- lib/babe/verify_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 58bc059888..728b7f1f85 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -408,7 +408,7 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale var ( ok bool ) - +fmt.Printf("d type %T\n", babePreDigest) switch d := babePreDigest.(type) { case types.BabePrimaryPreDigest: ok, err = b.verifyPrimarySlotWinner(d.AuthorityIndex, d.SlotNumber, d.VRFOutput, d.VRFProof) diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index ccbd549cf3..e32a32ae3a 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -18,6 +18,7 @@ package babe import ( "errors" + "fmt" "io/ioutil" "math/big" "os" @@ -183,9 +184,16 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { dig := createSecondaryVRFPreDigest(t, kp, 0, uint64(0), uint64(0), Randomness{}) + // todo (ed) remove after fix (see test below TestCreateSecondaryVRFPreDigestMarshal + fmt.Printf("dig %T\n", dig) + digEnc, err := scale.Marshal(dig) require.NoError(t, err) + babePreDigest, err := types.DecodeBabePreDigest(digEnc) + // todo (ed) remove after fix (see test below TestCreateSecondaryVRFPreDigestMarshal + fmt.Printf("decoded %T\n", babePreDigest) + // create pre-digest preDigest := &types.PreRuntimeDigest{ ConsensusEngineID: types.BabeEngineID, @@ -219,6 +227,31 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { require.EqualError(t, err, "failed to verify pre-runtime digest: could not verify slot claim VRF proof") } +func TestCreateSecondaryVRFPreDigestMarshal(t *testing.T) { + kp, err := sr25519.GenerateKeypair() + require.NoError(t, err) + + dig := createSecondaryVRFPreDigest(t, kp, 0, uint64(0), uint64(0), Randomness{}) + fmt.Printf("dig %T\n", dig) + + require.IsType(t, types.BabeSecondaryVRFPreDigest{}, *dig) + + // This used to be done with dig.Encode() + digEnc, err := scale.Marshal(dig) + require.NoError(t, err) + + babeDigest := types.NewBabeDigest() + err = scale.Unmarshal(digEnc, &babeDigest) + require.NoError(t, err) + // Why isn't this type types.BabeSecondaryVRFPreDigest? + require.IsType(t, types.BabePrimaryPreDigest{}, babeDigest) + + babePreDigest, err := types.DecodeBabePreDigest(digEnc) + require.NoError(t, err) + // Why isn't this type types.BabeSecondaryVRFPreDigest? + require.IsType(t, types.BabePrimaryPreDigest{}, babePreDigest) +} + func TestVerificationManager_VerifyBlock_MultipleEpochs(t *testing.T) { babeService := createTestService(t, nil) rt, err := babeService.blockState.GetRuntime(nil) From da13828c2cb27010c4963621eb973d15edea4275 Mon Sep 17 00:00:00 2001 From: Tim Wu Date: Tue, 2 Nov 2021 14:02:00 -0400 Subject: [PATCH 10/12] my wip --- lib/babe/verify_test.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index e32a32ae3a..8cc08c2583 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -187,17 +187,22 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { // todo (ed) remove after fix (see test below TestCreateSecondaryVRFPreDigestMarshal fmt.Printf("dig %T\n", dig) - digEnc, err := scale.Marshal(dig) + bd := types.NewBabeDigest() + err = bd.Set(dig) require.NoError(t, err) - babePreDigest, err := types.DecodeBabePreDigest(digEnc) - // todo (ed) remove after fix (see test below TestCreateSecondaryVRFPreDigestMarshal - fmt.Printf("decoded %T\n", babePreDigest) + bdEnc, err := scale.Marshal(bd) + require.NoError(t, err) + + // babePreDigest, err := types.DecodeBabePreDigest(digEnc) + // require.NoError(t, err) + // // todo (ed) remove after fix (see test below TestCreateSecondaryVRFPreDigestMarshal + // fmt.Printf("decoded %T\n", babePreDigest) // create pre-digest preDigest := &types.PreRuntimeDigest{ ConsensusEngineID: types.BabeEngineID, - Data: digEnc, + Data: bdEnc, } // create new block header @@ -224,7 +229,8 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { Body: nil, } err = vm.VerifyBlock(&block.Header) - require.EqualError(t, err, "failed to verify pre-runtime digest: could not verify slot claim VRF proof") + require.NoError(t, err) + // require.EqualError(t, err, "failed to verify pre-runtime digest: could not verify slot claim VRF proof") } func TestCreateSecondaryVRFPreDigestMarshal(t *testing.T) { @@ -240,11 +246,13 @@ func TestCreateSecondaryVRFPreDigestMarshal(t *testing.T) { digEnc, err := scale.Marshal(dig) require.NoError(t, err) + fmt.Printf("%v", digEnc) + babeDigest := types.NewBabeDigest() err = scale.Unmarshal(digEnc, &babeDigest) require.NoError(t, err) // Why isn't this type types.BabeSecondaryVRFPreDigest? - require.IsType(t, types.BabePrimaryPreDigest{}, babeDigest) + require.IsType(t, types.BabePrimaryPreDigest{}, babeDigest.Value()) babePreDigest, err := types.DecodeBabePreDigest(digEnc) require.NoError(t, err) From 1c21820be2f79434504a4ca60ea2dd4e20f6ea5d Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Tue, 2 Nov 2021 14:39:58 -0400 Subject: [PATCH 11/12] fix VRF encoding --- lib/babe/verify.go | 2 +- lib/babe/verify_test.go | 39 +-------------------------------------- 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 728b7f1f85..58bc059888 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -408,7 +408,7 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale var ( ok bool ) -fmt.Printf("d type %T\n", babePreDigest) + switch d := babePreDigest.(type) { case types.BabePrimaryPreDigest: ok, err = b.verifyPrimarySlotWinner(d.AuthorityIndex, d.SlotNumber, d.VRFOutput, d.VRFProof) diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index 8cc08c2583..3e1e49a167 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -18,7 +18,6 @@ package babe import ( "errors" - "fmt" "io/ioutil" "math/big" "os" @@ -184,9 +183,6 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { dig := createSecondaryVRFPreDigest(t, kp, 0, uint64(0), uint64(0), Randomness{}) - // todo (ed) remove after fix (see test below TestCreateSecondaryVRFPreDigestMarshal - fmt.Printf("dig %T\n", dig) - bd := types.NewBabeDigest() err = bd.Set(dig) require.NoError(t, err) @@ -194,11 +190,6 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { bdEnc, err := scale.Marshal(bd) require.NoError(t, err) - // babePreDigest, err := types.DecodeBabePreDigest(digEnc) - // require.NoError(t, err) - // // todo (ed) remove after fix (see test below TestCreateSecondaryVRFPreDigestMarshal - // fmt.Printf("decoded %T\n", babePreDigest) - // create pre-digest preDigest := &types.PreRuntimeDigest{ ConsensusEngineID: types.BabeEngineID, @@ -229,35 +220,7 @@ func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) { Body: nil, } err = vm.VerifyBlock(&block.Header) - require.NoError(t, err) - // require.EqualError(t, err, "failed to verify pre-runtime digest: could not verify slot claim VRF proof") -} - -func TestCreateSecondaryVRFPreDigestMarshal(t *testing.T) { - kp, err := sr25519.GenerateKeypair() - require.NoError(t, err) - - dig := createSecondaryVRFPreDigest(t, kp, 0, uint64(0), uint64(0), Randomness{}) - fmt.Printf("dig %T\n", dig) - - require.IsType(t, types.BabeSecondaryVRFPreDigest{}, *dig) - - // This used to be done with dig.Encode() - digEnc, err := scale.Marshal(dig) - require.NoError(t, err) - - fmt.Printf("%v", digEnc) - - babeDigest := types.NewBabeDigest() - err = scale.Unmarshal(digEnc, &babeDigest) - require.NoError(t, err) - // Why isn't this type types.BabeSecondaryVRFPreDigest? - require.IsType(t, types.BabePrimaryPreDigest{}, babeDigest.Value()) - - babePreDigest, err := types.DecodeBabePreDigest(digEnc) - require.NoError(t, err) - // Why isn't this type types.BabeSecondaryVRFPreDigest? - require.IsType(t, types.BabePrimaryPreDigest{}, babePreDigest) + require.EqualError(t, err, "failed to verify pre-runtime digest: could not verify slot claim VRF proof") } func TestVerificationManager_VerifyBlock_MultipleEpochs(t *testing.T) { From 1d70d135baa9a35ab9f96c2e4be545325266b903 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Wed, 3 Nov 2021 16:57:16 -0400 Subject: [PATCH 12/12] update linter tags --- lib/babe/verify.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/babe/verify.go b/lib/babe/verify.go index 58bc059888..a7c4b759d8 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -419,12 +419,12 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale } pub := b.authorities[d.AuthorityIndex].Key - pk, err := sr25519.NewPublicKey(pub.Encode()) // nolint + pk, err := sr25519.NewPublicKey(pub.Encode()) if err != nil { return nil, err } - ok, err = verifySecondarySlotVRF(&d, pk, b.epoch, len(b.authorities), b.randomness) // nolint + ok, err = verifySecondarySlotVRF(&d, pk, b.epoch, len(b.authorities), b.randomness) if err != nil { return nil, err }