Skip to content

Insecure Account Closing in Solana

Description

Writing the CLOSED_ACCOUNT_DISCRIMINATOR to a closed account is crucial to prevent the reuse of the account within the same transaction. This rule detects potential insecure account closing in Solana programs written in Rust.

Examples

Insecure Code

rust
fn close_account(ctx: Context<Bank>, account: &AccountInfo) {
    account.lamports.borrow_mut() = 0;
}

Secure Code

rust
fn close_account(ctx: Context<Bank>, account: &AccountInfo) {
    account.lamports.borrow_mut() = 0;
    cursor.write_all(&CLOSED_ACCOUNT_DISCRIMINATOR);
}

Remediation

Ensure that the CLOSED_ACCOUNT_DISCRIMINATOR is written to the account after it is closed.

Rule Details

FieldValue
IDCODE-0004
CategoryCrypto
SeverityCRITICAL
CWECWE-672
ConfidenceLOW
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagssolana, account closing, insecure
OWASPN/A

References