You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Match RSKj: pass its consensus tests, match every block of mainnet and testnet, handle forks and orphan blocks as RSKj does, and run faster - #374
RSKj's own tests of the network's rules pass on rustock, every block of mainnet and testnet matches RSKj, and rustock handles forks and orphan blocks as RSKj does. It is also faster than RSKj on every measure we took. All of it is held to RSKj's release VETIVER-9.0.4 and the bitcoinj-thin it builds with (0.14.4-rsk-18).
RSKj's tests pass
RSKj's tests that name one of the network's rules or upgrades, 1,239 of them, were each read, and each has its verdict in docs/rskj-tests/:
RSKj's tests of the network's rules
Ported to rustock, and passing
925
Ported, found rustock doing otherwise, rustock fixed, now passing
13
Held by a test rustock already had, which passes
206
Testing what has no counterpart in rustock: Java's nulls and constructor checks, RSKj's mocks and wiring, calls RSKj never makes
94
A class only in RSKj's master, not in its release
1
So every one that applies to rustock passes: 1,144 of 1,144. The 248 tests of RSKj's validators, miner and transaction pool are held the same way, with none left a gap (docs/rskj-test-parity.md).
Every block matches RSKj
As CLAUDE.md asks of a consensus change, this was checked against the chain, not reasoned about. Every block of both networks was replayed: mainnet from genesis to #9,420,342 and testnet from genesis to #8,306,564. Every block matched what its header records, its state root included wherever the header holds the unitrie's (all of testnet, and mainnet from #1,591,000), and each block the run ended on matches RSKj's public node, its hash and its state root. No block was refused, no node halted, and no node logged an error. The build was this PR's but for its last ten commits and upstream's newest main, merged in since. The ten change only what a mining node builds and answers (the gas limit and the minimum gas price it aims for, its answers to a pool, its timed miner and its development clock, evm_increaseTime) and a check at start-up, or add only documents and tests; upstream's brings the external-IP lookup, Docker files, a newer libz-sys and a section of CLAUDE.md. None of it changes how a node checks or runs a block it receives.
Five testnet blocks that rustock got wrong now replay to their headers' state and receipts roots. Each was a network rule, and each is fixed with a test that fails without it:
Leaves the creator's return data empty after a reverted creation
Faster than RSKj
rustock with this PR (at 8a00981), against RSKj VETIVER-9.0.4, on the same machine and the same mainnet blocks, all measured on 17 November:
rustock
RSKj
rustock vs RSKj
Catching up from the network: 6,907 blocks, start to finish¹
57 s
18 min
19× faster
Loading Rootstock's signed copy with --import²
18.5 s
59.9 s
3.2× faster
Memory while re-running the blocks³
0.45 GB
1.26 GB
2.8× less
CPU time to re-run the blocks³
21.8 s
42.6 s
2× less
Time per block inside the node while catching up⁴
3.8 ms
6.1 ms
1.6× faster
Re-running the blocks offline³
20.8 s
26.9 s
1.3× faster
In every run, every block matched its header's state root on both clients.
¹ From the moment each node had Rootstock's copy of mainnet #9,414,000 loaded (the end of each one's --import) to running block #9,420,907, the newest block when rustock had caught up, fetching the blocks from mainnet peers. RSKj took 18 min 0 s, rustock 57 s. Most of the gap is in fetching: rustock had all 6,907 blocks 46 s after its load, from up to 14 peers with up to 176 bodies in flight, while RSKj took in about 4.4 blocks a second for its first 14 minutes.
² The copy at mainnet #9,414,000, which all three signers list with the same hash (both clients trust the same three): 4,000 blocks, 781,768 long values and 10,683,761 state nodes. Both clients read the signers' lists, check their signatures and the file's SHA-256, and load it; the times are the load alone, after the download. RSKj's 59.9 s is by its own log, from after it unzipped the file; rustock's 18.5 s include unzipping it.
³ #9,405,001 to #9,412,300 (7,300 blocks), re-run from each client's own database with every state root checked against its header, and a cache of a million trie nodes in front of each (RSKj's default cache.states.max-elements): rustock with replay_bench (crates/cli/examples), RSKj with its own ExecuteBlocks tool. Four runs each, alternating, each client twice in a row, after a first pass that brought both databases into memory. Time is the average re-run: rustock's leaves out opening its store, and RSKj's leaves out the 0.9 s its tool takes for a single block. CPU is the whole process's, user and system. Memory is the highest peak resident set of each client's four runs.
⁴ The same stretch as ¹, from each node's log: for rustock, the time it spent executing and storing the blocks (26.3 s for 6,907); for RSKj, the time inside tryToConnect, which also validates them (42.2 s for 6,907).
Forks and orphan blocks, as RSKj handles them
Every block is executed as it arrives, against its own parent's state, beside the chain when it isn't on it. A heavier branch becomes the best only once this node has executed it, and switching to it re-points the chain and runs nothing again. An orphan block, one whose parent this node lacks, has the missing blocks asked of the peer that sent it, as RSKj asks, and its branch is executed as they come. A branch none of whose bodies arrive within 60 s is given up, so withholding bodies can't hold the node back. Before, a heavier branch known only by its headers took the head and pulled execution back to the fork point, where the miner built and every query was answered until its bodies came and it was re-run.
On a tie in total difficulty, the block store and the miner apply RSKj's SelectionRule (fees, then the lower hash), so a miner on rustock builds on the same block as RSKj's miners.
At the mainnet tip for four hours, as competing blocks met, the node ran 808 blocks beside the chain and switched to a heavier branch 333 times, running nothing again, and at each of 25 checks it was level with RSKj's public node.
See docs/follow-mode-rskj-vs-rustock.md §8, and §99 and §100 of docs/design-divergences.md, which records RSK's rules where they differ from Ethereum's.
Parity with RSKj, RSKIP by RSKIP
The 108 RSKIPs below were each read side by side in RSKj's release VETIVER-9.0.4 and in rustock, each under the upgrade that brings it: the code of each in both clients, with RSKj's own tests of it as the checklist. So was each statement rsk.zone makes about what a node does: merge mining, the PowPeg, REMASC, the EVM and its precompiles, the state tree, the chain IDs. Where rustock did otherwise than RSKj it now does as RSKj does, and each fix comes with a test that fails without it: 74 match RSKj, some of them through this PR's other fixes; 30 had differences, all fixed; and 4 have nothing for a node to implement. Where a row says so, RSKj confirmed the fix on its own regtest: a case builds blocks on RSKj's release, the replay's build imports them with every state root checked against its header and agrees, and a build from before the fix parts from RSKj where the fix says it would.
Every other RSKIP rsk.zone lists was read against RSKj as well, and each statement it makes about what a node does holds of rustock as it holds of RSKj.
Before any upgrade (from block 0)
RSKIP
What it makes a node do
What was found
0
The RSKIPs' purpose and guidelines
Nothing for a node to implement, in either client.
15
REMASC: a block's fees paid to its miner 4,000 blocks later, shared with its siblings
Three fixes. REMASC pays the matured block of the running block's own chain, and its siblings, in RSKj's order; rustock took them from the main chain by number, which shows only on a block run beside the chain (confirmed on RSKj's regtest). Its payment to the federation takes a new federation's activation age at the running block's upgrades, not the paid block's (confirmed on RSKj's regtest). A block or body the store lacks, when REMASC reads it, is the node's fault and no rule's; rustock refused the block (no regtest reaches it: a store fault).
40
The Bridge: peg-ins, the federation and its changes, peg-outs and their signatures
Fixed in each of its three parts. Bitcoin headers: before RSKIP-88, receiveHeaders fails for a header that counts its transactions below zero (no regtest reaches it: before the first upgrades, where RSKj's regtest cannot start); a Bitcoin block looked up by hash is read from the Bridge's storage alone, not from a node-wide cache that keeps other chains' blocks (confirmed on RSKj's regtest). The federation: with no federation pending, a vote to add a member whose key is no point answers -10 (confirmed on RSKj's regtest); a chain from RSKj's regtest genesis has its five authorizers, three deciding, and its ten free Bridge senders (confirmed on RSKj's regtest); a member key of the one byte 00 is kept, as RSKj keeps it (confirmed on RSKj's regtest); a migration halves the balance with no floor and, under dust, fails inside the migration age and retires the federation past it (confirmed on RSKj's regtest); and it pays the active federation as stored, in its own format (confirmed on RSKj's regtest). Peg-outs: a signature is read as bitcoinj reads it with Spongy Castle 1.58, every element of it; a high s signs nothing; the input gets the DER bitcoinj writes (confirmed on RSKj's regtest). The confirmed peg-out taken is the first in the walk order of the set the call read (confirmed on RSKj's regtest). addSignature writes back the set it read (confirmed on RSKj's regtest), logs the member's key compressed (confirmed on RSKj's regtest), and fails where an input has no redeem script (no regtest reaches it: the Bridge builds every transaction it signs). The federations' UTXOs are written back where RSKj reads them: by the fee estimate and by a peg-in turned down (confirmed on RSKj's regtest). Before RSKIP-88, a call answered with null saves nothing, and the state getters write back what they read (no regtest reaches it: before the first upgrades).
42
Receipts with no intermediate state root
Matches RSKj.
46
Mining fees in the header
Matches RSKj.
50
A code header in front of a contract's code
Fixed: code of four bytes or more that starts with its header (0xfc) runs from byte 4 + code[3], its jump destinations found from there, as RSKj runs every program from genesis; rustock ran it from byte 0 and failed it at the 0xfc with all its gas. Anyone can deploy such code, so one transaction calling it would have split rustock from the chain. The test is built from RSKj's own VMTest cases.
59
Child contracts
Nothing for a node to implement, in either client.
107
The unitrie's smaller nodes, as stored and hashed
Fixed: a tree node with bytes after its long value's length is refused (no regtest reaches it: no client writes one; a peer could send one in a snapshot).
148
The ERC1820 registry
Nothing for a node to implement, in either client.
157
Cumulative difficulty in JSON-RPC
Matches RSKj (RPC only).
159
A minimal proxy contract
Nothing for a node to implement, in either client.
225
The emergency keys of the federation's time-locked script
How a transaction's own call to a precompile is charged
Fixed: before it, RSKj holds such a call to its limit by the precompile's price alone, and charges the price on top of the intrinsic cost, past the limit if it comes to that; rustock did so for the Bridge only. Three more fixes in the same path, which also takes the federation's free Bridge transactions: a transaction is held to what TransactionExecutor.init checks (the sender's nonce, a limit that pays the intrinsic cost, a balance that covers the value and the limit), and a block holding one that fails it is refused, as RSKj refuses it, so the upstream test test_bridge_tx_gas0_fails_for_unknown_sender now asserts the refusal; a byte of data costs 16 gas from RSKIP-400, not 68; and where a block runs as its sublists, REMASC is paid each fee once, not twice.
Orchid (mainnet #729,000, testnet #0)
RSKIP
What it makes a node do
What was found
85
REMASC holds back a reward under the minimum payable
Fixed: REMASC holds back a reward under the block's whole minimum gas price times its minimum payable gas; rustock stopped the price at 2^64 − 1 (confirmed on RSKj's regtest, at a price of 2^65).
87
The lock whitelist's unlimited mode
Matches RSKj.
88
The Bridge refusing calls from contracts, and how it ends a call it can't read
Matches RSKj; how the Bridge ends a call before it is under RSKIP-40.
89
The Bridge's Bitcoin block query methods
Matches RSKj.
90
A precompile's output as the caller's return data
Fixed: before it, a precompile that returns leaves the caller's return data as it was; rustock made the output the return data (no block of mainnet or testnet reaches it).
Fixed: before it, STATICCALL takes a value, as CALL does, with CALL's charge and stipend for it; rustock took no value (no block of mainnet or testnet reaches it).
Fixed: a derivation whose HMAC's left half equals the curve's order keeps its parent's point; rustock threw (no regtest reaches it: it needs such an HMAC output).
110
The fork-detection data in a merged-mining coinbase
Matches RSKj.
119
The BlockHeader precompile
Matches RSKj.
120
The shift opcodes
Matches RSKj.
122
The Bridge's getBtcTransactionConfirmations, its price included
Matches RSKj.
123
Federation members with several keys
Fixed: the new federation is written back after any successful call that read it (no regtest reaches it: before Wasabi, where RSKj's regtest cannot start).
124
The Bridge's receiveHeaders: its price, who may call it, a header's size
Matches RSKj.
125
CREATE2
Matches RSKj.
126
The state root a header carries, and how a block's roots are checked
Matches RSKj.
131
CREATE2 after SUICIDE in the same block
Fixed: a CREATE2 at an address deleted earlier in the same block fails, as RSKj refuses it; rustock let it succeed.
Fixed: before it, a call that asks for 2^63 − 2,300 gas or more and sends a value overflows a Java long, and the calling frame fails with all its gas; rustock saturated the sum (no block of mainnet or testnet reaches it).
Fixed: increaseLockingCap fails the call where the new cap times its multiplier passes a long; rustock saturated the product and went on (no authorizer has asked for such a cap).
137
The altBN128 precompiles, and their answer to a point off the curve before RSKIP-197
Matches RSKj.
140
EXTCODEHASH
Matches RSKj.
143
The Bridge's coinbase-information methods
Fixed: the witness root registered for a Bitcoin block is read only from it (no regtest reaches it: a coinbase is registered only from RSKIP-143).
146
The Bridge's events in Solidity's encoding
Fixed: the release request queue is written back, both its cells, after every method that read it (confirmed on RSKj's regtest); getStateForDebugging leaves out the entries of the other encoding (confirmed on RSKj's regtest).
151
SELFBALANCE
Matches RSKj.
152
CHAINID
Matches RSKj.
156
The difficulty's bound divisor, 400 from it except on regtest
Fixed: regtest keeps its divisor of 2,048 under it (confirmed on RSKj's regtest).
Fixed: before it, EXTCODEHASH of a contract whose empty code a creation of the same block saved answers keccak256 of nothing; rustock answered 0 (confirmed on RSKj's regtest).
170
Peg-ins to any address
Fixed: a peg-in with an output bitcoinj can't parse is refunded; rustock credited it (confirmed on RSKj's regtest).
171
The return buffer cleared by the call opcodes
Matches RSKj.
174
A creation keeps the balance at its address
Fixed: before it, a deployment that fails leaves the balance at its address as it was (confirmed on RSKj's regtest); local calls, traces and estimates apply it as a block's run does (confirmed on RSKj's regtest).
176
Flyover: peg-ins to a programmable address
Fixed: before RSKIP-293, a Flyover payment with an output that is no address answers GENERIC_ERROR; rustock answered -304, or registered it (confirmed on RSKj's regtest).
179
BTC-RSK timestamp linking
Matches RSKj.
181
Peg-in rejection events
Matches RSKj.
185
Peg-out refunds and events
Fixed: before it, a contract's releaseBtc fails the contract that made the call, with all its gas; rustock failed only the call (confirmed on RSKj's regtest).
186
The active federation's creation block height
Fixed: the getter answers the next federation's creation block once it is active, before updateCollections moves it (confirmed on RSKj's regtest).
191
DUPN, SWAPN and TXINDEX removed
Fixed: before it, RSK's own opcodes DUPN, SWAPN and TXINDEX run as RSKj runs them; rustock had none of them.
197
Precompile calls with CALL's semantics
Matches RSKj; its window with RSKIP-185 is under that one.
199
registerBtcTransaction open to anyone
Matches RSKj.
200
Limits on receiveHeaders
Matches RSKj.
201
The federation's time-locked emergency script
Fixed: below the peg-out index, a registration is sorted by running each input's script as bitcoinj does, signatures checked; rustock compared the hash of the redeem script an input carried (confirmed on RSKj's regtest).
218
A new fee address for the Core Developers Fund
Matches RSKj.
219
New minimum values for peg-ins and peg-outs
Matches RSKj.
220
A Bitcoin block or header by hash or height in the Bridge's methods
Fixed: a request must cover the fee of a peg-out sized by the active federation's format (confirmed on RSKj's regtest); a batch is halved while it is over 100,000 bytes (no regtest reaches it: it needs hundreds of peg-ins); a batched request with no hash fails the call (confirmed on RSKj's regtest); the next peg-out height is written back (confirmed on RSKj's regtest).
284
Flyover refund addresses read anew
Matches RSKj; how an address is read before it is the fix for testnet block #2,122,593, above.
290
Testnet's minimum difficulty
Matches RSKj; testnet's headers are held to it under Consensus, below.
293
getActivePowpegRedeemScript, and more Flyover checks
Matches RSKj; the Flyover check before it is under RSKIP-176.
294
At most so many inputs in a migration
Matches RSKj.
297
A wider Bitcoin-to-RSK timestamp gap on testnet
Matches RSKj.
Hop 4.0.1 (mainnet #4,976,300, testnet #3,362,200)
RSKIP
What it makes a node do
What was found
353
Redeem scripts held to Bitcoin Core's standard checks
Peg-outs waiting for signatures keyed by their creation transaction's hash
Fixed: a confirmed peg-out under a key the set waiting for signatures already holds, or under none, fails updateCollections; rustock replaced the entry, or used the update's own hash (confirmed on RSKj's regtest, both).
377
The last retired federation's standard P2SH script kept
Matches RSKj; how a registration is classified by its index is under Consensus, below, and two of the peg-in rules it brings are fixed with testnet block #4,513,687, above.
398
PUSH0
Matches RSKj.
400
Cheaper calldata
Matches RSKj; its price of data in a transaction's own call to a precompile is under RSKIP-136.
412
BASEFEE
Matches RSKj.
415
Pegnatories' addresses derived rightly from their keys
Matches RSKj.
417
A Bridge call from a contract that answers an error no longer reverts it
Matches RSKj.
Arrowhead 6.3.1 (mainnet #6,549,300, not on testnet)
The PowPeg's spendability validation protocol (SVP)
Fixed: createFederation answers -4 while a proposed federation awaits its validation (confirmed on RSKj's regtest); a call to sign the SVP spend transaction with a key of no proposed member fails, and one with a member's key in its hybrid form signs (confirmed on RSKj's regtest).
427
Peg-out events' amounts in wei
Matches RSKj.
428
A peg-out creation event with its UTXOs' values
Matches RSKj.
438
Initcode's size limit and its gas per word
Matches RSKj.
445
MCOPY
Matches RSKj.
446
Transient storage
Matches RSKj.
453
No account made by a failed CREATE or CREATE2
Matches RSKj.
454
Bitcoin chain work of up to 32 unsigned bytes
Fixed: before it, a checkpoint whose chain work is past 12 bytes is refused, as bitcoinj refuses to write it; rustock kept its low 12 bytes (no regtest reaches it: RSKj's regtest seeds no checkpoint).
459
Rejected peg-ins marked processed
Matches RSKj.
460
Non-standard outputs skipped in finding the witness commitment
Fixed: a segwit input is signed only over the value kept for it, and only from RSKIP-305; before it, or with none kept, the call fails; rustock signed over a value of 0 (confirmed on RSKj's regtest).
516
Addition and multiplication on secp256k1 as precompiles
Matches RSKj; its input cut is under Consensus, below.
Matches RSKj; REMASC's fees where a block runs as its sublists are under RSKIP-136.
351
A block's sublist gas limits and their header field
Matches RSKj.
502
The PowPeg and Union Bridge integration
Fixed: rustock made its seven Bridge methods callable on mainnet from #8,804,200, where RSKj has none of them, so one transaction calling one would have split rustock from the chain.
529
The Union Bridge's event methods
Matches RSKj.
536
The BlockHeader precompile's getCumulativeWork and getDifficultyWithUncles
The header's version 2, and the Union Bridge's base event it carries (testnet only)
Matches RSKj.
540
The Bridge's getEstimatedFeesForPegOutAmount
Matches RSKj.
544
New code that starts with 0xEF refused
Matches RSKj.
551
Where a rejected peg-in stops being marked as processed
Matches RSKj.
552
BLAKE2F's price for a call with no data
Matches RSKj.
tbd1000 (scheduled on no network)
RSKIP
What it makes a node do
What was found
559
Sorting the peg-outs
Matches RSKj.
Other rules
Where
What was found
The EVM
A 32-byte word with bits set above an address's 20 bytes names no precompile, for a call, EXTCODESIZE or EXTCODEHASH (confirmed on RSKj's regtest). Stored code that starts 0xEF01 is code like any other, not a pointer (confirmed on RSKj's regtest). A transaction from an address that holds code runs (no regtest reaches it: it needs a key for such an address). BLOCKHASH answers from the running block's own ancestors, so a block beside the chain reads its own branch (confirmed on RSKj's regtest).
Block 0 and the genesis file
Block 0 hashes over its difficulty as its file writes it, and a zero coinbase or gas limit as RSKj hashes them (confirmed on RSKj's regtest). A genesis file is read as RSKj reads it: a timestamp or gas limit over 8 bytes, or no minimum gas price, refused (confirmed on RSKj's regtest).
The Bridge
A free Bridge transaction's receipt keeps what its Bridge call logged before it threw (confirmed on RSKj's regtest).
The miner
A solved block a rule refuses is answered INVALID_BLOCK (confirmed on RSKj's regtest), and so is one the node fails to store (no regtest reaches it: a store fault). A solution of work whose parent is no longer the head is connected as any block (confirmed on RSKj's regtest). Uncles are picked by the rule a block meets on import, and a block it solves is held to every rule, its fork detection data included; a gas limit target under the minimum is the minimum; a timed miner started again right after a stop runs one thread; evm_increaseTime ignores zero or fewer seconds (no regtest reaches it: what a node mines is its own). And the miner has the settings of RSKj's it lacked, with RSKj's tests of them ported: the gas limit it aims for (targetgaslimit, 6,800,000 unless set and 7,500,000 on a regtest) and the switch that, off, steers by the gas the parent used (forcegaslimit); and a minimum gas price held stable in a currency (miner.stableGasPrice), fetched from a web API or from a contract.
Sync and relay
A node on a new database runs block 1 in follow mode as it arrives (confirmed on RSKj's regtest). A block a peer sends whole, timed no later than its parent, is not relayed. Snap sync holds its blocks to the rules RSKj's snap client runs. An old store's block 0 is written again (no regtest reaches it: what a node relays and keeps).
What this PR does
It brings rustock in line with RSKj rule by rule, held to RSKj's release VETIVER-9.0.4 and the bitcoinj-thin it builds with (0.14.4-rsk-18), and then replays both networks from their first block to show it. It reads 108 RSKIPs side by side with RSKj, with RSKj's own tests ported as the checklist, and fixes each one that differed (above). It also gives rustock RSKj's --import and the miner settings of RSKj's it lacked. It is 264 commits, each one change, on upstream's main (640dfb9, merged in).
Native contracts run as RSKj's NativeContract: one argument decoder, gas charged before the method runs, and a throw settled as RSKj settles it.
Transactions, headers, gas limits and minimum gas prices are read, hashed, kept and written as RSKj does, by each network's activation heights, including headers that arrive compressed.
Headers are held to RSKj's rules: uncles, trunk timestamps and proof of work, fork detection, merged mining below Orchid, fallback-mined blocks' signatures, RSKIP-290's testnet minimum difficulty, and Java int arithmetic where RSKj uses it.
The Bridge decodes arguments as RSKj's decoder does, validates peg-ins in its order, holds Bitcoin headers to bitcoinj-thin's rules, classifies registered transactions by the peg-out index from RSKIP-379 and by the legacy rules below it, and seeds the BTC store as ensureBtcBlockStore does.
Precompiles: ECRecover, ModExp, BLAKE2F and RSKIP-516's input cut run as RSKj runs them, and what a precompile writes outside revm's journal goes back with a frame that fails.
RSKj's regtest: its schedule, Bridge constants, genesis federation and free senders.
Where the network's rule is simply what RSKj's code does, rustock does the same: docs/quirks-frozen-bugs.md records the RSKj behaviours that mainnet's and testnet's blocks depend on, and docs/design-divergences.md the places where RSK departs from Ethereum on purpose, each with the RSKj code rustock follows.
Nothing a stranger sends can panic the node
Everything a stranger can send was tried against it. A panic in a peer's session now ends that session and drops the peer, and nothing else. A peer offering a snapshot can no longer make the node hang, abort or grow its memory without limit. An RPC method that panics answers with an error, where the connection used to drop. Fuzz tests cover every RSK and P2P message, headers of every version, transactions, receipts, RLP, Bitcoin blocks and partial merkle trees, trie nodes and RSKj's snapshot chunks, and every precompile.
Sync and snapshot sync
Snapshot sync: the work a peer can make the node do is bounded (the header walk, the sampler, the rate limiter), a refused claim and headers nobody asked for stay out of the chain, RSKj's chunks are placed in the trie, and a node that has executed nothing tries the snapshot again instead of falling back to ordinary sync.
Ordinary sync: every block gets its own total difficulty with its uncles, a block sent whole is weighed with the uncles it brings, new blocks are announced, relayed and served as RSKj does, and RSKj's peer.bannedMiners is honoured.
The pool takes or refuses a sent transaction as RSKj's does, and reckons its cost in whole numbers.
--import, as RSKj's
rustock --import starts a node from the state copies Rootstock publishes for RSKj's --import, as RSKj's co.rsk.db.importer does: it reads each trusted signer's index.json, takes the highest height that more than half of the keys, and at least two, list with the same hash, checks their signatures over it, downloads the copy and checks its SHA-256, and loads its blocks and state with every check RSKj's reader makes, in both of the copy's formats. Mainnet and testnet use RSKj's URL and keys; another network names its own with --import-url and --import-trusted-key.
Where it differs from RSKj, it refuses rather than overwrites, and checks more. A data directory that already holds a chain is refused, where RSKj deletes it. If one signer's copy can't be fetched or doesn't hash right, the next one's is tried. The copy's blocks must form one chain, match their bodies, and end at the signed height with that block's state root among its nodes. Below the copy's lowest block, the chain is recorded as a pruned database records what it has dropped, so nothing looks for those blocks.
Run from an empty data directory against Rootstock's server: 3 of 3 signatures on #9,414,000, the 735 MB copy downloaded in 155 s and loaded in 18.5 s, and the node then caught up with mainnet, 6,907 blocks, in 57 s, to a block that matches RSKj's public node. A second --import into the same directory is refused, and a restart without it resumes.
RPC
Answers as RSKj gives them: a block's fields as BlockResultDTO prints them, block parameters and call arguments as RSKj reads them, eth_gasPrice computed in doubles as RSKj computes it, the methods that sign, traces (REMASC's and the Bridge's transfers as CALL subtraces, and traces and estimates run through the chain's own execution loop), the methods RSKj stubs or refuses, and a transaction answered from the main chain only.
For light clients, which check every byte against a block hash they trust: rsk_getStorageNodes, which proves a storage slot absent as well as present; rsk_getStateNodes, the trie walks along any keys; rsk_getRawBlocks, blocks as RSKj sends them to its peers; and rsk_getBlockNumberByHash.
macOS and Windows
The node runs on a thread with an 8 MiB stack on every OS, flatdb locks and reserves its files on Windows, a thread's CPU time is measured on macOS and Windows too, the alerts build on Windows, and the external-IP lookup's tests listen where localhost resolves first, since Windows takes two seconds to refuse a connection. CI builds and runs the whole test suite on macOS and Windows as well as Linux.
Changes a user may notice (not consensus changes)
None of these changes the network's rules: they are about how the node is started and configured, what its RPC answers, and how its miner works.
--import is new, with --import-url and --import-trusted-key for a network other than mainnet and testnet. They are command-line only: a config file can't set them, since a file that turned --import on would refuse every start after the first.
A new data directory starts on the default --trie-backend single. Upstream's check against a trie that isn't there (0c83af7) runs after block 0's header is written and before its state is built, so it refused every new database but one --import filled; it now refuses an empty trie only where blocks have run.
--max-gas-limit and [chain] max_gas_limit are gone, with the bound they lifted. RSKj has no maximum gas limit, and rustock refused gas limits above 1,000,000,000 (10,000,000 on regtest), which a gas limit raised as fast as the rules allow passes in about 5,100 blocks. A node given the flag now stops on it, so perf-lab's seed flags, which pass u64::MAX, need to drop it.
eth_call, eth_estimateGas and eth_sendTransaction take RSKj's defaults: a gas price of 0 when none is given, and 90,000 gas for a sent transaction. rustock took the block's minimum gas price for a call, and the tracker's price and the head's whole gas limit for a sent transaction. With RSKj's defaults, the same request gets the same answer from both.
eth_call is held to RSKj's call gas cap, 10,000,000, not the block's gas limit.
--hardfork refuses a schedule rustock would run otherwise than RSKj: one that leaves an upgrade out below an upgrade it schedules, or puts upgrades out of their order, or moves hop401, bahamas or orchid060, which rustock reads at one height per network. RSKj reads each upgrade's rules at that upgrade's own height, and rustock reads them from the upgrade in force, so before this it ran such a schedule silently otherwise than RSKj. No network has one.
A merged-mining pool gets RSKj's answer to a solution. A solved block that a rule or its run refuses, or that the node fails to store, is answered OK with INVALID_BLOCK, its hash and its height, and one whose parent the node lacks with NO_PARENT, where rustock failed the submission with an error; a merged-mining proof that fails is still an error, as in RSKj. A solution of work whose parent is no longer the head is run beside the chain, stored, and answered IMPORTED_NOT_BEST, or IMPORTED_BEST where it takes the head, where rustock refused it and the block was lost.
A mining node steers its blocks' gas limit as RSKj's does, by at most a 1024th of the parent's per block: toward --mining-gas-limit-target (gas_limit_target under [mining]), RSKj's targetgaslimit, 6,800,000 unless set and 7,500,000 on a regtest; and with --mining-force-gas-limit false (force_gas_limit), RSKj's forcegaslimit off, by the gas the parent used. rustock's miner kept the parent's gas limit.
A mining node's minimum gas price steers toward --mining-min-gas-price, RSKj's miner.minGasPrice, 0 unless set, where rustock kept the parent's when it wasn't set. The config file's [mining.stable_gas_price], RSKj's miner.stableGasPrice with RSKj's settings, can hold it stable in a currency instead: a configured price over the price of a bitcoin, which a web API answers as JSON or a contract answers to a call on the node, with the fixed price standing in until one is had. It has no flag, as RSKj's has none.
An RPC method that panics answers -32603 "Internal server error", as RSKj answers an exception, where the connection used to drop. eth_call and eth_estimateGas, which run on a blocking thread, keep upstream's -32603 "call failed".
RSKj's own tests of the network's rules pass on rustock, every block of mainnet and testnet matches RSKj, and rustock handles forks and orphan blocks as RSKj does. It is also faster than RSKj on every measure we took. All of it is held to RSKj's release
VETIVER-9.0.4and the bitcoinj-thin it builds with (0.14.4-rsk-18).RSKj's tests pass
RSKj's tests that name one of the network's rules or upgrades, 1,239 of them, were each read, and each has its verdict in
docs/rskj-tests/:master, not in its releaseSo every one that applies to rustock passes: 1,144 of 1,144. The 248 tests of RSKj's validators, miner and transaction pool are held the same way, with none left a gap (
docs/rskj-test-parity.md).Every block matches RSKj
As
CLAUDE.mdasks of a consensus change, this was checked against the chain, not reasoned about. Every block of both networks was replayed: mainnet from genesis to #9,420,342 and testnet from genesis to #8,306,564. Every block matched what its header records, its state root included wherever the header holds the unitrie's (all of testnet, and mainnet from #1,591,000), and each block the run ended on matches RSKj's public node, its hash and its state root. No block was refused, no node halted, and no node logged an error. The build was this PR's but for its last ten commits and upstream's newestmain, merged in since. The ten change only what a mining node builds and answers (the gas limit and the minimum gas price it aims for, its answers to a pool, its timed miner and its development clock,evm_increaseTime) and a check at start-up, or add only documents and tests; upstream's brings the external-IP lookup, Docker files, a newerlibz-sysand a section ofCLAUDE.md. None of it changes how a node checks or runs a block it receives.Five testnet blocks that rustock got wrong now replay to their headers' state and receipts roots. Each was a network rule, and each is fixed with a test that fails without it:
0xc4and the Bridge answers its generic errorupdateCollectionsends with nothing storedrejected_pegin, thenunrefundable_pegin); two more of RSKj's peg-in rules from RSKIP-379 on are fixed with itFaster than RSKj
rustock with this PR (at
8a00981), against RSKjVETIVER-9.0.4, on the same machine and the same mainnet blocks, all measured on 17 November:--import²In every run, every block matched its header's state root on both clients.
¹ From the moment each node had Rootstock's copy of mainnet #9,414,000 loaded (the end of each one's
--import) to running block #9,420,907, the newest block when rustock had caught up, fetching the blocks from mainnet peers. RSKj took 18 min 0 s, rustock 57 s. Most of the gap is in fetching: rustock had all 6,907 blocks 46 s after its load, from up to 14 peers with up to 176 bodies in flight, while RSKj took in about 4.4 blocks a second for its first 14 minutes.² The copy at mainnet #9,414,000, which all three signers list with the same hash (both clients trust the same three): 4,000 blocks, 781,768 long values and 10,683,761 state nodes. Both clients read the signers' lists, check their signatures and the file's SHA-256, and load it; the times are the load alone, after the download. RSKj's 59.9 s is by its own log, from after it unzipped the file; rustock's 18.5 s include unzipping it.
³ #9,405,001 to #9,412,300 (7,300 blocks), re-run from each client's own database with every state root checked against its header, and a cache of a million trie nodes in front of each (RSKj's default
cache.states.max-elements): rustock withreplay_bench(crates/cli/examples), RSKj with its ownExecuteBlockstool. Four runs each, alternating, each client twice in a row, after a first pass that brought both databases into memory. Time is the average re-run: rustock's leaves out opening its store, and RSKj's leaves out the 0.9 s its tool takes for a single block. CPU is the whole process's, user and system. Memory is the highest peak resident set of each client's four runs.⁴ The same stretch as ¹, from each node's log: for rustock, the time it spent executing and storing the blocks (26.3 s for 6,907); for RSKj, the time inside
tryToConnect, which also validates them (42.2 s for 6,907).Forks and orphan blocks, as RSKj handles them
Every block is executed as it arrives, against its own parent's state, beside the chain when it isn't on it. A heavier branch becomes the best only once this node has executed it, and switching to it re-points the chain and runs nothing again. An orphan block, one whose parent this node lacks, has the missing blocks asked of the peer that sent it, as RSKj asks, and its branch is executed as they come. A branch none of whose bodies arrive within 60 s is given up, so withholding bodies can't hold the node back. Before, a heavier branch known only by its headers took the head and pulled execution back to the fork point, where the miner built and every query was answered until its bodies came and it was re-run.
On a tie in total difficulty, the block store and the miner apply RSKj's
SelectionRule(fees, then the lower hash), so a miner on rustock builds on the same block as RSKj's miners.At the mainnet tip for four hours, as competing blocks met, the node ran 808 blocks beside the chain and switched to a heavier branch 333 times, running nothing again, and at each of 25 checks it was level with RSKj's public node.
See
docs/follow-mode-rskj-vs-rustock.md§8, and §99 and §100 ofdocs/design-divergences.md, which records RSK's rules where they differ from Ethereum's.Parity with RSKj, RSKIP by RSKIP
The 108 RSKIPs below were each read side by side in RSKj's release
VETIVER-9.0.4and in rustock, each under the upgrade that brings it: the code of each in both clients, with RSKj's own tests of it as the checklist. So was each statement rsk.zone makes about what a node does: merge mining, the PowPeg, REMASC, the EVM and its precompiles, the state tree, the chain IDs. Where rustock did otherwise than RSKj it now does as RSKj does, and each fix comes with a test that fails without it: 74 match RSKj, some of them through this PR's other fixes; 30 had differences, all fixed; and 4 have nothing for a node to implement. Where a row says so, RSKj confirmed the fix on its own regtest: a case builds blocks on RSKj's release, the replay's build imports them with every state root checked against its header and agrees, and a build from before the fix parts from RSKj where the fix says it would.Every other RSKIP rsk.zone lists was read against RSKj as well, and each statement it makes about what a node does holds of rustock as it holds of RSKj.
Before any upgrade (from block 0)
receiveHeadersfails for a header that counts its transactions below zero (no regtest reaches it: before the first upgrades, where RSKj's regtest cannot start); a Bitcoin block looked up by hash is read from the Bridge's storage alone, not from a node-wide cache that keeps other chains' blocks (confirmed on RSKj's regtest). The federation: with no federation pending, a vote to add a member whose key is no point answers -10 (confirmed on RSKj's regtest); a chain from RSKj's regtest genesis has its five authorizers, three deciding, and its ten free Bridge senders (confirmed on RSKj's regtest); a member key of the one byte00is kept, as RSKj keeps it (confirmed on RSKj's regtest); a migration halves the balance with no floor and, under dust, fails inside the migration age and retires the federation past it (confirmed on RSKj's regtest); and it pays the active federation as stored, in its own format (confirmed on RSKj's regtest). Peg-outs: a signature is read as bitcoinj reads it with Spongy Castle 1.58, every element of it; a high s signs nothing; the input gets the DER bitcoinj writes (confirmed on RSKj's regtest). The confirmed peg-out taken is the first in the walk order of the set the call read (confirmed on RSKj's regtest).addSignaturewrites back the set it read (confirmed on RSKj's regtest), logs the member's key compressed (confirmed on RSKj's regtest), and fails where an input has no redeem script (no regtest reaches it: the Bridge builds every transaction it signs). The federations' UTXOs are written back where RSKj reads them: by the fee estimate and by a peg-in turned down (confirmed on RSKj's regtest). Before RSKIP-88, a call answered with null saves nothing, and the state getters write back what they read (no regtest reaches it: before the first upgrades).VMTestcases.Bahamas (mainnet #3,397, testnet #0)
TransactionExecutor.initchecks (the sender's nonce, a limit that pays the intrinsic cost, a balance that covers the value and the limit), and a block holding one that fails it is refused, as RSKj refuses it, so the upstream testtest_bridge_tx_gas0_fails_for_unknown_sendernow asserts the refusal; a byte of data costs 16 gas from RSKIP-400, not 68; and where a block runs as its sublists, REMASC is paid each fee once, not twice.Orchid (mainnet #729,000, testnet #0)
Orchid 0.6.0 (mainnet #1,052,700, testnet #0)
Wasabi (mainnet #1,591,000, testnet #0)
getBtcTransactionConfirmations, its price includedreceiveHeaders: its price, who may call it, a header's sizereceiveHeadersTwoToThree (mainnet #2,018,000, testnet #504,000)
long, and the calling frame fails with all its gas; rustock saturated the sum (no block of mainnet or testnet reaches it).Papyrus (mainnet #2,392,700, testnet #863,000)
increaseLockingCapfails the call where the new cap times its multiplier passes along; rustock saturated the product and went on (no authorizer has asked for such a cap).getStateForDebuggingleaves out the entries of the other encoding (confirmed on RSKj's regtest).Iris (mainnet #3,614,800, testnet #2,060,500)
releaseBtcfails the contract that made the call, with all its gas; rustock failed only the call (confirmed on RSKj's regtest).updateCollectionsmoves it (confirmed on RSKj's regtest).registerBtcTransactionopen to anyonereceiveHeadersHop (mainnet #4,598,500, testnet #3,103,000)
getActivePowpegRedeemScript, and more Flyover checksHop 4.0.1 (mainnet #4,976,300, testnet #3,362,200)
Fingerroot (mainnet #5,468,000, testnet #4,015,800)
updateCollections; rustock replaced the entry, or used the update's own hash (confirmed on RSKj's regtest, both).getEstimatedFeesForNextPegOutEventimprovedArrowhead (mainnet #6,223,700, testnet #4,927,100)
getCallStackDepthprecompile methodArrowhead 6.3.1 (mainnet #6,549,300, not on testnet)
Lovell (mainnet #7,338,024, testnet #6,110,487)
createFederationanswers -4 while a proposed federation awaits its validation (confirmed on RSKj's regtest); a call to sign the SVP spend transaction with a key of no proposed member fails, and one with a member's key in its hybrid form signs (confirmed on RSKj's regtest).Reed (mainnet #8,052,200, testnet #6,835,700)
Reed 8.1.0 (testnet #7,139,600, not on mainnet)
getCumulativeWorkandgetDifficultyWithUnclesVetiver (mainnet #8,804,200, testnet #7,604,200)
getEstimatedFeesForPegOutAmounttbd1000(scheduled on no network)Other rules
0xEF01is code like any other, not a pointer (confirmed on RSKj's regtest). A transaction from an address that holds code runs (no regtest reaches it: it needs a key for such an address). BLOCKHASH answers from the running block's own ancestors, so a block beside the chain reads its own branch (confirmed on RSKj's regtest).INVALID_BLOCK(confirmed on RSKj's regtest), and so is one the node fails to store (no regtest reaches it: a store fault). A solution of work whose parent is no longer the head is connected as any block (confirmed on RSKj's regtest). Uncles are picked by the rule a block meets on import, and a block it solves is held to every rule, its fork detection data included; a gas limit target under the minimum is the minimum; a timed miner started again right after a stop runs one thread;evm_increaseTimeignores zero or fewer seconds (no regtest reaches it: what a node mines is its own). And the miner has the settings of RSKj's it lacked, with RSKj's tests of them ported: the gas limit it aims for (targetgaslimit, 6,800,000 unless set and 7,500,000 on a regtest) and the switch that, off, steers by the gas the parent used (forcegaslimit); and a minimum gas price held stable in a currency (miner.stableGasPrice), fetched from a web API or from a contract.What this PR does
It brings rustock in line with RSKj rule by rule, held to RSKj's release
VETIVER-9.0.4and the bitcoinj-thin it builds with (0.14.4-rsk-18), and then replays both networks from their first block to show it. It reads 108 RSKIPs side by side with RSKj, with RSKj's own tests ported as the checklist, and fixes each one that differed (above). It also gives rustock RSKj's--importand the miner settings of RSKj's it lacked. It is 264 commits, each one change, on upstream'smain(640dfb9, merged in).Closes #149.
Consensus
NativeContract: one argument decoder, gas charged before the method runs, and a throw settled as RSKj settles it.intarithmetic where RSKj uses it.ensureBtcBlockStoredoes.Where the network's rule is simply what RSKj's code does, rustock does the same:
docs/quirks-frozen-bugs.mdrecords the RSKj behaviours that mainnet's and testnet's blocks depend on, anddocs/design-divergences.mdthe places where RSK departs from Ethereum on purpose, each with the RSKj code rustock follows.Nothing a stranger sends can panic the node
Everything a stranger can send was tried against it. A panic in a peer's session now ends that session and drops the peer, and nothing else. A peer offering a snapshot can no longer make the node hang, abort or grow its memory without limit. An RPC method that panics answers with an error, where the connection used to drop. Fuzz tests cover every RSK and P2P message, headers of every version, transactions, receipts, RLP, Bitcoin blocks and partial merkle trees, trie nodes and RSKj's snapshot chunks, and every precompile.
Sync and snapshot sync
peer.bannedMinersis honoured.--import, as RSKj'srustock --importstarts a node from the state copies Rootstock publishes for RSKj's--import, as RSKj'sco.rsk.db.importerdoes: it reads each trusted signer'sindex.json, takes the highest height that more than half of the keys, and at least two, list with the same hash, checks their signatures over it, downloads the copy and checks its SHA-256, and loads its blocks and state with every check RSKj's reader makes, in both of the copy's formats. Mainnet and testnet use RSKj's URL and keys; another network names its own with--import-urland--import-trusted-key.Where it differs from RSKj, it refuses rather than overwrites, and checks more. A data directory that already holds a chain is refused, where RSKj deletes it. If one signer's copy can't be fetched or doesn't hash right, the next one's is tried. The copy's blocks must form one chain, match their bodies, and end at the signed height with that block's state root among its nodes. Below the copy's lowest block, the chain is recorded as a pruned database records what it has dropped, so nothing looks for those blocks.
Run from an empty data directory against Rootstock's server: 3 of 3 signatures on #9,414,000, the 735 MB copy downloaded in 155 s and loaded in 18.5 s, and the node then caught up with mainnet, 6,907 blocks, in 57 s, to a block that matches RSKj's public node. A second
--importinto the same directory is refused, and a restart without it resumes.RPC
Answers as RSKj gives them: a block's fields as
BlockResultDTOprints them, block parameters and call arguments as RSKj reads them,eth_gasPricecomputed in doubles as RSKj computes it, the methods that sign, traces (REMASC's and the Bridge's transfers as CALL subtraces, and traces and estimates run through the chain's own execution loop), the methods RSKj stubs or refuses, and a transaction answered from the main chain only.For light clients, which check every byte against a block hash they trust:
rsk_getStorageNodes, which proves a storage slot absent as well as present;rsk_getStateNodes, the trie walks along any keys;rsk_getRawBlocks, blocks as RSKj sends them to its peers; andrsk_getBlockNumberByHash.macOS and Windows
The node runs on a thread with an 8 MiB stack on every OS, flatdb locks and reserves its files on Windows, a thread's CPU time is measured on macOS and Windows too, the alerts build on Windows, and the external-IP lookup's tests listen where
localhostresolves first, since Windows takes two seconds to refuse a connection. CI builds and runs the whole test suite on macOS and Windows as well as Linux.Changes a user may notice (not consensus changes)
None of these changes the network's rules: they are about how the node is started and configured, what its RPC answers, and how its miner works.
--importis new, with--import-urland--import-trusted-keyfor a network other than mainnet and testnet. They are command-line only: a config file can't set them, since a file that turned--importon would refuse every start after the first.--trie-backend single. Upstream's check against a trie that isn't there (0c83af7) runs after block 0's header is written and before its state is built, so it refused every new database but one--importfilled; it now refuses an empty trie only where blocks have run.--max-gas-limitand[chain] max_gas_limitare gone, with the bound they lifted. RSKj has no maximum gas limit, and rustock refused gas limits above 1,000,000,000 (10,000,000 on regtest), which a gas limit raised as fast as the rules allow passes in about 5,100 blocks. A node given the flag now stops on it, so perf-lab's seed flags, which passu64::MAX, need to drop it.eth_call,eth_estimateGasandeth_sendTransactiontake RSKj's defaults: a gas price of 0 when none is given, and 90,000 gas for a sent transaction. rustock took the block's minimum gas price for a call, and the tracker's price and the head's whole gas limit for a sent transaction. With RSKj's defaults, the same request gets the same answer from both.eth_callis held to RSKj's call gas cap, 10,000,000, not the block's gas limit.--hardforkrefuses a schedule rustock would run otherwise than RSKj: one that leaves an upgrade out below an upgrade it schedules, or puts upgrades out of their order, or moveshop401,bahamasororchid060, which rustock reads at one height per network. RSKj reads each upgrade's rules at that upgrade's own height, and rustock reads them from the upgrade in force, so before this it ran such a schedule silently otherwise than RSKj. No network has one.INVALID_BLOCK, its hash and its height, and one whose parent the node lacks withNO_PARENT, where rustock failed the submission with an error; a merged-mining proof that fails is still an error, as in RSKj. A solution of work whose parent is no longer the head is run beside the chain, stored, and answeredIMPORTED_NOT_BEST, orIMPORTED_BESTwhere it takes the head, where rustock refused it and the block was lost.--mining-gas-limit-target(gas_limit_targetunder[mining]), RSKj'stargetgaslimit, 6,800,000 unless set and 7,500,000 on a regtest; and with--mining-force-gas-limit false(force_gas_limit), RSKj'sforcegaslimitoff, by the gas the parent used. rustock's miner kept the parent's gas limit.--mining-min-gas-price, RSKj'sminer.minGasPrice, 0 unless set, where rustock kept the parent's when it wasn't set. The config file's[mining.stable_gas_price], RSKj'sminer.stableGasPricewith RSKj's settings, can hold it stable in a currency instead: a configured price over the price of a bitcoin, which a web API answers as JSON or a contract answers to a call on the node, with the fixed price standing in until one is had. It has no flag, as RSKj's has none.eth_callandeth_estimateGas, which run on a blocking thread, keep upstream's -32603 "call failed".For the code owners
CLAUDE.md: