Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib/babe): add check of types.ConfigData.SecondarySlots for disabling secondary verification #1910

Merged
merged 22 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c8b46b5
add check for types.ConfigData.SecondarySlots
edwardmack Oct 19, 2021
250986d
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Oct 20, 2021
7d6f8cd
Update lib/babe/verify.go
edwardmack Oct 22, 2021
3692fd0
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Oct 22, 2021
09e702c
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Oct 25, 2021
d25c781
update ok = false if !b.secondarySlots
edwardmack Oct 25, 2021
c26553d
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Oct 26, 2021
4e2f925
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Oct 26, 2021
4ef4652
stub test for secondary verification
edwardmack Oct 27, 2021
ee0900d
add test to verify secondary digest
edwardmack Oct 27, 2021
1e221c3
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Oct 29, 2021
b6930bb
address PR comments
edwardmack Oct 29, 2021
83a4591
add err check
edwardmack Oct 29, 2021
ac41b7a
update pointers to fix tests
edwardmack Nov 1, 2021
2ae9e0f
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Nov 1, 2021
b4f4fad
add tests for decoding
edwardmack Nov 1, 2021
da13828
my wip
timwu20 Nov 2, 2021
1c21820
fix VRF encoding
edwardmack Nov 2, 2021
73f08b5
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Nov 2, 2021
1ee9ffc
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Nov 3, 2021
1d70d13
update linter tags
edwardmack Nov 3, 2021
fb16b0b
Merge branch 'development' into ed/use_types_configdata_secondarySlots
edwardmack Nov 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dot/types/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 34 additions & 23 deletions lib/babe/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
edwardmack marked this conversation as resolved.
Show resolved Hide resolved
}

ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness)
case *types.BabeSecondaryPlainPreDigest:
ok = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: we keep assinging ok = true if b.secondarySlots == false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, @noot did I make a correct assumption?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it should be ok == false!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, updated so ok = false

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update this to be the same logic as above (ie. if !ok b.secondarySlots { ok = false; break }?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

}
}

// verify that they are the slot winner
Expand Down