Skip to content

[nodes-from-anchor] PDA derivation with string seed incorrect #337

@swimricky

Description

@swimricky

solana-program/create-solana-program#108

if you have an Anchor program like the following

 #[program]
mod drp_test_scaffold {
    use super::*;

    pub fn create(ctx: Context<Create>, name: String, authority: Pubkey) -> Result<()> {
        let counter = &mut ctx.accounts.counter;
        counter.name = name;
        counter.authority = authority;
        counter.count = 0;
        Ok(())
    }
}

#[derive(Accounts)]
#[instruction(name: String)]
pub struct Create<'info> {
    #[account(
        init, 
        seeds = [name.as_bytes()],
        bump,
        payer = payer, space = 8 + Counter::INIT_SPACE
    )]
    pub counter: Account<'info, Counter>,
    #[account(mut)]
    pub payer: Signer<'info>,
    pub system_program: Program<'info, System>,
}

the generated Encoder for the seeds is incorrect.
it generates the following snippet for resolving the counter account if not provided

 // Resolve default values.
  if (!accounts.counter.value) {
    accounts.counter.value = await getProgramDerivedAddress({
      programAddress,
      seeds: [
        addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()).encode(
          expectSome(args.name)
        ),
      ],
    });
  }

it should be using

 getUtf8Encoder().encode(
          expectSome(args.name)
        ),

Metadata

Metadata

Assignees

No one assigned

    Labels

    anchorImproves conversion from Anchor IDLv2Something to look into when updating the Codama standard to v2

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions