blockblaz / blockblaz/zeam

network: per-peer rate-limit / DoS handling for blocks_by_range server

Open
#834 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Zig
Stars
97
Forks
39
PR merge metrics
No merged PRs in 30d

Description

# network: per-peer rate-limit / DoS handling for `blocks_by_range` server

Reported by @ch4r10t33r in review of #824.

## Problem

In `pkgs/node/src/node.zig:1209-1313`, the `blocks_by_range` server path has no per-peer concurrency limit and no token-bucket. An adversarial peer can spam `blocks_by_range` requests, and each request costs:

- O(`count`) DB reads (`loadFinalizedSlotIndex` + `loadBlock`)
- O(`head.slot − unfin_start`) forkchoice walk for the unfinalized portion
- O(`count`) `sszClone` of `SignedBlock` (~tens of KB each — for `count == 1024` that is ~10MB of clone work per request).

A peer with cheap status spoofing could pin a server's CPU on responses without paying any cost themselves. There is no admission control today.

## Suggested fix

- Per-peer concurrency cap (e.g., max 1 in-flight `blocks_by_range` per peer).
- Token-bucket rate limit (bytes/sec or chunks/sec) per peer.
- Optional: priority queue so honest requests don't get starved by adversarial bursts.

Worth flagging as a tracking item even if not blocking on the v0.4.x devnet milestone — once devnets get larger / external traffic starts arriving, this becomes exploitable.

## Acceptance criteria

- [ ] Per-peer concurrency cap on server-side `blocks_by_range` handling.
- [ ] Per-peer rate limit (configurable; sensible default).
- [ ] Tests that an adversarial peer issuing N >> cap concurrent requests gets throttled (rejected with appropriate error code) without affecting an honest peer's requests.
- [ ] Metrics: per-peer in-flight count, throttle/reject counter.

## Out of scope

- The corresponding race fix for the request-ID-vs-pending-state issue (separate follow-up).
- Catch-up cadence improvements for the requesting side (separate follow-up).

cc @ch4r10t33r

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in pkgs/node/src/node.zig:1209-1313 and trace the server-side blocks_by_range request handling, peer state, error reporting, and metrics conventions. The work is done when per-peer concurrency and configurable rate limits are enforced, adversarial requests are throttled without affecting an honest peer, and tests cover rejection plus the required in-flight and throttle metrics.

Written by the indexing model from the issue text.

Assessment

Tech stack
zig
Domain
networking, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.