Repository navigation
Description
Migrated from SergioDemianLerner/rustock#44 (pull request by @SDL-A1, 2026-09-22).
Merged: yes. The commits are already in this repository's history.
Original: SergioDemianLerner/rustock#44
Follow-up to #43, which merged before this work was pushed. Closes the largest remaining group from docs/audit-triage-medium-low.md: audit findings FRCR-873, FRCR-573, FRCR-677, FRCR-480 and FRCR-481, plus four gaps found by diffing rule sets rather than reading the audit.
rskj composes ~15 block-validation rules in RskContext.getBlockValidationRule. rustock had 8 header rules plus the root/gas checks in processor.rs. These eight were missing and are live on mainnet:
| rskj rule | rejects a block when… | active from |
|---|---|---|
TxsMinGasPriceRule |
a non-REMASC tx pays below block.minGasPrice |
always |
PrevMinGasPriceRule |
minGasPrice is outside BlockGasPriceRange of the parent's (±1%) |
always |
BlockTxsMaxGasPriceRule |
a tx pays above 100× minGasPrice (RSKIP252) |
fingerroot500 |
BlockUnclesValidationRule |
>10 uncles, >7 generations old, repeated, already used, or no common parent | always |
RemascValidationRule |
the last transaction is not the REMASC transaction | always |
ExtraDataRule |
extraData exceeds 32 bytes |
always |
ForkDetectionDataRule |
bad CPV/NU/BN in the coinbase (RSKIP110) | wasabi100 |
| RSKIP180 proof cap | merged-mining merkle proof over 960 bytes | iris300 |
The two remaining Group 1 rules — RSKIP144 sublist edges and RSKIP351 header checks — are gated on reed810, which rskj sets to -1 on mainnet. Testnet-only, so not implemented.
What kind of bug this is
All eight are accepts-too-much gaps. rustock still computes rskj's state root for every block rskj accepts, so none of them can produce a wrong answer on the canonical chain. What they mean is that rustock would follow a chain rskj rejects — a consensus failure in the chain-selection sense rather than the state-transition sense.
It is also why whole-chain replay can never surface them: mainnet contains no invalid block, so the missing rules are never handed anything to reject. 9.2M clean blocks is exactly as consistent with these rules existing as with them not existing.
Placement follows rskj
BlockValidatorImpl runs when a block arrives, separately from BlockExecutor. So the rules hang off BlockProcessor::validate_block and are called from the sync service's two acceptance paths; process_block stays the pure executor.
I initially wired them into process_block, which broke six existing fixtures — they would have needed REMASC transactions, and REMASC needs real ancestry those fixtures have no reason to build. Checking rskj showed that placement was wrong anyway.
Verified against real mainnet data, not just unit tests
These rules reject blocks, so the failure mode is the inverse of the usual one: a rule that is too strict halts the node on a block the network accepted, and no unit test can find that.
crates/execution/tests/mainnet_block_rules.rs (ignored by default; point RUSTOCK_BLOCKS_DB at a synced store) runs them over the local mainnet database:
- 425 sampled blocks across every era, plus dense runs either side of each activation
- 12,341 uncle-bearing blocks
- 300 consecutive blocks with fork detection enabled
Zero rejections. The fork-detection result is the one most likely to have been silently wrong — it reconstructs 12 bytes from 449 ancestors, including a commit-to-parents vector built from the least-significant byte of seven BTC block hashes in bitcoinj's reversed getBytes() order.
That check earned its keep on the first run: it caught that genesis has no REMASC transaction. rskj's BlockValidatorImpl.isValid returns false for genesis — it is loaded from the genesis file, never validated — so the pipeline now skips block 0. Without real data this would have shipped as a node that refuses its own genesis block.
Notes
- Fork detection is opt-in (
with_fork_detection_validation): it reads 449 ancestor headers per block. rskj caches the same view inConsensusValidationMainchainView, and theMainchainViewtrait leaves room for that. - Uncle and mainchain lookups go through
AncestorSource/MainchainViewtraits, so a cached implementation can replace the store walk. ActivationHeightsgainsiris300andfingerroot500. Doing so surfaced a third testnet height error: itspapyrus200was0where rskj'sconfig/testnet.confsays863,000, so RSKIP156's difficulty divisor was activating from testnet genesis instead of #863,000. An existing test had pinned the wrong value. Mainnet unaffected.
Full workspace suite: 1,261 tests, 0 failures.
🤖 Generated with Claude Code
Activity