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 -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-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를
amarna directory/ --disable-inline -s 산술 규칙을 file.cairo 파일에보고하지 않습니다.