Repository navigation
RUST.md: every account the program creates is a PDA unless it cannot be - #64
Merged
Merged
Conversation
The order-book example created its three vaults at public keys the client generated, for no reason beyond habit: each one cost an extra signer, and nothing but the market's record said where it was. Only the 180 KB order book had a real reason, since a program can allocate at most 10 KB when it creates an account through CPI. PDA Management now says so. Program-created accounts are PDAs by default. Size is the usual reason one can't be, and copying an example, saving a seed, or already holding a key pair are not reasons. An account at a generated public key carries a comment saying why and is bound by a stored-address check. An Anchor `init` without `seeds`, or a Quasar `init` without `address = X::seeds(..)`, without that comment is a finding. Tests derive every PDA the program creates. Claude-Session: https://claude.ai/code/session_011VUvZT5384GaSBhhgJwFp3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The order-book example created its base, quote, and fee vaults at public keys the client generated, for no reason beyond habit. Each vault cost the client an extra signer, and nothing but the market's record said where it was. quicknode/solana-program-examples#148 made them PDAs of the market. Only the 180 KB order book had a real reason to stay at a generated key, because a program can allocate at most 10 KB when it creates an account through CPI.
This adds the rule to PDA Management in
skills/solana/RUST.md, so new programs don't repeat the mistake:MAX_PERMITTED_DATA_INCREASE) the client has to create the account withcreate_account, and that needs the new account's own signature. Growing a PDA withreallocis named as the alternative. The rule also names three things that are not reasons:initwithoutseedsis such an account; in Quasar, aninitwithoutaddress = X::seeds(..)is. Either one without the comment is a finding.Keypair::new()for a program account is correct only for an allowed exception.🤖 Generated with Claude Code
https://claude.ai/code/session_011VUvZT5384GaSBhhgJwFp3
Generated by Claude Code