From d57f048c2c71d893418d03fd067db34e12e39eb3 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 19 Nov 2019 14:07:16 -0600 Subject: [PATCH] reject blocks with nil signatures --- chain/actors/actor_storagepower_test.go | 2 +- chain/events/events_test.go | 4 ++-- chain/events/tscache_test.go | 4 ++-- chain/sync.go | 4 ++++ chain/types/mock/chain.go | 8 +++----- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/chain/actors/actor_storagepower_test.go b/chain/actors/actor_storagepower_test.go index b5330be5a..20157ada8 100644 --- a/chain/actors/actor_storagepower_test.go +++ b/chain/actors/actor_storagepower_test.go @@ -170,5 +170,5 @@ func signBlock(t *testing.T, w *wallet.Wallet, worker address.Address, blk *type t.Fatal(err) } - blk.BlockSig = *sig + blk.BlockSig = sig } diff --git a/chain/events/events_test.go b/chain/events/events_test.go index ea0f6b225..6ceeb8db0 100644 --- a/chain/events/events_test.go +++ b/chain/events/events_test.go @@ -58,7 +58,7 @@ func makeTs(t *testing.T, h uint64, msgcid cid.Cid) *types.TipSet { Messages: msgcid, ParentMessageReceipts: dummyCid, - BlockSig: types.Signature{Type: types.KTBLS}, + BlockSig: &types.Signature{Type: types.KTBLS}, BLSAggregate: types.Signature{Type: types.KTBLS}, }, { @@ -71,7 +71,7 @@ func makeTs(t *testing.T, h uint64, msgcid cid.Cid) *types.TipSet { Messages: msgcid, ParentMessageReceipts: dummyCid, - BlockSig: types.Signature{Type: types.KTBLS}, + BlockSig: &types.Signature{Type: types.KTBLS}, BLSAggregate: types.Signature{Type: types.KTBLS}, }, }) diff --git a/chain/events/tscache_test.go b/chain/events/tscache_test.go index 7d715aea0..9c7c203bb 100644 --- a/chain/events/tscache_test.go +++ b/chain/events/tscache_test.go @@ -27,7 +27,7 @@ func TestTsCache(t *testing.T) { ParentStateRoot: dummyCid, Messages: dummyCid, ParentMessageReceipts: dummyCid, - BlockSig: types.Signature{Type: types.KTBLS}, + BlockSig: &types.Signature{Type: types.KTBLS}, BLSAggregate: types.Signature{Type: types.KTBLS}, }}) if err != nil { @@ -69,7 +69,7 @@ func TestTsCacheNulls(t *testing.T) { ParentStateRoot: dummyCid, Messages: dummyCid, ParentMessageReceipts: dummyCid, - BlockSig: types.Signature{Type: types.KTBLS}, + BlockSig: &types.Signature{Type: types.KTBLS}, BLSAggregate: types.Signature{Type: types.KTBLS}, }}) if err != nil { diff --git a/chain/sync.go b/chain/sync.go index c1e68b02e..c804afcd3 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -501,6 +501,10 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err } // fast checks first + if h.BlockSig == nil { + return xerrors.Errorf("block had nil signature") + } + if h.Timestamp > uint64(time.Now().Unix()+build.AllowableClockDrift) { return xerrors.Errorf("block was from the future") } diff --git a/chain/types/mock/chain.go b/chain/types/mock/chain.go index 09b37370a..474d8a92b 100644 --- a/chain/types/mock/chain.go +++ b/chain/types/mock/chain.go @@ -36,10 +36,8 @@ func MkBlock(parents *types.TipSet, weightInc uint64, ticketNonce uint64) *types return &types.BlockHeader{ Miner: addr, ElectionProof: []byte("cats won the election"), - Tickets: []*types.Ticket{ - { - VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)), - }, + Ticket: &types.Ticket{ + VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)), }, Parents: pcids, ParentMessageReceipts: c, @@ -48,7 +46,7 @@ func MkBlock(parents *types.TipSet, weightInc uint64, ticketNonce uint64) *types Messages: c, Height: height, ParentStateRoot: c, - BlockSig: types.Signature{Type: types.KTBLS, Data: []byte("boo! im a signature")}, + BlockSig: &types.Signature{Type: types.KTBLS, Data: []byte("boo! im a signature")}, } }