Skip to content

The sampled difficulty bound runs only in snapshot sync, not in ordinary peer selection #253

Open

Description

@SDL-A1

Migrated from SergioDemianLerner/rustock#253 (issue by @SDL-A1, 2026-10-04).
Original: SergioDemianLerner/rustock#253

Where each half runs

ordinary sync snapshot sync
free half — height at or below the checkpoint yes yes
sampled half — height above the checkpoint no yes

The free half is in the Status handler (handler.rs), so it applies to every
peer on every connection. The sampled half exists only as
Phase::SamplingClaim in snap/session.rs; ordinary sync never constructs a
SamplingGate.

Why that is the wrong way round

The free half secures nothing against an adversary — the sidestep is to claim
a height above the checkpoint, which is what an attacker wants to claim anyway
(see docs/difficulty-gate.md). So on the ordinary sync path, a peer claiming
any height above #9,020,000 has its total difficulty accepted into
peer-selection metadata with no bound on it at all.

That matters more for ordinary sync than for snapshot sync, because of what the
claim is used for:

  • snapshot sync — the claim picks a checkpoint, and the header walk then
    verifies the entire chain behind it. A lie is caught, expensively.
  • ordinary sync — the claim drives peer selection and best-chain comparison
    continuously, with no walk-to-genesis behind it. The node simply prefers
    whoever claims most.

So the only place the sampled bound runs is the place that already has a
thorough verification behind it, and the place with no backstop gets only the
check an attacker steps around for free.

The fix

Make the sampled bound available to ordinary peer selection, not only to a
snapshot session. The sampler is per-peer and costs requests, so when it runs
is a policy question — on first hearing a claim, on a claim that would change
the best peer, or on a schedule — but it should be reachable from the path
where the claim actually steers the node.

Configuration

This and #252 are two switches, and the matrix the user specified is:

check checkpoint hash bound work + sample result
no no no defence
yes no good defence
no yes good defence, and does not ask core developers to choose a fork in code
yes yes strongest

The second switch covers the cumulative-difficulty bound and the sampling
together, and they must not be separable: bounding without sampling is the free
half, which secures nothing. Enabling "check the bound" alone would be an
option that looks like a defence and is not.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions