[fix] detect vault.SubFunds clamping on outbound observation

Depends-On: !4800 (merged) (EVM solvency consensus). Without !4800, halts triggered here have no auto-unhalt path and require manual operator intervention via STOPSOLVENCYCHECKETH mimir.

Problem

When an outbound observation debits a vault, vault.SubFunds calls common.SafeSub (in x/thorchain/types/type_vault.go:243) which silently clamps to zero when the recorded balance is below the requested debit. The L1 actually sent the full amount, but TC's ledger then carries phantom credit equal to the missed delta, with no event emitted to flag the divergence.

This is what happened to retiring vaults vtxv (~152.63 ETH) and pysp (~117.80 ETH) in the May 2026 incident. The solvency check could not catch it because the EVM solvency consensus bug prevented MsgSolvency from reaching quorum (now fixed in !4800), but the underlying clamp itself remains silent and would catch future incidents only via the downstream solvency path.

Fix

Surface the clamp at its source — handleObservedTxOutQuorum, just before each vault.SubFunds call (both the slashed-vault gas debit and the main coin debit):

  • Emit an EventSecurity carrying vault, asset, requested, available, missed, and the L1 tx id, so operators can correlate against on-chain logs.
  • Set SolvencyHalt<Chain>Chain to the current block height, mirroring the mimir shape processSolvencyAttestation uses (so SolvencyCheckRunner auto-unhalts once a subsequent solvent attestation arrives — same operator workflow as today).
  • Preserve the existing vault.SubFunds clamp behaviour (don't change the on-chain state outcome, only add visibility + halt).

The helper takes the coins-to-debit explicitly so both call sites (gas debit when vaultSlash, and the main coin debit) are covered.

Why not fix vault.SubFunds directly

Changing the clamp itself would alter consensus state outcomes — handled in a separate, larger MR with proper scheduling-side reservation logic + a Vault.Deficit field that auto-settles from future credits. This MR keeps the same state semantics and only ensures the bug is no longer invisible.

Reproduction

Confirmed on mainnet against a local archive node:

  • vtxv clamp: tx 0x95dbc7251853826df43b914755abbf26715d9d9cc1ee36f17a34bfd14baa92dc at THOR consensus_height 25,864,952 — observed 169.230658 ETH, vault had 16.601087 ETH, missed = 152.629571 ETH.
  • pysp clamps: txs 0xd7b648ca... (REFUND, 43.93 ETH missed) and 0xdc8bd8d3... (OUT, ~73.87 ETH missed).

A network-wide scan across all 5 active asgard vaults found zero clamping events, so the active set is currently clean — but a recurrence in any high-traffic period would be silent until this lands.

Tests

  • TestDetectVaultSubFundsClampHalts — vault with 10 ETH, observed outbound of 100 ETH → asserts SolvencyHaltETHChain is set to current block height.
  • TestDetectVaultSubFundsClampNoOpWhenSolvent — vault with 100 ETH, observed outbound of 50 ETH → asserts mimir remains unset (happy path).
  • TestDetectVaultSubFundsClampHaltsOnGasDebit — vault with 100 wei of ETH, observed gas of 1 ETH → asserts halt fires on the gas-debit path.
  • !4800 — fixes EVM solvency consensus non-determinism (so the solvency check can actually fire). This MR + that one together restore full insolvency detection on EVM chains.
  • Store migration to reconcile the existing 270 ETH of phantom credit on vtxv/pysp is a separate MR.
  • Underlying scheduling-side fix to prevent over-commitment + Vault.Deficit auto-settlement is a 3.19.0 follow-up.
Edited by Itzamna

Merge request reports

Loading
Loading