A Solana vault program built with Anchor for security research and vulnerability analysis practice. This program implements a token vault system with share-based deposits and redemptions, along with protocol ownership management.
DO NOT USE THIS CODE IN PRODUCTION!
This program contains intentional security vulnerabilities for educational and training purposes. It is designed for security researchers and developers to practice identifying and exploiting common Solana program vulnerabilities.
Using this code with real funds will result in loss of assets.
Note for Security Researchers: This program is designed as a practice environment for finding and exploiting common Solana program vulnerabilities. Some tests are intentionally left as placeholders for you to implement proof-of-concept exploits.
The Vault PDA program demonstrates core Solana concepts including:
- Program Derived Addresses (PDAs) for deterministic account derivation
- Token minting and burning using SPL Token program
- Share-based vault mechanics with proportional deposit/redeem calculations
- Protocol-level authority management with ownership controls
- Multi-vault architecture supporting different underlying assets
Located in programs/vault-pda/src/instructions/:
-
initialize- Initializes the protocol (one-time setup)- Creates the
ProtocolStateaccount to store the protocol owner - Creates the
VaultAuthorityPDA that serves as mint/burn authority for all vaults
- Creates the
-
initialize_vault- Creates a new vault for a specific underlying token- Creates a
Vaultaccount (PDA derived from underlying mint) - Creates a
share_mintfor vault shares - Sets the vault_authority as the mint authority
- Creates a
-
deposit- Deposit underlying tokens and receive vault shares- First deposit: 1:1 share minting
- Subsequent deposits: Proportional shares based on vault state
- Formula:
shares = (amount × total_shares) / total_assets
-
redeem- Burn vault shares and withdraw underlying tokens- Proportional redemption based on share amount
- Formula:
underlying = (shares × total_assets) / total_shares
-
transfer_ownership- Transfer protocol ownership to a new owner- Updates the owner in ProtocolState
- Validates ownership before transfer
Located in programs/vault-pda/src/state/:
-
ProtocolState- Stores the protocol owner
- PDA seeds:
[b"protocol_state"] - Size: 41 bytes
-
VaultAuthority- Global authority for minting/burning vault shares
- PDA seeds:
[b"vault_authority"] - Size: 9 bytes
-
Vault- Stores vault configuration for each underlying asset
- Contains share_mint, underlying_mint, and vault_token_account references
- PDA seeds:
[b"vault", underlying_mint] - Size: 105 bytes
solana-program/
├── programs/
│ └── vault-pda/
│ ├── src/
│ │ ├── lib.rs # Program entry point
│ │ ├── instructions/ # Instruction handlers
│ │ │ ├── initialize.rs
│ │ │ ├── initialize_vault.rs
│ │ │ ├── deposit.rs
│ │ │ ├── redeem.rs
│ │ │ ├── transfer_ownership.rs
│ │ │ └── mod.rs
│ │ ├── state/ # State account definitions
│ │ │ ├── protocol_state.rs
│ │ │ ├── vault_authority.rs
│ │ │ ├── vault.rs
│ │ │ └── mod.rs
│ │ ├── constants.rs
│ │ └── error.rs
│ └── Cargo.toml
├── tests/
│ └── vault-pda.ts # Integration tests
├── Anchor.toml # Anchor configuration
└── package.json # Node dependencies
- Rust (latest stable version)
- Solana CLI (v1.18.0 or higher)
- Anchor (v0.31.1)
- Node.js (v18 or higher)
- Yarn
- Clone the repository:
git clone <repository-url>
cd solana-program- Install dependencies:
yarn install- Build the program:
anchor build- Run tests:
anchor testanchor testThis command will:
- Start a local Solana test validator
- Build the program
- Deploy the program to the local validator
- Run the test suite
- Stop the validator
anchor test --skip-local-validatorUse this if you already have a validator running on localhost:8899.
The test suite (tests/vault-pda.ts) includes:
Functional Tests:
- Initializes the protocol
- Creates an underlying token mint
- Initializes a vault for the underlying token
- Makes first deposit (1:1 share calculation)
- Makes second deposit (proportional share calculation)
- Redeems partial shares
- Redeems all remaining shares
Security Tests: 8. PoC Placeholder - For security researchers to implement exploits 9. Second PoC Placeholder - For security researchers to implement exploits
For Security Researchers: Tests 8 and 9 are intentionally left as placeholders. Your task is to analyze the program, find vulnerabilities, and implement proof-of-concept exploits in these test cases.
This program is designed to help beginner security researchers practice:
- Finding missing account validations
- Identifying authorization vulnerabilities
- Understanding the difference between pubkey checks and signature verification
- Learning why passing tests don't guarantee secure code
- Writing proof-of-concept exploits
The program ID is declared in lib.rs:
8qsydpwMiRcFtJ8wrKkM4xrMMEWfnw2szibQGLgBw6KH
- PDA Derivation: All program accounts use PDAs for deterministic addresses
- Token Interface: Uses
anchor_spl::token_interfacefor compatibility with Token and Token-2022 - Global Authority: Single
vault_authorityPDA manages all vault share mints - Vault Isolation: Each underlying asset gets its own isolated vault
- Share Mechanics: Proportional share calculations for fair deposits and redemptions
ISC