basics/pda-rent-payer: create_new_account has no caller check — worth a note for people copying it?

Aperta Adatta ai principianti
#671 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@khoap1220-hue ci sta già lavorando.

Dal 25/10/2026.

  • #732 di @devtechedge — chiusa senza merge
  • #760 di @khoap1220-hue — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
78/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
blockchain, rust

Direzione di ricerca

Inizia in basics/pda-rent-payer, nella accounts struct di create_new_account, quindi confronta le indicazioni relative ad Authority in basics/checking-accounts. Aggiungi solo il commento esplicativo o il riferimento incrociato concordato, preservando il comportamento intenzionalmente non vincolato dell’esempio; il lavoro è completato quando la limitazione del controllo del caller e le alternative più sicure nel mondo reale sono chiare ai lettori.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

create_new_account spends from a program-owned vault, and nothing in the
instruction constrains who may call it.

The accounts struct is:

pub struct CreateNewAccount<'info> {
    #[account(mut)]
    new_account: Signer<'info>,

    #[account(mut, seeds = [b"rent_vault"], bump)]
    rent_vault: SystemAccount<'info>,
    system_program: Program<'info, System>,
}

new_account is a Signer, but it signs for itself — it is the account being
created, and the caller generates that keypair. rent_vault is a PDA on a
single literal seed, shared by everyone. So there is no authority account and
no has_one, and each call moves one rent-exempt minimum out of the shared
vault into an account the caller controls.

That is almost certainly intentional for the example's purpose — it exists to
show a PDA signing for itself, and it does that cleanly and readably. My
question is only about the people who copy it, since a rent vault is exactly
the kind of helper that gets lifted into a real program.

Would a short comment on the accounts struct be welcome? Something like:

// NOTE: this example does not restrict who may call it. A real rent vault
// needs an authority check — a `has_one` against an admin recorded at
// initialisation, seeds that bind the vault to one funder, or a per-caller
// limit. (A bare `authority: Signer` alone is not enough — any keypair
// can sign for itself.)

Happy to open a PR with just that comment if it's useful. I did not want to add
a constraint, since that would change what the example teaches.

For context: basics/checking-accounts is the example that teaches exactly this
check, so a pointer between the two might do the job on its own.

Lingua principale
Rust
Stelle
1.4k
Fork
559
Merge medio
20h 9m
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di solana-foundation/program-examples

Tutte le issue di solana-foundation/program-examples

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.