Rule

redundant-boolean-branch

Both branch arms only return opposite Boolean literals.

Release v0.1.1View Markdown

Specimen 21 of 96 · Audit-default ordinary rules

Severity
info
Confidence
high
Maturity
experimental
Selection
Audit default
Policy intent
not required
Release
v0.1.1
Engine facts used
resolved-model typed-source-constants

Selection and scope#

Selected by the default audit profile, so an ordinary scan runs it.

Shell
./.nightshade/node_modules/.bin/nightshade ./contracts --detectors redundant-boolean-branch
./.nightshade/node_modules/.bin/nightshade detector show redundant-boolean-branch

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/22/20/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/redundant-boolean-branch.md at v0.1.1.

Availability: default-on, severity info, confidence high.

The rule identifies an if with explicit else whose arms contain only opposite Boolean literal returns. Disclosure and identity casts of the literals, and single-statement nested blocks, preserve that shape. Conditions reduced to source constants and statements after definite rejection stay quiet. Physical generic claims must agree across every materialized instance.

Example and scenario#

Compact
export circuit belowLimit(limit: Uint<64>): Boolean {
  if (disclose(round < limit)) { return true; } else { return false; }
}

This view can express its predicate directly with return disclose(round < limit);. Inverse literal returns suggest the negated predicate. The condition, its effects and its disclosure boundary still matter.

Recommendation and limits#

Consider a direct predicate return when it improves readability. Intentional explanatory branches can be retained. The rule describes source structure; it does not claim a security defect, reduced proof cost or compiler equivalence for an arbitrary rewrite. Validate a proposed rewrite with the project's compiler.

Any additional branch statement, computed result, equal literal returns, sequence result or missing explicit else is excluded. This does not implement general Boolean optimization or arithmetic algorithm replacement. It addresses only the literal-return branch class, without analyzing deployed contracts.

Evidence and known false positives#

Typed controls preserve condition effects/constraints across instruction/reference engines and cached/uncached modes. Compiler-valid source examples support the observation; intentional readability choices are factually matching informational reviews. Work/depth exhaustion emits rule-scoped source-observation-budget and never certifies a clean result. Source facts do not prove successful execution or natural recall.

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 redundant-boolean-branch -- 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#