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

amarna crashes on starkware.cairo.common.patricia #29

Closed axic closed 2 years ago

axic commented 2 years ago
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 126, in feed_token
    action, arg = states[state][token.type]
KeyError: 'IDENTIFIER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/bin/amarna", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/amarna/command_line.py", line 154, in main
    results = analyze_directory(filename, rule_set_names)
  File "/opt/homebrew/lib/python3.9/site-packages/amarna/amarna.py", line 149, in analyze_directory
    parsed_cairo_file = amarna.parse_cairo_file(fname)
  File "/opt/homebrew/lib/python3.9/site-packages/amarna/amarna.py", line 130, in parse_cairo_file
    return self.parser.parse(f.read() + "\n", start="cairo_file")
  File "/opt/homebrew/lib/python3.9/site-packages/lark/lark.py", line 625, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
  File "/opt/homebrew/lib/python3.9/site-packages/lark/parser_frontends.py", line 96, in parse
    return self.parser.parse(stream, chosen_start, **kw)
  File "/opt/homebrew/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 41, in parse
    return self.parser.parse(lexer, start)
  File "/opt/homebrew/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 171, in parse
    return self.parse_from_state(parser_state)
  File "/opt/homebrew/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 188, in parse_from_state
    raise e
  File "/opt/homebrew/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 179, in parse_from_state
    state.feed_token(token)
  File "/opt/homebrew/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 129, in feed_token
    raise UnexpectedToken(token, expected, state=self, interactive_parser=None)
lark.exceptions.UnexpectedToken: Unexpected token Token('IDENTIFIER', 'PatriciaUpdateConstants') at line 476, column 43.
Expected one of: 
    * LBRACE
    * MINUS
    * _DBL_STAR
    * COMMENT
    * STAR
    * SLASH
    * _NEWLINE
    * LSQB
    * RPAR
    * LPAR
    * PLUS
    * DOT
    * COMMA

I believe it crashes on this file:

./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:# Holds the constants needed for Patricia updates.
./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:struct PatriciaUpdateConstants:
./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:# Performs an efficient update of multiple leaves in a Patricia Merkle tree.
./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:# preimage - a dictionary from the hash value of a Patricia node to either
./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:    let (patricia_update_constants : PatriciaUpdateConstants*) = patricia_update_constants_new()
./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:func patricia_update_constants_new() -> (patricia_update_constants : PatriciaUpdateConstants*):
./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:    return (patricia_update_constants=new PatriciaUpdateConstants(globals_pow2=globals_pow2))
./lib/python3.9/site-packages/starkware/cairo/common/patricia.cairo:    patricia_update_constants : PatriciaUpdateConstants*,

I'm using cairo-lang 0.8.2.1.

It seems the new PatriciaUpdateConstants(...) expression is not supported.