Skip to content

Commit

Permalink
added more panics if keys aren't BLS12-381
Browse files Browse the repository at this point in the history
  • Loading branch information
alesforz committed Jan 9, 2025
1 parent 2b2d2d5 commit 1fd3cd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ func (cs *State) createProposalBlock(ctx context.Context) (*types.Block, error)

case cs.LastCommit.HasTwoThirdsMajority():
// Make the commit from LastCommit.
_, blsKey := cs.privValidatorPubKey.(*bls12381.PubKey)
key, blsKey := cs.privValidatorPubKey.(*bls12381.PubKey)
canBeAggregated := blsKey &&
cs.state.Validators.AllKeysHaveSameType()
if canBeAggregated {
Expand All @@ -1320,7 +1320,7 @@ func (cs *State) createProposalBlock(ctx context.Context) (*types.Block, error)
}
lastExtCommit = cs.LastCommit.MakeBLSCommit()
} else {
lastExtCommit = cs.LastCommit.MakeExtendedCommit(cs.state.ConsensusParams.Feature)
panic("last commit's validators keys are not BLS12-381. Found: " + key.Type())
}

default: // This shouldn't happen.
Expand Down
10 changes: 8 additions & 2 deletions types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ func verifyAggregatedCommit(
}
pk, ok := val.PubKey.(*bls12381.PubKey)
if !ok {
pk2 := val.PubKey.(bls12381.PubKey)
pk2, ok2 := val.PubKey.(bls12381.PubKey)
if !ok2 {
panic("Validator key is " + val.PubKey.Type() + ". Must be BLS12_381")
}
pk = &pk2
}
pubkeys1 = append(pubkeys1, pk)
Expand All @@ -385,7 +388,10 @@ func verifyAggregatedCommit(
}
pk, ok := val.PubKey.(*bls12381.PubKey)
if !ok {
pk2 := val.PubKey.(bls12381.PubKey)
pk2, ok2 := val.PubKey.(bls12381.PubKey)
if !ok2 {
panic("Validator key is " + val.PubKey.Type() + ". Must be BLS12_381")
}
pk = &pk2
}
pubkeys2 = append(pubkeys2, pk)
Expand Down

0 comments on commit 1fd3cd1

Please sign in to comment.