EPIC-SEC-002CRITICALTarget: Layout Deserialization
Missing Struct Discriminant Modification
Description
Protects struct field byte offsets.
Technical Rationale
Solana programs store serialized state on-chain. Inserting new fields in the middle of a struct shifts the serialization offsets of subsequent fields. This shifts the binary layout, causing older active accounts on mainnet to fail to deserialize properly.
Code Assessment Examples
Insecure Practice
// Vulnerable: Mid-struct field insertion shifts offset of 'balance'
struct UserState {
authority: Pubkey,
is_restricted: bool, // Inserted in version 2
balance: u64,
} Secure Resolution
// Safe: Appending new fields preserves byte offsets of older fields
struct UserState {
authority: Pubkey,
balance: u64,
is_restricted: bool, // Appended to end
}