diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af4d05f..1eb6381f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `ShortCircuitCondition` detector: PR [#202](https://github.com/nowarp/misti/pull/202) +### Changed +- `SuspiciousMessageMode` detector now suggests using SendDefaultMode instead of 0 for mode: PR [#199](https://github.com/nowarp/misti/pull/199/) ## [0.5.0] - 2024-10-31 diff --git a/src/detectors/builtin/suspiciousMessageMode.ts b/src/detectors/builtin/suspiciousMessageMode.ts index d53cc320..05b7c06b 100644 --- a/src/detectors/builtin/suspiciousMessageMode.ts +++ b/src/detectors/builtin/suspiciousMessageMode.ts @@ -72,6 +72,20 @@ export class SuspiciousMessageMode extends ASTDetector { expr: AstExpression, warnings: MistiTactWarning[], ): void { + if (expr.kind === "number" && expr.value === 0n) { + warnings.push( + this.makeWarning( + "Setting `mode` to `0` is redundant as it has no effect.", + expr.loc, + { + suggestion: + "Remove the `mode` field or set it to `SendDefaultMode`.", + }, + ), + ); + return; + } + const flagsUsed = new Set(); forEachExpression(expr, (e) => { switch (e.kind) { diff --git a/test/detectors/SuspiciousMessageMode.expected.out b/test/detectors/SuspiciousMessageMode.expected.out index fb6ffc98..ec311b5c 100644 --- a/test/detectors/SuspiciousMessageMode.expected.out +++ b/test/detectors/SuspiciousMessageMode.expected.out @@ -68,4 +68,13 @@ test/detectors/SuspiciousMessageMode.tact:61:21: ^ 62 | }); Help: Use the '|' operator (bitwise OR) to combine flags +See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode + +[MEDIUM] SuspiciousMessageMode: Setting `mode` to `0` is redundant as it has no effect. +test/detectors/SuspiciousMessageMode.tact:79:15: + 78 | value: 0, +> 79 | mode: 0 // Bad: Should trigger warning about `mode: 0` being redundant + ^ + 80 | }); +Help: Remove the `mode` field or set it to `SendDefaultMode`. See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode \ No newline at end of file diff --git a/test/detectors/SuspiciousMessageMode.tact b/test/detectors/SuspiciousMessageMode.tact index a6dc898b..836c2e70 100644 --- a/test/detectors/SuspiciousMessageMode.tact +++ b/test/detectors/SuspiciousMessageMode.tact @@ -71,4 +71,12 @@ contract SendParametersTestContract { mode: modeFlag // Ok }); } + + fun modeZeroUsage() { + send(SendParameters{ + to: sender(), + value: 0, + mode: 0 // Bad: Should trigger warning about `mode: 0` being redundant + }); +} }