Repository navigation
Description
Migrated from SergioDemianLerner/rustock#258 (issue by @SDL-A1, 2026-10-04).
Original: SergioDemianLerner/rustock#258
session.rs:774 fails a snap sync with SnapFailure::OverstatedDifficulty when the peer's claim exceeds
established_difficulty() + checkpoint.difficulty * (1 + checkpoint.uncle_count)established_difficulty() is anchor_difficulty + walked_difficulty, and walked_difficulty is accumulated in headers.rs:403-418:
match proven.get(&hash) {
Some(exact) => { self.walked_difficulty += *exact; }
None => {
self.walked_difficulty += header.difficulty; // uncles not counted
if header.uncle_count > 0 { self.uncles_omitted += header.uncle_count; }
}
}Its own doc comment says so: "from anyone else walked_difficulty is a lower bound, widened by every block that included an uncle."
So the ceiling is built from a quantity that understates the chain, and compared against a claim of cumulative difficulty, which includes uncle work. That is the same shape as #256 — a bound on header difficulty compared against a claim of cumulative difficulty — in the post-walk check rather than in the sampling gate.
Scale
Uncles add ~90.9% to the work over the 276,000 blocks above the shipped checkpoint. Where proven is empty, established is therefore about 52% of the true total, and an honest peer stating its true cumulative difficulty would be failed with OverstatedDifficulty.
The uncle correction is applied to the checkpoint block's own slack and nowhere else — and the comment immediately above that line warns against exactly this failure mode:
Bounding it low instead would reject every honest peer whose totals are right, which is what the header-only bound did.
What needs establishing
I have not confirmed this fires in practice. proven is a map of exact difficulties for blocks whose bodies are in hand; on a fresh snap sync it should be empty, but the walk may anchor somewhere that makes this unreachable, and the check is skipped entirely while established_difficulty() is None. Before fixing:
- Does a fresh snap sync reach this check with
provenempty? - If so, is
uncles_omittednon-zero at that point? (It is the direct signal — non-zero meanswalked_difficultyis known to understate.)
Likely fix
Bound each walked block the way the checkpoint block is already bounded — header.difficulty * (1 + header.uncle_count) when the body is absent — so the ceiling stays an upper bound. uncle_count is a header field and inside what the block's proof of work commits to, so it costs nothing to use.
Once RSKIP-698 is active the walk can carry the uncle headers and the quantity becomes exact, at which point the bound is unnecessary rather than merely sound.
Found while documenting the crossover between the sampling gate and a full header+uncle download (follow-up to #256 / #257).
@SDL-A1 commented on 2026-10-04:
Narrowing the scope of this, having traced the path.
The understatement is specific to rsk/62 peers. For a peer that negotiated rsk/63, session.rs:588 already builds proven from HeaderWithUncles::cumulative_difficulty(), and service.rs:1177 already upgrades the walk's BlockHeadersRequest to BlockHeadersWithUnclesRequest at the send site. So walked_difficulty takes the exact branch at headers.rs:409, uncles_omitted stays zero, and the OverstatedDifficulty ceiling is sound.
So this is not "the walk understates" but "the walk understates against an rskj peer", which is every rskj node today and the reason the check is worth fixing rather than waiting out.
Revised scope:
- The bug only bites when
uncles_omitted > 0. That is already the exact signal — it is non-zero precisely when a block's uncle difficulty was skipped. - The fix is to bound rather than skip:
header.difficulty * (1 + header.uncle_count)in theNonearm, matching whatsession.rs:775already does for the checkpoint block alone.uncle_countis a header field and inside what the proof of work commits to. - Alternatively, and more cheaply: refuse to run the check at all when
uncles_omitted > 0, since a ceiling known to understate is not worth comparing against. That loses the check for rsk/62 peers rather than making it wrong for them.
(2) is better — it keeps a sound upper bound in both cases.
Still not confirmed that a fresh snap sync against an rsk/62 peer reaches this check with established_difficulty() as Some. That is the one thing to establish before fixing.
Related: #257 now skips the sampling gate for an rsk/63 peer over a short window, on the grounds that the walk establishes the work exactly. That reasoning depends on the exact branch above being taken, so these two are coupled — if the uncle path ever regresses, the gate skip becomes unsound as well as the ceiling.
Activity