Skip to main content
NEAR accounts must maintain a balance proportional to the data they store. If users can grow contract state without paying for it, an attacker can create enough entries to lock the contract’s available balance.

How the attack works

Consider a guest book that stores any message:
  1. An attacker stores a message, for which the contract - not the visitor - pays the storage cost
  2. An attacker repeats, storing thousands of inexpensive messages
  3. More of the contract’s NEAR becomes locked for storage
  4. The contract eventually lacks liquid balance for other operations
The attack is an economic imbalance: each write is cheap for the attacker but consumes balance belonging to the contract.

Charge for state growth

Measure the bytes written and require the attached deposit to cover them. The exact implementation depends on whether you charge per operation or use a storage-management standard.
If the deposit is insufficient, the panic reverts the state written by that receipt. Define what happens to any excess deposit and how users recover storage deposits when their data is removed.