Repository navigation
Description
Migrated from SergioDemianLerner/rustock#257 (pull request by @SDL-A1, 2026-10-04).
Merged: yes. The commits are already in this repository's history.
Original: SergioDemianLerner/rustock#257
Closes #256.
ceiling_for bounded header difficulty and was compared against a claim of cumulative difficulty, which in RSK is header difficulty plus every referenced uncle's. Those are not the same number.
Measured over the 276,000 blocks above the shipped checkpoint, uncles add 90.9% to the work. So the 1.68× header-difficulty bound was 0.88× the real work — below the honest chain. Every truthful peer would have been judged impossible, and tightening the sampling interval, the obvious optimisation, made it worse.
The allowance
uncle_allowance_per_mille turns the sampled uncle_counts into a bound on the population mean by empirical Bernstein — rather than Hoeffding, because mainnet's counts are clustered against a range of 10, so paying for the observed variance in the square-root term is far cheaper than paying for the range there.
This replaces a mean-plus-25%-slack figure that was not a bound at all: no confidence attached, no argument for why a quarter was enough. The new one is sound and it is wider.
With no samples it now returns the consensus cap rather than 1.000. "Nothing observed" means the worst case assumed, not no uncles assumed — the old answer was a ceiling below the honest chain.
The selection
choose_samples splits into a random draw of 340 heights and deterministic gap filling to 768. Only the draw carries the uncle argument: the peer is committed to its chain before it learns where it will be checked, so the counts are a uniform sample of a population it has already fixed.
The fixed grid it replaces was a function a peer could evaluate in advance — mine real uncles at checkpoint + k*768, fabricate between them, for a fraction of a percent of the claimed work.
ChainSampler now keeps its draw and tops it up as the skeleton arrives, instead of redrawing and unioning one draw onto the next (which would have grown the request count without bound).
The honest numbers
| samples | allowance | vs. the true 1.91 | vs. the 11.0 cap |
|---|---|---|---|
| 340 | 4.20 | 2.20× | 0.38× |
| 1,000 | 2.78 | 1.45× | 0.25× |
| 3,400 | 2.22 | 1.16× | 0.20× |
End to end, the ceiling sits about 17% above the real chain — not the 1% the tests asserted while uncles were assumed away. A peer can overstate its work by a sixth and be judged plausible. The tests now assert 17%, and the comments say why it is still worth having: the claim an attacker needs to make is not 17% high but orders of magnitude high.
At these sample counts the bound is dominated by the range term 3Rln(3/δ)/k, which does not depend on what was observed and shrinks only as 1/k. More samples is the lever, and it runs out: skeleton granularity caps k in the low thousands, and with it the allowance at ~1.4× the truth. Closing the rest is a consensus question — RSKIP-699 — not a sampling one.
Fixture
SAMPLES is now 340 real samples over 276,000 blocks. The allowance's slack falls as 1/k, so the previous 39-sample fixture exercised a bound an order of magnitude looser than the one that ships, and said nothing about it.
2,007 tests pass.
🤖 Generated with Claude Code
Activity