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

Đang mở Phù hợp với người mới
#671 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@khoap1220-hue đang làm issue này rồi.

Từ ngày 25/10/2026.

  • #732 của @devtechedge — đã đóng, không merge
  • #760 của @khoap1220-hue — đang mở

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
78/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
blockchain, rust
Lĩnh vực
documentation, security

Hướng nghiên cứu

Bắt đầu trong basics/pda-rent-payer tại accounts struct của create_new_account, sau đó so sánh hướng dẫn về Authority trong basics/checking-accounts. Chỉ thêm bình luận giải thích hoặc tham chiếu chéo đã được thống nhất, đồng thời giữ nguyên hành vi cố ý không hạn chế của ví dụ; hoàn thành khi giới hạn của caller-check và các phương án thay thế an toàn hơn trong thực tế đã rõ ràng với người đọc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
1.4k
Fork
559
Merge trung bình
20 giờ 9 phút
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solana-foundation/program-examples

Tất cả issue của solana-foundation/program-examples

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.