Skip to main content
Sigvex

Rent Epoch Validation Remediation

How to fix improper rent epoch validation.

Rent Epoch Validation Remediation

Overview

Detector Reference: Rent Epoch Validation

This guide explains how to properly validate rent-exempt status before modifying accounts, particularly relevant for programs handling account lifecycle operations.

Query the Rent sysvar dynamically before modifying account state:

let rent = Rent::get()?;
require!(
    account.lamports() >= rent.minimum_balance(account.data_len()),
    ErrorCode::NotRentExempt
);

Alternative Mitigations

  1. Ensure rent exemption at creation: use SystemProgram::create_account with sufficient lamports from the start.
  2. Anchor init: #[account(init, payer = user, space = ...)] ensures rent exemption at creation.
  3. Skip for rent-exempt-only programs: if your program only creates and operates on rent-exempt accounts, this finding is informational and can be acknowledged.

Common Mistakes

  • Caching the rent-exempt minimum: storing the value in account data creates a stale reference. Always query Rent::get() dynamically.
  • Checking rent before realloc but not after: reallocation changes the minimum balance. Check again after resizing.
  • Ignoring epoch transitions: while rare, rent parameter changes across epochs can affect the minimum balance.

References