consolidate signature validation logic.
This commit is contained in:
parent
a8c33de80b
commit
6b8d4b4de2
@ -577,16 +577,9 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
|
||||
|
||||
smArr := blockadt.MakeEmptyArray(tmpstore)
|
||||
for i, m := range b.SecpkMessages {
|
||||
switch nv := filec.sm.GetNetworkVersion(ctx, b.Header.Height); {
|
||||
case nv >= network.Version14 && nv < network.Version18:
|
||||
if typ := m.Signature.Type; typ != crypto.SigTypeSecp256k1 {
|
||||
return xerrors.Errorf("block had invalid secpk message at index %d: %w", i, err)
|
||||
}
|
||||
case nv >= network.Version18:
|
||||
if typ := m.Signature.Type; typ != crypto.SigTypeSecp256k1 && typ != crypto.SigTypeDelegated {
|
||||
if !filec.ValidateSecpkSigType(nv, m.Signature.Type) {
|
||||
return xerrors.Errorf("block had invalid signed message at index %d: %w", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := checkMsg(m); err != nil {
|
||||
return xerrors.Errorf("block had invalid secpk message at index %d: %w", i, err)
|
||||
@ -908,4 +901,17 @@ func (filec *FilecoinEC) isChainNearSynced() bool {
|
||||
return build.Clock.Since(timestampTime) < 6*time.Hour
|
||||
}
|
||||
|
||||
// ValidateSecpkSigType checks that a signature type is valid for the network
|
||||
// version, for a "secpk" message.
|
||||
func (filec *FilecoinEC) ValidateSecpkSigType(nv network.Version, typ crypto.SigType) bool {
|
||||
switch {
|
||||
case nv < network.Version14:
|
||||
return true // no check for signature type before nv14
|
||||
case nv >= network.Version14 && nv < network.Version18:
|
||||
return typ == crypto.SigTypeSecp256k1
|
||||
default:
|
||||
return typ == crypto.SigTypeSecp256k1 || typ == crypto.SigTypeDelegated
|
||||
}
|
||||
}
|
||||
|
||||
var _ consensus.Consensus = &FilecoinEC{}
|
||||
|
Loading…
Reference in New Issue
Block a user