Rule

duplicated-branch-tail

Terminating branch repeats its immediate following expression and return tail.

Release v0.1.1View Markdown

Specimen 06 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 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 detectedCorrected quietLookalike quietOther negative quietIncomplete
1/11/11/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/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 for fingerprint suppressions and baselines.

References#