# duplicated-branch-tail

> Terminating branch repeats its immediate following expression and return tail.

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

| Field | Value |
| --- | --- |
| Rule ID | `duplicated-branch-tail` |
| 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 duplicated-branch-tail
./.nightshade/node_modules/.bin/nightshade detector show duplicated-branch-tail
```

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 |
| ---: | ---: | ---: | ---: | ---: |
| 1/1 | 1/1 | 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](https://nightshade.dicksonwu.xyz/evaluation.md#synthetic-corpus).

## Rule documentation

From https://github.com/DicksonWu654/nightshade/blob/v0.1.1/docs/detectors/duplicated-branch-tail.md at v0.1.1.

Availability: **default-on**; no policy required.
Severity **info**, confidence **high** for the resolved source observation.
Use `--min-severity low` to hide informational findings.

Reports one to seven expression statements and an explicit return copied between
the end of a terminating branch and its immediate following continuation. Both
copies must resolve to the same symbols, operations, types and expression tree.
This is source duplication across alternative routes, not duplicate execution.

### Example and review scenario

For example:

```compact
if (disclose(flag)) {
  round.increment(1);
  return [];
}
round.increment(1);
return [];
```

Each route increments once. Consider sharing the tail after any branch-specific
work. The finding is a source-quality observation, not an authorization or
monetary defect.

### False positives and limitations

Authors may deliberately keep alternative routes visually independent. Identical
resolved source is the fact reported; removal or hoisting is a review decision.
Preserve return behavior, proof constraints, disclosure and transaction ordering.
No optimized compiler/prover cost reduction is claimed.

Resolved circuit bodies in the compilation unit are examined, including imported
instances and calls in source-excluded code. Unresolved unused library APIs are
outside this observation; this is not a whole-library analysis. Unknown conditions retain
both alternatives; source-constant excluded branches and unreachable suffixes
are quiet. Bindings, callbacks, nested control inside the copied tail, implicit
returns, longer tails and merely value-equivalent expressions are outside the
contract. Same-name references that resolve differently stay quiet. Exhausted
source traversal produces explicit rule-scoped incomplete diagnostics for every
entry. Baseline transfer completion and unrelated rules remain independently
reported. With no entry row, exhaustion retains an explicit root diagnostic.

## 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 duplicated-branch-tail -- 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/duplicated-branch-tail.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)
