Skip to content

fix(idl): warn on unsupported seed syntax and fix init seed discovery #4081

Open
spellsaif wants to merge 1 commit into
otter-sec:masterfrom
spellsaif:fix/idl-generation
Open

fix(idl): warn on unsupported seed syntax and fix init seed discovery #4081
spellsaif wants to merge 1 commit into
otter-sec:masterfrom
spellsaif:fix/idl-generation

Conversation

@spellsaif

Copy link
Copy Markdown

This PR addresses two issues regarding how the IDL generator processes PDA seeds:

  1. Silent Failures on Complex Seeds: Previously, if a seed contained syntax not supported by the IDL parser (e.g., function calls or complex expressions), the parser would return an Err. The existing implementation used .ok(), which silently swallowed the error and removed the pda field from the generated IDL entirely. This left developers confused as to why their IDL was incomplete.
  2. Seed Discovery in init: It improves the resolution of seeds defined within the init constraint, ensuring they are correctly located even if not present at the top level.

Changes

  • Refactored get_pda in lang/syn/src/idl/accounts.rs.
  • Replaced the error-swallowing .ok() chain with an explicit check for parsing errors.
  • Added an eprintln! warning. Now, if seeds cannot be parsed, the build continues (returning None for the PDA), but the user is explicitly warned in the terminal.

Reproduction / Example Case

Given this account struct with a custom function call in seeds:

#[account(
    init,
    seeds = [
        b"pool",
        &max_key(token_a.key(), token_b.key()) // <--- Unsupported by IDL parser
    ],
    bump,
    payer = payer,
    space = 8 + Pool::INIT_SPACE
)]
pub pool: AccountLoader<'info, Pool>,

Before:

  • anchor build succeeds.
  • The generated IDL is missing the pda field for pool.
  • No warning is shown. The developer assumes the IDL is correct until their client code fails.

After

  • anchor build succeeds.
  • The generated IDL is still missing the pda field (correct, as we cannot represent logic in JSON).

Terminal Output:

  WARNING: Anchor IDL generation skipped for PDA seeds in account `Pool`. 
  Reason: Seeds contain unsupported complex expressions (e.g., function calls). 
  Workaround: Derive this PDA manually in your client.

Motivation

This improves the Developer Experience (DX) significantly. Developers often use helper functions in seeds. Without this warning, they waste time debugging client-side errors ("ConstraintSeeds") without realizing the IDL itself generated incomplete data. This change makes the limitation explicit.

1. Updates `get_pda` to correctly locate seeds defined within `init` constraints.
2. Adds an explicit check for parsing errors. Instead of silently swallowing errors with `.ok()`, it now prints a warning to stderr explaining that IDL generation was skipped for the specific account due to complex expressions.
@vercel

vercel Bot commented Nov 21, 2025

Copy link
Copy Markdown

@spellsaif is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

});

// Parse Seeds
let pda = seed_constraints

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsupported seeds::program expressions still fail silently,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants