From 74a89c4186e4a2664a5b2caa3b45b9989d00d717 Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Thu, 31 Oct 2024 12:25:47 +0000 Subject: [PATCH] fix(sendInLoop): Stack overflow on large contracts --- src/detectors/builtin/sendInLoop.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/detectors/builtin/sendInLoop.ts b/src/detectors/builtin/sendInLoop.ts index fe458c5b..6945cc04 100644 --- a/src/detectors/builtin/sendInLoop.ts +++ b/src/detectors/builtin/sendInLoop.ts @@ -1,5 +1,9 @@ import { CompilationUnit } from "../../internals/ir"; -import { foldStatements, foldExpressions, isSelf } from "../../internals/tact"; +import { + forEachStatement, + foldExpressions, + isSelf, +} from "../../internals/tact"; import { MistiTactWarning, Severity } from "../../internals/warnings"; import { ASTDetector } from "../detector"; import { @@ -38,18 +42,16 @@ export class SendInLoop extends ASTDetector { async check(cu: CompilationUnit): Promise { const processedLoopIds = new Set(); - return Array.from(cu.ast.getProgramEntries()).reduce((acc, node) => { - return acc.concat( - ...foldStatements( - node, - (acc, stmt) => { - return acc.concat(this.analyzeStatement(stmt, processedLoopIds)); - }, - acc, - { flatStmts: true }, - ), - ); - }, [] as MistiTactWarning[]); + const allWarnings: MistiTactWarning[] = []; + + Array.from(cu.ast.getProgramEntries()).forEach((node) => { + forEachStatement(node, (stmt) => { + const warnings = this.analyzeStatement(stmt, processedLoopIds); + allWarnings.push(...warnings); + }); + }); + + return allWarnings; } private analyzeStatement(