Repository navigation
Description
Migrated from SergioDemianLerner/rustock#47 (issue by @SDL-A1, 2026-09-22).
Original: SergioDemianLerner/rustock#47
Applies to testnet only. Mainnet is unaffected and cannot be affected again.
From the consensus audit triage (docs/audit-triage-medium-low.md, Group 2 — findings FRCR-274 and FRCR-275, both rated LOW there because the RSKIPs were never adopted; rskj shipped the opcodes anyway).
rskj implements three opcodes rustock does not:
| opcode | rskj | gas | live on testnet | live on mainnet |
|---|---|---|---|---|
DUPN |
OpCode.DUPN(0xa8, 2, 1, VERY_LOW_TIER), VM.doDUPN |
3 | genesis → #2,060,499 | genesis → #3,614,799 |
SWAPN |
OpCode.SWAPN(0xa9, 3, 2, VERY_LOW_TIER), VM.doSWAPN |
3 | genesis → #2,060,499 | genesis → #3,614,799 |
TXINDEX |
OpCode.TXINDEX(0xaa, 0, 1, BASE_TIER), VM.doTXINDEX |
2 | genesis → #2,060,499 | genesis → #3,614,799 |
RSKIP191 (iris300) disables all three: from that height rskj throws invalidOpCode, which is what rustock already does at every height. So the gap is confined to blocks below iris300, which is #2,060,500 on testnet and #3,614,800 on mainnet.
Why mainnet needs nothing
The window is permanently closed there, and it was never entered. rustock's processor.rs validates gas_used, paid_fees, the transactions root, the receipts root and the logs bloom on every block from genesis (the state root only from #1,591,000). Executing an unimplemented opcode halts the frame and consumes its gas, which would move gas_used and the receipts root. The 2026-09-16 replay of all 9,230,008 mainnet blocks passed, so no mainnet block ever executed one.
Testnet has never been replayed, so the equivalent evidence does not exist for it.
Semantics to reproduce
Taken from VM.java. Two details are easy to miss:
DUPN (0xa8) — doDUPN:
spendOpCodeGas();
program.step(); // (1)
int n = stack.pop().intValueCheck() + 1;
program.verifyStackSize(n);
program.verifyStackOverflow(n, n + 1);
DataWord word1 = stack.get(stack.size() - n);
program.stackPush(word1);
program.step(); // (2)SWAPN (0xa9) — doSWAPN:
spendOpCodeGas();
program.step(); // (1)
int n = stack.pop().intValueCheck() + 2;
program.verifyStackSize(n);
program.verifyStackOverflow(n, n);
stack.swap(stack.size() - 1, stack.size() - n);
program.step(); // (2)TXINDEX (0xaa) — doTXINDEX: push program.getTransactionIndex(), one step().
DUPNandSWAPNcallprogram.step()twice.Program.step()issetPC(pc + 1), so the PC advances by 2 and the byte after the opcode is skipped, even though neither takes an immediate operand. ComparedoDUP/doSWAP, which step once. This looks like a leftover from an immediate-operand design, and it has to be reproduced exactly.- The operand count comes off the stack, and
intValueCheck()throws if the popped word does not fit in a Javaint.
Suggested implementation
Same pattern as the other RSK-specific opcodes in crates/execution/src/rsk_instructions.rs — rsk_push0 (RSKIP398) and the RSKIP91 STATICCALL gate added in #43 are the closest models. Install the three unchecked from genesis and replace them with invalid_opcode from iris300, gated on a has_rskip191-style helper keyed off RskNetworkUpgrade::Iris300 so the height is per-chain.
Acceptance
- Unit tests pinning the gas tiers (3 / 3 / 2) and the PC-advances-by-2 quirk.
- An activation test asserting the opcodes are valid one block before iris300 and invalid at it, on both chain configs.
- Ideally, a testnet replay over a pre-iris300 range. That is the only evidence that actually settles it, and it does not exist for testnet today.
🤖 Generated with Claude Code
Activity