Repository navigation
Description
RSK contracts may carry a code header: a first byte of 0xfc, then three bytes, the third giving how many more follow. Execution and jumpdest analysis both start after it. It was intended for selecting a VM version, it is honoured by every program rskj builds under no activation rule (Program.processAndSkipCodeHeader), and rustock mirrors it in skip_code_header.
The open question is whether any contract was ever deployed with one.
What is already known
opcode_census (added in #TBD) walked the state at #3,614,799 — 9,130 contracts, 24 MB of code, 2.94M trie nodes, no unresolved references — and found:
- no contract alive at that block carries a header, and
- no contract alive there can reach
DUPN(0xa8),SWAPN(0xa9) orTXINDEX(0xaa), the three opcodes RSKIP191 removed at iris300.
Also worth recording: rskj's VM.checkOpcode has the per-opcode gate the header exists for —
if (op.scriptVersion() > program.getScriptVersion()) {
throw Program.ExceptionHelper.invalidOpCode(program);
}— but of 145 opcode declarations in OpCode.java, not one uses the 5-argument constructor that sets a non-zero scriptVersion. The test is always 0 > N, so the gate can never fire. The header currently decides nothing in either client, which is why rustock's not implementing that gate is not a divergence.
What is not known, and why the census cannot answer it
A state at one block holds the code of contracts alive at that block. It cannot hold:
- a contract created and
SELFDESTRUCTed earlier, and - anything about blocks after the one scanned.
So two gaps remain: the whole chain above #3,614,799, and destroyed contracts anywhere.
Proposed work, cheapest first
1. Census the tip. Run opcode_census against the highest state an archive can serve — #9,238,111 for /mnt/import/rustock-trie, which archive_bound confirms. One walk, order of 20–30 minutes, and it covers every contract that survives today across all of history rather than just the pre-iris300 era. This is the large majority of the question for a small cost and needs no new code.
2. Count creations during a replay. rsk_instructions::record_contract_created now counts every creation that keeps its code and logs any that carries a header, called from rsk_return_create — the point at which a contract exists with that code, so it sees destroyed contracts too. reexec_all prints the totals beside its verdict.
The scoped run already prepared for the pre-iris300 era (#1..#3,620,064, 29 segments, ~4.5–8 h depending on the memory budget) therefore returns a partial answer for free: every contract deployed below iris300, headered or not.
3. The full chain. Extending (2) to all 9.4M blocks is the exact answer. Measured at 12.8 h on two threads with the whole segment set resident one segment at a time (docs/reexecution-rustock-vs-rskj.md §7). Worth doing only if (1) and (2) leave something open, or alongside the next whole-chain certification run rather than as its own job.
Residue even after all three
Code a contract computes at runtime and then destroys — a metamorphic contract — is invisible to (1) and is only caught by (2)/(3) because those observe the deployment itself. After (3) over the whole chain there is no residue: every contract that ever existed was created by some executed transaction.
Why it is worth knowing
Two reasons, neither urgent:
- It decides whether the header is dead weight in both clients. If nothing ever used it, the consensus rules around it are untestable against the chain and can only be checked against rskj's own test vectors — which is what
a_code_header_is_skipped_as_rskj_skips_itdoes today. - A headered contract would be the only place where
exeVersion/scriptVersionhave ever been non-zero on mainnet, which is the one piece of evidence about what the mechanism was actually for.
Activity