agents/skills/niche/semantic-consistency-audit/SKILL.md
Trigger HAS_MULTI_CONTRACT flag in template_recommendations.md (recon detects 2+ in-scope contracts/modules sharing parameters or formulas) - Agent Type general-purpose (standal...
npx skillsauth add plamentsv/plamen semantic-consistency-auditInstall 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:
HAS_MULTI_CONTRACTflag intemplate_recommendations.md(recon detects 2+ in-scope contracts/modules sharing parameters or formulas) Agent Type:general-purpose(standalone niche agent, NOT injected into another agent) Budget: 1 depth budget slot in Phase 4b iteration 1 Finding prefix:[SC-N]Added in: v1.1
Recon Agent 3 (Patterns + Surface + Templates) produces contract_inventory.md and constraint_variables.md.
If contract_inventory.md lists 2+ in-scope contracts/modules AND constraint_variables.md shows parameters or formulas appearing in multiple contracts (same variable name, same constant, or same formula pattern), recon sets HAS_MULTI_CONTRACT flag in the BINDING MANIFEST.
The orchestrator spawns this agent in Phase 4b iteration 1 alongside the 8 standard agents (counts as 1 budget slot).
Task(subagent_type="general-purpose", prompt="
You are the Semantic Consistency Agent. You audit cross-contract consistency of config variables, formulas, and magic numbers.
## Your Inputs
Read:
- {SCRATCHPAD}/constraint_variables.md (all constraint/config variables with setters)
- {SCRATCHPAD}/contract_inventory.md (all contracts/modules in scope)
- {SCRATCHPAD}/state_variables.md (all state variables)
- {SCRATCHPAD}/function_list.md (all functions)
- Source files in scope
## Processing Protocol (MANDATORY — applies to every CHECK below)
For each CHECK, execute three steps in order:
1. **ENUMERATE targets**: List every entity the CHECK applies to (functions, handlers, collections, call sites) as a numbered list before analysis begins.
2. **PROCESS exhaustively**: Analyze each numbered entity against the CHECK's criteria. Mark each "DONE" or "N/A (reason)" before moving to the next.
3. **COVERAGE GATE**: Count enumerated vs processed. If any entity lacks a marker, process it before proceeding to the next CHECK.
## Pre-Commit Dimension Enumeration (MANDATORY — fill BEFORE any finding)
**Per-sibling disposition rule**: When a finding holds for one contract in
a sibling set, force a per-sibling disposition row; do not self-refute
across siblings in one paragraph. A bug confirmed for one member of a
sibling set must be independently dispositioned for every other member,
because no narrative forces per-sibling disposition on its own. To
enforce this, every audit run begins with the four dimension tables
below. Fill them by reading recon artifacts
(`contract_inventory.md`, `function_summary.md`, `caller_map.md`,
`attack_surface.md`) — NOT from your own analysis.
```markdown
## Pre-Commit Dimension Enumeration
### Sibling Set (from contract_inventory.md)
| Member | In Scope? | Bug-Mirror Candidate? |
|--------|-----------|----------------------|
| <contract A> | YES | reference |
| <contract B> | YES | mirror sibling |
| <contract C> | YES | mirror sibling |
### Decoded-Field Set (from function_summary.md + source)
For each function consuming decoded calldata/payload, list every field:
| Field | Type | Origin | Validated? | Trust Class |
|-------|------|--------|-----------|------------|
| <field name> | <type> | <calldata/storage/etc> | YES/NO | <UNTRUSTED/SEMI/TRUSTED> |
### Mirror-Direction Set (from caller_map.md mirror pairs)
| Forward Op | Reverse Op | Both Symmetric? |
|-----------|-----------|-----------------|
| <op> | <op> | YES/NO |
### Actor Set (Rule 12 categories from attack_surface.md)
| Actor | Can Reach Subject? | Path |
|-----------------------|-------------------|------|
| permissionless | YES/NO | <path> |
| semi-trusted role | YES/NO | <path> |
| natural ops | YES/NO | <path> |
| external event | YES/NO | <path> |
| user action sequence | YES/NO | <path> |
Per-row independence (HARD RULE): when you mark a row REPORTED or
DISMISSED, you cite a file:line for THAT row only. A REFUTED verdict on
row N cannot be evidence for row M. Each sibling, each field, each
direction, each actor stands on its own code citation.
The driver checks for the ## Pre-Commit Dimension Enumeration heading
in your output file. First audit cycle: missing PDE is a WARNING (no
halt). Future cycles will promote to FAIL with a retry hint.
For EVERY config variable that appears in 2+ contracts/modules (same name or same semantic role - e.g., feeRate, maxDelay, precision):
| Variable | Contract A | Unit in A | Contract B | Unit in B | Match? | Finding? | |----------|-----------|-----------|-----------|-----------|--------|----------|
Finding criteria: If Contract A treats feeRate as BPS (divide by 10000) but Contract B treats it as WAD (divide by 1e18), the same setter value produces wildly different behavior. This is a semantic unit mismatch - severity Medium minimum if it affects fund calculations.
For EVERY formula pattern that appears in 2+ locations (copy-pasted or structurally similar arithmetic):
| Formula Pattern | Location A | Location B | Same Semantics? | Divergence | Finding? | |----------------|-----------|-----------|-----------------|------------|----------|
Finding criteria: If calculateReward() in Contract A rounds down but the structurally identical calculateReward() in Contract B rounds up, users can arbitrage the difference. If one handles zero-input gracefully but the other reverts, there is an inconsistency that may cause DoS. Severity depends on whether the divergence affects fund flows (Medium+) or only view functions (Low).
For EVERY magic number (literal constant not assigned to a named constant - e.g., 10000, 1e18, 86400, 365):
10000 for BPS denominator, multiple 1e18 for WAD precision)10000 to 1000000 in Contract A but not Contract B)| Magic Number | Semantic Role | Locations | Consistent? | Finding? | |-------------|--------------|-----------|-------------|----------|
Finding criteria: If the BPS denominator is 10000 in 3 locations but 100000 in a 4th (typo or intentional change that wasn't propagated), this is a consistency bug. Severity: High if it affects fund calculations by 10x+, Medium if smaller impact, Low if view-only.
For EVERY pair of structs (or abi.encode/abi.decode layouts) where one is
built/encoded from, decoded into, or mirrors the other across an encode↔decode,
serialize↔deserialize, or message-build↔message-parse boundary:
*Params struct passed into an
encoder vs the Decoded*/*Message struct produced by the matching decoder; an
abi.encode(...) field order vs the abi.decode(..., (T1,T2,...)) types.| Struct/Layout A (fields) | Struct/Layout B (fields) | Same count/order/type? | Mis-read field | Finding? | |--------------------------|--------------------------|------------------------|----------------|----------|
Finding criteria: a <EncodedParams>(N fields) vs <DecodedMessage>(M≠N fields)
mismatch, or an abi.encode order that differs from the abi.decode type list, that
causes a token/amount/recipient field to be mis-read, is a confirmed finding
(arbitrary/mis-validated withdrawal class). Pure off-by-layout in a non-value field is
Low/Informational. Report the distinct layout-mismatch root cause even if an adjacent
value-binding finding already touches the same function.
Coverage assertion: Before returning, verify every entity enumerated under each CHECK has been processed. Report enumerated vs analyzed counts in your return message.
Use standard finding format with [SC-N] IDs.
For each finding, include:
| Finding ID | Location | Root Cause (1-line) | Verdict | Severity | Precondition Type | Postcondition Type |
Write to {SCRATCHPAD}/niche_semantic_consistency_findings.md
Return: 'DONE: {N} consistency issues found - {U} unit mismatches, {F} formula drifts, {M} magic number inconsistencies' ")
## Why Niche Agent (Not Scanner Sub-Check)
- Cross-contract consistency requires reading and comparing multiple files simultaneously - scanner sub-checks operate within a single pass
- Unit mismatch detection requires understanding arithmetic context (what does `/ 10000` mean here?) - not a simple grep pattern
- Formula drift detection requires structural comparison of code blocks across contracts - exceeds scanner complexity budget
- The concern is protocol-agnostic: applies to any multi-contract system regardless of chain (EVM, Solana, Aptos, Sui)
data-ai
Trigger Pattern Always (run during recon TASK 0, not breadth) - Inject Into Recon agent only (meta_buffer.md enrichment)
data-ai
Trigger Pattern Always (run during recon TASK 0, not breadth) - Inject Into Recon agent only (meta_buffer.md enrichment)
data-ai
Trigger Pattern Always (run during recon TASK 0, not breadth) - Inject Into Recon agent only (meta_buffer.md enrichment)
data-ai
Trigger STABLESWAP_FORK flag (fork-ancestry detects Curve/StableSwap parent via get_d/get_y/ramp_a/StableSwap patterns) - Agent Type general-purpose (standalone niche agent, 1 budget slot)