Skip to content
PluginImportedContains scriptsShare-alike license

dimensional-analysis

Audits code for unit and decimal-scaling bugs and annotates it with dimensional comments recording the units of each value. Use when someone asks to audit or review code for unit confusion, decimals or scaling mismatches, WAD/RAY scale errors, or the wrong token's decimals; to annotate units in a codebase; or to perform a dimensional analysis of a DeFi protocol, offchain code, or other arithmetic-heavy codebase. Catches formulas that combine values carrying different units or scales.

Imported description, not reviewed yet

This item came from its original repository and was only scanned automatically; no editor has written an Arabic description for it yet. Read its content yourself before you rely on it. This page is not indexed by search engines until it is reviewed.

Download

Read this before you download

Talqeen never runs anything from this item. But what you download runs on your machine if you run it or let Claude Code run it, so read the files first.

  • The item has script files.

Files: 44 · Size: 217 KB

Download the ZIP

The file carries the license of the original source.

Install

Plugins are installed from a plugin marketplace in Claude Code, not by copying files. Download the package to read its content and its license.

Instructions

Dimensional Analysis Plugin

Add dimensional annotations to codebases and detect dimensional bugs. Uses an annotation format inspired by Reserve Protocol's Solidity conventions, but applicable to any language or protocol performing numeric arithmetic with mixed units, precisions, or scaling factors.

Overview

This plugin runs one automatic workflow:

  1. Discover the dimensional vocabulary in your codebase (tokens, shares, prices, etc.)
  2. Annotate your code with dimensional comments like D18{tok}, D27{UoA/tok}
  3. Propagate dimensions through arithmetic and call paths
  4. Validate dimensional consistency and detect bugs

Annotation Format

Based on Reserve Protocol's format (shown here in Solidity, but adaptable to any language):

// State variables
uint256 public tvlFee; // D18{1/s} demurrage fee on AUM
uint256 public lastPoke; // {s}

// Struct fields
struct RebalanceLimits {
    uint256 low;  // D18{BU/share} (0, 1e27]
    uint256 spot; // D18{BU/share} (0, 1e27]
    uint256 high; // D18{BU/share} (0, 1e27]
}

// Function parameters (NatSpec)
/// @param weights D27{tok/BU} Basket weight ranges
/// @param prices D27{UoA/tok} Prices for each token
/// @return price D27{buyTok/sellTok}

// Inline arithmetic
// D27{buyTok/sellTok} = D27{UoA/sellTok} * D27 / D27{UoA/buyTok}
uint256 startPrice = Math.mulDiv(sellPrices.high, D27, buyPrices.low);

Usage

The skill always executes in full-auto mode. Any supplied mode argument is ignored.

Workflow phases are implemented in:

  • skills/dimensional-analysis/references/step1.md
  • skills/dimensional-analysis/references/step2.md
  • skills/dimensional-analysis/references/step3.md
  • skills/dimensional-analysis/references/step4.md

Automatic Behavior

  • Uses existing DIMENSIONAL_UNITS.md if present; otherwise auto-generates and saves it
  • Persists DIMENSIONAL_SCOPE.json as a source-of-truth manifest for large repos
  • Applies annotations directly without approval gates
  • Uses best-guess inference for uncertainties and flags them in output
  • Reports results in a single summary at the end

Coverage Guarantees

  • All in-scope arithmetic files from scanner output are required scope (CRITICAL/HIGH/MEDIUM/LOW)
  • Discoverer narrowing (for vocabulary speed) does not reduce annotation or validation scope
  • Each in-scope file must be marked as completed in Phase 2, Phase 3, and Phase 4 before finalization

Agents

AgentPurpose
arithmetic-scannerScans repo for files with dimensional arithmetic to scope discovery
dimension-discovererDiscovers dimensional vocabulary from naming, interfaces, and patterns
dimension-annotatorAdds dimensional annotations at anchor points (comments only)
dimension-propagatorPropagates dimensional annotations through arithmetic and call chains, reporting mismatches
dimension-validatorValidates dimensional consistency and detects bugs

Tests

DETERMINISTIC_ONLY=1 tests/smoke-test.sh   # free: validator self-test
tests/smoke-test.sh                        # also runs the semantic eval (paid)

tests/fixtures/src/ is a cross-margin borrowing protocol with five planted dimensional bugs, three of which only surface by tracing dimensions across files (a RAY borrow index consumed as WAD, per-asset decimals from a registry, and Uniswap v3 Q96 encoding). StakingRewards.sol is a dimensionally correct control for measuring false positives. Ground truth is in tests/fixtures/ANSWER-KEY.md.

The eval copies fixtures to /tmp/dimensional-analysis-eval before running. This is deliberate: arithmetic-scanner post-filters any path containing /tests/, so analysing the fixtures in place would exclude every file and score a vacuous pass.

The harness requires uv and runs each eval arm against pristine fixtures. Use the smoke-test script for ablation comparisons: the built-in --ablation option shares annotated sources between arms and contaminates the baseline.

Requirements

  • A codebase performing numeric arithmetic with mixed units, precisions, or scaling factors
  • Most effective for DeFi protocols (Solidity, Rust/Anchor, CosmWasm, etc.) but works with any language
  • Optional for Solidity projects: slither-mcp for enhanced static analysis

References

See the references/ directory for:

  • dimension-algebra.md - Rules for dimensional arithmetic
  • common-dimensions.md - DeFi dimension vocabulary
  • bug-patterns.md - Dimensional bug patterns with examples
  • annotate.md - Full annotated protocol examples (ERC-4626, AMM, Lending)
  • step1.md - Phase 1 workflow instructions
  • step2.md - Phase 2 workflow instructions
  • step3.md - Phase 3 workflow instructions
  • step4.md - Phase 4 workflow instructions

Author

Coriolan Pinhas & Benjamin Samuels - Trail of Bits

Codex support

Requires a writable target and native agent dispatch for the scanner, discovery, annotation, propagation and validation stages. Coverage, retry and blocked-file gates remain mandatory. Invoke the named skill in Codex; existing Claude entry points and metadata remain supported.

Calcifier recipe for dimensional-analysis

The dimensional-analysis Python recipe was generated with Calcifier 0.1.0. It pins the source skill and its packaged resources so source changes can be detected before execution.

Install Calcifier with Python 3.13 or later, and configure the worker role(s) in an agent-config v1 file following the provider setup. Review the generated Python before granting trust.

Run the portable check from this plugin directory:

calcifier lint skills/dimensional-analysis/.calcifier/recipe.py --portable

Then use calcifier exec with the recipe path, --agent-config agents.json, and one --input NAME=VALUE for each required input below. Add --trust only after reviewing the recipe; execution records consent for those exact bytes.

InputTypeDefault
project_rootstrRequired

Depending on the execution path, tool providers may also be needed for Write. See the provider setup for --tool-config.

Files

  • folder.claude-plugin724 B
    • plugin.json724 B
  • folderagents49 KB
    • arithmetic-scanner.md11 KB
    • dimension-annotator.md8.6 KB
    • dimension-discoverer.md7.8 KB
    • dimension-propagator.md9.6 KB
    • dimension-validator.md13 KB
  • folderevals5.1 KB
    • folderplanted-bugs3 KB
      • foldergraders2 KB
        • criteria.md2 KB
      • prompt.md1,006 B
    • foldertrigger-annotate533 B
      • foldergraders233 B
        • criteria.md233 B
      • prompt.md300 B
    • foldertrigger-audit511 B
      • foldergraders233 B
        • criteria.md233 B
      • prompt.md278 B
    • foldertrigger-explicit528 B
      • foldergraders233 B
        • criteria.md233 B
      • prompt.md295 B
    • foldertrigger-oblique535 B
      • foldergraders233 B
        • criteria.md233 B
      • prompt.md302 B
  • folderskills84 KBscript
    • folderdimensional-analysis84 KBscript
      • folder.calcifier15 KBscript
        • recipe.py15 KBscript
      • folderagents245 B
        • openai.yaml245 B
      • folderassets3 KB
        • trail-of-bits-mark.svg3 KB
      • folderreferences56 KB
        • annotate.md12 KB
        • bug-patterns.md12 KB
        • common-dimensions.md7.3 KB
        • dimension-algebra.md6.3 KB
        • step1.md5.1 KB
        • step2.md3.6 KB
        • step3.md3.9 KB
        • step4.md6.5 KB
      • SKILL.md9.7 KB
  • foldertests52 KBscript
    • folderfixtures27 KB
      • folderselftest2.5 KB
        • findings-complete.json2.5 KB
      • foldersrc17 KB
        • folderlibraries1.9 KB
          • FixedPointMath.sol779 B
          • PriceLib.sol1.1 KB
        • AssetRegistry.sol2.1 KB
        • InterestIndex.sol1.8 KB
        • MarginVault.sol5.5 KB
        • StakingRewards.sol4 KB
        • UniV3Oracle.sol1.6 KB
      • foldertrigger1.5 KB
        • foldersrc1.5 KB
          • Vault.sol1.5 KB
      • ANSWER-KEY.md6.5 KB
    • smoke-test.sh8.3 KBscript
    • summarize_arms.py4.5 KBscript
    • trigger-test.sh3.6 KBscript
    • validate_eval_result.py1.4 KBscript
    • validate_findings.py6.5 KBscript
  • LICENSE20 KB
  • README.md6.3 KB

What the automatic scan found

We scanned the files automatically when they were imported. This is what the scan pointed at. It does not mean the item is harmful, and it does not mean it is safe: read it yourself.

  • Needs a lookA script file

    In file plugins/dimensional-analysis/skills/dimensional-analysis/.calcifier/recipe.py

  • Needs a lookObfuscation or dynamic evaluation of text

    In file plugins/dimensional-analysis/README.md, line 77

  • Needs a lookDeletes files forcibly and recursively

    In file plugins/dimensional-analysis/tests/smoke-test.sh, line 27

  • Needs a lookDeletes files forcibly and recursively

    In file plugins/dimensional-analysis/tests/trigger-test.sh, line 39

Comments (0)

No comments yet. Be the first.

Sign in to comment. Commenting comes at level 1 (Member).

Report

Similar items

  • PluginImported

    blockchain-web3

    Smart contract development with Solidity, DeFi protocol implementation, NFT platforms, and Web3 application architecture

    MITFiles: 11

  • PluginImported

    building-secure-contracts

    Comprehensive smart contract security toolkit based on Trail of Bits' Building Secure Contracts framework. Includes vulnerability scanners for 6 blockchains and 5 development guideline assistants.

    CC-BY-SA-4.0Files: 58

  • PluginImportedContains scripts

    burpsuite-project-parser

    Search and extract data from Burp Suite project files (.burp) for security analysis

    CC-BY-SA-4.0Files: 8

  • PluginImportedContains scripts

    c-review

    Comprehensive C/C++ security code review, with coverage verified against a parse of the source

    CC-BY-SA-4.0Files: 24

  • PluginImported

    claude-md-management

    Tools to maintain and improve CLAUDE.md files - audit quality, capture session learnings, and keep project memory current.

    Apache-2.0Files: 10

  • PluginImported

    comprehensive-review

    Multi-perspective code analysis covering architecture, security, and best practices

    MITFiles: 6