Fix support for constant variable lookup in yul

Fix #1610
pull/1611/head
Feist Josselin 2 years ago
parent 4c976d5af5
commit fb3c863dc8
  1. 5
      slither/solc_parsing/yul/parse_yul.py
  2. BIN
      tests/ast-parsing/compile/yul-state-constant-access.sol-0.8.16-compact.zip
  3. 12
      tests/ast-parsing/expected/yul-state-constant-access.sol-0.8.16-compact.json
  4. 25
      tests/ast-parsing/yul-state-constant-access.sol
  5. 1
      tests/test_ast_parsing.py

@ -792,8 +792,9 @@ def parse_yul_identifier(root: YulScope, _node: YulNode, ast: Dict) -> Optional[
return Identifier(local_variable)
if isinstance(parent_func, FunctionContract):
assert parent_func.contract
state_variable = parent_func.contract.get_state_variable_from_name(name)
# Variables must be looked from the contract declarer
assert parent_func.contract_declarer
state_variable = parent_func.contract_declarer.get_state_variable_from_name(name)
if state_variable:
return Identifier(state_variable)

@ -0,0 +1,12 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n",
"f2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: INLINE ASM 2\n\"];\n2->3;\n3[label=\"Node Type: EXPRESSION 3\n\"];\n}\n",
"f3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n",
"f2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: INLINE ASM 2\n\"];\n2->3;\n3[label=\"Node Type: EXPRESSION 3\n\"];\n}\n",
"f3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,25 @@
contract A{
uint private constant a = 10;
function f() public returns(uint){
return a;
}
function f2() public returns(uint){
uint ret;
assembly{
ret := a
}
}
function f3() public returns(uint){
uint ret;
unchecked{
ret = a;
}
}
}
contract B is A{
}

@ -443,6 +443,7 @@ ALL_TESTS = [
Test("top-level-struct-0.8.0.sol", ["0.8.0"]),
Test("yul-top-level-0.8.0.sol", ["0.8.0"]),
Test("complex_imports/import_aliases_issue_1319/test.sol", ["0.5.12"]),
Test("yul-state-constant-access.sol", ["0.8.16"])
]
# create the output folder if needed
try:

Loading…
Cancel
Save