Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fevm: address #9617 review comments (FEVM nv18 merge) #9984

Merged
merged 24 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions chain/consensus/filcns/filecoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/types/ethtypes"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/lib/async"
"github.com/filecoin-project/lotus/lib/sigs"
Expand Down Expand Up @@ -578,10 +577,15 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl

smArr := blockadt.MakeEmptyArray(tmpstore)
for i, m := range b.SecpkMessages {
if filec.sm.GetNetworkVersion(ctx, b.Header.Height) >= network.Version14 {
if m.Signature.Type != crypto.SigTypeSecp256k1 && m.Signature.Type != crypto.SigTypeDelegated {
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 err := checkMsg(m); err != nil {
Expand All @@ -595,21 +599,8 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
return xerrors.Errorf("failed to resolve key addr: %w", err)
}

digest := m.Message.Cid().Bytes()
if m.Signature.Type == crypto.SigTypeDelegated {
txArgs, err := ethtypes.NewEthTxArgsFromMessage(&m.Message)
if err != nil {
return err
}
msg, err := txArgs.ToRlpUnsignedMsg()
if err != nil {
return err
}
digest = msg
}

if err := sigs.Verify(&m.Signature, kaddr, digest); err != nil {
return xerrors.Errorf("secpk message %s has invalid signature: %w", m.Cid(), err)
if err := chain.AuthenticateMessage(m, kaddr); err != nil {
return xerrors.Errorf("failed to validate signature: %w", err)
}

c, err := store.PutMessage(ctx, tmpbs, m)
Expand Down
19 changes: 3 additions & 16 deletions chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

"github.com/filecoin-project/lotus/chain"
"github.com/hashicorp/go-multierror"
lru "github.com/hashicorp/golang-lru"
"github.com/ipfs/go-cid"
Expand All @@ -37,10 +38,8 @@ import (
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/types/ethtypes"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/lib/sigs"
"github.com/filecoin-project/lotus/metrics"
"github.com/filecoin-project/lotus/node/modules/dtypes"
)
Expand Down Expand Up @@ -795,20 +794,8 @@ func (mp *MessagePool) VerifyMsgSig(m *types.SignedMessage) error {
return nil
}

if m.Signature.Type == crypto.SigTypeDelegated {
txArgs, err := ethtypes.NewEthTxArgsFromMessage(&m.Message)
if err != nil {
return xerrors.Errorf("failed to convert to eth tx args: %w", err)
}
msg, err := txArgs.ToRlpUnsignedMsg()
if err != nil {
return err
}
if err := sigs.Verify(&m.Signature, m.Message.From, msg); err != nil {
return err
}
} else if err := sigs.Verify(&m.Signature, m.Message.From, m.Message.Cid().Bytes()); err != nil {
return err
if err := chain.AuthenticateMessage(m, m.Message.From); err != nil {
return xerrors.Errorf("failed to validate signature: %w", err)
}

mp.sigValCache.Add(sck, struct{}{})
Expand Down
38 changes: 38 additions & 0 deletions chain/signatures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package chain

import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/types/ethtypes"
"github.com/filecoin-project/lotus/lib/sigs"
"golang.org/x/xerrors"
)

// AuthenticateMessage authenticates the message by verifying that the supplied
// SignedMessage was signed by the indicated Address, computing the correct
// signature payload depending on the signature type. The supplied Address type
// must be recognized by the registered verifier for the signature type.
func AuthenticateMessage(msg *types.SignedMessage, signer address.Address) error {
var digest []byte

switch typ := msg.Signature.Type; typ {
case crypto.SigTypeDelegated:
txArgs, err := ethtypes.NewEthTxArgsFromMessage(&msg.Message)
if err != nil {
return xerrors.Errorf("failed to reconstruct eth transaction: %w", err)
}
msg, err := txArgs.ToRlpUnsignedMsg()
if err != nil {
return xerrors.Errorf("failed to repack eth rlp message: %w", err)
}
digest = msg
default:
digest = msg.Message.Cid().Bytes()
}

if err := sigs.Verify(&msg.Signature, signer, digest); err != nil {
return xerrors.Errorf("secpk message %s has invalid signature: %w", msg.Cid(), err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessarily secp here

}
return nil
}