From 78387523524ce8719993e33b5b980e41a8a4eb59 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 17 Nov 2020 01:34:06 -0500 Subject: [PATCH] Avoid sending messages to the zero BLS address --- build/params_shared_funcs.go | 9 +++++++++ build/params_shared_vals.go | 3 +++ build/params_testground.go | 3 ++- chain/messagepool/messagepool.go | 4 ++-- chain/sync.go | 2 +- chain/types/message.go | 8 +++++++- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/build/params_shared_funcs.go b/build/params_shared_funcs.go index 77fd9256d44..bcd82bb4821 100644 --- a/build/params_shared_funcs.go +++ b/build/params_shared_funcs.go @@ -19,3 +19,12 @@ func DhtProtocolName(netName dtypes.NetworkName) protocol.ID { func SetAddressNetwork(n address.Network) { address.CurrentNetwork = n } + +func MustParseAddress(addr string) address.Address { + ret, err := address.NewFromString(addr) + if err != nil { + panic(err) + } + + return ret +} diff --git a/build/params_shared_vals.go b/build/params_shared_vals.go index 5070777bd6f..c84f558bfb1 100644 --- a/build/params_shared_vals.go +++ b/build/params_shared_vals.go @@ -61,6 +61,9 @@ const TicketRandomnessLookback = abi.ChainEpoch(1) const AddressMainnetEnvVar = "_mainnet_" +// the 'f' prefix doesn't matter +var ZeroAddress = MustParseAddress("f3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaby2smx7a") + // ///// // Devnet settings diff --git a/build/params_testground.go b/build/params_testground.go index 6a8e2abf321..eb3df1cd1e2 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -97,7 +97,8 @@ var ( NewestNetworkVersion = network.Version5 ActorUpgradeNetworkVersion = network.Version4 - Devnet = true + Devnet = true + ZeroAddress = MustParseAddress("f3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaby2smx7a") ) const BootstrapPeerThreshold = 1 diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index d9a92073a17..a507b60cfd6 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -465,7 +465,7 @@ func (mp *MessagePool) verifyMsgBeforeAdd(m *types.SignedMessage, curTs *types.T epoch := curTs.Height() minGas := vm.PricelistByEpoch(epoch).OnChainMessage(m.ChainLength()) - if err := m.VMMessage().ValidForBlockInclusion(minGas.Total()); err != nil { + if err := m.VMMessage().ValidForBlockInclusion(minGas.Total(), build.NewestNetworkVersion); err != nil { return false, xerrors.Errorf("message will not be included in a block: %w", err) } @@ -546,7 +546,7 @@ func (mp *MessagePool) checkMessage(m *types.SignedMessage) error { } // Perform syntactic validation, minGas=0 as we check the actual mingas before we add it - if err := m.Message.ValidForBlockInclusion(0); err != nil { + if err := m.Message.ValidForBlockInclusion(0, build.NewestNetworkVersion); err != nil { return xerrors.Errorf("message not valid for block inclusion: %w", err) } diff --git a/chain/sync.go b/chain/sync.go index fabf8f37964..d5c6f73fd46 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -1075,7 +1075,7 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock // Phase 1: syntactic validation, as defined in the spec minGas := pl.OnChainMessage(msg.ChainLength()) - if err := m.ValidForBlockInclusion(minGas.Total()); err != nil { + if err := m.ValidForBlockInclusion(minGas.Total(), syncer.sm.GetNtwkVersion(ctx, b.Header.Height)); err != nil { return err } diff --git a/chain/types/message.go b/chain/types/message.go index c53ecc7c160..4f6bb78224b 100644 --- a/chain/types/message.go +++ b/chain/types/message.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/build" @@ -144,7 +146,7 @@ func (m *Message) EqualCall(o *Message) bool { return (&m1).Equals(&m2) } -func (m *Message) ValidForBlockInclusion(minGas int64) error { +func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version) error { if m.Version != 0 { return xerrors.New("'Version' unsupported") } @@ -153,6 +155,10 @@ func (m *Message) ValidForBlockInclusion(minGas int64) error { return xerrors.New("'To' address cannot be empty") } + if m.To == build.ZeroAddress && version >= network.Version7 { + return xerrors.New("invalid 'To' address") + } + if m.From == address.Undef { return xerrors.New("'From' address cannot be empty") }