0

I'm passing two accounts to my program: a payer account and a PDA.

The PDA should be derived from the payer address.

How do I verify it inside the program? Without Anchor.

2 Answers 2

1

you can generate a pda from the program id and any &[&[u8]] using Pubkey::find_program_address. here is an example from the spl single pool program:

fn find_pool_stake_authority_address_and_bump(
    program_id: &Pubkey,
    pool_address: &Pubkey,
) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[POOL_STAKE_AUTHORITY_PREFIX, pool_address.as_ref()],
        program_id,
    )
}

prefix is a static string, used for namespacing different kinds of pdas. since the user also passes in the pda as an account, you must check that the generated pda address matches the address they give you, and return an error if it doesnt

also, assuming payer is meant to own the derived account, you should enforce in your program that it is a signer

-1

You could add a field authority to the account data and initialize it with the payer's address.

Below is pseudo-code for illustration purposes

account.authority = payer

You could then do an initiation check on the account after which an address check will ascertain that the authority field matches payer address calling the ix.

2
  • this is anchor, solana accounts do not have an authority field
    – hana
    Commented Oct 21 at 0:23
  • I meant having an authority field in the account data.
    – Jimii
    Commented Oct 21 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.