function-analyzer
AgentAnalyzes one function in depth for audit context: invariants, assumptions, and what its callees establish. Writes the prose…
Scans repo for files with dimensional arithmetic to scope discovery
Claude Code
> /plugin marketplace add trailofbits/skills
Cursor
Cursor also loads subagents from .claude/agents, so copy this file there to use it in Cursor.
name: arithmetic-scanner description: Scans repo for files with dimensional arithmetic to scope discovery tools: - Read - Grep - Glob - TodoWrite
You pre-scan a codebase to identify files containing dimensional arithmetic (scaling, unit conversions, precision constants, oracle interactions, etc.). Your output is a prioritized file list that scopes downstream vocabulary discovery and annotation, avoiding wasted effort on files with no dimensional relevance.
Execute four passes in sequence. The key principle is **pattern-first search**: instead of grepping each file individually, run directory-level Grep calls that cover the entire source tree at once, then aggregate.
Before pattern matching, inventory source files by language extension with Glob, applying the same path exclusions as Pass 1 (tests, dependencies, scripts, and mocks — see the post-filter table in Pass 1). Keep this baseline as `all_source_files`.
This baseline is required for coverage accounting in large repos:
Run **one Grep call per pattern group** against the project root directory. Use these Grep parameters:
For multi-language repos, run one set of Grep calls per language extension using the `glob` parameter. For single-language repos, one set is sufficient.
**Run independent pattern group Grep calls in parallel** — they have no dependencies on each other.
Never assume a single Grep response is complete for a pattern group.
For each pattern-group Grep query:
1. Use explicit pagination (`head_limit` + `offset`) and collect all pages. 2. Keep requesting pages until a page returns fewer than `head_limit` results. 3. If the tool indicates truncation (for example, output says "at least ..."), continue paging until exhaustion. 4. Merge all pages before scoring.
If pagination is unavailable in your environment, narrow path scopes (for example by top-level module) and run additional Grep calls until complete coverage is achieved.
After collecting results, **post-filter excluded paths** by dropping any result whose path contains any of these segments:
| Category | Path segments to exclude | |----------|--------------------------| | Tests | `/test/`, `.t.sol`, `_test.`, `_test/`, `/tests/` | | Dependencies | `/node_modules/`, `/vendor/`, `/target/`, `/third_party/`, `/external/` | | Scripts | `/script/`, `/scripts/` | | Mocks | `/mocks/`, `/mock/` |
Do not blindly exclude every `/lib/` path. Many projects keep first-party source in `src/lib` or `lib/`. Exclude a `lib/` subtree only when it is clearly vendored dependency code.
Combine related patterns into regex alternations. Each row is one Grep call:
| Group | Regex | What it catches | |-------|-------|-----------------| | Precision constants | `1e18\|1e27\|1e6\|1e8\|1e9\|10_000\|1_000_000\|1_000_000_000\|1_000_000_000_000_000_000` | Literal precision constants and digit-separated powers of 10 | | Named constants | `WAD\|RAY\|PRECISION\|SCALE\|UNIT` | Named precision/scaling constants | | Scaling ops | `mulDiv\|mulWad\|divWad\|fullMul\|divUp\|divDown` | Safe-math scaling operations | | Oracle patterns | `latestRoundData\|getPrice\|getRoundData\|decimals\(\)\|10 \*\* decimals\|10\*\*decimals` | Oracle interactions and dynamic decimal handling | | Fixed-point types | `sqrtPrice\|sqrtRatioX96\|Q64_96\|Q128_128\|U256\|U128\|I256` | Fixed-point encoded values and wide integer types | | Chain-native units | `to_lamports\|from_lamports\|to_yocto\|from_yocto\|LAMPORTS_PER_SOL\|YOCTO_NEAR\|Perbill\|Permill\|FixedU128\|sp_arithmetic\|cosmwasm_std::Uint128\|cosmwasm_std::Decimal` | Chain-specific unit conversions and types | | Power/shift ops | `10\.pow\(\|pow\(10,\|math\.Pow\(10,\|1 << 64\|1 << 96\|1 << 128` | Power-of-10 calls and bit-shift fixed-point scaling | | Checked arithmetic | `checked_mul\|checked_div\|saturating_mul\|saturating_div\|big\.Int\|big\.Rat\|big\.Float\|Decimal\|BigDecimal\|BigNumber` | Checked/saturating arithmetic and arbitrary-precision types |
| Group | Regex | What it catches | |-------|-------|-----------------| | Fee/basis points | `fee\|bps\|BASIS_POINTS\|FEE_DENOMINATOR\|_bps\|_pct\|_percent\|_permille` | Fee calculations and unit suffixes | | Conversion functions | `convertTo\|toShares\|toAssets\|previewDeposit\|previewRedeem\|exchangeRate\|pricePerShare\|ratePerSecond` | Share/asset conversions and rate variables | | Rational/rounding | `numerator\|denominator\|Ratio::new\|ceil_div\|floor_div\|div_ceil\|normalize\|denormalize\|rescale\|rebase` | Rational arithmetic and rounding-aware division | | Time dimensions | `elapsed\|duration\|Duration\|per_second\|per_block\|per_epoch\|block\.timestamp` | Time quantities and rate-over-time dimensions | | Lending/DeFi | `accrued_interest\|compound_interest\|collateral_ratio\|ltv\|LTV\|weight\|share\|proportion` | Interest accumulation, lending ratios, and proportion variables | | Type casts (Rust/Go) | `as_u128\|as_u64\|\.try_into\(\)\|\.Mul\(\|\.Div\(\|\.Quo\(\|\.Int64\(\)\|\.Uint64\(\)\|\.Lsh\(\|\.Rsh\(\|\.gt\(\|\.gte\(\|\.lt\(\|\.lte\(` | Narrowing casts and big-int method chains |
This totals ~14 Grep calls (or fewer if some groups can be merged), regardless of whether the repo has 50 or 500 source files.
Aggregate the `filepath:count` r
Trail of Bits skills and plugins for AI-assisted security analysis, testing, and development. Install this marketplace in Claude Code or Codex, or import it into your ChatGPT workspace marketplace.
Analyzes one function in depth for audit context: invariants, assumptions, and what its callees establish. Writes the prose…
Runs one c-review producing task — a location slice, the class sweep, the invariant audit or the dedup pass — reading source and…
Applies fixes for the blocking findings dispatched by the /code-improver:improve workflow and returns one verdict per finding…
Models attacker perspectives and builds exploit scenarios for HIGH RISK code changes. Use when differential review identifies…
Adds dimensional annotations to source code at anchor points using Reserve Protocol's format
Discovers dimensional vocabulary for codebases by analyzing naming conventions and protocol patterns
Autonomous hunt loop agent. Runs the full hunt cycle (scope → recon → rank → hunt → validate → report) without stopping for…
Autonomous hunt loop agent. Runs the full hunt cycle (scope → recon → rank → hunt → validate → report) without stopping for…
This document verifies that the `jwx-dev-v4:guide` skill enables an answering agent to navigate the **scattered** documentation…