Rules › Anchor (Rust)

Account closed by draining lamports by hand

mediumAnchor (Rust)Rule anchor-manual-close

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

ToolDetector or reference
Sealevel attacks9-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.

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.