Skip to main content
Sigvex

Rent Exempt Epoch Transition Remediation

How to fix cached rent-exempt minimum balances.

Rent Exempt Epoch Transition Remediation

Overview

Detector Reference: Rent Exempt Epoch Transition

This guide explains how to fix patterns where the rent-exempt minimum is cached in account data, creating stale values across epoch transitions.

Always query the Rent sysvar dynamically instead of reading cached values:

// Instead of reading from account data:
// let cached_min = u64::from_le_bytes(data[32..40].try_into()?);

// Always query fresh:
let rent = Rent::get()?;
let min_balance = rent.minimum_balance(account.data_len());
require!(account.lamports() >= min_balance, NotRentExempt);

Alternative Mitigations

  1. Refresh instruction: if caching is required for compute budget, add an update_rent_minimum instruction that refreshes the cached value.
  2. Conservative buffer: cache the rent minimum with an additional safety margin (e.g., 2x) to account for potential increases.
  3. Remove caching entirely: the Rent::get() sysvar access is inexpensive and should be called dynamically.

Common Mistakes

  • Caching for performance: the Rent sysvar access costs very few compute units. Caching provides negligible savings while introducing staleness risk.
  • Assuming rent parameters are immutable: while Solana has not changed rent parameters recently, the capability exists and caching assumes immutability.
  • Not invalidating on realloc: if the account size changes, the cached minimum is doubly wrong (wrong size AND potentially wrong rate).

References