consolidate signature validation logic.

This commit is contained in:
Raúl Kripalani 2023-01-10 22:42:01 +00:00 committed by raulk
parent a8c33de80b
commit 6b8d4b4de2

View File

@ -577,15 +577,8 @@ 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 {
return xerrors.Errorf("block had invalid signed message at index %d: %w", i, err)
}
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 {
@ -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{}