由于权限升级,更改 PDA 拥有的令牌帐户权限失败

问题描述 投票:0回答:3

当我尝试更改 SPL 的权限时,出现权限升级错误 (

Hw5dRzdcUNHahscRYr1AtsS3t6KXoxyHiGaeShjF7Wq3's signer privilege escalated
)。
Hw5dRzdcUNHahscRYr1AtsS3t6KXoxyHiGaeShjF7Wq3
是下面代码中escrow_signer的地址。

我可以确认 SPL 代币帐户归 PDA 所有,因为我在另一笔交易中更改了其权限。

        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>,
}

以下是我创建 PDA 地址的方法:

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

感谢您的帮助。

rust anchor blockchain solana
3个回答
0
投票

你的种子实际上应该是:

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

而不是签名者?

我想知道它们是否以错误的方式传递,因此

escrow_signer
实际上是
escrow_account
,它没有签署此指令,这可以解释错误。


0
投票
  1. 确保种子正确
  2. 确保相关帐户被标记为可变(这一点经常被忽视)

0
投票

我在这里添加此问题的另一个可能原因:

假设您正在使用 PDA 帐户通过 CPI 从您的帐户内部调用另一个程序,并且您使用签名者种子来实现此目的。

如果您调用

solana_program::program::invoke
而不是
solana_program::program::invoke_signed
,您也可能会遇到这种情况。

© www.soinside.com 2019 - 2024. All rights reserved.