Rule

forbidden-state-transition

A scalar state write may cross a transition explicitly forbidden by policy.

Release v0.1.1View Markdown

Specimen 36 of 96 · Policy-dependent rules

Severity
medium
Confidence
medium
Maturity
experimental
Selection
Audit; needs policy
Policy intent
required
Release
v0.1.1
Engine facts used
successful-paths state-writes constant-constraints transition-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.

Shell
./.nightshade/node_modules/.bin/nightshade ./contracts --detectors forbidden-state-transition
./.nightshade/node_modules/.bin/nightshade detector show forbidden-state-transition

The 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 detectedCorrected quietLookalike quietOther negative quietIncomplete
2/22/21/10/00

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/forbidden-state-transition.md at v0.1.1.

Availability: policy-required; selected by default, but needs policies.transitions. Severity medium, confidence medium.

Reports a scalar ledger write whose modeled prior-state constants/exclusions and next value do not exclude a forbidden transition. Policies support enum, Boolean and numeric state; "to": "*" forbids any mutation from the selected prior state.

Example and review scenario#

The compiler-qualified owned fixture sets phase to OPEN without excluding CLOSED. Its policy is:

JSON
{ "transitions": [{ "state": "phase", "from": "CLOSED", "to": "OPEN" }] }

Place this object under policies in the configuration. The correction enforces:

Compact
assert(phase != Phase.CLOSED, "terminal state");
phase = Phase.OPEN;

Recommendation: compare the reported write with the application's transition table and constrain the old state before mutation. Review terminal states and all writers, including helper-mediated writes.

False positives and limitations#

Unknown prior or next values leave transitions possible; a report does not prove that the old state is reachable across transactions. Application invariants outside the modeled invocation can make a match intentional or infeasible. Aggregate/collection member transitions and general transaction sequences are outside this scalar rule. Policies provide the intended prohibition; findings do not infer it. Missing models and exhausted budgets remain incomplete.

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/forbidden-transition.compact).

Compact
pragma language_version >= 0.26.0;
export enum Phase { OPEN, CLOSED }
export ledger phase: Phase;
export circuit reopen(): [] {
  phase = Phase.OPEN;
}

Example 2#

Correction (source: tests/corpus/safe/forbidden-transition.compact).

Compact
pragma language_version >= 0.26.0;
export enum Phase { OPEN, CLOSED }
export ledger phase: Phase;
export circuit reopen(): [] {
  assert(phase != Phase.CLOSED, "terminal state");
  phase = Phase.OPEN;
}

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:

Compact
// nightshade-disable-next-line forbidden-state-transition -- Reason this match is intentional

Diagnostics cannot be suppressed, and an unmatched directive for a selected rule makes analysis incomplete. See configuration for fingerprint suppressions and baselines.

References#