Skip to content

Commit 40505a9

Browse files
jsvisarjl493456442cskiraly
authored
eth/protocols/eth: reject message containing duplicated txs and drop peer (#32728)
Drop peer if sending the same transaction multiple times in a single message. Fixes #32724 --------- Signed-off-by: Csaba Kiraly <[email protected]> Co-authored-by: Gary Rong <[email protected]> Co-authored-by: Csaba Kiraly <[email protected]>
1 parent 3cfc334 commit 40505a9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

eth/protocols/eth/handlers.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,19 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
494494
if err := msg.Decode(&txs); err != nil {
495495
return err
496496
}
497+
// Duplicate transactions are not allowed
498+
seen := make(map[common.Hash]struct{})
497499
for i, tx := range txs {
498500
// Validate and mark the remote transaction
499501
if tx == nil {
500502
return fmt.Errorf("Transactions: transaction %d is nil", i)
501503
}
502-
peer.markTransaction(tx.Hash())
504+
hash := tx.Hash()
505+
if _, exists := seen[hash]; exists {
506+
return fmt.Errorf("Transactions: multiple copies of the same hash %v", hash)
507+
}
508+
seen[hash] = struct{}{}
509+
peer.markTransaction(hash)
503510
}
504511
return backend.Handle(peer, &txs)
505512
}
@@ -514,12 +521,19 @@ func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
514521
if err := msg.Decode(&txs); err != nil {
515522
return err
516523
}
524+
// Duplicate transactions are not allowed
525+
seen := make(map[common.Hash]struct{})
517526
for i, tx := range txs.PooledTransactionsResponse {
518527
// Validate and mark the remote transaction
519528
if tx == nil {
520529
return fmt.Errorf("PooledTransactions: transaction %d is nil", i)
521530
}
522-
peer.markTransaction(tx.Hash())
531+
hash := tx.Hash()
532+
if _, exists := seen[hash]; exists {
533+
return fmt.Errorf("PooledTransactions: multiple copies of the same hash %v", hash)
534+
}
535+
seen[hash] = struct{}{}
536+
peer.markTransaction(hash)
523537
}
524538
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
525539

0 commit comments

Comments
 (0)