0

I am getting a privilege escalation error (Hw5dRzdcUNHahscRYr1AtsS3t6KXoxyHiGaeShjF7Wq3's signer privilege escalated) when I try to change the authority of an SPL. Hw5dRzdcUNHahscRYr1AtsS3t6KXoxyHiGaeShjF7Wq3 is the address of the escrow_signer in the code below.

I can confirm the SPL token account is owned by the PDA, as I changed its authority in another transaction.

        token::set_authority(
            ctx.accounts.into(),
            AuthorityType::AccountOwner,
            Some(ctx.accounts.escrow_signer.key()),
        )?;
    pub fn terminate_escrow  (ctx: Context<Terminate>) -> ProgramResult {
        let seeds = &[
            ctx.accounts.escrow_signer.key.as_ref(),
            &[ctx.accounts.escrow_account.nonce],
        ];

        let cpi_accounts = SetAuthority {
            account_or_mint: ctx.accounts
                .initializer_lp_token_account
                .to_account_info()
                .clone(),
            current_authority: ctx.accounts.escrow_signer.clone(),
        };

        let cpi_program = ctx.accounts.token_program.clone();

        token::set_authority(
            CpiContext::new(cpi_program, cpi_accounts)
                .with_signer(&[&seeds[..]]),
            AuthorityType::AccountOwner,
            Some(ctx.accounts.initializer.key()),
        )?;
}

#[derive(Accounts)]
pub struct Terminate<'info> {
    ...
    #[account(
        seeds = [escrow_account.to_account_info().key.as_ref()],
        bump = escrow_account.nonce,
    )]
    pub escrow_signer: AccountInfo<'info>,
}

Here is how I am creating the PDA address:

        const [_escrowSigner, _nonce] = await anchor.web3.PublicKey.findProgramAddress(
            [escrowAccount.publicKey.toBuffer()],
            program.programId
        );

Thanks for helping.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
motia
  • 1,939
  • 16
  • 22

2 Answers2

0

Should your seeds actually be:

let seeds = &[
    ctx.accounts.escrow_account.key.as_ref(),
    &[ctx.accounts.escrow_account.nonce],
];

Instead of the signer?

I wonder if they were passed the wrong way around, so that escrow_signer is actually escrow_account, which is not signing this instruction, which would explain the error.

Jon C
  • 7,019
  • 10
  • 17
0
  1. Ensure seeds is correct
  2. Ensure relevant account is marked as mutable (THIS is often overlooked)
noooooooob
  • 1,872
  • 3
  • 21
  • 27