External precondition audit

From PlamenTSV/plamen · View interactive version

External precondition audit is an AI agent skill from the GitHub repository PlamenTSV/plamen. Trigger Pattern Any external package function call detected in program - Inject Into Breadth agents (merged via M5 hierarchy)

How to use this skill

Skill file

Skill: External Precondition Audit (Sui)

Trigger Pattern: Any external package function call detected in program

Inject Into: Breadth agents (merged via M5 hierarchy)

Finding prefix: [EPA-N]

Rules referenced: R1, R4, R8, R10

Constraint: Interface-level inference only -- no production fetch required

use.*external|friend|public.*package|transfer::public_|dynamic_field|coin::from_balance|
clock::timestamp_ms|sui::pay|dex|swap|oracle|price_feed

For every external package the protocol calls:

1. Interface-Level Requirement Inference

From the imported module signatures, infer what the external package requires:

| External Function Called | Parameters Passed | Likely Preconditions (from signature) | Our Protocol Validates? | Package Immutable? |

|-------------------------|-------------------|--------------------------------------|------------------------|--------------------|

Inference method: Read the function signature, type constraints, and any doc comments. Example: pool::swap<A, B>(pool: &mut Pool<A, B>, coin_in: Coin<A>, ...) -> infer that pool must be the correct pool for A/B pair, coin_in must have sufficient balance, and return Coin<B> may have zero value (slippage).

Package immutability check (CRITICAL Sui-specific):

2. Return Value Consumption

| External Call | Return Type | How Protocol Uses Return | Failure Mode if Return Unexpected |

|--------------|-------------|-------------------------|----------------------------------|

For each return value:

Sui-specific: External package calls within a PTB share the same abort scope. If any external call aborts, the entire PTB reverts. Model: can an attacker cause an external call to abort to grief a user's multi-step PTB?

3. State Dependency Mapping

| Protocol State | Depends on External Shared Object | External State Can Change Between Epochs/Txns? |

|---------------|----------------------------------|------------------------------------------------|

For each dependency: model what happens when the external shared object state changes between our protocol's transactions.

Sui-specific concerns:

3b. Package Upgrade Risk Assessment

For each external package dependency:

| External Package | UpgradeCap Status | Upgrade Policy | Impact if Upgraded | Our Protocol's Mitigation |

|------------------|-------------------|---------------|-------------------|--------------------------|

| {package} | {destroyed (immutable) / held by {who}} | {compatible / additive / dep_only / immutable} | {behavior change risk} | {version pin / none} |

Check:

Finding Template

**ID**: [EPA-N]
**Verdict**: CONFIRMED / PARTIAL / REFUTED / CONTESTED
**Step Execution**: (see checklist below)
**Rules Applied**: [R1:___, R4:___, R8:___, R10:___]
**Severity**: Critical/High/Medium/Low/Info
**Location**: sources/{module}.move:LineN
**Title**: {missing external validation / unexpected return / state dependency}
**Description**: {specific issue with code reference}
**Impact**: {what attacker can achieve via the external package weakness}

Step Execution Checklist (MANDATORY)

| Section | Required | Completed? | Notes |

|---------|----------|------------|-------|

| 1. Interface-Level Requirement Inference | YES | | Includes package immutability check |

| 2. Return Value Consumption | YES | | Hot potato return paths checked |

| 3. State Dependency Mapping | YES | | Cross-epoch + package upgrade state |

| 3b. Package Upgrade Risk | YES | | UpgradeCap holder + upgrade policy |

If any step skipped, document valid reason (N/A, no external packages, framework-only deps).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.