agents/skills/aptos/migration-analysis/SKILL.md
Trigger Protocol has migration patterns (reinitialize, V2/V3, deprecated, upgrade, legacy, Coin-to-FA) - Covers Token type mismatches, stranded assets, interface incompatibiliti...
npx skillsauth add plamentsv/plamen migration-analysisInstall 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: Protocol has migration patterns (reinitialize, V2/V3, deprecated, upgrade, legacy, Coin-to-FA) Covers: Token type mismatches, stranded assets, interface incompatibilities, module upgrade safety Required: YES when MIGRATION flag detected
Aptos modules are upgradeable by default under the compatible upgrade policy. Key differences from EVM:
immutable policy freezes module permanently; compatible allows additive changesCoin<T> to FungibleAsset migration is a major ecosystem-wide transitionV2|V3|_deprecated|migrat|upgrade|legacy|old_token|new_token|coin_to_fungible|fungible_asset_to_coin|reinitialize
Find all token migration patterns:
Coin<T> to FungibleAsset migration (ecosystem-wide)For each transition:
| Old Standard/Type | New Standard/Type | Migration Function | Bidirectional? | Framework Support? | |-------------------|-------------------|-------------------|----------------|-------------------| | Coin<CoinType> | FungibleAsset | coin::coin_to_fungible_asset | YES (coin::fungible_asset_to_coin) | aptos_framework | | ModuleV1::Resource | ModuleV2::Resource | custom migrate() | {YES/NO} | N/A |
For each external call that involves migrated tokens or upgraded modules:
Coin<T> or FungibleAsset or Object<Metadata>)// Example mismatch:
// Protocol still uses Coin<USDC>
public fun deposit(coin: Coin<USDC>) { ... }
// But external DEX now returns FungibleAsset
public fun swap(...): FungibleAsset { ... }
// Mismatch: protocol receives FA but expects Coin
Aptos-specific: Check if external modules have migrated from coin to primary_fungible_store while the protocol still uses the coin interface. The aptos_framework provides automatic pairing between Coin<T> and its corresponding FungibleAsset, but this pairing has edge cases.
For each function that interacts with migrated tokens:
| Function | User Provides | Protocol Tracks | External Expects | Mismatch? | |----------|---------------|-----------------|------------------|-----------|
When migration changes token types or interaction patterns, check whether external call side effects produce tokens that the current logic handles correctly.
For each external call that returns tokens or triggers side effects:
| External Call | Pre-Migration Side Effect | Post-Migration Side Effect | Logic Handles Both? | Mismatch? | |---------------|--------------------------|---------------------------|---------------------|-----------| | {ext_call} | Returns Coin<T> | Returns FungibleAsset | YES/NO | {describe} |
Pattern: Migration changes the primary token standard (e.g., Coin -> FA), but external modules still return the old standard as rewards, receipts, or side effects. The new logic may not handle the old token type.
Check: For each external dependency, does the post-migration logic correctly handle ALL token types that external calls can produce -- including legacy types from pre-migration interactions still in flight?
Before analyzing stranded asset paths, inventory what resources CURRENTLY EXIST in global storage:
| Resource Type | Published At | How It Arrived | Post-Upgrade Logic Handles? | Exit Path Post-Upgrade? | |---------------|-------------|---------------|----------------------------|------------------------| | Coin<T> store | User addresses | User deposits via coin::register + deposit | YES/NO | {function or NONE} | | FungibleStore | Object addresses | primary_fungible_store::deposit | YES/NO | {function or NONE} | | Custom resource | @protocol | Module initialization | YES/NO | {function or NONE} |
Pattern: Upgrade changes which token standard the protocol uses, but global storage still holds resources from pre-upgrade operations. If the new logic only handles FungibleAsset, Coin<T> balances at user addresses are stranded.
Check: For every resource type the protocol can create pre-upgrade:
CRITICAL: This step uses exhaustive methodology. Every sub-step is MANDATORY.
List ALL assets the protocol handles, categorized by migration era:
| Asset | V1 Entry Path | V2 Entry Path | V1 Exit Path | V2 Exit Path | |-------|---------------|---------------|--------------|--------------| | Coin<T> balance | deposit_coin() | N/A (removed) | withdraw_coin() | withdraw() converts? | | FungibleAsset balance | N/A | deposit_fa() | N/A | withdraw_fa() |
Rule: If V1 Entry exists but V2 Exit does not handle V1 state -> potential stranding
For EACH asset and EACH possible state combination:
| Asset Era | State Condition | Available Exit Paths | Works? | Reason | |-----------|-----------------|---------------------|--------|--------| | V1 Coin deposit | V2 logic active | withdraw() | Y/N | {does V2 read CoinStore?} | | V1 Coin deposit | V1 functions removed in upgrade | withdraw_coin() | Y/N | {removed in compatible upgrade?} | | V1 resource | In-flight during upgrade | ??? | Y/N | {resource persists but handler changed} |
Aptos-specific: Under compatible upgrade policy, public functions cannot be removed -- only new functions can be added. However, the function logic CAN change. A V1 function that previously handled Coin<T> might be updated to expect FungibleAsset internally, breaking for users with V1 state.
STRANDING RULE: If ALL exit paths = N for any state -> STRANDED ASSETS FINDING
Document ALL functions that could recover stranded assets:
| Function | Who Can Call | What Assets Can Recover | Limitations | |----------|--------------|------------------------|-------------| | admin_rescue() | Admin signer | All resources at @protocol | Requires admin action | | migrate_user() | Any user | User own Coin -> FA | One-time conversion | | sweep() | Admin | Unaccounted tokens | Cannot recover user resources at their addresses |
Question: Is there a recovery path for EVERY stranding scenario in 4b?
Model these specific scenarios with code traces:
Scenario 1: V1 Deposit + V2 Logic
State: User deposited via V1 function, CoinStore<T> has balance
Event: Protocol upgraded to V2 (now uses FungibleAsset internally)
Question: Can user withdraw via V2 withdraw()?
Trace: [document code path -- does V2 read CoinStore or only FungibleStore?]
Result: [SUCCESS/STRANDED + amount]
Scenario 2: Resource Persistence After Upgrade
State: Custom resource R published at user address by V1 logic
Event: V2 module changes struct R layout (adds new field at end)
Question: Can V2 functions read/use the old R?
Trace: [compatible upgrade -- struct deserialization with new fields defaulting]
Result: [SUCCESS/ABORT + which functions break]
Scenario 3: Paired Coin/FA Migration
State: Protocol has Coin<T> and paired FungibleAsset for same underlying
Event: External module migrates to FA only, stops accepting Coin<T>
Question: Can protocol still interact with external module?
Trace: [does protocol auto-convert via coin::coin_to_fungible_asset?]
Result: [SUCCESS/STRANDED + which paths break]
Step Execution Output: check4a,4b,4c,4d,4e or ?4X(incomplete reason)
Check whether user actions can create state that prevents admin migration or management operations:
| Admin/Migration Function | Precondition Required | User Action That Blocks It | Timing Window | Severity | |--------------------------|----------------------|---------------------------|---------------|----------| | {admin_func} | {precondition} | {user_action creating conflicting state} | {window size} | {assess} |
Pattern: Admin migration or management functions require certain state conditions (e.g., "no pending operations", "all users migrated", "no active borrows"). Users performing normal operations (deposits, withdrawals, claims) may create state that blocks these admin functions.
Aptos-specific: Resource existence checks (exists<R>(addr)) used as preconditions -- can a user create or destroy a resource to block admin functions?
Check for each admin/migration function:
If blocking is possible AND permanent -> minimum MEDIUM severity If blocking is temporary but repeatable -> assess with Rule 10 worst-state
For each external call:
| External Module | Function | Protocol Sends | Module Expects | Match? | |----------------|----------|----------------|-----------------|--------| | aptos_framework::coin | withdraw<T> | signer + amount | signer must have CoinStore<T> | VERIFY | | dex_module::swap | swap() | FungibleAsset | FungibleAsset with correct metadata | VERIFY | | oracle::get_price | get_price() | - | Returns u64 or FixedPoint64? | VERIFY |
When the protocol changes token standards, interfaces, or behavior during migration, check how downstream consumers are affected:
| Protocol Change | Downstream Consumer Type | Expected Interface/Token | Actual Post-Migration | Breaking Change? | |-----------------|--------------------------|--------------------------|----------------------|-----------------| | {what changed} | DeFi integrations (DEX, lending) | {expected Coin<T>?} | {actual FA?} | YES/NO | | {what changed} | Indexers/APIs | {expected events} | {actual events} | YES/NO | | {what changed} | Other protocol modules | {expected function sig} | {actual -- compatible?} | YES/NO | | {what changed} | View functions | {expected return type} | {actual return type} | YES/NO |
Pattern: Protocol migrates from Coin<T> to FungibleAsset, but downstream integrators still call the old Coin<T> interface. Under compatible upgrade policy, old functions remain callable but may behave differently internally.
Check:
compatible policy, public function signatures cannot change -- but internal behavior CAN{CONTRACTS} -- List of modules to analyze
{MIGRATION_TYPE} -- Coin-to-FA / V1-to-V2 / Module upgrade
{OLD_STANDARD} -- What the protocol used before
{NEW_STANDARD} -- What the protocol uses now
{EXTERNAL_MODULES} -- External modules that may have migrated independently
For each finding:
## Finding [MG-N]: Title
**Verdict**: CONFIRMED / PARTIAL / REFUTED / CONTESTED
**Step Execution**: check1,2,3,4,5 | X(reason) | ?(uncertain)
**Severity**: Critical/High/Medium/Low/Info
**Location**: module::function (source_file.move:LineN)
**Token Transition**:
- Old: {old_standard/type}
- New: {new_standard/type}
- Mismatch Point: {where types diverge}
**Description**: What is wrong
**Impact**: What can happen (stranded funds, wrong accounting, DoS)
**Evidence**: Code showing mismatch
### Precondition Analysis (if PARTIAL/REFUTED)
**Missing Precondition**: [What blocks exploitation]
**Precondition Type**: STATE / ACCESS / TIMING / EXTERNAL / BALANCE
### Postcondition Analysis (if CONFIRMED/PARTIAL)
**Postconditions Created**: [What conditions this creates]
**Postcondition Types**: [List applicable types]
After completing analysis, verify:
If any step skipped, document valid reason (N/A, single token, no external deps, no downstream consumers).
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