Replay Protection
Nonce-based replay prevention ensures each signed message can only be used once.
The Replay Attack Problem
Without replay protection, an attacker who intercepts a valid signed order could re-submit it to the engine repeatedly. Since the signature is valid, the engine would accept each submission and create multiple fills — draining the account balance far beyond the trader's intent. Replay protection makes each signed message single-use.
Order Nonces
Every order includes a nonce field — a strictly positive integer chosen by the sender. The engine tracks the set of used nonces per account. When an order arrives, the engine checks whether the nonce has already been used. If it has, the order is rejected with E_NONCE_USED.
Unlike some systems that require a strictly monotonic nonce, Vela allows any positive integer as a nonce, as long as it has not been used before by the same account. The simplest correct strategy is to start at 1 and increment by 1 for each order. Nonces do not need to be sequential — gaps are allowed.
WebSocket Challenge Nonces
Challenge nonces issued by the server for WebSocket authentication are different from order nonces. They are server-generated, 16-byte random hex strings, and they expire after 60 seconds. A challenge nonce can only be used once — the server marks it as consumed immediately upon receiving a valid auth message using it.
Nonce Storage
Used order nonces are stored in the MPT state layer under the key nonce:{address}. This ensures they are persisted across engine restarts and included in the published state root, making them verifiable by the fraud proof system.
E_NONCE_USED rejections.