• Stars
    star
    147
  • Rank 243,912 (Top 5 %)
  • Language
    Python
  • License
    GNU Affero Genera...
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Amarna is a static-analyzer and linter for the Cairo programming language.

Amarna

Amarna is a static-analyzer and linter for the Cairo programming language.

Features

  • Finds code-smells and potential vulnerabilities in Cairo code
  • Compiler-identical parsing of Cairo code and StarkNet contracts
  • Supports creating local and global rules
  • Exports the parsed AST of a Cairo file
  • Exports static-analysis results to the SARIF format.

Basic Usage

Analyze a Cairo project in the current directory and export the SARIF results to a file:

amarna . -o out.sarif

Analyze a single file file.cairo and export the SARIF results to a file:

amarna file.cairo -o out.sarif

Analyze a single file file.cairo and print a summary of the results:

amarna file.cairo -s

Integration

Currently supported rules

# Rule What it finds Impact Precision
1 Arithmetic operations All uses of arithmetic operations +, -, *, and / Info High
2 Unused arguments Function arguments that are not used in the functions in which they appear Warning High
3 Unused imports Unused imports Info High
4 Mistyped decorators Mistyped code decorators Info High
5 Unused functions Functions that are never called Info Medium
6 Error codes Function calls that have return values that must be checked Info High
7 Inconsistent assert usage Asserts that use the same constant in different ways, e.g., assert_le(amount, BOUND) and assert_le(amount, BOUND - 1) Warning High
8 Dead stores Variables that are assigned values but not used before a return statement Info Medium
9 Unchecked overflows Function calls that ignore the returned overflow flags, e.g., uint256_add Warning High
10 Caller address return value Function calls to the get_caller_address function. Info High
11 Storage variable collision Multiple @storage_var with the same name. (deprecated) Warning High
12 Implicit function import Function with decorator @external, @view, @l1_handler that is being implicitly imported. (deprecated) Info High
13 Unenforced view function State modification within a @view function Info High
14 Uninitialized variable Local variables that are never initialized. Info High

Usage

Analyze a Cairo project in the current directory and export results to a file:

amarna . -o out.sarif

Analyze a single file deleverage.cairo and export results to a file:

amarna deleverage.cairo -o deleverage.sarif

Analyze a single file code.cairo and print a summary of the results:

amarna code.cairo -s

Parse a Cairo file and output the recovered AST in png:

amarna file.cairo -png

Analyze a Cairo file with the unused_import rule:

amarna file.cairo --rules=unused-imports

Analyze a Cairo file using all rules except the arithmetic-add rule:

amarna file.cairo --except-rules=arithmetic-add

The full help menu is:

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 file format

The SARIF file format is a standard format for static-analysis tools and can be viewed in vscode with the official extension.

Installation

pip install amarna

How the rules work

The static-analysis rules can be:

  • local rules, which analyse each file independently.
  • gatherer rules, which analyse each file independently and gather data to be used in post-process rules.
  • post-process rules, which run after all files were analyzed can use the data gathered in the gatherer rules.

Examples of these are:

  • local rules: find all arithmetic operations in a file
  • gatherer rules: gather all declared functions, and called functions
  • post-process rules: find unused functions using the gathered data, i.e., functions that were declared but never called.

Rule allowlist, denylist and inline comments

Rule names

Obtain the names of the currently implemented rules with:

 amarna --show-rules

Rule allowlist

Run amarna with a defined set of rules using

 amarna --rules=rule1,rule2 .

The following command will only run the unused-imports rule and print the summary result

 amarna --rules=unused-imports . -s

Rule denylist

Run amarna with all rules except a defined set of rules using

 amarna --exclude-rules=arithmetic-add,arithmetic-sub . -s

Inline rule disabling comments

You can change the first line of a cairo file to disable a specific rule set on that file. For example, adding the line

// amarna: disable=arithmetic-div,arithmetic-sub,arithmetic-mul,arithmetic-add

as the first line of file.cairo and running amarna with

amarna directory/ --disable-inline -s

will not report any arithmetic rule to the file.cairo file.

More Repositories

1

slither

Static Analyzer for Solidity and Vyper
Python
4,971
star
2

echidna

Ethereum smart contract fuzzer
Solidity
2,588
star
3

not-so-smart-contracts

Examples of Solidity security issues
Solidity
2,097
star
4

building-secure-contracts

Guidelines and training material to write secure smart contracts
Solidity
2,069
star
5

evm-opcodes

Ethereum opcodes and instruction reference
1,270
star
6

awesome-ethereum-security

A curated list of awesome Ethereum security references
1,256
star
7

ethersplay

EVM dissassembler
Python
816
star
8

solc-select

Manage and switch between Solidity compiler versions
Python
730
star
9

blockchain-security-contacts

Directory of security contacts for blockchain companies
395
star
10

rattle

evm binary static analysis
Python
348
star
11

pyevmasm

Ethereum Virtual Machine (EVM) disassembler and assembler
Python
341
star
12

etheno

Simplify Ethereum security analysis and testing
Python
330
star
13

ida-evm

IDA Processor Module for the Ethereum Virtual Machine (EVM)
Python
297
star
14

medusa

Parallelized, coverage-guided, mutational Solidity smart contract fuzzing, powered by go-ethereum
Go
254
star
15

properties

Pre-built security properties for common Ethereum operations
Solidity
237
star
16

crytic-compile

Abstraction layer for smart contract build systems
Python
137
star
17

caracal

Static Analyzer for Starknet smart contracts
Cairo
124
star
18

slither-action

Shell
121
star
19

evm_cfg_builder

EVM CFG recovery
Python
110
star
20

optik

Optik is a set of symbolic execution tools that assist smart-contract fuzzers
Python
89
star
21

echidna-streaming-series

A 6-part series on how to use Echidna on real-world codebases
Solidity
88
star
22

roundme

Rust
85
star
23

tayt

StarkNet smart contract fuzzer
Python
75
star
24

fuzz-utils

A tool to automatically generate Foundry unit test cases from Echidna and Medusa failed properties
Solidity
75
star
25

diffusc

Experimental tool to ease the review of smart contracts upgrades
Solidity
69
star
26

tealer

Static Analyzer for Teal
Python
61
star
27

echidna-action

GitHub Action to run Echidna, the Ethereum smart contract fuzzer
Shell
58
star
28

fluxture

A crawling framework for blockchains and peer-to-peer systems
Python
46
star
29

attacknet

Tool and testing methodology for subjecting blockchain devnets to simulated network and side channel attacks
Go
43
star
30

secureum-medusa

Solidity
42
star
31

echidna-spearbit-demo

Example code for testing using Echidna explained during the Spearbit presentation
Solidity
38
star
32

slither-docs-action

Write documentation for your code in pull requests using Slither and OpenAI.
TypeScript
36
star
33

echidna-parade

Python
28
star
34

solana-lints

Lints based on the Sealevel Attacks
Rust
28
star
35

contract-explorer

Visual Studio Code integration for Slither, a Solidity static analysis framework
TypeScript
28
star
36

whipstaff

A specification of the CBC Casper consensus protocols written in TLA+ and PlusCal (transpiled to TLA+)
TLA
20
star
37

trailofbits-security

The Trail of Bits Truffle Security Toolbox
JavaScript
20
star
38

cloudexec

A general purpose foundation for cloud-based fuzzing and mutation testing jobs
Go
15
star
39

damn-vulnerable-defi-echidna

Solidity
13
star
40

amarna-action

Github action for the Amarna static analyzer
Shell
10
star
41

medusa-geth

A go-ethereum fork enabling additional testing capabilities for medusa
10
star
42

slightly-smarter-contracts

Python
7
star
43

slither-docs-demo

A demo on how to use the slither-docs actions (https://github.com/crytic/slither-docs-action)
Solidity
7
star
44

vscode-starknet-explorer

StarkNet support extension for VSCode. Visualize StarkNet contracts: view storage variables, external and view functions, and events.
TypeScript
6
star
45

solc

4
star
46

embark-contract-info

embark-contract-info
JavaScript
3
star
47

fuzz-vs-fv

TypeScript
3
star
48

addressarrayutils_demo

Demonstration for using echidna to test a Solidity library
Solidity
2
star
49

remix-plugin-8000

JavaScript
2
star
50

ethdam

1
star
51

slither-lsp

Python
1
star