Skip to content

Commit 8c0c043

Browse files
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 03157b6 commit 8c0c043

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
@@ -148,6 +148,13 @@ func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) {
148148
if len(params.ExtraData) > 32 {
149149
return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
150150
}
151+
if len(params.LogsBloom) != 256 {
152+
return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom))
153+
}
154+
// Check that baseFeePerGas is not negative or too big
155+
if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) {
156+
return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
157+
}
151158
header := &types.Header{
152159
ParentHash: params.ParentHash,
153160
UncleHash: types.EmptyUncleHash,

eth/catalyst/api_test.go

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

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

0 commit comments

Comments
 (0)