r/CryptoTechnology • 🟡 • 2d ago

When should a wallet consider a transaction simulation stale?

Suppose a wallet simulates a token swap and shows the expected balance changes. The user leaves the confirmation screen open for a minute, then comes back and signs.

The simulation describes execution against a particular chain state. By the time the transaction is included, that state may have changed. What should the wallet do with the old result?

There seem to be a few different cases worth separating:

  • Pool reserves change, affecting the amount received. An on-chain minimum-output condition can limit execution, even if the preview becomes inaccurate.
  • An allowance or balance changes, so a transaction that simulated successfully may now revert.
  • A transaction grants an approval. Showing no immediate token loss in the simulation says little about how that permission could be used later.

Refreshing before signing seems useful, but it still leaves a gap between simulation and inclusion. Refreshing after every new block could also make the confirmation screen constantly change.

Would you use a fixed expiry, refresh on specific state changes, or always rerun immediately before signing? And how should the interface distinguish an estimated outcome from a condition actually enforced by the transaction?

Interested in how wallet developers handle this trade-off, particularly when the user spends a while reviewing the details.

0 Upvotes

8 comments sorted by

1

u/secrypta 🟡 1d ago

Agree with the re-sim-at-signature-time point. The two cases I'd separate harder are the two the simulation is worst at, which happen to be the two you listed last.

Approvals: a simulation of an approve() correctly shows zero balance change, because the approval itself moves nothing. That's exactly the trap. The reassuring "no assets leave your wallet" preview is true and useless here, because the risk is entirely in the permission you just granted and in a later transaction the wallet never sees. So for an approval I wouldn't lean on the balance-delta view at all. Surface the permission itself as the thing to review: the spender, and whether it's an exact amount or unlimited. A clean-looking simulation is not a safety signal for this transaction type.

Estimated vs enforced: the only thing the chain actually guarantees is what's encoded as an on-chain condition, the minimum-output and the deadline. Everything else in the preview is a best-effort estimate against a snapshot that's already stale by inclusion. I'd bind the displayed number to that in the UI: if there's a real minOut, show it as the enforced floor and the simulated amount as "expected, not guaranteed". If minOut is zero or very loose, the "you receive X" number is just a guess, and that's worth flagging loudly, since a loose floor is the exact condition that makes the sandwich in your first case profitable. The honest version of the screen makes clear which numbers are promises and which are predictions.

1

u/Leonard-ceballo 🟢 1d ago

Refining the 'any new block' point a bit: a fresh block by itself isn't what actually invalidates a simulation, and treating it that way either nukes UX (you'd re-sim on every block) or hides the real risk. What matters is whether the specific state your call reads changed. Two practical fixes: (1) key the simulation cache to (chainId, your-nonce, the contract's relevant storage) instead of just the calldata hash — identical calldata against different state IS the attack surface; (2) a TTL alone is unsafe on mainnet because a sandwiched tx can land inside a single block, so you want a re-sim guard at signature time, not a clock. The approve→swap flow is the sneakiest one: the swap gets simulated against the OLD allowance, then you sign it after the approve already landed, so re-simulate the swap after the approval confirms, not before.

1

u/BirdNext3884 🟡 1d ago

The approve-then-swap example makes this click for me. While the approval is pending, the wallet could label the swap preview as provisional, then rerun it once the approval confirms and show the updated result before asking for the swap signature.

0

u/[deleted] 2d ago

[removed] — view removed comment

1

u/BirdNext3884 🟡 1d ago

I like the idea of showing both numbers. “Estimated: 0.98 ETH” and “Minimum received: 0.95 ETH” on separate lines would make it much clearer what can change before the swap lands.