diff --git a/chain/consensus/filcns/filecoin.go b/chain/consensus/filcns/filecoin.go index c163c9c3b..a698abd47 100644 --- a/chain/consensus/filcns/filecoin.go +++ b/chain/consensus/filcns/filecoin.go @@ -577,7 +577,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl smArr := blockadt.MakeEmptyArray(tmpstore) for i, m := range b.SecpkMessages { - if !filec.ValidateSecpkSigType(nv, m.Signature.Type) { + if nv >= network.Version14 && !chain.IsValidSecpkSigType(nv, m.Signature.Type) { return xerrors.Errorf("block had invalid signed message at index %d: %w", i, err) } @@ -901,17 +901,4 @@ 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{} diff --git a/chain/consensus/filcns/mine.go b/chain/consensus/filcns/mine.go index 992453178..b80937c4b 100644 --- a/chain/consensus/filcns/mine.go +++ b/chain/consensus/filcns/mine.go @@ -3,6 +3,7 @@ package filcns import ( "context" + "github.com/filecoin-project/lotus/chain" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -54,6 +55,7 @@ func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api. var blsMsgCids, secpkMsgCids []cid.Cid var blsSigs []crypto.Signature + nv := filec.sm.GetNetworkVersion(ctx, bt.Epoch) for _, msg := range bt.Messages { if msg.Signature.Type == crypto.SigTypeBLS { blsSigs = append(blsSigs, msg.Signature) @@ -65,7 +67,7 @@ func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api. } blsMsgCids = append(blsMsgCids, c) - } else if msg.Signature.Type == crypto.SigTypeSecp256k1 || msg.Signature.Type == crypto.SigTypeDelegated { + } else if chain.IsValidSecpkSigType(nv, msg.Signature.Type) { c, err := filec.sm.ChainStore().PutMessage(ctx, msg) if err != nil { return nil, err diff --git a/chain/signatures.go b/chain/signatures.go index 4558dd1b3..e09aa7079 100644 --- a/chain/signatures.go +++ b/chain/signatures.go @@ -3,6 +3,7 @@ package chain import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types/ethtypes" "github.com/filecoin-project/lotus/lib/sigs" @@ -36,3 +37,14 @@ func AuthenticateMessage(msg *types.SignedMessage, signer address.Address) error } return nil } + +// IsValidSecpkSigType checks that a signature type is valid for the network +// version, for a "secpk" message. +func IsValidSecpkSigType(nv network.Version, typ crypto.SigType) bool { + switch { + case nv < network.Version18: + return typ == crypto.SigTypeSecp256k1 + default: + return typ == crypto.SigTypeSecp256k1 || typ == crypto.SigTypeDelegated + } +}