Anchor Framework
The standard development framework for Solana programs that provides declarative security constraints, automatic account validation, and serialization through Rust macros.
The Anchor framework is the dominant development framework for building programs on Solana. It provides a set of Rust macros and abstractions that handle boilerplate tasks like account deserialization, ownership checks, and PDA validation, allowing developers to focus on business logic. Anchor has become the de facto "standard library" of the Solana ecosystem, similar to how Hardhat and Foundry serve the Ethereum development workflow.
Core features
Declarative account validation: Anchor's #[derive(Accounts)] macro generates account validation logic from struct-level attributes. Constraints like has_one, seeds, and constraint are checked before the instruction handler executes.
1#[derive(Accounts)]2pub struct Initialize<'info> {3 #[account(4 init,5 payer = authority,6 space = 8 + 32 + 8,7 seeds = [b"vault", authority.key().as_ref()],8 bump9 )]10 pub vault: Account<'info, Vault>,11 #[account(mut)]12 pub authority: Signer<'info>,13 pub system_program: Program<'info, System>,14}
Automatic discriminators: Anchor prepends an 8-byte discriminator (SHA-256 hash of the account type name) to all account data. This prevents type cosplay attacks where a Borsh-deserialized account of one type is misinterpreted as another.
IDL generation: Anchor automatically generates an Interface Description Language (IDL) file that describes the program's instructions and accounts, enabling client-side SDK generation.
Security constraints reference
| Constraint | Purpose |
|---|---|
has_one = field | Verifies an account matches a stored public key |
seeds = [...] | Validates PDA derivation with canonical bump |
constraint = expr | Custom boolean validation expression |
close = target | Closes account and transfers lamports |
realloc | Safely resizes account data |
Audit considerations
While Anchor eliminates entire classes of vulnerabilities through its constraint system, auditors should still verify:
- Custom
constraintexpressions cover all edge cases remaining_accounts(unvalidated accounts passed outside the struct) are properly checked in the instruction handler- CPI calls within Anchor programs correctly propagate signer seeds
- Account
closeoperations handle the rent-refund vulnerability (account can be reopened in the same transaction)
Anchor significantly raises the security baseline for Solana programs, but its abstractions can also hide subtle vulnerabilities from developers who do not understand the underlying native mechanics.
Articles Using This Term
Learn more about Anchor Framework in these articles:
Related Terms
SVM (Solana Virtual Machine)
The runtime environment that executes programs on Solana using a parallelized, stateless account model, compiled to Solana Bytecode Format (SBF).
Program Derived Address (PDA)
A deterministic address derived from a combination of seeds and a program ID that falls off the Ed25519 curve, allowing programs to sign transactions without a private key.
Borsh
Binary Object Representation Serializer for Hashing, a deterministic serialization format used by Solana for encoding and decoding on-chain account data.
Bump Seed Canonicalization
The practice of using the first valid bump seed found during PDA derivation to ensure a single canonical address per seed set, preventing duplicate account attacks.
Need expert guidance on Anchor Framework?
Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.
Get a Quote

