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文件報告任何算法規則。