# redundant-boolean-branch

> Both branch arms only return opposite Boolean literals.

Canonical: https://nightshade.dicksonwu.xyz/rules/redundant-boolean-branch.html
Release: Nightshade 0.1.1 (v0.1.1)

| Field | Value |
| --- | --- |
| Rule ID | `redundant-boolean-branch` |
| Severity | info |
| Confidence | high |
| Maturity | experimental |
| Selection | Audit default |
| Policy intent | not required |
| Default enabled | yes |
| Category | Audit-default ordinary rules |
| Engine facts used | resolved-model, typed-source-constants |
| Release | v0.1.1 |

## Selection and scope

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

```sh
./.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 detected | Corrected quiet | Lookalike quiet | Other negative quiet | Incomplete |
| ---: | ---: | ---: | ---: | ---: |
| 2/2 | 2/2 | 2/2 | 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](https://nightshade.dicksonwu.xyz/evaluation.md#synthetic-corpus).

## Rule documentation

From https://github.com/DicksonWu654/nightshade/blob/v0.1.1/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](https://nightshade.dicksonwu.xyz/configuration.md#suppress-an-intentional-match) for fingerprint suppressions and baselines.

## References

- [Rule source document at v0.1.1](https://github.com/DicksonWu654/nightshade/blob/v0.1.1/docs/detectors/redundant-boolean-branch.md)
- [Catalog entry in rules.json](https://nightshade.dicksonwu.xyz/rules.json)
- [All rules](https://nightshade.dicksonwu.xyz/rules.md#audit-default-ordinary-rules)
- [Limitations](https://nightshade.dicksonwu.xyz/limitations.md)
