@@ -39,6 +39,7 @@ import (
3939 "github.com/ethereum/go-ethereum/core/rawdb"
4040 "github.com/ethereum/go-ethereum/core/txpool"
4141 "github.com/ethereum/go-ethereum/core/types"
42+ "github.com/ethereum/go-ethereum/crypto/kzg4844"
4243 "github.com/ethereum/go-ethereum/eth/downloader"
4344 "github.com/ethereum/go-ethereum/eth/ethconfig"
4445 "github.com/ethereum/go-ethereum/eth/fetcher"
@@ -125,6 +126,10 @@ type votePool interface {
125126 SubscribeNewVoteEvent (ch chan <- core.NewVoteEvent ) event.Subscription
126127}
127128
129+ // MBConfigGetter is a function type for getting malicious behavior configuration.
130+ // Used by handler to check blob chaos flags during P2P operations.
131+ type MBConfigGetter func () (corruptBlob , dropBlob bool )
132+
128133// handlerConfig is the collection of initialization parameters to create a full
129134// node network handler.
130135type handlerConfig struct {
@@ -158,6 +163,7 @@ type handler struct {
158163 evnNodeIdsWhitelistMap map [enode.ID ]struct {}
159164 proxyedValidatorAddressMap map [common.Address ]struct {}
160165 proxyedNodeIdsMap map [enode.ID ]struct {}
166+ mbConfigGetter MBConfigGetter // For blob chaos testing
161167
162168 snapSync atomic.Bool // Flag whether snap sync is enabled (gets disabled if we already have blocks)
163169 synced atomic.Bool // Flag whether we're considered synchronised (enables transaction processing)
@@ -204,6 +210,60 @@ type handler struct {
204210 handlerDoneCh chan struct {}
205211}
206212
213+ // SetMBConfigGetter sets the malicious behavior config getter (called after miner init).
214+ func (h * handler ) SetMBConfigGetter (getter MBConfigGetter ) {
215+ h .mbConfigGetter = getter
216+ }
217+
218+ // getMBConfig returns the current blob chaos config flags.
219+ func (h * handler ) getMBConfig () (corruptBlob , dropBlob bool ) {
220+ if h .mbConfigGetter != nil {
221+ return h .mbConfigGetter ()
222+ }
223+ return false , false
224+ }
225+
226+ // processSidecarsForBroadcast processes blob sidecars based on malicious behavior config.
227+ // Returns (processed sidecars, whether modified).
228+ func (h * handler ) processSidecarsForBroadcast (sidecars types.BlobSidecars ) (types.BlobSidecars , bool ) {
229+ corruptBlob , dropBlob := h .getMBConfig ()
230+
231+ if dropBlob {
232+ log .Warn ("Malicious behavior: dropping blob sidecars during P2P broadcast" ,
233+ "originalCount" , len (sidecars ))
234+ return nil , true
235+ }
236+
237+ if corruptBlob && len (sidecars ) > 0 {
238+ log .Warn ("Malicious behavior: corrupting blob sidecars during P2P broadcast" ,
239+ "count" , len (sidecars ))
240+ corrupted := make (types.BlobSidecars , len (sidecars ))
241+ for i , sc := range sidecars {
242+ if sc != nil && len (sc .Blobs ) > 0 {
243+ newSc := & types.BlobSidecar {
244+ BlobTxSidecar : types.BlobTxSidecar {
245+ Blobs : make ([]kzg4844.Blob , len (sc .Blobs )),
246+ Commitments : make ([]kzg4844.Commitment , len (sc .Commitments )),
247+ Proofs : make ([]kzg4844.Proof , len (sc .Proofs )),
248+ },
249+ TxIndex : sc .TxIndex ,
250+ TxHash : sc .TxHash ,
251+ }
252+ copy (newSc .Blobs , sc .Blobs )
253+ copy (newSc .Commitments , sc .Commitments )
254+ copy (newSc .Proofs , sc .Proofs )
255+ newSc .Blobs [0 ][0 ] ^= 0xFF // Corrupt first byte
256+ corrupted [i ] = newSc
257+ } else {
258+ corrupted [i ] = sc
259+ }
260+ }
261+ return corrupted , true
262+ }
263+
264+ return sidecars , false
265+ }
266+
207267// newHandler returns a handler for all Ethereum chain management protocol.
208268func newHandler (config * handlerConfig ) (* handler , error ) {
209269 // Create the protocol manager with the base fields
@@ -819,6 +879,14 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
819879 return
820880 }
821881 }
882+
883+ // Process sidecars based on malicious behavior config (blob chaos testing)
884+ if len (block .Sidecars ()) > 0 {
885+ if processedSidecars , modified := h .processSidecarsForBroadcast (block .Sidecars ()); modified {
886+ block = block .WithSidecars (processedSidecars )
887+ }
888+ }
889+
822890 hash := block .Hash ()
823891 peers := h .peers .peersWithoutBlock (hash )
824892
0 commit comments