Skip to content

SPL Token accounts generates redundant and sometimes wrong owner checks in Anchor #84

@julianzamt

Description

@julianzamt

Describe the bug
Anchor has wrappers for SPL types that generates taylor made security checks.
One of them is the metadata owner check.
When generating code from a CIDL that has SPL types as inputs, Codigo is placing redundant owner checks.
But furthermore, this check is wrong in the case of an ATA: the owner of an ATA is the Token Program, not the ATA program

To Reproduce

methods:
  - name: mint
    uses:
      - csl_spl_token.mint_to

Generated anchor code:

#[account(mut, signer)]
pub fee_payer : AccountInfo<'info>,
#[account(mut, owner=Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap())]
pub mint: Account<'info,anchor_spl::token::Mint>,
#[account(mut, owner=Pubkey::from_str("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL").unwrap())]
pub assoc_token_account: Account<'info,anchor_spl::token::TokenAccount>,

Expected behavior
To generate code that follows Anchor's guidelines. In this case:

#[account(mut, signer)]
pub fee_payer : AccountInfo<'info>,
#[account(mut)]
pub mint: Account<'info,anchor_spl::token::Mint>,
#[account(mut)]
pub assoc_token_account: Account<'info,anchor_spl::token::TokenAccount>,

is enough to fire the proper checks.

Platform version:

  • CLI Version [e.g. v0.1.0]
  • GenService Version v0.8

Extension (mark with an X the extension):

  • Solana Native [ ]
  • Solana Anchor [x]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis is an item that causes unwanted behaviorTriageThis item needs to be prioritize

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions