Sign in

One-way state

Suggest an edit

Sometimes the program logic requires one transaction to happen strictly before another, otherwise the state becomes invalid. On Solana there is no sender nonce, so two transactions can land in either order if sent simultaneously.

EVM contracts rely on transaction nonces to enforce sequential order, and track message ids natively. Trying to replicate this on Solana would be an antipattern. You would allocate a separate account to store the number and pay rent for it, and it still wouldn't be bullet-proof: used ids and nonces give uniqueness, but they do not guarantee commutativity (A + B = B + A).

The One-Way State pattern flips the design: instead of attempting to restore message delivery order, you design in a way that order stops mattering at all. The message carries the destination, not the step: the total earned so far, not today's reward. Deltas break this even when they only move forward: +5 applied twice is not +5 applied once. A total applied twice is just the total.

The program only accepts actions that move state progress forward or restrict capabilities, strictly rejecting attempts to roll back the value or broaden access. When the state can only move in one direction (never down, never wider), a delayed, re-submitted transaction is no longer a security risk. The program never compares two messages with each other, it only checks the message against the current state. You don't have to ask the question "which one came later" when you can ask the question "has this already been taken into account". When you're moving in one direction, you can't suddenly find yourself at point 80 if you've already passed point 100.

One-way stateA number line pointing right with the state at 100. A message with 80 arrives late and bounces off, rejected. A message with 100 arrives twice and changes nothing. A message with 120 moves the state forward. One-way state 80 100 120 state 80 arrives late 100 again = same 120 only forward The message carries the destination, not the step. Order and duplicates stop mattering.

Examples

Helium rewards. The oracle signs the total a device has earned since the beginning. The device's account stores how much was already paid. A claim pays the difference and moves the paid amount up to the signed total. Send it twice, and the second claim pays zero. Bring an older signature with a smaller total, and it pays nothing, because the paid amount is already above it. The counter never goes down, so nobody can take back what was paid.

Squads does the same with rights: when signers change, one counter moves to the latest proposal, and every older proposal can be cancelled but not approved.

Drift's binary markets turn reduce-only near expiry: you can close a position but not open or grow one.

The One-Way State survives a simple test: any two transactions, swapped, land on the same final state.