ability-analysis
Trigger Pattern Always (Aptos Move) - foundational security check - Inject Into Breadth…
Trigger Pattern Always (Aptos Move) - generic type exploitation - Inject Into Breadth agents, depth-state-trace
$ npx -y skills add PlamenTSV/plamen --skill type-safety --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/type-safetyContext preview
The summary Claude sees to decide when to auto-load this skill.
Trigger Pattern Always (Aptos Move) - generic type exploitation - Inject Into Breadth agents, depth-state-trace
name: "type-safety" description: "Trigger Pattern Always (Aptos Move) - generic type exploitation - Inject Into Breadth agents, depth-state-trace"
> **Trigger Pattern**: Always (Aptos Move) --- generic type exploitation > **Inject Into**: Breadth agents, depth-state-trace
Move's type system is its primary security mechanism. Generic type parameters allow modules to be polymorphic, but incorrect or insufficient type constraints enable attackers to substitute unexpected types, bypass access control, confuse token types, or exploit phantom type assumptions. This skill audits every generic interface for type safety violations.
**STEP PRIORITY**: Steps 2 (Type Parameter Substitution) and 5 (Coin/FungibleAsset Type Confusion) are where HIGH/CRITICAL severity findings most commonly hide. Do NOT rush these steps. If constrained, skip conditional sections (3, 4) before skipping 2 or 5.
Enumerate ALL public, public(friend), and entry functions with generic type parameters:
| Function | Module | Type Params | Constraints | Visibility | Entry? | Who Can Call | |----------|--------|-------------|-------------|-----------|--------|-------------| | `withdraw<T>` | vault | T | `key` | public | YES | Any signer | | `swap<X, Y>` | dex | X, Y | `store` | public | YES | Any signer |
**MANDATORY GREP**: Search all `.move` files for `fun .*<` to find every generic function. Include internal (`fun`), `public(friend) fun`, `public fun`, and `public entry fun`.
For each generic function, additionally note:
For each generic function identified in Step 1, analyze what happens when an attacker substitutes an unexpected type:
| Function | Type Param | Expected Type | Attacker Substitutes | Guard Against Wrong Type? | Impact | |----------|-----------|---------------|---------------------|--------------------------|--------| | `withdraw<T>(store)` | T | RealCoin | FakeCoin (attacker-defined) | YES --- {mechanism} / NO | {impact} |
**Attack methodology per function**:
1. **Identify expected type**: What type does the protocol developer intend callers to use? This is often documented but NOT enforced at the type level. 2. **Check enforcement**: Is there an on-chain mechanism that restricts T to the expected type? Common mechanisms:
3. **If NO enforcement**: What happens if attacker creates `module attacker::fake { struct FakeCoin has store {} }` and calls `withdraw<FakeCoin>()`?
For protocols with pools, markets, or vaults parameterized by type:
| Pool/Market | Type Parameter | Can Attacker Create Pool With Arbitrary Type? | Impact If Confusion | |-------------|---------------|----------------------------------------------|---------------------| | `Pool<T>` | T | YES --- anyone can call `create_pool<T>()` / NO | {drain, mispricing, accounting error} |
**Check**: If Pool<RealCoin> and Pool<FakeCoin> exist, can operations on one affect the other? Common issues:
Tag: `[TRACE:substitute T=FakeCoin → {function} → {bypass/confusion} → impact: {X}]`
For structs with phantom type parameters (`phantom T`):
| Struct | Phantom Param | Purpose | Runtime Impact of T | Can T Be Forged? | |--------|--------------|---------|--------------------|--------------------| | `Pool<phantom CoinType>` | CoinType | Type-tag discrimination | None (phantom) | {analysis} |
**Phantom type rules in Move**:
**Check for each phantom type**: 1. Is the phantom parameter used ONLY for type discrimination (correct use)? 2. Does any function extract or operate on the phantom type at runtime? (should be impossible by compiler, but verify no workarounds) 3. Can an attacker create a struct with a phantom type that aliases an existing legitimate phantom type? (e.g., creating `Pool<AttackerCoin>` that interacts with `Pool<USDC>` state) 4. Are phantom type parameters properly propagated through nested generics? (`Wrapper<phantom T>` containing `Inner<T>` --- is T phantom in Inner too?)
| Pattern | Risk | Check | |---------|------|-------| | Phantom used for access control | Medium | Can attacker define their own type to bypass access gate? | | Phantom used for pool isolation | High | Does pool isolation rely solely on phantom type discrimination? | | Phantom type in event emission | Low | Can attacker emit events with spoofed phantom types for off-chain confusion? |
For functions that accept type witnesses:
| Witness Struct | Creating Module | Who Can
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…