Temporal parameter staleness

From PlamenTSV/plamen · View interactive version

Temporal parameter staleness is an AI agent skill from the GitHub repository PlamenTSV/plamen. Trigger Pattern interval|epoch|period|duration|delay|cooldown|lock_period|timelock|unbonding|claim_delay|withdraw_delay|maturity - Inject Into Breadth agents, depth-state-trace

How to use this skill

Skill file

TEMPORAL_PARAMETER_STALENESS Skill (Solana)

Trigger Pattern: interval|epoch|period|duration|delay|cooldown|lock_period|timelock|unbonding|claim_delay|withdraw_delay|maturity

Inject Into: Breadth agents, depth-state-trace

Finding prefix: [TPS-N]

Rules referenced: R2, R8, R10, R13, R14

Cached parameters in multi-step operations become stale when authority changes them mid-operation. On Solana, timing has unique properties: 400ms slot time, Clock sysvar shared across all instructions in a transaction, Solana epoch boundaries (~2-3 days, 432k slots), and leader schedule predictability.


Step 1: Enumerate Multi-Step Operations

Find all operations that span multiple transactions:

| Operation | Step 1 (Initiate) | Wait Condition | Step N (Complete) | Clock Source |

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

| {op_name} | {initiate_ix}() | {wait_condition} | {complete_ix}() | slot / unix_timestamp / epoch |

For each multi-step operation:

Solana Clock Semantics

| Clock Field | Resolution | Monotonicity | Accuracy | Use Case |

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

| slot | ~400ms | Strictly increasing | Exact (validator-produced) | Short-duration timing, cooldowns |

| unix_timestamp | ~400ms | Mostly increasing (can drift +-1-2s) | +/- 1-2 seconds (estimated by validator) | Human-readable delays, longer durations |

| epoch | ~2-3 days (432k slots) | Strictly increasing | Exact | Staking epoch boundaries, long cycles |

Critical property: Within a single transaction, ALL instructions see the same Clock values. Unlike EVM where multi-block operations have timing variation per block, a Solana transaction's instructions share identical timing. Multi-step timing attacks require separate transactions.


Step 2: Identify Cached Parameters

For each parameter used across steps:

| Parameter | Account Stored In | Read At Step | Cached in User Account? | Authority-Changeable? | Re-Validated At Completion? |

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

| {param} | {config_account} | initiate() | YES/NO | YES/NO (which authority) | YES/NO |

Solana caching patterns:

Red flags: Parameter is cached in a user account at Step 1 AND authority can change the source account AND Step N does NOT re-read from source.


Step 3: Model Staleness Impact

For each cached parameter that can become stale:

Scenario A: Parameter INCREASES between steps
1. User initiates at Step 1 - user PDA stores param = X (read from config account)
2. Authority updates config account: param = X + delta
3. User completes at Step N - uses cached X from user PDA
4. Impact: {what happens with stale value X when current is X + delta}

Scenario B: Parameter DECREASES between steps
1. User initiates at Step 1 - user PDA stores param = X
2. Authority updates config account: param = X - delta
3. User completes at Step N - uses cached X
4. Impact: {what happens with stale value X when current is X - delta}

BOTH directions are mandatory - increase and decrease often have different impacts.

Solana-Specific Staleness Vectors

| Vector | Description | Severity Modifier |

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

| Epoch boundary crossing | Operation initiated in epoch N, completed in epoch N+1. Staking yields, validator rewards, inflation rate change at epoch boundary. | Higher if protocol depends on epoch-specific rates |

| Slot leader timing | Leader schedule known ~2 epochs ahead. Authority can time parameter changes to specific slots with high precision. | Increases likelihood for timing-sensitive parameters |

| Same-tx guarantee | Within one tx, Clock is constant. Cannot have intra-tx staleness. Multi-instruction composition is safe from timing drift. | Reduces severity for single-tx operations |

| Clock drift | unix_timestamp can drift +-1-2s from wall clock. If protocol uses tight timestamp comparisons (<5s), drift can cause unexpected behavior. | Medium if tight comparisons used |


Step 3b: Update Source Audit

For each parameter updated from an external source (oracle account, other program's state):


Step 4: Retroactive Application Analysis

For fee/rate parameters that apply to existing state:

| Parameter | Stored In | Applies To | Retroactive? | Impact |

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

| {fee_param} | {config PDA} | {what it affects} | YES/NO | {if retroactive: who is harmed} |

Solana retroactive patterns:

Rule 2 direction check: Can the authority's parameter change make a user-facing instruction behave unexpectedly? (e.g., setting cooldown_slots = 0 removes timing protection, setting max_deviation = 0 disables oracle bounds). Does the change retroactively affect users in active positions?


Step 5: Assess Severity

For each staleness issue:

Severity Assessment (Rule 10 - Worst-State)

Use worst realistic operational state, not current on-chain snapshot:

Severity assessed at: pending_claims=MAX_USERS, fee_delta=MAX_FEE-MIN_FEE, tvl=$XXM
Rationale: Protocol designed for up to {N} concurrent pending operations per documentation

Key Questions (must answer all)

  1. What multi-step operations exist? (request/claim, stake/cooldown/unstake, propose/vote/execute)
  2. For each cached parameter: can authority change it between steps?
  3. What happens if a delay DECREASES after initiation? (users locked longer than necessary vs original expectation)
  4. What happens if a delay INCREASES after initiation? (users can claim too early relative to new policy)
  5. Are fees applied retroactively to existing positions or only to new ones?
  6. Is there a maximum parameter range that bounds the staleness impact?
  7. Solana-specific: Does the protocol use slot or unix_timestamp for timing? If unix_timestamp, is the +-1-2s drift handled?
  8. Solana-specific: Do any operations span Solana epoch boundaries? If so, what changes at the boundary?
  9. Solana-specific: Is there a crank/refresh instruction? What happens if it is never called?

Common False Positives


Instantiation Parameters

{CONTRACTS}           - Programs to analyze
{MULTI_STEP_OPS}      - Identified multi-step operations
{CACHED_PARAMS}       - Parameters cached at initiation (stored in user PDAs/accounts)
{AUTHORITY_PARAMS}    - Authority-changeable parameters
{DELAY_PARAMS}        - Delay/cooldown parameters (in slots, timestamps, or epochs)
{FEE_PARAMS}          - Fee/rate parameters that may apply retroactively
{CLOCK_SOURCE}        - Clock field used (slot/unix_timestamp/epoch)

Output Schema

| Field | Required | Description |

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

| multi_step_ops | yes | List of multi-step operations found |

| cached_params | yes | Parameters cached across steps (stored in which account) |

| staleness_vectors | yes | How cached params can become stale |

| retroactive_fees | yes | Fees applied retroactively |

| clock_source_audit | yes | Which Clock field is used and whether appropriate |

| epoch_boundary_effects | yes | Operations spanning epoch boundaries |

| finding | yes | CONFIRMED / REFUTED / CONTESTED |

| evidence | yes | Code locations with line numbers |

| step_execution | yes | Status for each step |


Step Execution Checklist (MANDATORY)

| Step | Required | Completed? | Notes |

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

| 1. Enumerate Multi-Step Operations | YES | | |

| 2. Identify Cached Parameters | YES | | |

| 3. Model Staleness Impact (both directions) | YES | | |

| 3b. Update Source Audit | YES | | |

| 4. Retroactive Application Analysis | YES | | |

| 5. Assess Severity | YES | | |

Cross-Reference Markers

After Step 2: If cached parameters are authority-changeable -> MUST complete Step 3 with BOTH increase and decrease scenarios.

After Step 4: Cross-reference with SEMI_TRUSTED_ROLES (Solana version) for authority functions that change these parameters.

After Step 3: If protocol uses unix_timestamp for comparisons tighter than 5 seconds -> FLAG clock drift concern.

After Step 1: If any operation spans Solana epoch boundaries -> cross-reference with staking/inflation rate changes.

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.