adjust IsValidSecpkSigType and usages.

This commit is contained in:
Raúl Kripalani 2023-01-10 23:39:39 +00:00 committed by raulk
parent 8f4c4268ba
commit a71816279d
3 changed files with 16 additions and 15 deletions

View File

@ -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{}

View File

@ -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

View File

@ -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
}
}