Rule
circuit-work-budget
Expanded source-operation estimate exceeds an explicit circuit work budget.
Specimen 33 of 96 · Policy-dependent rules
- Severity
- low
- Confidence
- high
- Maturity
- experimental
- Selection
- Audit; needs policy
- Policy intent
- required
- Release
- v0.1.1
- Engine facts used
cfgresolved-callsstatic-loop-boundswork-policy
Selection and scope#
Selected by the default audit profile, but it stays dormant until policies in nightshade.json declares the matching application intent. Selecting it alone does not supply that intent.
./.nightshade/node_modules/.bin/nightshade ./contracts --detectors circuit-work-budget
./.nightshade/node_modules/.bin/nightshade detector show circuit-work-budgetThe first command runs only this rule; --detectors takes a comma-separated list. The second prints the rule's metadata from your installed version.
Severity is review priority. It does not express exploitability or impact. Confidence is detector metadata, not a probability. All built-in rules are experimental.
Compiler scope: the engine supports the pinned profiles 0.28.0, 0.29.0, 0.30.0, 0.31.1, 0.33.0-rc.2, 0.34.0, 0.35.0-rc.1 and 0.35.0, with ZKIR2 by default. Support for this rule can be narrower; the rule documentation below states any narrower scope.
Corpus checks#
Synthetic corpus checks for this rule in the 0.1.1 proof run. A check counts only with compiler acceptance and complete analysis.
| Positive detected | Corrected quiet | Lookalike quiet | Other negative quiet | Incomplete |
|---|---|---|---|---|
| 2/2 | 2/2 | 1/1 | 0/0 | 0 |
No deviations were recorded for this rule.
These are behavior checks on synthetic fixtures, not a precision or recall estimate. See evaluation.
Rule documentation#
From docs/detectors/circuit-work-budget.md at v0.1.1.
Availability: policy-required; selected by default, but needs policies.workBudgets. Severity low, confidence high for the source estimate.
Reports an expanded source-operation upper bound above a configured circuit budget. The estimate expands static loops and callee work and conservatively counts both branch alternatives.
Example and review scenario#
The compiler-qualified owned fixture repeats a Counter update four times. Its explicit review threshold is:
{ "workBudgets": [{ "circuit": "update", "maxUnits": 5 }] }Place this object under policies in the configuration. The correction contains one update. Use the rule to notice source-work growth beyond an agreed project limit.
Recommendation: inspect repeated loop and callee work, then measure actual compiler/prover cost before optimizing or adjusting the budget. For an opt-in fixed threshold without policy, see circuit-cost.
False positives and limitations#
Intentional large circuits or conservative branch expansion can exceed a useful application budget. Units are not proof rows, optimized compiler cost, runtime, memory usage or prover time. A finding is not evidence of an attacker-controlled unbounded loop or denial of service. An unavailable finite estimate emits an incomplete diagnostic instead of passing the configured check. A configured threshold is a project review limit, not a performance guarantee.
Source examples#
These short regression examples are included here for installed-package readers. Rule-specific policy requirements and limits above still apply.
Example 1#
Fixture (source: tests/corpus/vulnerable/work-budget.compact).
pragma language_version >= 0.26.0;
import CompactStandardLibrary;
export ledger count: Counter;
export circuit update(): [] {
for (const index of 0..4) { count += 1; }
}Example 2#
Correction (source: tests/corpus/safe/work-budget.compact).
pragma language_version >= 0.26.0;
import CompactStandardLibrary;
export ledger count: Counter;
export circuit update(): [] {
count += 1;
}Suppress a match#
If a match is intentional, suppress it on the line before with the exact rule ID and a reason of at least eight characters:
// nightshade-disable-next-line circuit-work-budget -- Reason this match is intentionalDiagnostics cannot be suppressed, and an unmatched directive for a selected rule makes analysis incomplete. See configuration for fingerprint suppressions and baselines.