From 493dabe8ce8176b5c7cb278fe99ed235a5758c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sat, 11 Feb 2023 14:16:50 +0000 Subject: [PATCH] delegated signature: allow it to carry MethodSend before nv20. --- chain/consensus/filcns/filecoin.go | 2 +- chain/messagepool/messagepool.go | 7 ++++++- chain/signatures.go | 6 +++++- chain/types/ethtypes/eth_transactions.go | 8 +++++++- node/impl/full/eth.go | 7 +++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/chain/consensus/filcns/filecoin.go b/chain/consensus/filcns/filecoin.go index 2cd680746..7f94e4806 100644 --- a/chain/consensus/filcns/filecoin.go +++ b/chain/consensus/filcns/filecoin.go @@ -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) } diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index dabd2cb33..e30d8c5e3 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -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) } diff --git a/chain/signatures.go b/chain/signatures.go index 1dc67fd2c..0074bc42f 100644 --- a/chain/signatures.go +++ b/chain/signatures.go @@ -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) diff --git a/chain/types/ethtypes/eth_transactions.go b/chain/types/ethtypes/eth_transactions.go index 7c065928e..4f350c4ca 100644 --- a/chain/types/ethtypes/eth_transactions.go +++ b/chain/types/ethtypes/eth_transactions.go @@ -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 diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 8401d7d51..6122143f8 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -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{