Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor idl build fails on seeds::program constraint #3471

Open
giangcsp opened this issue Jan 9, 2025 · 1 comment
Open

Anchor idl build fails on seeds::program constraint #3471

giangcsp opened this issue Jan 9, 2025 · 1 comment
Labels
bug Something isn't working compile error Issues related to compile errors idl related to the IDL, either program or client side

Comments

@giangcsp
Copy link

giangcsp commented Jan 9, 2025

Program created fresh with:

  1. anchor-cli v0.30.1
  2. solana-cli 2.0.21
  3. rustc 1.83.0
use anchor_lang::prelude::*;

declare_id!("EqESFSyZPGyB4S72cv7vdy2fkFQZZkZcCTjySYd8wmZZ");

#[program]
pub mod test {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
        msg!("Greetings from: {:?}", ctx.program_id);
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(mut)]
    pub signer: Signer<'info>,

    #[account(
        mut,
        seeds = ["something".as_bytes().as_ref()],
        bump,
        seeds::program = test_program
    )]
    pub test_pda: UncheckedAccount<'info>,

    pub test_program: Program<'info, System>,
}

Error:

error[E0425]: cannot find value `test_program` in this scope
  --> programs/test/src/lib.rs:24:26
   |
24 |         seeds::program = test_program
   |                          ^^^^^^^^^^^^ not found in this scope
@acheroncrypto acheroncrypto added bug Something isn't working idl related to the IDL, either program or client side compile error Issues related to compile errors labels Jan 9, 2025
@acheroncrypto
Copy link
Collaborator

Similar to #3209 and #2903, IDL resolution requires certain information to be available in compile time, but you're using a runtime value (test_program). To solve, you can simply use seeds::program = System::id() instead (or any other value that's known in compile time).

For this specific example, the parser could be a little smarter and decide test_program's key can be known in compile time (because it's using the Program type).

There are certainly improvements to be made here, so I'm leaving the issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compile error Issues related to compile errors idl related to the IDL, either program or client side
Projects
None yet
Development

No branches or pull requests

2 participants