diff --git a/chain/consensus/filcns/filecoin.go b/chain/consensus/filcns/filecoin.go index 9f16c7d99..c163c9c3b 100644 --- a/chain/consensus/filcns/filecoin.go +++ b/chain/consensus/filcns/filecoin.go @@ -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{}