Repository navigation
Description
Migrated from SergioDemianLerner/rustock#295 (issue by @SDL-A1, 2026-10-12).
Original: SergioDemianLerner/rustock#295
Follow-up to the partial fix that made testnet #808,484 execute.
rskj
Program.callToPrecompiledAddress chooses between two implementations:
if (getActivations().isActive(ConsensusRule.RSKIP197)) {
executePrecompiledAndHandleError(contract, msg, requiredGas, track, data);
} else {
executePrecompiled(contract, msg, requiredGas, track, data);
}The older one has no error handling at all — the comment above it says so:
/**
* This is for compatibility before RSKIP197, no error handling was implemented
* when calling to precompiled contracts.
*/
@Deprecated
private void executePrecompiled(...) {
try {
this.refundGas(msg.getGas().longValue() - requiredGas, CALL_PRECOMPILED_CAUSE);
byte[] out = contract.execute(data);
...
} catch (VMException e) {
throw new RuntimeException(e);
}
}That RuntimeException escapes the VM entirely. TransactionExecutor.go()
catches it as a runtime failure, so the transaction is charged its whole gas
limit no matter how much the caller still held. RSKIP197 is iris300 —
mainnet #3,614,800, testnet #2,060,500 — so every block below those is
affected.
What rustock does now
The throw is modelled as a non-revert precompile error that spends the entire
forwarded gas. That reproduces rskj exactly when the caller forwarded
everything, because the caller then runs out too — which is the common case,
and the case at #808,484 (gasUsed 1000000, both roots matching).
It does not reproduce it when the caller caps what it forwards.
a_capped_forward_still_survives_the_pre_rskip197_throw pins the gap: a
contract doing call{gas: 50000} into a throwing Bridge method uses 96,733
where rskj charges the full 1,000,000.
Why it was left
There is no clean propagation channel in revm for "abort the whole
transaction" from inside a frame. InstructionResult::FatalExternalError
panics if it reaches insert_call_outcome or post_execution — it is
reserved for the database layer.
Shape of the fix
Return Err from the precompile provider, which revm surfaces as an EVM error
aborting handler.run(), and have the executor recognise it:
- Checkpoint the journal per transaction, so the aborted transaction's state
can be dropped — the free-bridge path already does this
(journal_mut().checkpoint()/checkpoint_commit()). - Intercept the marker before
out.map_err(|e| ExecutionError::Evm(...))?
and build a failedTxExecutionResultwithgas_used = tx.gas_limit, no
logs, state rolled back.
Needs care: it changes control flow in the hot path, so it wants the existing
mainnet replay fixtures run against it before merging.
Reachability
Any contract calling a precompile that throws, with a capped gas forward,
below iris300. The Bridge throws on an unknown or disabled selector
(post-RSKIP88) and on validateCall failures, so this is reachable by
ordinary contract code, not just malformed calls.
Activity
native contracts run as rskj's NativeContract; a throw in a transacti…
execution: a precompile that throws before RSKIP197 fails its caller,…