Skip to content

Add Token-2022 basics Pinocchio example - #705

Open
MarkFeder wants to merge 2 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-basics-pinocchio
Open

Add Token-2022 basics Pinocchio example#705
MarkFeder wants to merge 2 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-basics-pinocchio

Conversation

@MarkFeder

Copy link
Copy Markdown
Contributor

Ports the anchor tokens/token-2022/basics example to Pinocchio.

Exposes the same five instructions, dispatched on a leading discriminator byte:

  • CreateToken — creates a Token-2022 mint (6 decimals, no extensions) at the [b"token-2022-token", signer, token_name] PDA, signed by the PDA; signer is the mint authority, no freeze authority.
  • CreateTokenAccount — creates a Token-2022 token account at the [b"token-2022-token-account", signer, mint] PDA (the anchor example's non-ATA reference path).
  • CreateAssociatedTokenAccount — creates the signer's ATA via pinocchio-associated-token-account (program-agnostic; the Token-2022 program is passed through).
  • MintToken / TransferTokenMintTo and TransferChecked; transfer creates the recipient's ATA idempotently first.

There is no Pinocchio crate for Token-2022, so its instructions (InitializeMint2, InitializeAccount3, MintTo, TransferChecked) are built by hand and CPI'd — matching the sibling immutable-owner/group examples.

A single LiteSVM test drives all five instructions end to end and asserts balances, account sizes, and owners with the official Token-2022 codec.

@MarkFeder
MarkFeder requested a review from dev-jodee as a code owner August 29, 2026 18:28
@greptile-apps

greptile-apps Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a Pinocchio implementation of the Token-2022 basics example, covering mint creation, token-account creation, associated accounts, minting, and checked transfers.

  • Adds the on-chain Pinocchio program and manual Token-2022 CPI instruction encoding.
  • Adds LiteSVM coverage for the five supported instructions and oversized PDA seed rejection.
  • Registers the program in the Rust workspace and adds its TypeScript test/build configuration.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
tokens/token-2022/basics/pinocchio/program/src/instructions/create_token.rs Creates the Token-2022 mint PDA and now rejects token-name seeds longer than 32 bytes before derivation, resolving the previous finding.
tokens/token-2022/basics/pinocchio/program/src/processor.rs Dispatches the five instructions by discriminator and forwards all remaining CreateToken bytes through the validated token-name path.
tokens/token-2022/basics/pinocchio/tests/test.ts Exercises the complete token lifecycle and verifies that a 33-byte token-name seed is rejected.
tokens/token-2022/basics/pinocchio/program/src/instructions/transfer_token.rs Creates the recipient ATA idempotently and performs a Token-2022 TransferChecked CPI.
tokens/token-2022/basics/pinocchio/program/src/instructions/create_token_account.rs Creates and initializes the signer-scoped Token-2022 token-account PDA.

Reviews (2): Last reviewed commit: "token-2022 basics: reject oversized toke..." | Re-trigger Greptile

Comment on lines +35 to +37
// Derive the mint PDA and confirm the supplied account matches it.
let (mint_pda, bump) =
Address::find_program_address(&[TOKEN_SEED, signer.address().as_ref(), token_name], program_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unbounded PDA seed input

token_name contains all instruction bytes after the discriminator and is passed directly to find_program_address. Names longer than Solana's 32-byte per-seed limit reach invalid PDA derivation instead of returning a deliberate InvalidInstructionData error.

Suggested change
// Derive the mint PDA and confirm the supplied account matches it.
let (mint_pda, bump) =
Address::find_program_address(&[TOKEN_SEED, signer.address().as_ref(), token_name], program_id);
// Derive the mint PDA and confirm the supplied account matches it.
if token_name.len() > 32 {
return Err(ProgramError::InvalidInstructionData);
}
let (mint_pda, bump) =
Address::find_program_address(&[TOKEN_SEED, signer.address().as_ref(), token_name], program_id);

Knowledge Base Used: Program-derived address design

@MarkFeder

Copy link
Copy Markdown
Contributor Author

Good catch — pushed 766e743: create_token now rejects a token_name longer than 32 bytes (the PDA seed limit) with InvalidInstructionData before derivation, plus a test asserting the oversized name is rejected.

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.

1 participant