amarna
v0.1.5 - Support for Cairo v0.10
Amarna是开罗编程语言的静态分析仪和衬里。
分析当前目录中的开罗项目,并将SARIF结果导出到文件:
amarna . -o out.sarif分析单个文件file.cairo并将SARIF结果导出到文件:
amarna file.cairo -o out.sarif分析单个文件file.cairo并打印结果摘要:
amarna file.cairo -s| # | 规则 | 它找到的 | 影响 | 精确 |
|---|---|---|---|---|
| 1 | 算术操作 | 算术操作的所有用途 +, - , *和 / | 信息 | 高的 |
| 2 | 未使用的论点 | 它们出现的功能中未使用的函数参数 | 警告 | 高的 |
| 3 | 未使用的进口 | 未使用的进口 | 信息 | 高的 |
| 4 | 错误的装饰器 | 错误的代码装饰器 | 信息 | 高的 |
| 5 | 未使用的功能 | 从未被调用的功能 | 信息 | 中等的 |
| 6 | 错误代码 | 具有必须检查的返回值的函数调用 | 信息 | 高的 |
| 7 | 不一致的说法 | 断言以不同方式使用相同常数的断言,例如, assert_le(amount, BOUND)和assert_le(amount, BOUND - 1) | 警告 | 高的 |
| 8 | 死商店 | 分配值但在返回语句之前未使用的变量 | 信息 | 中等的 |
| 9 | 未检查的溢出 | 忽略返回溢出标志的函数调用,例如, uint256_add | 警告 | 高的 |
| 10 | 呼叫者地址返回值 | 函数调用到get_caller_address函数。 | 信息 | 高的 |
| 11 | 存储变量碰撞 | 多个@storage_var具有相同名称。 (弃用) | 警告 | 高的 |
| 12 | 隐式函数导入 | 使用Decorator @external, @view, @l1_handler函数,该功能被隐式导入。 (弃用) | 信息 | 高的 |
| 13 | 未经执行的视图功能 | @view功能中的状态修改 | 信息 | 高的 |
| 14 | 非初始化的变量 | 从未初始化的本地变量。 | 信息 | 高的 |
分析当前目录中的开罗项目,并将结果导出到文件:
amarna . -o out.sarif分析单个文件deleverage.cairo和导出结果:
amarna deleverage.cairo -o deleverage.sarif分析单个文件code.cairo并打印结果摘要:
amarna code.cairo -s解析开罗文件并输出png中恢复的AST:
amarna file.cairo -png用UNUSED_IMPORT规则分析开罗文件:
amarna file.cairo --rules=unused-imports使用所有规则除外的所有规则分析开罗文件:
amarna file.cairo --except-rules=arithmetic-add完整的帮助菜单是:
usage: amarna [-h] [-p] [-o OUTPUT] [-s] [-png] [-rules RULES] [-exclude-rules EXCLUDE_RULES] [-show-rules] [-disable-inline] -f
Amarna is a static-analyzer for the Cairo programming language.
positional arguments:
-f the name of the .cairo file or directory with .cairo files to analyze
optional arguments:
-h, --help show this help message and exit
-p, --print print output
-o OUTPUT, --output OUTPUT
file to write the output results in sarif format
-s, -summary, --summary
output summary
-png, --png save a png with the AST of a file
-rules RULES, --rules RULES
Only run this set of rules. Enter rule names comma-separated, e.g., dead-store,unused-arguments
-exclude-rules EXCLUDE_RULES, --exclude-rules EXCLUDE_RULES
Exclude these rules from the analysis. Enter rule names comma-separated, e.g., dead-store,unused-arguments
-show-rules, --show-rules
Show all supported rules and descriptions.
-disable-inline, --disable-inline
Disable rules with inline comments. The comments should be the first line and of the form: # amarna: disable=rulename1,rulename2
SARIF文件格式是用于静态分析工具的标准格式,可以在VSCODE中查看官方扩展名。
pip install amarna静态分析规则可能是:
这些例子是:
获取当前实施规则的名称:
amarna --show-rules使用一套定义的规则运行Amarna
amarna --rules=rule1,rule2 .以下命令只会运行unused-imports规则并打印摘要结果
amarna --rules=unused-imports . -s除了使用定义的规则集以外,运行Amarna
amarna --exclude-rules=arithmetic-add,arithmetic-sub . -s您可以更改开罗文件的第一行,以禁用该文件上的特定规则。例如,添加行
// amarna: disable=arithmetic-div,arithmetic-sub,arithmetic-mul,arithmetic-add作为第一行file.cairo和与
amarna directory/ --disable-inline -s不会向file.cairo文件报告任何算法规则。