Repository navigation
Description
Migrated from SergioDemianLerner/rustock#43 (pull request by @SDL-A1, 2026-09-21).
Merged: yes. The commits are already in this repository's history.
Original: SergioDemianLerner/rustock#43
Fixes the four high-severity findings from audit archive rustock-4796682 that hold up against the rskj source (rustock's acceptance criterion is agreement with deployed mainnet, not with the RSKIP text). The fifth, FRCR-77, is contested — see below.
Full write-up for the auditor, including the coverage analysis: docs/audit-response-2026-09.md.
| FRCR | Defect | Commit |
|---|---|---|
| FRCR-679 / -879 | BASEFEE (0x48) not installed, arrowhead600→lovell700 (~1.1M blocks) | 3b57e9c |
| FRCR-280 | secp256k1 ECADD/ECMUL charge 0 gas on a failed call from reed800 | 77d3682 |
| FRCR-476 | receiveHeader missing the −20 size-mismatch code; oversized headers truncated |
088b53d |
| FRCR-75 / -76 | getBtcTransactionConfirmations wrong codes, wrong order, no depth or best-chain check |
9f623df |
| FRCR-77 | receiveHeaders cost gating "inverted" vs RSKIP-132 |
not a defect |
The substantive ones
BASEFEE is the most serious because the window is historical: rskj gates it on RSKIP412 (reference.conf: rskip412 = arrowhead600), but revm bundles BASEFEE into LONDON and rustock maps arrowhead600 to ISTANBUL. A rustock node replaying mainnet already diverges on any block in that range containing a BASEFEE. Fixed the same way PUSH0 (RSKIP398) already was — an unchecked instruction installed on the RSK activation height rather than the revm spec.
The missing best-chain check in getBtcTransactionConfirmations is the most dangerous of the rest. connect_block persists every valid header and only moves the head on strictly more work, so a block on an orphaned BTC fork stays in Bridge storage. rustock reported a positive confirmation count for a transaction that exists only on that fork, where rskj returns −2.
Why FRCR-77 is not a defect
Bridge.receiveHeadersGetCost contains the identical ternary rustock does:
final long BASE_COST = activations.isActive(ConsensusRule.RSKIP132) ? 25_000L : 66_000L;The audit's reading of RSKIP-132 is right; the RSKIP text is stale. Changing rustock to match it would introduce a fork. Left alone.
Tests
Eight new tests, each failing on its fix's parent commit. Four of them drive the real Bridge precompile through RskExecutor::execute_block and assert on the ABI-encoded int256 actually returned, rather than on an internal function's result — three of the four defects lived in the gap between "the logic is right" and "the caller sees what rskj's caller sees".
Also found and fixed while running these: add_signature_rejects_key_not_in_redeem_script in bridge/peg.rs had been separated from its #[test] attribute by a later insertion and had never run. The compiler reported it as a warning on every build.
Full workspace suite: 1,253 tests, 0 failures.
🤖 Generated with Claude Code
Update: medium/low triage
All 15 medium and 25 low findings re-checked against the rskj 9.1.0 source. Full write-up: docs/audit-triage-medium-low.md.
| Verdict | Count |
|---|---|
| Real divergence from rskj | 13 |
| Spec is stale — rustock matches rskj, acting on the recommendation would fork | 13 |
| Local-only getter / mempool policy — no consensus effect | 6 |
| Premise does not hold against rskj | 8 |
The severity column is calibrated to the RSKIP baseline and inverts in both directions. Nine MEDIUM rows are stale spec text (HDWalletUtils gas and selectors, BlockHeader precompile names and gas, REMASC selection rule and federation payout threshold, uncle window). Three LOW rows are EVM opcodes rskj shipped and rustock never had: DUPN (0xa8), SWAPN (0xa9) and TXINDEX (0xaa) were live from genesis until RSKIP191 disabled them at iris300 — rated low because the RSKIPs were never adopted, but rskj implemented them anyway.
Eight findings across six RSKIPs are one structural gap rather than eight patches: rskj composes ~15 block-validation rules, rustock has 8 header rules plus the root/gas checks in processor.rs. Missing: tx min/max gas price, the RSKIP252 100× cap, the minGasPrice vote bound, fork-detection data, the RSKIP180 960-byte proof cap, extraData size, uncle validation, the REMASC last-transaction rule, RSKIP144 sublist edges, RSKIP351 header checks. All are accepts-too-much gaps — rustock still computes rskj's state root for every block rskj accepts, but would follow a chain rskj rejects. Replay can never surface them, because mainnet contains no invalid block.
Fixed here (7afe72c):
- STATICCALL gated on RSKIP91 (orchid, #729,000). rustock mapped Genesis to BYZANTIUM and installed
rsk_static_callunconditionally, executing for 729,000 blocks an opcode rskj rejects. - Testnet activation ladder corrected against rskj
config/testnet.conf— worse than the audit reported: rskj'spapyrus200 = 863,000had been written into rustock'swasabi100slot and everything below it shifted;lovell700andreed800were also wrong. Mainnet was and is exact. Tests now transcribe both networks' tables as a block.
Found while checking, not reported by the audit: rskj's STATICCALL pops a value word before RSKIP103 (orchid060, #1,052,700) — VM.calculateCallValue special-cases only DELEGATECALL until then — and charges VT_CALL when it is non-zero. rustock always pops two items. Window permanently closed and proven unexercised; documented rather than patched, because a wrong emulation is worse than a recorded gap.
Also fixed (60c200e): getEstimatedFeesForNextPegOutEvent (FRCR-78/-678) — the one medium/low finding that can fork the canonical chain today. It returned a hardcoded 0 from a transaction-callable Bridge method, so a contract that CALLs it and branches on the answer diverges. RSKIP385 (fingerroot500, #5,468,000) removes rskj's zero short-circuit and RSKIP305 (reed800, #8,052,200) switches it to a full peg-out simulation — mainnet is millions of blocks past both, so every call returns a real fee on rskj and 0 on rustock.
rustock already had the parts: complete_pegout_tx is the same builder updateCollections uses for real batched peg-outs, and pegout_tx_size_segwit/_legacy already reproduce rskj's pre-cardamom sizers. Missing was the wiring — the release-queue load (rskj concatenates the legacy and with-txhash queues once RSKIP146 is active), the hypothetical extra request at rskj's deterministic recipient, inputSum - outputSum, and the fallback to the size estimate on builder failure. getEstimatedFeesForPegOutAmount was the same stub and now runs the same simulation with the caller's amount.
Test drives it end to end: releaseBtc transactions build a real queue, then the getter is called and its int256 read back — covering the pre-RSKIP385 zero, its removal at fingerroot500, the reed800 fallback, and that three queued peg-outs cost strictly more than none.
Full workspace suite: 1,256 tests, 0 failures.
Update: the eight mainnet block-validity rules
Implemented in 94194c0. rskj composes ~15 block-validation rules; 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, RSKIP351 header checks) are gated on reed810, which rskj sets to -1 on mainnet — testnet-only, so not implemented.
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.
Verified against real mainnet data, not just unit tests. These rules reject blocks, so their 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 runs them over the local mainnet store — 425 sampled blocks across every era plus dense runs either side of each activation, 12,341 uncle-bearing blocks, and 300 consecutive blocks with fork detection enabled. Zero rejections.
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.
Two notes. The fork-detection rule 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; it is opt-in (with_fork_detection_validation) because of the 449 header reads per block, and the MainchainView trait leaves room for the cache rskj uses. And extending ActivationHeights surfaced a third testnet height error: papyrus200 was 0 where rskj's config/testnet.conf says 863,000, so RSKIP156's difficulty divisor was activating from testnet genesis. Mainnet unaffected.
Full workspace suite: 1,261 tests, 0 failures.
Activity