agents/skills/solana/share-allocation-fairness/SKILL.md
Trigger Pattern SHARE_ALLOCATION flag detected in pattern scan - Inject Into Breadth agents, depth-edge-case
npx skillsauth add plamentsv/plamen share-allocation-fairnessInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Trigger Pattern: SHARE_ALLOCATION flag detected in pattern scan Inject Into: Breadth agents, depth-edge-case Finding prefix:
[SAF-N]Rules referenced: S1, S4, S9, R5, R10, R13, R14
shares|allocation|distribute|pro.rata|proportional|vest|reward.*per.*share|
mint_to|burn_from|reward_index|cumulative
Analyze fairness of share/token allocation mechanisms on Solana where users receive SPL Token shares proportional to deposits, contributions, or participation -- checking for late-entry advantages, PDA-based accounting manipulation, queue-position gaming, and time-weighting omissions.
Identify which pattern the protocol uses:
| Type | Solana Pattern | Key Risk |
|------|---------------|----------|
| Pro-rata snapshot | SPL shares minted at fixed ratio via mint_to at deposit time | Late depositors dilute early depositors' accrued value |
| Time-weighted | Per-user PDA tracks reward_per_share_paid and accrued_rewards | Checkpoint manipulation, stale reward index |
| Queue-based | Account-based queue (Vec in PDA or linked PDAs) | Queue position gaming, front-running batch processing via MEV bundles |
| Epoch-based | Shares valued per epoch boundary, epoch tracked in global PDA | Cross-epoch timing arbitrage at epoch transition slots |
For each allocation entry instruction:
| Entry Instruction | Accrual Source | Time-Weighted? | Late Entry Possible? | Impact | |------------------|----------------|----------------|---------------------|--------|
Solana-specific timing: With 400ms slots, timing attacks are tighter but MEV bundles allow precise instruction ordering within a slot. An attacker can bundle: [deposit_ix] -> [crank_distribute_ix] to enter just before distribution.
For each entry instruction accepting a beneficiary: Pubkey parameter or deriving a PDA from a user key that is NOT the signer:
| Entry Instruction | Accepts Beneficiary? | Default State for New PDA | Exploitable? | Impact | |------------------|---------------------|--------------------------|-------------|--------|
Check: When a PDA is initialized for a new beneficiary address:
reward_per_share_paid = 0? last_deposit_slot = 0?)reward_per_share_paid starts at 0 while the global index is at N, the new PDA holder is entitled to ALL historical rewards on their deposit -- FINDING (late-entry variant)deposit(beneficiary, amount) where beneficiary != signer be used to create a new PDA that captures historical rewards the beneficiary did not earn?init vs init_if_needed? With init_if_needed, repeated deposits for the same beneficiary reuse the existing PDA, but first deposit creates it with potentially exploitable defaults.For each authority-settable reward/rate parameter:
| Parameter Setter | Staked-Before-Set? | Retroactive Rewards? | Fair? | |-----------------|-------------------|---------------------|-------|
Model the sequence: user deposits (PDA created with current index) -> authority sets reward rate -> rewards accrue.
For the allocation mechanism identified in Step 1:
| Configuration Step | Account/PDA Initialized | Instructions Available Before Init | Exploitable Default? | |--------------------|------------------------|-----------------------------------|---------------------|
initialize_* instructions in order.is_initialized flag that prevents interaction before configuration completes?If users can interact during partial initialization AND default PDA values create unfair advantage → FINDING (minimum Medium, Rule 13: design gap).
For protocols with batch/queue processing:
CU-aware batching: If batch processing iterates over a Vec<Pubkey> in a PDA:
Check that entry and exit use consistent valuation:
SPL Token authority risks:
For independently-settable allocation rates/shares (e.g., per-pool weights, fee splits, distribution percentages stored in separate PDAs):
| Rate/Weight Setter | Aggregate Constraint | Enforced On-Chain? | What if Sum Exceeds/Falls Short? | |-------------------|---------------------|-------------------|--------------------------------|
Solana-specific: If weights are stored in separate PDA accounts (one per pool/vault), the setter instruction may update ONE PDA without checking the sum across ALL PDAs. This requires reading multiple accounts in one instruction -- check if the instruction accounts struct includes ALL weight PDAs for validation.
If aggregate constraint NOT enforced and rates independently settable -> FINDING (Rule 14).
Also check: Can the authority set a weight to 0 for an active pool? What happens to users with deposits in that pool? (Rule 14 setter regression -- setting weight below accumulated state)
For each finding, specify:
**ID**: [SAF-N]
**Verdict**: CONFIRMED / PARTIAL / REFUTED / CONTESTED
**Step Execution**: (see checklist below)
**Rules Applied**: [S1:___, S4:___, S9:___, R5:___, R10:___, R13:___, R14:___]
**Severity**: Critical/High/Medium/Low/Info
**Location**: programs/{program}/src/instructions/{file}.rs:LineN
**Title**: {fairness violation type}
**Description**: {specific issue with numerical example}
**Impact**: {quantified at worst-state parameters -- who loses how much}
| Step | Required | Completed? | Notes | |------|----------|------------|-------| | 1. Classify Allocation Mechanism | YES | | | | 2. Late Entry Attack Model | YES | | | | 2c. Cross-Address Deposit Model | YES | | Check beneficiary != signer patterns | | 2d. Pre-Setter Timing Model | YES | | Model deposit-before-rate-set sequence | | 2e. Pre-Configuration State Analysis | YES | | Deployment window + unconfigured defaults | | 3. Queue Position and Batch Processing | IF queue/batch detected | | Include CU-aware batch analysis | | 4. Share Redemption Symmetry | YES | | Include mint/freeze authority check | | 4b. Aggregate Constraint Coherence | IF multiple settable weights | | Rule 14 enforcement check |
If any step skipped, document valid reason (N/A, no queue, single pool, no settable weights).
development
Prepare Solidity projects for a security audit — test coverage, test quality, NatSpec docs, code hygiene, dependency health, best-practice enforcement, deployment readiness, and project documentation checks. Generates a scored Audit Readiness Report and optionally runs static analysis. Trigger on: "prepare for audit", "audit readiness", "pre-audit check", "audit prep", "NatSpec check", or any request to review a Solidity codebase before a security review.
development
Launch the Plamen deterministic Web3 security audit pipeline
development
Run the Plamen smart-contract audit wizard in Codex
testing
Launch the Plamen deterministic L1 infrastructure audit pipeline