Anti-Sniping
Setting nLockTime near the current time so a miner cannot quietly re-mine an old block and steal fees from it.
Basically
Anti-sniping sets when a Bitcoin transaction can be mined. It discourages miners from redoing recent blocks to collect the fees.
Key Takeaways
- Anti-sniping is a wallet-level defence against fee sniping. It sets a transaction's nLockTime to the current block height, so the transaction cannot enter an earlier block and miners lose the incentive to re-mine recent blocks.
- Bitcoin Core has applied anti-sniping by default since version 0.11.0 (2015). The technique costs nothing, requires no consensus changes, and makes a simple but effective contribution to network stability.
- Anti-sniping matters more as the block subsidy declines with each halving. When transaction fees dominate miner revenue, the rational incentive to re-mine fee-rich blocks increases, and anti-sniping directly reduces that incentive.
What Is Anti-Sniping?
Anti-sniping is a transaction construction technique used by Bitcoin wallets to discourage a theoretical mining attack called fee sniping. In a fee-sniping attack, a miner with sufficient hashpower re-mines a recently confirmed block rather than building on it, aiming to capture its high-fee transactions in the miner's own replacement block.
The defence starts when a wallet constructs a transaction and sets the nLockTime field to the current block height. The transaction is then invalid for inclusion in any block at a lower height. If every wallet does this, a miner re-mining an earlier block cannot include new high-fee transactions in the replacement block because they are locked to the current height or later.
Anti-sniping is neither a consensus rule nor a protocol change. It is voluntary wallet behaviour that strengthens the network when adopted widely. Bitcoin Core introduced it in 2015, and other wallets like Electrum have since adopted it.
How It Works
Fee sniping is the attack that anti-sniping is designed to prevent. The next sections explain the attack first and then the defence.
The Fee-Sniping Attack
The blockchain in this example is at height 800,000. A miner has just found block 800,000, which contains transactions paying a total of 0.5 BTC in fees, while the mempool for the next block contains transactions paying only 0.01 BTC in fees. A rational miner with enough hashpower then faces a choice.
A large enough fee gap between consecutive blocks makes the second option, re-mining the recent block, economically rational. Miners then have a perverse incentive to compete to rewrite recent history rather than extend the chain, undermining the longest chain rule that Bitcoin relies on for consensus.
The Anti-Sniping Defence
Anti-sniping neutralises this attack by constraining when transactions can be mined. A wallet that sets nLockTime to the current block height, 800,000 in the example above, makes the transaction valid only for inclusion in block 800,001 or later. A miner attempting to re-mine block 800,000 cannot include this transaction in the replacement block because the locktime forbids it.
Universal use of nLockTime would dramatically shrink the pool of "snipeable" transactions. An attacking miner could include only transactions that were already in the original block, which the honest chain also includes, and could not capture newly broadcast high-fee transactions.
Bitcoin Core Implementation
Bitcoin Core implements anti-sniping in a function called DiscourageFeeSniping, introduced in PR #2340. The function uses the following logic.
The random offset in step 2 serves two purposes. Privacy is the first purpose: if every transaction had nLockTime set to exactly the same height, an observer could infer which block a wallet was synced to when constructing the transaction. The second purpose is to accommodate transactions that are signed but not immediately broadcast, ensuring they remain valid after a few blocks pass.
BIP 326 and Taproot
BIP 326 proposes an alternative approach for Taproot transactions. Taproot uses Schnorr signatures and can leverage nSequence for relative timelocks, so BIP 326 suggests a 50/50 split: half the time use nLockTime-based anti-sniping as described above, and half the time use nSequence-based anti-sniping instead. The variation improves privacy by making anti-sniping transactions less distinguishable from transactions that use timelocks for other purposes, such as Lightning channel closes.
Why It Matters
Anti-sniping addresses a long-term structural concern in Bitcoin's incentive design. The block subsidy, currently 3.125 BTC per block after the 2024 halving, dwarfs transaction fees in most blocks today. A miner would gain little by re-mining a recent block for its fees when the subsidy is the same regardless of which block they mine.
The subsidy halves approximately every four years and will eventually approach zero. Fees will become a larger share of miner revenue, and the variance between blocks will grow significant. A block with 1 BTC in fees next to a block with 0.02 BTC in fees creates a strong incentive to re-mine the richer block, raising the core security budget debate: whether Bitcoin's fee market alone can sustain enough miner revenue to keep the network secure against reorg attacks.
Anti-sniping is one piece of this puzzle, not a solution to the security budget problem on its own. It directly reduces the profitability of fee-sniping attacks and, when widely adopted, makes honest mining relatively more profitable than reorg-based strategies. Research has shown that wider use of transaction lock fields could reduce the payoff from fee-sniping attempts, making honest chain extension the dominant strategy even when fee variance is high.
The research article on Bitcoin's fee-only security budget offers a deeper analysis of how Bitcoin's security model evolves as subsidies decline. Readers can find more detail there.
Wallet Transaction Construction
Wallet transaction construction is the primary use case: every time a wallet creates a transaction, it should set nLockTime to the current block height. Bitcoin Core, Electrum, and several other wallet implementations do this by default, and wallet developers building on Bitcoin SDKs should ensure their transaction construction logic includes anti-sniping by default.
Layer 2 Protocol Transactions
Layer 2 protocols that create on-chain transactions can also benefit from anti-sniping. Cooperative Lightning channel closes and splice transactions can set nLockTime to the current height when broadcast, ensuring these transactions contribute to anti-sniping as well.
Exchange and Institutional Wallets
Exchanges and custodians that process large volumes of batched transactions have an outsized impact on anti-sniping adoption. A single large exchange implementing anti-sniping can meaningfully increase the share of transactions that carry a locktime, making fee sniping less viable across the network.
Privacy Fingerprinting
Exact current-height nLockTime settings can reveal information about when and where a transaction was constructed. A node stuck on a stale block may produce transactions with a distinctive locktime that differs from the rest of the network, allowing observers to cluster transactions by wallet. Bitcoin Core's random offset, subtracting 0-99 blocks with 10% probability, partially mitigates this, but the pattern remains identifiable for chain analysis tools.
Incomplete Adoption
Anti-sniping works only as a collective defence. Transactions without locktime constraints remain available for sniping if only a fraction of transactions use it. Estimates suggest that roughly 20% of Bitcoin transactions used anti-sniping locktime as of 2021, which is meaningful, but broader adoption across all major wallets would significantly strengthen the defence.
Not a Complete Solution
Anti-sniping reduces the profitability of fee sniping but does not eliminate it entirely. Transactions already in the original block can still be included in a replacement block, and transactions constructed with nLockTime set to 0, either intentionally or due to stale chain tips, remain snipeable. Anti-sniping is one layer of defence within a broader set of mechanisms that protect Bitcoin's security budget.
Interaction with Replace-by-Fee
Replace-by-fee (RBF) fee bumps should also give the replacement transaction an appropriate nLockTime. A recent Bitcoin Core discussion identified that fee-bumped transactions created after a long offline period could inadvertently set nLockTime to 0. The result can drop below the original transaction's locktime and create a wallet fingerprint, and ongoing development work continues to address these edge cases.
The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.