アマルナは、カイロプログラミング言語の静的アナリーザーとリナーです。
現在のディレクトリでカイロプロジェクトを分析し、SARIFの結果をファイルにエクスポートします。
amarna . -o out.sarif単一のファイルfile.cairoを分析して、cairo。サリフの結果をファイルにエクスポートします。
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 | 暗黙の関数インポート | デコレーター@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カイロファイルを解析し、回収されたASTをpngに出力します。
amarna file.cairo -pngUNUSED_IMPORTルールを使用してカイロファイルを分析します。
amarna file.cairo --rules=unused-imports算術-ADDルールを除くすべてのルールを使用して、カイロファイルを分析します。
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-rulesAmarnaを使用して定義された一連のルールを実行します
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を実行している
amarna directory/ --disable-inline -s算術ルールはfile.cairoファイルに報告されません。