From 0cb4b7ac935be017458e73c7e5cecd4698ad40d9 Mon Sep 17 00:00:00 2001 From: devtechedge Date: Sat, 12 Sep 2026 03:54:52 +0530 Subject: [PATCH] pda-rent-payer: note that create_new_account has no caller check create_new_account spends from a shared rent_vault PDA and the only signer is the newly created account itself, so anyone can drain the vault one rent-exempt minimum at a time. Add a caution note above the instruction in the anchor, native and pinocchio flavors pointing copyists at the authority checks a real rent vault needs. The example itself is unchanged since it exists to show a PDA signing for itself. Fixes #671 --- .../src/instructions/create_new_account.rs | 5 +++++ .../native/program/src/instructions/create_new_account.rs | 4 ++++ .../pinocchio/program/src/instructions/create_new_account.rs | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/basics/pda-rent-payer/anchor/programs/anchor-program-example/src/instructions/create_new_account.rs b/basics/pda-rent-payer/anchor/programs/anchor-program-example/src/instructions/create_new_account.rs index 706746382..30803262b 100644 --- a/basics/pda-rent-payer/anchor/programs/anchor-program-example/src/instructions/create_new_account.rs +++ b/basics/pda-rent-payer/anchor/programs/anchor-program-example/src/instructions/create_new_account.rs @@ -1,6 +1,11 @@ use anchor_lang::prelude::*; use anchor_lang::system_program::{create_account, CreateAccount}; +// 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 +// initialization, seeds that bind the vault to one funder, or a per-caller +// limit. A bare `authority: Signer` alone is not enough, since any keypair +// can sign for itself. #[derive(Accounts)] pub struct CreateNewAccount<'info> { #[account(mut)] diff --git a/basics/pda-rent-payer/native/program/src/instructions/create_new_account.rs b/basics/pda-rent-payer/native/program/src/instructions/create_new_account.rs index 071b8127e..23fec2e9d 100644 --- a/basics/pda-rent-payer/native/program/src/instructions/create_new_account.rs +++ b/basics/pda-rent-payer/native/program/src/instructions/create_new_account.rs @@ -8,6 +8,10 @@ use solana_program::{ use crate::state::RentVault; +// NOTE: this example does not restrict who may call it. A real rent vault +// needs an authority check: an authority recorded at initialization with +// seeds that bind the vault to one funder, or a per-caller limit. A bare +// signer alone is not enough, since any keypair can sign for itself. pub fn create_new_account(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult { let accounts_iter = &mut accounts.iter(); let new_account = next_account_info(accounts_iter)?; diff --git a/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs b/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs index 7b65e3661..6a45c51c1 100644 --- a/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs +++ b/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs @@ -6,6 +6,10 @@ use pinocchio::{ use crate::state::RentVault; +// NOTE: this example does not restrict who may call it. A real rent vault +// needs an authority check: an authority recorded at initialization with +// seeds that bind the vault to one funder, or a per-caller limit. A bare +// signer alone is not enough, since any keypair can sign for itself. pub fn create_new_account( program_id: &Address, accounts: &mut [AccountView],