Semi trusted roles

From PlamenTSV/plamen · View interactive version

Semi trusted roles is an AI agent skill from the GitHub repository PlamenTSV/plamen. Trigger Pattern Crank/bot/operator signer checks, authority-gated instructions - Inject Into Breadth agents, depth-state-trace

How to use this skill

Skill file

Skill: Semi-Trusted Role Analysis (Solana)

Trigger Pattern: Crank/bot/operator signer checks, authority-gated instructions

Inject Into: Breadth agents, depth-state-trace

Finding prefix: [STR-N]

Rules referenced: S1, S3, S9, R2, R6, R10, R13

crank|bot|operator|keeper|authority|admin|has_one\s*=\s*authority|
constraint\s*=\s*.*signer|role|guardian|relayer

Reasoning Template

Step 1: Inventory Role Permissions

| Instruction | Signer Check | Mutable Accounts | CPI Calls | Parameters |

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

Step 2: Analyze Within-Scope Abuse

For each permitted action, ask:

Timing Abuse (400ms slots):

Parameter Abuse:

Sequence Abuse:

Omission Abuse:

Step 3: Model Attack Scenarios

Scenario A: Timing Attack (MEV Bundle)
1. {ROLE_NAME} monitors pending transactions in mempool
2. {ROLE_NAME} creates MEV bundle: [role_instruction, user_instruction]
3. Role instruction executes first within same slot, changing state
4. User instruction executes with worse conditions
5. Impact: {TIMING_IMPACT}

Scenario B: Parameter Attack
1. {ROLE_NAME} calls {ROLE_INSTRUCTION} with {MALICIOUS_PARAMS}
2. Instruction data is not validated against {EXPECTED_CONSTRAINTS}
3. Impact: {PARAM_IMPACT}

Scenario C: Key Compromise
1. {ROLE_NAME} keypair is compromised
2. Attacker can call: {ROLE_FUNCTIONS}
3. Maximum extractable value: {MAX_DAMAGE}
4. Recovery: {RECOVERY_PATH} - can authority be rotated? Timelock?

Step 4: Assess Mitigations

Step 5: Model User-Side Exploitation (Direction 2 - MANDATORY)

Predictability Analysis:

Scenario D: User Exploits Crank Timing

1. User observes that {ROLE_NAME} executes {ROLE_INSTRUCTION} at predictable times
2. User submits transaction with high priority fee to land BEFORE crank in same slot
3. {ROLE_INSTRUCTION} executes, changing state (e.g., reward distribution, rate update)
4. User benefits from known state change
5. Impact: {USER_EXPLOIT_IMPACT}

Scenario E: User Griefs Crank Preconditions

1. {ROLE_INSTRUCTION} requires account state: {PRECONDITION}
2. User manipulates account state to violate {PRECONDITION}
3. {ROLE_NAME} sends transaction, instruction fails
4. Protocol enters degraded state (no crank actions possible)
5. Impact: {GRIEF_IMPACT}

Scenario F: User Forces Suboptimal Crank Action

1. {ROLE_NAME} must choose between options based on on-chain state
2. User manipulates state (deposits/withdrawals) to make worst option appear best
3. {ROLE_NAME} (following honest behavior) chooses suboptimal path
4. User profits from forced suboptimal execution
5. Impact: {SUBOPTIMAL_IMPACT}

Scenario G: Same-Chain Rate Staleness via Discrete Updates

1. Protocol's exchange rate only updates when {ROLE_NAME} cranks (discrete updates)
2. Between crank calls, rate is stale (does not reflect accumulated value)
3. User monitors for {ROLE_NAME} pending transaction
4. User enters at stale rate (favorable), crank executes, rate updates
5. User exits at updated rate (or holds appreciating position)
6. Impact: {RATE_ARBIT_IMPACT}

Step 6: Precondition Griefability Check

For each instruction callable by {ROLE_NAME}:

| Instruction | Preconditions | User Can Manipulate? | Grief Impact |

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

| {ix} | account balance > 0 | YES - withdraw all | Crank stuck |

| {ix} | Clock timestamp > last_crank + interval | NO - time-based | N/A |

| {ix} | threshold met | YES - partial withdraw | Delayed execution |

CU budget griefing: Can a user submit CU-heavy transactions to fill the leader's block and delay crank execution? Priority fee escalation can push crank costs above economic viability.

Step 6b: Admin/Privileged Instruction Griefability (EXHAUSTIVE)

Enumerate ALL authority-gated instructions across the program:

| Instruction | Authority Type | Preconditions | User Can Manipulate? | Grief Impact |

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

| {admin_ix} | {owner/admin/operator} | {preconditions} | YES/NO | {impact} |

Enumeration completeness check:

Solana-specific checks:

Common False Positives

Finding Template

**ID**: [STR-N]
**Severity**: Critical/High/Medium/Low/Info
**Step Execution**: (see below)
**Rules Applied**: [S1:___, S3:___, S9:___, R2:___, R6:___, R10:___, R13:___]
**Location**: programs/{program}/src/instructions/{file}.rs:LineN
**Title**: {what role can do / what user can exploit}
**Description**: {specific abuse vector with code reference}
**Impact**: {quantified damage at worst-state parameters}

Step Execution Checklist (MANDATORY)

| Step | Required | Completed? | Notes |

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

| 1. Inventory Role Permissions | YES | | |

| 2. Analyze Within-Scope Abuse | YES | | |

| 3. Model Attack Scenarios (A,B,C) | YES | | |

| 4. Assess Mitigations | YES | | |

| 5. Model User-Side Exploitation (D,E,F,G) | YES | | MANDATORY -- never skip |

| 6. Precondition Griefability Check | YES | | MANDATORY -- never skip |

| 6b. Admin Instruction Griefability | YES | | MANDATORY -- never skip |

Cross-Reference Markers

After Step 4: DO NOT STOP HERE -- Steps 5-6 analyze the reverse direction.

After Step 5: Cross-reference with TOKEN_FLOW_TRACING for token-related griefing vectors. IF crank actions are predictable -> document Jito MEV vectors.

After Step 6: IF any precondition is user-griefable -> severity >= MEDIUM. Document protocol degradation timeline if crank is blocked.

Output Format for Step Execution

**Step Execution**: check1,2,3,4,5,6,6b | (no skips for this skill)
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.