From 854af2a48535586a5b409582fbc759d0bc01514e Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 24 May 2022 17:15:08 +0200 Subject: [PATCH 1/4] core/beacon: prevent invalid logsBloom length panic --- core/beacon/types.go | 3 +++ eth/catalyst/api_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/beacon/types.go b/core/beacon/types.go index 18d5d2ab78b46..9d99ee8ebb828 100644 --- a/core/beacon/types.go +++ b/core/beacon/types.go @@ -148,6 +148,9 @@ func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) { if len(params.ExtraData) > 32 { return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData)) } + if len(params.LogsBloom) != 256 { + return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom)) + } header := &types.Header{ ParentHash: params.ParentHash, UncleHash: types.EmptyUncleHash, diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 8a3a554069a16..d397a43d6d353 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -794,3 +794,27 @@ func TestTrickRemoteBlockCache(t *testing.T) { time.Sleep(100 * time.Millisecond) } } + +func TestInvalidBloom(t *testing.T) { + genesis, preMergeBlocks := generatePreMergeChain(10) + n, ethservice := startEthService(t, genesis, preMergeBlocks) + ethservice.Merger().ReachTTD() + defer n.Close() + + commonAncestor := ethservice.BlockChain().CurrentBlock() + api := NewConsensusAPI(ethservice) + + // Setup 10 blocks on the canonical chain + setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Block) {}) + + // (1) check LatestValidHash by sending a normal payload (P1'') + payload := getNewPayload(t, api, commonAncestor) + payload.LogsBloom = append(payload.LogsBloom, byte(1)) + status, err := api.NewPayloadV1(*payload) + if err != nil { + t.Fatal(err) + } + if status.Status != beacon.INVALIDBLOCKHASH { + t.Errorf("invalid status: expected VALID got: %v", status.Status) + } +} From 5e7a49d0cde709dd4f18318cc294f9e963b5c237 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 24 May 2022 20:19:53 +0200 Subject: [PATCH 2/4] core/beacon: prevent negative baseFeePerGas --- core/beacon/types.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/beacon/types.go b/core/beacon/types.go index 9d99ee8ebb828..acb90b04aea2c 100644 --- a/core/beacon/types.go +++ b/core/beacon/types.go @@ -151,6 +151,10 @@ func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) { if len(params.LogsBloom) != 256 { return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom)) } + // Check that baseFeePerGas is not negative or too big + if common.Big0.Cmp(params.BaseFeePerGas) == 1 || params.BaseFeePerGas.BitLen() > 256 { + return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas) + } header := &types.Header{ ParentHash: params.ParentHash, UncleHash: types.EmptyUncleHash, From 035cb54c0fef4f25b5939993c860782cc0f0d791 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Mon, 30 May 2022 15:03:54 +0200 Subject: [PATCH 3/4] Update core/beacon/types.go Co-authored-by: Martin Holst Swende --- core/beacon/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/beacon/types.go b/core/beacon/types.go index acb90b04aea2c..97bf66cd3fe41 100644 --- a/core/beacon/types.go +++ b/core/beacon/types.go @@ -152,7 +152,7 @@ func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) { return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom)) } // Check that baseFeePerGas is not negative or too big - if common.Big0.Cmp(params.BaseFeePerGas) == 1 || params.BaseFeePerGas.BitLen() > 256 { + if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) { return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas) } header := &types.Header{ From e63cb8e366413f5ba29cefbb1a77018da5a293e9 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 31 May 2022 10:16:14 +0200 Subject: [PATCH 4/4] eth/catalys: go format --- eth/catalyst/api_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index b4e6645559973..e593a280a56db 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -808,9 +808,9 @@ func TestInvalidBloom(t *testing.T) { } if status.Status != beacon.INVALIDBLOCKHASH { t.Errorf("invalid status: expected VALID got: %v", status.Status) - } + } } - + func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) { genesis, preMergeBlocks := generatePreMergeChain(100) fmt.Println(genesis.Config.TerminalTotalDifficulty)