Skip to content
← Browse all courses
Solana topic

Pinocchio vs Anchor for Solana programs

Measured first (psyto/pinocchio-bench: Anchor 0.32.1, Pinocchio 0.11.1, LiteSVM, median of 100 runs, 2026-06-06): a signer check plus one state write costs 908 CU in Anchor and 38 in Pinocchio; an SPL Token transfer CPI 3,856 vs 1,179; a Kamino-shaped lending refresh with five mutable accounts 2,956 vs 685; a Token-2022 transfer through a no-op hook 12,352 vs 8,169. The gap grows by about 329 CU per extra mutable account and about 1,968 CU per extra CPI hop, and the Pinocchio binaries are about 16 to 59 times smaller.

Anchor is a framework. #[program] generates the instruction dispatch (each instruction has a discriminator, 8 bytes by default), #[account] gives each account type a discriminator and Borsh serialization, #[derive(Accounts)] generates the account checks you declare as constraints (has_one, seeds, owner, signer), and the build produces an IDL for clients.

Pinocchio (anza-xyz/pinocchio) is a library for writing native programs without those macros: a no_std entrypoint, direct access to the account data the runtime passes in, and helpers for PDAs and CPI. You write the dispatch, the byte layout and every account check yourself, so nothing is generated between your checks and the bytes.

The difference that matters later is where the checks live. In Anchor most are attributes on the accounts struct; in a Pinocchio program they are ordinary if statements in the handler. In both, a later change can drop a check without any test failing. Over 1,133 merged pull requests of ten public Anchor programs, solinv found two mango-v4 changes that dropped a has_one an audit restored 7 and 17 days later; over 1,164 commits of native and Pinocchio code (percolator-prog, SPL Token and p-token, princeps-solana, openhl-solana) it raised 43 warnings, 10 of them real loosenings. On a pull request, a removed Anchor constraint fails solinv and a removed native or Pinocchio check is a warning.

API at a glance

pinocchio::program_entrypoint!(process_instruction); pinocchio::default_allocator!(); pinocchio::nostd_panic_handler!();
The entrypoint, allocator and panic handler of a no_std program. process_instruction receives (program_id: &Pubkey, accounts: &[AccountInfo], data: &[u8]) and returns ProgramResult; the dispatch on data is yours.
account.owner() / account.try_borrow_mut_data()
Read who owns an account and borrow its bytes. Checks such as "this mint is owned by Token-2022" are written as comparisons on owner(); the layout is read from the borrowed bytes (princeps-solana casts them with bytemuck).
pubkey::find_program_address(seeds, program_id) / create_program_address(seeds_with_bump, program_id)
Derive a PDA. find_program_address searches for the bump; create_program_address checks a bump you stored, which is cheaper on later calls.
CreateAccount { from, to, lamports, space, owner }.invoke_signed(&[signer])
Create an account at a PDA through the System program (pinocchio-system), signing for the PDA with a Signer built from its seeds and bump (instruction::{Seed, Signer}).
pinocchio::cpi::slice_invoke_signed(&instruction, &account_infos, signers)
Call any other program (for example a Token-2022 transfer) with an Instruction you build from AccountMeta entries, signing with PDA signers where needed.

Checked against psyto/princeps-solana at f316295 (2026-11-06): programs/psol-vault/src/lib.rs, Cargo.toml

Related parts

Lessons on this topic