A static analyzer for Clarity smart contracts that reasons over semantic facts — call graph, authorization propagation, value origin, operation ordering — rather than matching syntactic patterns.
Output is a ranked set of hypotheses to falsify, not a list of confirmed findings. Every item carries the question a human needs to answer.
Existing tooling covers a narrow slice. Clarinet's check_checker handles
unchecked input and response data. Stacy (CoinFabrik) ships 11 detectors, of
which 4 target security and 7 are code-quality lints.
Neither reasons across the call graph — the analysis Clarity's decidability was specifically designed to make possible. This project does.
- Full lexer + AST. Comment-, string-, trait- and principal-aware, with position preservation. Not regex over source text.
- Call graph and authorization propagation. A public function is treated as guarded if it, or any private function reachable from it, contains an authorization check.
- Value origin tracking. Parameters, state reads, constants and literals are
distinguished; taint propagates through
letbindings. - Branch-aware operation ordering. Findings that depend on ordering require the operations to share an execution path, not merely a file.
- Evidence-based correlation. Correlated leads require their component findings in the same function with ordering evidence. No global pairing.
| Axis | Meaning |
|---|---|
severity_hint |
Impact if confirmed |
triage_priority |
How soon a human should read it |
confidence |
Quality of the static evidence |
Collapsing these into a single "severity" is what makes most static analyzer output unusable. A high-impact pattern with weak evidence and a low-impact pattern with strong evidence are different things.
13 rules over semantic facts. Security profile by default; governance and
hygiene rules are available behind --profile all.
| ID | Focus |
|---|---|
CLR-AUTH-001 |
Privileged mutation with no guard on any dominating path |
CLR-RESP-004 |
Response not consumed by parent expression |
CLR-ORD-017 |
External call before invariant update |
CLR-EXT-011 |
Callee principal supplied by caller |
CLR-ASC-003 |
as-contract payout from contract balance |
CLR-DEF-019 |
default-to collapsing absent into zero |
CLR-MAP-008 |
Map overwrite without prior read |
CLR-AUTHZ-010 |
tx-sender authorization without contract-caller |
CLR-MINT-013 |
Mint authority reachability |
CLR-SCALE-016 |
Incompatible decimal scales in one expression |
CLR-MATH-005 |
Division before multiplication |
CLR-ADMIN-014 |
Single-step ownership transfer (governance) |
CLR-SUPPLY-018 |
Uncapped fungible token supply (governance) |
python3 triage.py ./contracts -o out # security profile
python3 triage.py ./contracts --profile all # + governance and hygiene
python3 run_corpus.py # measurement harnessProduces out/triage.md (human-readable, with a paste-back block for LLM-assisted
review) and out/triage.json (machine-readable, with stable fingerprints for
delta detection across commits).
Requires Python 3.10+. No dependencies.
The repository includes a precision harness (run_corpus.py) and a labeled
corpus. The corpus is currently synthetic: three contracts, one with
deliberately planted flaws and two written to be safe. Current output:
positive : 14 findings, 6 urgent, 1 lead, 12 distinct rules
negative : 5 findings, 1 urgent
These are counts on synthetic fixtures, not precision and recall. A corpus written by the same person who wrote the rules measures internal consistency, not real-world accuracy. Numbers from it should not be quoted as accuracy metrics.
What the harness does provide is a regression gate: any rule change is measured
against both corpora before it lands. Three bugs in this analyzer were found
that way — a response-consumption check that missed as-contract wrappers, an
authorization rule that fired on every legitimate deposit, and an unresolved
let alias in self-keyed map writes.
Real precision and recall require a corpus of production contracts with established ground truth. That work is not done. It is the next milestone.
| File | Role |
|---|---|
clast.py |
Lexer and AST |
facts.py |
Functions, call graph, auth propagation, value origins, operation ordering |
rules.py |
Rules over facts; evidence-based correlator |
triage.py |
CLI, markdown and JSON renderers |
run_corpus.py |
Measurement harness |
Rules read facts, never source text. Adding a rule means writing a function over the fact layer, not another regex.
LEAD-EXT-ORDmisses state writes insidebeginblocks with no conditional branching; the branch-path matching is stricter than it needs to be.- Authorization propagation does not model capability maps or trait allowlists.
A contract using either will produce false positives on
CLR-AUTH-001. - No reachability analysis: a flagged function may be unreachable in deployment.
- No cross-contract analysis. Each contract is analyzed in isolation.
- Economic logic, incentive design and oracle manipulation are entirely out of scope. These are where most exploitable bugs live; this tool narrows where to look, it does not find them.
Rule proposals should include a positive fixture (the rule must fire), a negative fixture (it must not), and the question a human needs to answer when it does fire. Rules that cannot articulate that question are pattern matches, not analysis.
MIT