<!-- XE-0025 · 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-0025>. The page is the record; this is the same page for reading.*

XE-0025 · Bounty

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

Accepted
claimed High
[xe#47](https://github.com/xeprotocol/xe/issues/47)
filed 2026-10-25 11:12 UTC
by byfor8

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   High

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   internally

Updated
:   2026-11-10 11:38 UTC

Told
:   2026-11-10 00:15 UTC

### Patches

- [xe#137](https://github.com/xeprotocol/xe/pull/137) open by arturbarszcz78
  fix(net): per-IP rate limiting and LRU eviction in peerRateLimiter (#47)

### History

- [61382](https://bounty.xe.network/log/61382) 2026-11-10 00:15 UTC reply.mirrored
- [61339](https://bounty.xe.network/log/61339) 2026-11-10 00:15 UTC reply.sent
- [15392](https://bounty.xe.network/log/15392) 2026-11-06 21:27 UTC proposal.adopted
- [15391](https://bounty.xe.network/log/15391) 2026-11-06 21:27 UTC ticket.award
- [15390](https://bounty.xe.network/log/15390) 2026-11-06 21:27 UTC proposal.rejected
- [6871](https://bounty.xe.network/log/6871) 2026-11-05 13:45 UTC proposal.created
- [1795](https://bounty.xe.network/log/1795) 2026-11-02 19:16 UTC proposal.created
- [1450](https://bounty.xe.network/log/1450) 2026-11-02 10:11 UTC note.added
- [704](https://bounty.xe.network/log/704) 2026-10-29 14:22 UTC note.added
- [703](https://bounty.xe.network/log/703) 2026-10-29 14:22 UTC ticket.facts area
- [571](https://bounty.xe.network/log/571) 2026-10-29 14:04 UTC github.labels
- [363](https://bounty.xe.network/log/363) 2026-10-29 14:04 UTC ticket.status triaging → accepted

[Full history](https://bounty.xe.network/log?ref=XE-0025) · [JSON](https://bounty.xe.network/v1/tickets/XE-0025) · [markdown](https://bounty.xe.network/XE-0025.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

**XE desk**team2026-11-10 00:15 UTCgithub

Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is
updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0025.
