Replay Protection
How Sahyadri prevents a signed transaction from being applied twice without a global nonce registry, without UTXO references, and without assuming any ordering across the DAG. Replay markers live inside the account leaf, committed by the same SMT root that commits to balance.
1. The Replay Problem
A digital signature is a function of a message and a private key. It is not a function of time, position, or application count. Given a signature over a message, anyone can broadcast that (message, signature) pair to anyone, at any time, any number of times.
Threat model: Given: (m, σ) where Verify(pk, m, σ) = ⊤ Attack: Adversary broadcasts (m, σ) to the network. If the network accepts (m, σ) more than once, and (m, σ) transfers value, the sender loses value multiple times against a single signature. Definition 1.1 (Replay) A transaction tx is replayed if it is accepted into a block more than once, across the entire chain history. Replay protection: Pr[tx accepted twice] ≤ negl(λ)
Every blockchain must solve this. There are two dominant approaches:
UTXO approach (Bitcoin): Each transaction spends specific outputs identified by (tx_id, output_index). Spending the same output twice fails: the first spend removes it from the UTXO set. Replay protection is implicit in the UTXO set. Account-nonce approach (Ethereum, Cosmos): Each account carries a monotonically increasing nonce. Each transaction includes the current nonce, which increments on acceptance. Replaying with an old nonce fails: the account's stored nonce has advanced. Replay protection is explicit in the nonce field. Sahyadri approach: Each transaction carries a 32-byte flash_id derived from its own contents. Each account stores a bounded vector of recent flash_ids. Replay is detected by membership: flash_id ∈ recent_flashes. Replay protection is a set-membership check per account.
2. Why Neither UTXO nor Nonce Fits
Both classical approaches assume something that a DAG does not provide. UTXO assumes that spending an output removes it — but in a DAG, a transaction may appear in parallel blocks, and the "removal" is not a sequential event. Nonces assume strict per-account ordering — but in a DAG, there is no ordering between transactions in parallel blocks.
SahyadriDAG property (from consensus):
Blocks may be produced in parallel.
Their canonical order is determined by Ashwa Consensus
(depth, cumulative work, hash).
Two transactions in parallel blocks may be ordered either
way by two honest nodes before the DAG resolves.
Implication for UTXO:
A UTXO can be spent by two transactions in parallel
blocks. Both are valid at time of production. Only after
canonical ordering does one become invalid.
UTXO-based replay protection breaks.
Implication for nonce:
Two transactions with the same nonce in parallel blocks
cannot both be valid, but which one is applied depends
on the canonical ordering. Nonce-based replay protection
forces a specific ordering that the DAG does not provide.
Requirement:
Replay protection must be:
(a) Order-independent within a mergeset
(b) Bounded in storage per account
(c) Deterministic across nodes
(d) Committed to by the same proof as balanceA time-bounded, per-account replay window is the only construction that satisfies all four. It does not assume ordering; it stores a bounded set; it prunes deterministically; it commits inside the account leaf.
3. Flash Identifier
Every flash transaction has a deterministic 32-byte identifier derived from its own fields. Two transactions are identical if and only if their identifiers match.
Definition 3.1 (flash_id)
flash_id : Transaction → {0,1}^256
flash_id(tx) = SHA3-256(
D_FLASH_ID ||
tx.version (u16 LE) ||
tx.pubkey (1952 B) ||
tx.recipient (20 B) ||
tx.amount (u64 LE) ||
tx.fee (u64 LE) ||
tx.expiry_daa_score (u64 LE) ||
tx.salt (16 B)
)
where D_FLASH_ID = "SAHYADRI_FLASH_ID_V1"The salt is 16 random bytes chosen by the sender at signing time. Its only purpose is to make two intentional distinct transfers of the same amount to the same recipient produce distinct identifiers. Without the salt, a user who wanted to send 100 CSM twice to the same recipient could not — the transactions would be indistinguishable.
The identifier is derived from the signed fields. An adversary cannot alter any field without invalidating the signature:
Lemma 3.2 (flash_id binding) If flash_id(tx_1) = flash_id(tx_2), then tx_1 = tx_2 as tuples, except with probability ≤ 2^(-128) (SHA3-256 collision resistance). If flash_id(tx_1) ≠ flash_id(tx_2), and tx_1 ≠ tx_2 as tuples, then at least one field differs. The signature over that field is not valid for the other transaction.
4. The Replay Window
Each account state contains a bounded vector of recently applied flash entries. The vector is part of what the SMT commits to for that account.
Definition 4.1 (Account state with replay window)
struct AccountState {
balance: u64,
recent_flashes: Vec<FlashEntry>,
nonce: u64, // legacy path — deprecated
last_applied_tx_id: [u8; 32], // legacy path — deprecated
}
struct FlashEntry {
flash_id: Hash,
expiry_daa_score: u64,
block_hash: Hash, // local to reorg bookkeeping
// NOT part of committed hash
}
Definition 4.2 (Replay detection)
For account A and transaction tx:
is_replay(A, tx) ⟺ flash_id(tx) ∈ A.recent_flashes
If is_replay(A, tx) = ⊤, tx is rejected from any block that
would apply it to A.The window is bounded by three protocol constants. They define how long a signed transaction is valid, and how much history each account must retain to make membership checking sound.
Constants:
FLASH_EXPIRY_BLOCKS = 100 (DAA score units)
FLASH_PRUNE_BUFFER = 50
FLASH_PRUNE_WINDOW = 150 (= 100 + 50)
Invariant (window bound):
∀ A, ∀ entry e ∈ A.recent_flashes:
A.entry_count ≤ |{tx : expiry(tx) > current_daa - PRUNE_BUFFER}|
The window grows with per-account activity within the window,
not with chain length.5. Why Two Constants
The 100 and 50 constants are not arbitrary. Both are grounded in protocol timing, and the second is strictly necessary for soundness.
FLASH_EXPIRY_BLOCKS = 100
A transaction signed at DAA score T is valid until T + 100.
At 1 BPS, this is a 100-second validity window.
Rationale:
- Long enough for inclusion under adversarial network conditions
- Short enough that a stale transaction cannot be replayed much later
- 100 seconds is a reasonable maximum delay for a user to tolerate
FLASH_PRUNE_BUFFER = 50
An entry is pruned only when current_daa > expiry + 50.
Rationale:
The DAA score advances faster than the selected chain depth.
A block at chain depth 100 may see DAA score 130-140 above
the signing point. Without the buffer, pruning could remove
an entry that is still relevant to a block in flight, allowing
a race-based replay.
Attack without buffer:
1. User signs tx with expiry T + 100.
2. Block B_1 at DAA score T + 101 includes tx.
3. A reorg removes B_1. Entry for tx is pruned at DAA score
T + 100 + 1 (immediately, no buffer).
4. Attacker rebroadcasts tx. At DAA score T + 101, tx is
expired — but so is every node's pruning decision, so the
entry is already gone. Whether tx is accepted depends on
whether expiry check or replay check runs first.
5. With buffer, entry survives until DAA score T + 150.
Attacker's rebroadcast at T + 101 sees the entry — rejected.
At T + 151, tx is expired anyway. No race window.6. The Committed Encoding
The replay window is not stored in a side table. It is part of the account state, hashed by the same content hash that produces the SMT leaf value. This is the property that makes replay protection a consequence of the state commitment rather than a separate system.
Content hash (from account_store.rs):
fn content_hash(&self) -> Hash {
let mut out = Vec::with_capacity(12 + self.recent_flashes.len() * 40);
out.extend_from_slice(&self.balance.to_le_bytes());
// Sort by flash_id — mandatory for determinism
let mut flashes: Vec<&FlashEntry> = self.recent_flashes.iter().collect();
flashes.sort_by(|a, b| a.flash_id.as_bytes().cmp(&b.flash_id.as_bytes()));
out.extend_from_slice(&(flashes.len() as u32).to_le_bytes());
for f in flashes {
out.extend_from_slice(&f.flash_id.as_bytes());
out.extend_from_slice(&f.expiry_daa_score.to_le_bytes());
// block_hash is NOT included
}
SHA3-256(b"SAHYADRI_ACCOUNT_STATE_V1" ‖ out)
}Two design choices are load-bearing for the commitment to be deterministic across nodes.
Choice 6.1: Flashes sorted by flash_id
Reorgs, pruning, and mergeset application can reorder
the in-memory vector. If the hash were order-sensitive,
a reorg could silently change the committed root —
forking the chain.
Sorting by flash_id makes the hash a function of the SET
of entries, not the order of the vector:
hash({e_1, e_2, e_3}) = hash({e_2, e_1, e_3})
= hash({e_3, e_2, e_1})
= ... (any permutation)
Choice 6.2: block_hash excluded
The block_hash field is local to each node's reorg
bookkeeping. It identifies which block added an entry,
so that reorg can remove exactly that block's contributions.
Two nodes that saw the same flash in different blocks
must agree on state. If block_hash were part of the hash,
they would not.
The block_hash is therefore stored alongside the entry
but never enters the content hash.7. Deterministic Pruning
Pruning removes expired entries. It must be deterministic across nodes — two nodes that accept the same block must prune identically, or they will compute different roots.
Pruning rule (from block transition):
For each account A touched by block B:
cutoff = B.daa_score - FLASH_PRUNE_BUFFER
A.recent_flashes.retain(|e| e.expiry_daa_score > cutoff)
Critical distinction:
Pruning uses B.daa_score (the block's own DAA score),
NOT the virtual tip's DAA score.
Why: two nodes may have different virtual tips (they see
different headers). If pruning used the tip's DAA score,
they would prune different entries for the same block,
producing different roots and forking the chain.
Touched-account rule: pruning runs ONLY on accounts that
block B's effects actually modify. Accounts not touched
by B keep their entries. This is deterministic because
"touched" is a function of B's effects, which are
themselves deterministic.The touched-account rule is what makes pruning safe in a DAG. A naive "prune everything on every block" approach would fail because the pruning decision would depend on the block, not the state — two blocks at the same height with different histories would produce different prunings.
Corollary: state compaction is lazy. An account that no block touches for longer than FLASH_PRUNE_WINDOW keeps its expired entries until some future block touches it. When that block runs, all expired entries are pruned in a single pass, and the leaf collapses to what it would have been had no flash ever been sent.
8. Reorg Correctness
Each FlashEntry carries the hash of the block that added it. Reorg unwinds a block by removing exactly those entries whoseblock_hash matches.
Algorithm 8.1 (Reorg-unwind) Input: account A, block_hash B_h Output: A with B_h's entries removed A.recent_flashes.retain(|e| e.block_hash ≠ B_h) Correctness argument: Entries added by B_h all have block_hash = B_h. Entries added by any other block have block_hash ≠ B_h. The retain removes exactly B_h's entries. Parallel flash transactions from other blocks in the same mergeset are untouched. Their entries remain, so they stay replay-protected through the reorg.
This is the property that makes reorgs safe in Sahyadri. A naive reorg would reset the entire replay window, opening a window for the reorged block's flash transactions to be re-applied. The block_hash tagging makes the unwind surgical.
After unwinding, the reorg handler applies the newly-canonical blocks in standard order. Any flash transaction that appeared in a removed block and reappeared in an added block is treated as a fresh apply — its flash_id is re-inserted with the new block's hash. Because duplicates are skipped rather than rejected (see Section 9), a flash transaction already present from a parallel block does not cause the added block to be rejected.
9. Batch Validation
A block's flash transactions are validated as a batch before any state is touched. The order of checks is chosen for efficiency, and the handling of duplicates is chosen for DAG correctness.
Algorithm 9.1 (Batch-validate)
Input: flash_txs [tx_1..tx_N], block_daa_score
Output: accepted_effects (some txs may be skipped)
Step 1: Aggregate sender debits
debits = {}
for tx in flash_txs:
debits[tx.pubkey] += tx.amount + tx.fee
Step 2: Cumulative balance check (all-or-nothing per sender)
for (pubkey, total) in debits:
if balance(pubkey) < total:
reject entire batch
Step 3: Per-transaction validation
seen = {}
for tx in flash_txs:
id = flash_id(tx)
if id ∈ seen:
skip tx (duplicate in this batch)
if block_daa_score > tx.expiry_daa_score:
skip tx (expired)
if is_replay(sender(tx), id):
skip tx (replay from earlier block)
seen.insert(id)
emit tx
Design choices:
(a) Balance check first — cheapest, rejects early.
(b) Duplicates skipped, not rejected — in a DAG, the same
flash transaction can appear in parallel blocks. Rejecting
the batch would drop unrelated valid flash txs from the
same block.
(c) Signature verification last — Dilithium-3 is expensive,
only runs on txs that survived all cheaper checks.The duplicate handling in step 3 is what makes batch validation DAG-correct. A block whose transactions include a flash transaction already applied by a parallel block should not be rejected wholesale — it should skip the duplicate and apply the rest.
10. Attack Scenarios
Six attack classes. Each is bounded by a specific mechanism. No attack requires trusting any party to defend against.
Attack 10.1: Direct replay
Adversary rebroadcasts a signed transaction.
Defense: flash_id ∈ recent_flashes → reject.
Bound: P[success] = 0 (deterministic).
Attack 10.2: Mutation replay
Adversary changes amount, recipient, or salt to produce
a new flash_id.
Defense: signature no longer verifies over the changed
payload. MLWE hardness bound.
Bound: P[success] ≤ Adv_MLWE(λ) + negl(λ).
Attack 10.3: Delayed replay
Adversary holds the transaction past its expiry, hoping
replay protection was pruned.
Defense: expiry check is independent of replay check.
Even if the flash_id were pruned, the expiry check
rejects at DAA score > expiry_daa_score.
Bound: P[success] = 0 (deterministic — two checks).
Attack 10.4: Cross-account replay
Adversary tries to apply Alice's signed transaction
against Bob's account.
Defense: sender is derived from tx.pubkey, not from the
recipient field. Bob's account never sees a
transaction signed by Alice.
Bound: P[success] = 0 (sender derivation is deterministic).
Attack 10.5: Batch duplicate
Same flash_id appears twice in one block, or a flash_id
from a parallel block appears again.
Defense: batch validator skips duplicates.
Bound: P[double-apply] = 0 (skip, not apply).
Attack 10.6: Reorg replay
A block applies a flash transaction, then the block is
reorged out. Adversary rebroadcasts the transaction.
Defense: two mechanisms.
(a) Reorg removes exactly the reorged block's entries.
If the transaction is rebroadcast after the entry
is removed, it is a fresh apply, not a replay —
but only if the transaction is not expired.
(b) Expiry is checked independently.
Bound: If expiry_daa_score > current_daa, transaction
is accepted (this is legitimate — it was undone
by reorg, and the sender wants it applied).
If expiry_daa_score ≤ current_daa, transaction
is rejected (expired).
Both outcomes are correct.
Attack 10.7: Insider broadcast
The recipient of a transfer rebroadcasts the transaction
to receive double credit.
Defense: same as direct replay — flash_id is already in
recent_flashes.
Bound: P[success] = 0.11. Comparison with Other Schemes
| Scheme | Mechanism | Order req. | Side registry | In commitment |
|---|---|---|---|---|
| Bitcoin UTXO | Output references | Yes | UTXO set | UTXO set hash |
| Ethereum | Monotonic nonce | Yes (strict) | State trie | State trie (includes nonce) |
| Cosmos | Account sequence | Yes | IAVL tree | IAVL (includes seq) |
| Solana | Recent blockhash | Yes | Blockhash cache | Not in commitment |
| Stellar | Sequence + timebounds | Yes | Ledger entry | Ledger entry |
| Monero | Key image set | No | Key image set | Set hash (grows) |
| Sahyadri | Bounded flash_id window | Not required | None (in leaf) | Account leaf (SMT) |
Time-bounded replay windows are not unique to Sahyadri. Stellar uses timebounds; Monero uses a growing key-image set; several newer DAG chains use bounded replay windows. What differs is the combination:
Sahyadri's combination:
(a) Order-independent within a mergeset — no per-account ordering
is required, because membership is a set check.
(b) Bounded in per-account storage — the window contains only entries
from the last ~150 DAA score, not chain history.
(c) Committed inside the same SMT leaf as balance — one state proof
simultaneously attests to both.
(d) No side registry — no second Merkle tree, no auxiliary store,
no cross-store consistency to maintain.12. Storage Analysis
| Metric | Value | Bound |
|---|---|---|
| Entry size | 72 B | 32 flash_id + 8 expiry + 32 block_hash |
| Typical entries per account | 0-5 | Most accounts have 0 at any moment |
| Typical footprint per account | ~360 B | 5 entries × 72 B |
| Worst case (adversarial) | Unbounded | No hard cap today; planned |
| Per 1M accounts | ~360 MB | Typical; scales with activity |
The bound is activity-based, not chain-length-based. An account that sends five flash transactions per minute has ~750 entries in a 150-second window; an account that sends one per day has ~1 entry.
13. Limitations
Limitation 13.1: No hard cap on entries per account
An adversary can flood their own account with flash
transactions inside one window, inflating their own leaf
until the window clears. This costs them fees and storage,
but does not affect other accounts.
Status: Per-account cap planned. Not implemented.
Limitation 13.2: Duplicate handling under mergeset (in progress)
The batch validator currently needs to skip duplicates rather
than reject the whole batch, because a flash transaction can
appear in parallel blocks.
Status: Skip logic implemented. Some code paths still reject
on duplicate; fix pending.
Limitation 13.3: Pruning must use the block's own DAA score
If pruning runs at the virtual tip's DAA score instead of
the block being processed, two nodes with different virtual
tips could prune different entries and produce different
roots.
Status: Enforced by policy in the current implementation.
Tests cover the invariant.
Limitation 13.4: Legacy account transactions still accepted
The chain's account-model-native path is flash-only. The
validator does not yet reject legacy account txs, which are
treated as no-ops for the SMT commitment.
Status: Will be removed by deleting the legacy path
entirely. Date not scheduled.14. Summary
Replay protection is not a side system in Sahyadri. It is part of what account state means. Balance and replay markers are committed together by the same SMT leaf, verified by the same proof, and updated by the same pure transition function. Every property of the SMT — canonical roots, content addressing, atomic commitment — extends automatically to replay protection.
The scheme is order-independent, registry-free, and cryptographically bound to balance. It borrows the time-window idea from chains like Stellar and Monero and adapts it to a DAG context where ordering assumptions cannot be made.
The cost is small: 16 bytes of salt per transaction, and a bounded vector per account that self-prunes lazily when the account is next touched. The benefit is a replay-protection scheme whose correctness follows from the same primitive that proves the balance — the SMT root.