Skip to content

Commit

Permalink
feat(callgraph): Add effects (#227)
Browse files Browse the repository at this point in the history
Closes #189

---------

Co-authored-by: Georgiy Komarov <[email protected]>
  • Loading branch information
Esorat and jubnzv authored Dec 2, 2024
1 parent db3d24a commit 21e0af1
Show file tree
Hide file tree
Showing 17 changed files with 1,375 additions and 200 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `ShortCircuitCondition` detector: PR [#202](https://github.com/nowarp/misti/pull/202)
- `PreferredStdlibApi` detector now suggest some preferred replacements for cell methods
- Add Callgraph: PR [#185](https://github.com/nowarp/misti/pull/185)
- Add function effects to Callgraph: PR [#227](https://github.com/nowarp/misti/pull/227)

### Changed
- `SuspiciousMessageMode` detector now suggests using SendDefaultMode instead of 0 for mode: PR [#199](https://github.com/nowarp/misti/pull/199/)
Expand Down
18 changes: 8 additions & 10 deletions src/detectors/builtin/ensurePrgSeed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { CompilationUnit } from "../../internals/ir";
import { forEachExpression } from "../../internals/tact";
import {
forEachExpression,
PRG_INIT_NAMES,
PRG_NATIVE_USE_NAMES,
} from "../../internals/tact";
import { MistiTactWarning, Severity } from "../../internals/warnings";
import { ASTDetector } from "../detector";
import { AstStaticCall, idText } from "@tact-lang/compiler/dist/grammar/ast";
Expand Down Expand Up @@ -38,20 +42,14 @@ export class EnsurePrgSeed extends ASTDetector {
severity = Severity.MEDIUM;

async check(cu: CompilationUnit): Promise<MistiTactWarning[]> {
const prgInitNames = new Set([
"nativePrepareRandom",
"nativeRandomize",
"nativeRandomizeLt",
]);
const prgUseNames = new Set(["nativeRandom", "nativeRandomInterval"]);
const randomCalls = cu.ast.getProgramEntries().reduce(
(acc, node) => {
forEachExpression(node, (expr) => {
if (expr.kind === "static_call") {
if (prgInitNames.has(idText(expr.function))) {
if (PRG_INIT_NAMES.has(idText(expr.function))) {
acc.hasInitializer = true;
}
if (prgUseNames.has(idText(expr.function))) {
if (PRG_NATIVE_USE_NAMES.has(idText(expr.function))) {
acc.uses.push(expr);
}
}
Expand All @@ -72,7 +70,7 @@ export class EnsurePrgSeed extends ASTDetector {
`PRG seed should be initialized before using ${idText(use.function)}`,
use.loc,
{
suggestion: `Use ${Array.from(prgInitNames)
suggestion: `Use ${Array.from(PRG_INIT_NAMES)
.map((name) => "`" + name + "`")
.join(
", ",
Expand Down
4 changes: 2 additions & 2 deletions src/detectors/builtin/sendInLoop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompilationUnit } from "../../internals/ir";
import { CallGraph } from "../../internals/ir/callGraph";
import { CallGraph, Effect } from "../../internals/ir/callGraph";
import { forEachStatement, foldExpressions } from "../../internals/tact";
import { isSendCall } from "../../internals/tact/util";
import { MistiTactWarning, Severity } from "../../internals/warnings";
Expand Down Expand Up @@ -120,7 +120,7 @@ export class SendInLoop extends ASTDetector {
const calleeNodeId = callGraph.getNodeIdByName(calleeName);
if (calleeNodeId !== undefined) {
const calleeNode = callGraph.getNode(calleeNodeId);
if (calleeNode && calleeNode.hasFlag(0b0001)) {
if (calleeNode && calleeNode.hasEffect(Effect.Send)) {
const functionName = calleeNode.name.includes("::")
? calleeNode.name.split("::").pop()
: calleeNode.name;
Expand Down
Loading

0 comments on commit 21e0af1

Please sign in to comment.