ability-analysis
Trigger Pattern Always (Aptos Move) - foundational security check - Inject Into Breadth…
Trigger Pattern Vault/pool/first-depositor pattern detected - Inject Into Depth-edge-case
$ npx -y skills add PlamenTSV/plamen --skill zero-state-return --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/zero-state-returnContext preview
The summary Claude sees to decide when to auto-load this skill.
Trigger Pattern Vault/pool/first-depositor pattern detected - Inject Into Depth-edge-case
name: "zero-state-return" description: "Trigger Pattern Vault/pool/first-depositor pattern detected - Inject Into Depth-edge-case"
> **Trigger Pattern**: Vault/pool/first-depositor pattern detected > **Inject Into**: Depth-edge-case > **Purpose**: Analyze zero-state transitions in Aptos Move protocols -- initial zero state, return to zero after operations, residual assets, and re-entry vulnerabilities
This skill covers BOTH initial zero state AND return-to-zero-state analysis:
Find all vault/pool/staking mechanisms and their zero-state boundaries:
| State | Resource / Variable | Zero Condition | Trigger | Code Location | |-------|-------------------|----------------|---------|---------------| | Total shares | {resource.total_supply} | `== 0` | All users withdrew/burned | {module:line} | | Total assets | {resource.total_assets} | `== 0` | No funds deposited | {module:line} | | Pool liquidity | {resource.reserves} | Both reserves `== 0` | All LP withdrawn | {module:line} | | Staking pool | {resource.total_staked} | `== 0` | All unstaked | {module:line} |
For each state: what is the protocol behavior when this condition is true?
Can the first depositor manipulate share price?
| Protocol | Formula | When totalShares == 0 | First Deposit Behavior | |----------|---------|----------------------|----------------------| | {name} | `shares = amount * totalShares / totalAssets` | {special case?} | {describe} |
**Classic first depositor attack on Aptos**: 1. First depositor deposits minimal amount (e.g., 1 unit) 2. Attacker directly deposits tokens to the protocol's FungibleStore (unsolicited -- bypasses accounting) 3. Exchange rate inflates: `totalAssets` increases but `totalShares` stays at 1 4. Next depositor receives 0 shares due to rounding (their deposit amount < inflated share price) 5. First depositor withdraws, capturing the second depositor's funds
**Checks**:
| Protection | Present? | Implementation | Bypass Possible? | |-----------|----------|----------------|-----------------| | Minimum first deposit | YES/NO | {code ref} | {analysis} | | Virtual shares/assets offset | YES/NO | {code ref} | {analysis} | | Dead shares (initial mint to zero) | YES/NO | {code ref} | {analysis} | | Internal accounting (not balance-based) | YES/NO | {code ref} | {analysis} | | Decimal offset in share calculation | YES/NO | {code ref} | {analysis} |
After normal operations, can the protocol return to zero state?
| Scenario | Trigger | Residual State After | Re-entry Safe? | |----------|---------|---------------------|---------------| | All shares redeemed | Last user withdraws | {what remains?} | YES/NO | | Emergency withdraw | Admin drains | {what remains?} | YES/NO | | All stakers unstake | Last unstake | {what remains?} | YES/NO | | Pool fully drained | All LP removed | {what remains?} | YES/NO |
Trace the withdrawal/burn path:
When supply returns to zero, check for stranded value:
| Reward Source | Persists When totalShares = 0? | Claimable By Next Depositor? | Amount Bounded? | |-------------|-------------------------------|-----------------------------:|----------------| | {reward_source} | YES/NO | YES/NO | {max amount or UNBOUNDED} |
If rewards persist AND next depositor can claim -> FINDING (severity based on amount).
| Fee Type | Persists When totalShares = 0? | Captured By Next Depositor? | Reconciliation Mechanism? | |----------|-------------------------------|----------------------------|--------------------------| | {fee_type} | YES/NO | YES/NO | {mechanism or NONE} |
Does re-entering zero state recreate first-depositor attack conditions?
| Scenario | Initial State | Return-to-Zero State | Same Vulnerability? | |----------|---------------|---------------------|---------------------| | First depositor attack | totalSupply=0, totalAssets=0 | totalSupply=0, totalAssets=X (residual) | **WORSE** if residual > 0 | | Exchange rate manipulation | No shares exist | No shares, but balance exists | YES + amplified | | Donation attack | Clean state | Dirty state | YES + pre-seeded |
**Key question**: Is the first-deposit protection (from Section 2b) applied ONLY on initial deployment, or does
Autonomous Web3 security auditor for Claude Code and OpenAI Codex CLI. Orchestrates 18-100 AI agents across 40+ phases to produce audit reports with verified PoC exploits — for smart contracts and L1 node-client infrastructure.
Repo: PlamenTSV/plamen
Trigger Pattern Always (Aptos Move) - foundational security check - Inject Into Breadth…
Trigger Pattern Always (Aptos Move) - Move VM aborts on shift = bit width - Inject Into…
Trigger Protocol has privileged roles (admin, operator, governance, resource account owner) -…
Trigger EXTERNAL_LIB flag detected (protocol uses third-party Move dependencies) - Used by…
Trigger Pattern MONETARY_PARAMETER flag (required) - Inject Into Breadth agents (merged via…