Rules › Anchor (Rust)
Account closed by draining lamports by hand
Zeroing lamports without clearing data and owner lets the account be revived in the same transaction; use close = target.
Why it matters
Closing an account by moving its lamports out and leaving its data and owner in place lets an attacker "revive" it in the same transaction (by topping up rent) and reuse stale state. Anchor's close = destination constraint zeroes the data, sets a closed discriminator, transfers the lamports and assigns the account back to the system program.
Vulnerable
**ctx.accounts.receiver.try_borrow_mut_lamports()? += vault_lamports;
**ctx.accounts.vault.to_account_info().try_borrow_mut_lamports()? = 0;
Fixed
#[account(mut, has_one = authority, close = authority)]
pub vault: Account<'info, Vault>,
What other tools call it
| Tool | Detector or reference |
|---|---|
| Sealevel attacks | 9-closing-accounts |
Check your code
Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.
Related rules
- Unchecked account without a /// CHECK: note
- Authority account that isn't a Signer
- CPI to a program the caller chooses
- Account data deserialized without an owner check
- init_if_needed (reinitialization risk)
- overflow-checks not enabled for release builds
Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.