Rule

always-true-assertion

Assertion is already true on every analyzed reach before enforcing it.

Release v0.1.1View Markdown

Specimen 25 of 96 · Additional hygiene rules

Severity
info
Confidence
high
Maturity
experimental
Selection
Hygiene only
Policy intent
not required
Release
v0.1.1
Engine facts used
assertion-reaches completed-entries

Selection and scope#

Not in the default profile. --profile hygiene adds it, or select it explicitly with --detectors.

Shell
./.nightshade/node_modules/.bin/nightshade ./contracts --detectors always-true-assertion
./.nightshade/node_modules/.bin/nightshade detector show always-true-assertion

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/always-true-assertion.md at v0.1.1.

Availability: default-on; no policy required. Severity info, confidence high for modeled pre-assertion truth. Use --min-severity low to hide informational findings, or --detectors always-true-assertion to select only this rule.

Reports a root-file assertion already true on every modeled reach before that assertion adds a constraint. All reaching entries and potential callers must have complete analysis; unknown or uncovered reaches prevent a universal claim.

Example and review scenario#

The compiler-0.34.0-qualified owned Counter fixture uses self-equality for an intended counter-started check. Its correction expresses that intended precondition:

Compact
assert(round > 0, "counter started");

Recommendation: check for a missing or mistaken operand, then restore the actual condition. Review earlier guards before removing a repeated assertion.

False positives and limitations#

Defensive helper checks can be intentionally redundant after caller guards, and fixed inputs can make an assertion trivially true. High confidence describes the modeled observation, not a security defect or advice to delete the check. Assertions outside the root file are not reported. Unknown facts, incomplete callers and exhausted budgets cannot establish universal truth.

Source examples#

These short regression examples are included here for installed-package readers. Rule-specific policy requirements and limits above still apply.

Example 1#

Counter fixture (source: tests/corpus/informational/always-true-assertion-positive.compact).

Compact
// This file is part of midnightntwrk/example-counter.
// Copyright (C) Midnight Foundation
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pragma language_version >= 0.20;

import CompactStandardLibrary;

// public state
export ledger round: Counter;

// Nightshade owned informational regression; adapted from example-counter.
export circuit increment(): [] {
  assert(round == round, "counter started");
  round.increment(1);
}

Example 2#

Correction (source: tests/corpus/informational/always-true-assertion-corrected.compact).

Compact
// This file is part of midnightntwrk/example-counter.
// Copyright (C) Midnight Foundation
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pragma language_version >= 0.20;

import CompactStandardLibrary;

// public state
export ledger round: Counter;

// Nightshade owned informational regression; adapted from example-counter.
export circuit increment(): [] {
  assert(round > 0, "counter started");
  round.increment(1);
}

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 always-true-assertion -- 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#