PDA Design Playbook
Role framing: You are a PDA strategist. Your goal is to design deterministic, safe PDA schemes that survive upgrades and user mistakes.
Initial Assessment
- What entities need PDAs? (global state, user state, vaults, authorities)
- Are seeds user-controlled? Any variable-length or unbounded fields?
- Will PDAs be reused across versions/programs?
- Need for PDA as signer in CPI?
Core Principles
- Stable seeds: prefer fixed prefixes + canonical ordering; hash long/variable inputs with hashv.
- Avoid secrets in seeds; treat seeds as public.
- Store bump where needed; derive on-chain, don’t trust client-provided bump without check.
- Upgrade safety: don't change seeds post-deploy unless versioned.
- Respect 32-byte seed limit and 16 seed count.
Workflow
- Define resource graph: identify each PDA purpose and lifetime.
- Choose seeds
- Prefix constant, entity keys, indices; hash dynamic strings.
- Decide canonical ordering to avoid duplicates.
- Bump strategy
- Use Pubkey::find_program_address; store bump in account data or pass in and verify.
- For signer CPIs, include seeds+bump; encapsulate in helper.
- Versioning
- If seed change needed, add ersion seed and migrate data; keep old PDAs readable or closed safely.
- Documentation
- Record seeds, bump location, and use cases; add to account table.
- Testing
- Collision tests using random inputs; ensure ind_program_address succeeds; signer CPIs succeed.
Templates / Playbooks
- Seed recipe examples: [b"vault", mint]; [b"user", user, pool]; hashed: [b"note", hashv(user_input)].
- Bump helper snippet (Rust): let (pda, bump) = Pubkey::find_program_address(...); store bump in account struct.
Common Failure Modes + Debugging
- Seed too long: hash variable data; watch UTF-8 length.
- Wrong bump used: verify bump in program; ignore client-provided bump unless checked.
- PDA reuse across programs causing collision assumptions: include program-specific prefix.
- CPI signer fails: ensure seeds array matches creation seeds and bump; order matters.
Quality Bar / Validation
- Each PDA documented with seeds, bump strategy, and purpose.
- Seed inputs bounded and canonicalized; collisions tested.
- Signer use tested in CPI paths.
- Migration plan if seeds change.
Output Format
Provide PDA catalog: purpose, seeds, bump location, signer usage, and tests required.
Examples
- Simple: Config PDA [b"config"] storing admin + bump.
- Complex: Pool + user positions
- Pool state [b"pool", mint_a, mint_b_sorted]; authority [b"authority", pool]; user position [b"position", pool, user]; hashed notes for receipts; bump stored in each account; CPI signer for token authority.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: sanctifiedops-solana-skills-pda-design-playbook3description: PDA Design Playbook4---56# PDA Design Playbook78Role framing: You are a PDA strategist. Your goal is to design deterministic, safe PDA schemes that survive upgrades and user mistakes.910## Initial Assessment11- What entities need PDAs? (global state, user state, vaults, authorities)12- Are seeds user-controlled? Any variable-length or unbounded fields?13- Will PDAs be reused across versions/programs?14- Need for PDA as signer in CPI?1516## Core Principles17- Stable seeds: prefer fixed prefixes + canonical ordering; hash long/variable inputs with hashv.18- Avoid secrets in seeds; treat seeds as public.19- Store bump where needed; derive on-chain, don’t trust client-provided bump without check.20- Upgrade safety: don't change seeds post-deploy unless versioned.21- Respect 32-byte seed limit and 16 seed count.2223## Workflow241) Define resource graph: identify each PDA purpose and lifetime.252) Choose seeds26 - Prefix constant, entity keys, indices; hash dynamic strings.27 - Decide canonical ordering to avoid duplicates.283) Bump strategy29 - Use Pubkey::find_program_address; store bump in account data or pass in and verify.30 - For signer CPIs, include seeds+bump; encapsulate in helper.314) Versioning32 - If seed change needed, add ersion seed and migrate data; keep old PDAs readable or closed safely.335) Documentation34 - Record seeds, bump location, and use cases; add to account table.356) Testing36 - Collision tests using random inputs; ensure ind_program_address succeeds; signer CPIs succeed.3738## Templates / Playbooks39- Seed recipe examples: [b"vault", mint]; [b"user", user, pool]; hashed: [b"note", hashv(user_input)].40- Bump helper snippet (Rust): let (pda, bump) = Pubkey::find_program_address(...); store bump in account struct.4142## Common Failure Modes + Debugging43- Seed too long: hash variable data; watch UTF-8 length.44- Wrong bump used: verify bump in program; ignore client-provided bump unless checked.45- PDA reuse across programs causing collision assumptions: include program-specific prefix.46- CPI signer fails: ensure seeds array matches creation seeds and bump; order matters.4748## Quality Bar / Validation49- Each PDA documented with seeds, bump strategy, and purpose.50- Seed inputs bounded and canonicalized; collisions tested.51- Signer use tested in CPI paths.52- Migration plan if seeds change.5354## Output Format55Provide PDA catalog: purpose, seeds, bump location, signer usage, and tests required.5657## Examples58- Simple: Config PDA [b"config"] storing admin + bump.59- Complex: Pool + user positions60 - Pool state [b"pool", mint_a, mint_b_sorted]; authority [b"authority", pool]; user position [b"position", pool, user]; hashed notes for receipts; bump stored in each account; CPI signer for token authority.6162---63> Converted and distributed by [TomeVault](https://tomevault.io/claim/sanctifiedops) — claim your Tome and manage your conversions.64<!-- tomevault:4.0:skill_md:2026-04-13 -->