[Medium] Sync retry loop re-verifies never-appliable retryable blocks twice per round, forever (CPU DoS from one malicious peer)
Report
Summary
The sync apply loop re-verifies never-appliable retryable blocks twice per round, forever, with no quarantine and no peer penalty — so one malicious peer serving validly-signed blocks with bogus parents can burn ~0.3–1.7 cores on a victim indefinitely, repeating every 10 s periodic round.
Root Cause
requestSync (net/sync.go:826-880):
- Two full passes per round in the all-retryable case. The retry loop (
:826-852) callsledger.AddSyncedBlock(b)on every pending block; when all fail retryably it breaks immediately (if len(retryable) == len(pending) { break }). The "collect reasons" block afterwards (:854-870) then callsledger.AddSyncedBlock(b)a second time on every remaining block, just to log the error strings. - Retryable failures are never quarantined. Only non-retryable failures are quarantined (
:840) and marked unreachable. A block failing with retryableprevious mismatchstays appliable-forever. skipUnreachable(:811-820) never helps here. It only skips blocks whosePreviousis already in the unreachable set; a bogus parent is merely missing, never marked.- No peer penalty. There is no Ban/Disconnect/peer-score call anywhere in
net/sync.go. - The frontier never advances, so the same blocks are re-served every 10 s (
periodicSyncInterval,net/sync.go:36, ticker:443).
The cost is incurred because signature verification happens before the parent check: VerifyBlock (core/crypto.go:145-167) only verifies signatures for open blocks, so non-open blocks pay a full ed25519 verify in verifyBlockCredential (core/ledger.go:1474, called at :859) before failing with previous mismatch (core/ledger.go:1040, same error at other apply sites).
Impact
Attack: a malicious peer serves validly-signed blocks whose Previous doesn't exist. Each block passes hash + PoW + full ed25519 verification, then fails retryably — twice per round, every 10 s, forever.
Measured (executed PoC, 2,000 validly-signed bogus-parent sends):
pass 1 (retry 0): 1.20s for 2000 blocks (601.0 us/block); retryable=2000 other-err=0 nil=0
pass 2 (final pass): 1.47s for 2000 blocks (737.2 us/block); retryable=2000 other-err=0 nil=0
sample error: previous mismatch
Extrapolation: 10,000 blocks × 2 passes × ~670 µs ≈ 13 s CPU/round/peer at VM rates (≈3–4 s bare metal), repeating every 10 s — one peer sustains ~0.3–1.7 cores indefinitely, ×4 concurrent rounds. Attacker cost is one-time (sign 10k blocks once, re-serve ~5 MB/round). Amplifier: #613 (sync caps bypassed by framing) lets a peer serve more than 10k blocks/round.
Note on related reports
Distinct from #245 (opposite direction — the client discards retryable blocks after 10 passes, honest-server livelock), #613 (cap bypass; complementary amplifier, different mechanism), #167 (quarantine poisoning), #59 (honest first-sync memory, no in-flight guard), and #633 (junk block blocking lease archiving — different mechanism and impact). Searched "sync retry re-verify AddSyncedBlock" — no covering report.
Suggested fix
Quarantine blocks failing retryably in 2 consecutive rounds (time-bounded); record errors from the retry loop instead of re-verifying in the reasons pass; penalize peers with high served-block failure rates.
Thread
Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-16882 and says what differs; it is read like any other.