Skip to content

Commit 2c0649f

Browse files
MariusVanDerWijdenholiman
authored andcommitted
core/beacon: prevent invalid logsBloom length panic (ethereum#24946)
* core/beacon: prevent invalid logsBloom length panic * core/beacon: prevent negative baseFeePerGas * Update core/beacon/types.go Co-authored-by: Martin Holst Swende <[email protected]> * eth/catalys: go format Co-authored-by: Martin Holst Swende <[email protected]>
1 parent 6dd3b96 commit 2c0649f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

core/beacon/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) {
150150
if len(params.ExtraData) > 32 {
151151
return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
152152
}
153+
if len(params.LogsBloom) != 256 {
154+
return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom))
155+
}
156+
// Check that baseFeePerGas is not negative or too big
157+
if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) {
158+
return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
159+
}
153160
header := &types.Header{
154161
ParentHash: params.ParentHash,
155162
UncleHash: types.EmptyUncleHash,

eth/catalyst/api_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,30 @@ func TestTrickRemoteBlockCache(t *testing.T) {
788788
}
789789
}
790790

791+
func TestInvalidBloom(t *testing.T) {
792+
genesis, preMergeBlocks := generatePreMergeChain(10)
793+
n, ethservice := startEthService(t, genesis, preMergeBlocks)
794+
ethservice.Merger().ReachTTD()
795+
defer n.Close()
796+
797+
commonAncestor := ethservice.BlockChain().CurrentBlock()
798+
api := NewConsensusAPI(ethservice)
799+
800+
// Setup 10 blocks on the canonical chain
801+
setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Block) {})
802+
803+
// (1) check LatestValidHash by sending a normal payload (P1'')
804+
payload := getNewPayload(t, api, commonAncestor)
805+
payload.LogsBloom = append(payload.LogsBloom, byte(1))
806+
status, err := api.NewPayloadV1(*payload)
807+
if err != nil {
808+
t.Fatal(err)
809+
}
810+
if status.Status != beacon.INVALIDBLOCKHASH {
811+
t.Errorf("invalid status: expected VALID got: %v", status.Status)
812+
}
813+
}
814+
791815
func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
792816
genesis, preMergeBlocks := generatePreMergeChain(100)
793817
fmt.Println(genesis.Config.TerminalTotalDifficulty)

0 commit comments

Comments
 (0)