crytic / amarna

Amarna is a static-analyzer and linter for the Cairo programming language.
https://blog.trailofbits.com/2022/04/20/amarna-static-analysis-for-cairo-programs/
GNU Affero General Public License v3.0
149 stars 7 forks source link

Add a rule to point out unused variables #62

Closed milancermak closed 1 year ago

milancermak commented 1 year ago

Amarna already lovingly warns about unused imports, function call arguments or functions themselves. Can you add a rule to warn about unused variables to its arsenal as well?

Example:

func foo{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (val):
    let (caller) = get_caller_address()
    return (42)
end

In the above example, caller is never used. The rule would point it out.

fcasal commented 1 year ago

Hi @milancermak, Amarna already finds this with the dead-store rule: there was a value saved in caller but never used before a return statement: image

Let me know if there are examples where you don't see this being found!

milancermak commented 1 year ago

Ah, you're right. I even though I saw it before but whilst doing code review on a PR, I've noticed an unused variable but no Amarna warning attached (link if you're curious, line 131 in Food.cairo). It probably has something to do with the GitHub action, because when I run amarna locally on the file, it does catch it. Sorry for the false alarm 🙏