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.
وصف مستورد لم يراجعه محرر بعد
جاء هذا العنصر من مستودعه الأصلي وفحصناه آلياً فقط، ولم يكتب له محرر وصفاً عربياً بعد. اقرأ محتواه بنفسك قبل أن تعتمد عليه. ولا تُفهرس هذه الصفحة في محركات البحث حتى تُراجَع.
التنزيل
اقرأ هذا قبل أن تنزّل
لا يشغّل تلقين أي شيء من هذا العنصر. لكن ما تنزّله يعمل على جهازك إن شغّلته أنت أو سمحت لكلود كود بتشغيله، فاقرأ الملفات أولاً.
- في العنصر ملفات سكربت.
التثبيت
تُثبَّت الإضافات من سوق الإضافات في كلود كود، لا بنسخ الملفات. نزّل الحزمة لتقرأ محتواها وترخيصها.
التعليمات
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:
- Discover the dimensional vocabulary in your codebase (tokens, shares, prices, etc.)
- Annotate your code with dimensional comments like
D18{tok},D27{UoA/tok} - Propagate dimensions through arithmetic and call paths
- 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.mdskills/dimensional-analysis/references/step2.mdskills/dimensional-analysis/references/step3.mdskills/dimensional-analysis/references/step4.md
Automatic Behavior
- Uses existing
DIMENSIONAL_UNITS.mdif present; otherwise auto-generates and saves it - Persists
DIMENSIONAL_SCOPE.jsonas 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
| Agent | Purpose |
|---|---|
arithmetic-scanner | Scans repo for files with dimensional arithmetic to scope discovery |
dimension-discoverer | Discovers dimensional vocabulary from naming, interfaces, and patterns |
dimension-annotator | Adds dimensional annotations at anchor points (comments only) |
dimension-propagator | Propagates dimensional annotations through arithmetic and call chains, reporting mismatches |
dimension-validator | Validates 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 arithmeticcommon-dimensions.md- DeFi dimension vocabularybug-patterns.md- Dimensional bug patterns with examplesannotate.md- Full annotated protocol examples (ERC-4626, AMM, Lending)step1.md- Phase 1 workflow instructionsstep2.md- Phase 2 workflow instructionsstep3.md- Phase 3 workflow instructionsstep4.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.
| Input | Type | Default |
|---|---|---|
project_root | str | Required |
Depending on the execution path, tool providers may also be needed for Write. See the provider setup for --tool-config.
الملفات
- مجلد.claude-plugin724 بايت
- plugin.json724 بايت
- مجلدagents49 ك.ب
- arithmetic-scanner.md11 ك.ب
- dimension-annotator.md8.6 ك.ب
- dimension-discoverer.md7.8 ك.ب
- dimension-propagator.md9.6 ك.ب
- dimension-validator.md13 ك.ب
- مجلدevals5.1 ك.ب
- مجلدplanted-bugs3 ك.ب
- مجلدgraders2 ك.ب
- criteria.md2 ك.ب
- prompt.md1,006 بايت
- مجلدtrigger-annotate533 بايت
- مجلدgraders233 بايت
- criteria.md233 بايت
- prompt.md300 بايت
- مجلدtrigger-audit511 بايت
- مجلدgraders233 بايت
- criteria.md233 بايت
- prompt.md278 بايت
- مجلدtrigger-explicit528 بايت
- مجلدgraders233 بايت
- criteria.md233 بايت
- prompt.md295 بايت
- مجلدtrigger-oblique535 بايت
- مجلدgraders233 بايت
- criteria.md233 بايت
- prompt.md302 بايت
- مجلدskills84 ك.بسكربت
- مجلدdimensional-analysis84 ك.بسكربت
- مجلد.calcifier15 ك.بسكربت
- recipe.py15 ك.بسكربت
- مجلدagents245 بايت
- openai.yaml245 بايت
- مجلدassets3 ك.ب
- trail-of-bits-mark.svg3 ك.ب
- مجلدreferences56 ك.ب
- annotate.md12 ك.ب
- bug-patterns.md12 ك.ب
- common-dimensions.md7.3 ك.ب
- dimension-algebra.md6.3 ك.ب
- step1.md5.1 ك.ب
- step2.md3.6 ك.ب
- step3.md3.9 ك.ب
- step4.md6.5 ك.ب
- SKILL.md9.7 ك.ب
- مجلدtests52 ك.بسكربت
- مجلدfixtures27 ك.ب
- مجلدselftest2.5 ك.ب
- findings-complete.json2.5 ك.ب
- مجلدsrc17 ك.ب
- مجلدlibraries1.9 ك.ب
- FixedPointMath.sol779 بايت
- PriceLib.sol1.1 ك.ب
- AssetRegistry.sol2.1 ك.ب
- InterestIndex.sol1.8 ك.ب
- MarginVault.sol5.5 ك.ب
- StakingRewards.sol4 ك.ب
- UniV3Oracle.sol1.6 ك.ب
- مجلدtrigger1.5 ك.ب
- مجلدsrc1.5 ك.ب
- Vault.sol1.5 ك.ب
- ANSWER-KEY.md6.5 ك.ب
- smoke-test.sh8.3 ك.بسكربت
- summarize_arms.py4.5 ك.بسكربت
- trigger-test.sh3.6 ك.بسكربت
- validate_eval_result.py1.4 ك.بسكربت
- validate_findings.py6.5 ك.بسكربت
- LICENSE20 ك.ب
- README.md6.3 ك.ب
ما وجده الفحص الآلي
فحصنا الملفات آلياً وقت الاستيراد. هذا ما نبّه إليه الفحص، ولا يعني أن العنصر ضار ولا أنه سليم: اقرأه بنفسك.
- يحتاج مراجعةملف سكربت
في الملف plugins/dimensional-analysis/skills/dimensional-analysis/.calcifier/recipe.py
- يحتاج مراجعةتعمية أو تقييم ديناميكي للنص
في الملف plugins/dimensional-analysis/README.md، السطر 77
- يحتاج مراجعةيحذف ملفات بالقوة وبالتكرار
في الملف plugins/dimensional-analysis/tests/smoke-test.sh، السطر 27
- يحتاج مراجعةيحذف ملفات بالقوة وبالتكرار
في الملف plugins/dimensional-analysis/tests/trigger-test.sh، السطر 39
التعليقات (0)
لا تعليقات بعد. كن أول من يعلّق.
سجّل الدخول لتعلّق. التعليق من المستوى 1 (عضو).