Object ownership

From PlamenTSV/plamen · View interactive version

Object ownership is an AI agent skill from the GitHub repository PlamenTSV/plamen. Trigger Pattern Always required for Sui Move audits -- object lifecycle and ownership model - Inject Into Breadth agents, depth-state-trace, depth-token-flow

How to use this skill

Skill file

OBJECT_OWNERSHIP Skill

Trigger Pattern: Always required for Sui Move audits -- object lifecycle and ownership model

Inject Into: Breadth agents, depth-state-trace, depth-token-flow

Finding prefix: [OO-N]

Rules referenced: R4, R5, R9, R10, R13

Sui's object-centric model is fundamentally different from account-based chains. Every struct with the key ability is an on-chain object with a globally unique ID, and its ownership model (owned/shared/frozen/wrapped) determines who can access and mutate it. Incorrect ownership choices, missing transfer restrictions, orphaned UIDs, and uncontrolled dynamic fields are the primary Sui-specific vulnerability classes.


1. Object Inventory

For EVERY struct with key ability in the codebase, build this table:

| # | Object Name (Module) | Abilities | Ownership Model | Created Where | Transferred Where | Destroyed Where | Has store? |

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

| 1 | {name} ({module}) | {key, store, ...} | OWNED / SHARED / FROZEN / WRAPPED / MIXED | {function:line} | {function:line or NEVER} | {function:line or NEVER} | YES/NO |

Ability rules:

Ownership model classification:


2. Ownership Model Analysis

2a. Owned Object Audit

For each OWNED object:

| Object | Should Be Shared Instead? | Ownership Transfer Possible? | Transfer Restriction Correct? | Assumption Risk |

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

| {name} | YES/NO ({reason}) | YES (has store) / NO (no store) | {analysis} | {risk if ownership changes} |

Check patterns:

2b. Shared Object Audit

For each SHARED object:

| Object | Mutation Functions | Access Guards | Concurrent Mutation Risk | Ordering Dependency |

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

| {name} | {list all functions that take &mut ref} | {what prevents unauthorized mutation} | YES/NO ({analysis}) | YES/NO ({analysis}) |

CRITICAL checks:

2c. Frozen Object Audit

For each FROZEN object:

| Object | Should Updates Be Possible? | Freezing Reversible? | Data Staleness Risk |

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

| {name} | YES/NO ({reason}) | NO (by design) | {risk if frozen data becomes stale} |

Check: If frozen object holds configuration that may need updating (fee rates, oracle addresses, admin keys), freezing is likely wrong -- should be shared with access control instead.

2d. Wrapped Object Audit

For each WRAPPED object:

| Parent Object | Wrapped Object | Unwrap Path Exists? | Dynamic Fields on Wrapped? | Destruction Safety |

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

| {parent} | {wrapped} | YES ({function}) / NO | YES/NO | {what happens to wrapped when parent destroyed} |

Check patterns:


3. Object Transfer Analysis

For each transfer::transfer, transfer::public_transfer, transfer::share_object, transfer::public_share_object, transfer::freeze_object, transfer::public_freeze_object call:

| # | Transfer Call | Object Type | Initiator | store Required? | store Present? | Recipient Validation | Stranded Risk |

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

| 1 | {function:line} | {type} | {who calls} | YES (public_*) / NO (module-only) | YES/NO | {is recipient validated?} | {can object be sent to address that cannot use it?} |

Check patterns:


4. Shared Object Mutation Safety

For each shared object, build the mutation map:

| Shared Object | Function | Mutation Type | Guard | Re-entrancy Risk | Ordering Sensitivity |

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

| {obj} | {func} | FIELD_UPDATE / BALANCE_CHANGE / CHILD_ADD / CHILD_REMOVE | {capability check, address check, or NONE} | {can another function on same object be called mid-execution?} | {does outcome depend on call order?} |

Sui-specific re-entrancy note: Move's borrow checker prevents re-entrancy within a single module (you cannot pass &mut Obj to a function that also borrows &mut Obj). However, cross-module re-entrancy is possible if Object A's mutation calls a function in Module B that calls back to Module A with a different entry point that accesses a DIFFERENT shared object whose state is coupled with Object A.

Concurrent mutation checklist:


5. Object Wrapping/Unwrapping

For each wrapping relationship (object stored as field in another object):

| Wrapper | Wrapped | Wrap Point | Unwrap Point | Dynamic Fields Before Wrap | UID Preserved on Unwrap? |

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

| {parent} | {child} | {function:line} | {function:line or NONE} | YES/NO | YES/NO/N/A |

Check patterns:


6. UID Lifecycle Audit

Every call to object::new(ctx) creates a UID. Every UID must be either:

  1. Stored in an object with key ability (the object's id field), OR
  2. Explicitly destroyed via object::delete(id)

For each object::new(ctx) call:

| # | Creation Location | UID Stored In | Destruction Location | Lifecycle Complete? | Orphan Risk |

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

| 1 | {function:line} | {object field or VARIABLE} | {function:line or NONE} | YES/NO | {if NO: resource leak} |

Check patterns:


7. Dynamic Field Audit

For each dynamic_field::add, dynamic_field::remove, dynamic_object_field::add, dynamic_object_field::remove:

| # | Operation | Parent UID | Field Name/Type | Value Type | Access Control | Unbounded Growth? | Cleanup on Delete? |

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

| 1 | ADD | {parent:line} | {name type + value} | {type} | {who can add} | YES/NO | {is field removed before parent UID deleted?} |

Check patterns:

| Parent Object | Destruction Function | Dynamic Fields Added | Dynamic Fields Removed Before Delete | Complete? |

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

| {obj} | {func:line} | {list all add operations} | {list all remove operations in destructor} | YES/NO |


Finding Template

## Finding [OO-N]: Title

**Verdict**: CONFIRMED / PARTIAL / REFUTED / CONTESTED
**Step Execution**: checkmark1,2,3,4,5,6,7 | x(reasons) | ?(uncertain)
**Rules Applied**: [R4:Y/N, R5:Y/N, R9:Y/N, R10:Y/N, R13:Y/N]
**Severity**: Critical/High/Medium/Low/Info
**Location**: sources/{module}.move:LineN
**Description**: [Specific ownership/lifecycle issue with code reference]
**Impact**: [What can happen -- fund loss, state corruption, DoS, stranded assets]

### Precondition Analysis (if PARTIAL or REFUTED)
**Missing Precondition**: [What blocks this attack]
**Precondition Type**: STATE / ACCESS / TIMING / EXTERNAL / BALANCE
**Why This Blocks**: [Specific reason]

### Postcondition Analysis (if CONFIRMED or PARTIAL)
**Postconditions Created**: [What conditions this creates]
**Postcondition Types**: [STATE, ACCESS, TIMING, EXTERNAL, BALANCE]
**Who Benefits**: [Who can use these]

Step Execution Checklist (MANDATORY)

| Section | Required | Completed? | Notes |

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

| 1. Object Inventory | YES | Y/N/? | Every struct with key ability |

| 2a. Owned Object Audit | IF owned objects exist | Y/N(none)/? | Transfer restriction + assumption risk |

| 2b. Shared Object Audit | IF shared objects exist | Y/N(none)/? | Access control on mutation |

| 2c. Frozen Object Audit | IF frozen objects exist | Y/N(none)/? | Staleness risk |

| 2d. Wrapped Object Audit | IF wrapped objects exist | Y/N(none)/? | Unwrap path + value preservation |

| 3. Object Transfer Analysis | YES | Y/N/? | Every transfer/share/freeze call |

| 4. Shared Object Mutation Safety | IF shared objects mutated | Y/N(none)/? | Concurrent mutation + ordering |

| 5. Object Wrapping/Unwrapping | IF wrapping relationships exist | Y/N(none)/? | Dynamic field orphaning + UID preservation |

| 6. UID Lifecycle Audit | YES | Y/N/? | Every object::new matched to storage or delete |

| 7. Dynamic Field Audit | IF dynamic fields used | Y/N(none)/? | Growth bounds + cleanup completeness |

Cross-Reference Markers

After Section 2b (Shared Object Audit): Feed unguarded mutation functions to SEMI_TRUSTED_ROLES skill if roles are involved in access control.

After Section 3 (Transfer Analysis): Feed objects with store ability to TOKEN_FLOW_TRACING skill for balance flow analysis.

After Section 6 (UID Lifecycle): Feed orphaned UIDs and incomplete dynamic field cleanup to depth-edge-case for stranded asset analysis (Rule 9).

After Section 7 (Dynamic Field Audit): Feed unbounded growth patterns to ECONOMIC_DESIGN_AUDIT for DoS cost analysis.

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.