delegated signature: allow it to carry MethodSend before nv20.
This commit is contained in:
@@ -592,7 +592,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
|
||||
return xerrors.Errorf("failed to resolve key addr: %w", err)
|
||||
}
|
||||
|
||||
if err := chain.AuthenticateMessage(m, kaddr); err != nil {
|
||||
if err := chain.AuthenticateMessage(m, kaddr, nv); err != nil {
|
||||
return xerrors.Errorf("failed to validate signature: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -794,7 +794,12 @@ func (mp *MessagePool) VerifyMsgSig(m *types.SignedMessage) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := chain.AuthenticateMessage(m, m.Message.From); err != nil {
|
||||
nv, err := mp.getNtwkVersion(mp.curTs.Height())
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failedl to get network version: %w", err)
|
||||
}
|
||||
|
||||
if err := chain.AuthenticateMessage(m, m.Message.From, nv); err != nil {
|
||||
return xerrors.Errorf("failed to validate signature: %w", err)
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -1,6 +1,7 @@
|
||||
package chain
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-state-types/builtin"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
@@ -16,12 +17,15 @@ import (
|
||||
// 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 {
|
||||
func AuthenticateMessage(msg *types.SignedMessage, signer address.Address, nv network.Version) error {
|
||||
var digest []byte
|
||||
|
||||
typ := msg.Signature.Type
|
||||
switch typ {
|
||||
case crypto.SigTypeDelegated:
|
||||
if msg.Message.Method == builtin.MethodSend && nv >= network.Version20 {
|
||||
return xerrors.Errorf("nv20 and above no longer admits method 0 on messages with Ethereum delegated signatures")
|
||||
}
|
||||
txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(&msg.Message)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to reconstruct eth transaction: %w", err)
|
||||
|
||||
@@ -117,7 +117,13 @@ func EthTxArgsFromUnsignedEthMessage(msg *types.Message) (EthTxArgs, error) {
|
||||
default:
|
||||
return EthTxArgs{}, fmt.Errorf("unsupported EAM method")
|
||||
}
|
||||
} else if msg.Method == builtintypes.MethodsEVM.InvokeContract {
|
||||
} else if msg.Method == builtintypes.MethodsEVM.InvokeContract || msg.Method == builtintypes.MethodSend {
|
||||
// < nv20 (Hyperspace): The condition here is technically too lenient.
|
||||
// The correct behavior would be to _only_ allow MethodSend on < nv20.
|
||||
// However, snaking through the network version here is too expensive, and not worth it,
|
||||
// given that the transition period will only last for ~24h anyway.
|
||||
// AuthenticateMessage is the _crucial_ spot, and it's already applying a stricter check.
|
||||
// The Eth API endpoint is also selecting the right method depending on the network version.
|
||||
addr, err := EthAddressFromFilecoinAddress(msg.To)
|
||||
if err != nil {
|
||||
return EthTxArgs{}, err
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
"github.com/google/uuid"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
@@ -768,6 +769,12 @@ func (a *EthModule) ethCallToFilecoinMessage(ctx context.Context, tx ethtypes.Et
|
||||
}
|
||||
|
||||
method = builtintypes.MethodsEVM.InvokeContract
|
||||
|
||||
// < nv20 (Hyperspace): reset method to MethodSend if no params.
|
||||
nv := a.StateManager.GetNetworkVersion(ctx, a.Chain.GetHeaviestTipSet().Height())
|
||||
if nv < network.Version20 && len(tx.Data) == 0 {
|
||||
method = builtintypes.MethodSend
|
||||
}
|
||||
}
|
||||
|
||||
return &types.Message{
|
||||
|
||||
Reference in New Issue
Block a user