-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acdab6e
commit 66eee51
Showing
9 changed files
with
133 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Detector } from "../detector"; | ||
import { MistiContext } from "../../internals/context"; | ||
import { CompilationUnit } from "../../internals/ir"; | ||
import { foldExpressions } from "../../internals/tactASTUtil"; | ||
import { createError, MistiTactError, Severity } from "../../internals/errors"; | ||
import { ASTExpression } from "@tact-lang/compiler/dist/grammar/ast"; | ||
|
||
function findZeroAddress( | ||
acc: MistiTactError[], | ||
expr: ASTExpression, | ||
): MistiTactError[] { | ||
if (expr.kind === "op_static_call") { | ||
if ( | ||
expr.name === "newAddress" && | ||
expr.args.length === 2 && | ||
expr.args[1].kind === "number" && | ||
expr.args[1].value === 0n | ||
) { | ||
acc.push( | ||
createError("Using zero address", Severity.MEDIUM, expr.args[1].ref), | ||
); | ||
} | ||
} | ||
return acc; | ||
} | ||
|
||
/** | ||
* A detector that identifies uses of zero address. | ||
* | ||
* Using the zero address in smart contracts is typically problematic because it can be | ||
* exploited as a default or uninitialized address, leading to unintended transfers and | ||
* security vulnerabilities. Additionally, operations involving the zero address can | ||
* result in loss of funds or tokens, as there is no private key to access this address. | ||
*/ | ||
export class ZeroAddress extends Detector { | ||
get id(): string { | ||
return "ZeroAddress"; | ||
} | ||
|
||
check(_ctx: MistiContext, cu: CompilationUnit): MistiTactError[] { | ||
return cu.ast.getProgramEntries().reduce((acc, node) => { | ||
return acc.concat(foldExpressions(node, [], findZeroAddress)); | ||
}, [] as MistiTactError[]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"projectName": "zero-address", | ||
"functions": [], | ||
"contracts": [ | ||
{ | ||
"name": "SampleContract", | ||
"methods": [ | ||
{ | ||
"name": "SampleContract.init", | ||
"cfg": { | ||
"nodes": [ | ||
{ | ||
"id": 606, | ||
"stmtID": 8037, | ||
"srcEdges": [], | ||
"dstEdges": [] | ||
} | ||
], | ||
"edges": [] | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
/home/jubnzv/Dev/misti/test/contracts/zero-address.tact:3:23: | ||
2 | init() { | ||
> 3 | newAddress(1, 0x000000000000000000000000000000000000000000000000); | ||
^ | ||
4 | } | ||
Using zero address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract SampleContract { | ||
init() { | ||
newAddress(1, 0x000000000000000000000000000000000000000000000000); | ||
} | ||
} |