diff --git a/slither/solc_parsing/yul/parse_yul.py b/slither/solc_parsing/yul/parse_yul.py index f7c9938fc..6be4803ca 100644 --- a/slither/solc_parsing/yul/parse_yul.py +++ b/slither/solc_parsing/yul/parse_yul.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) diff --git a/tests/ast-parsing/compile/yul-state-constant-access.sol-0.8.16-compact.zip b/tests/ast-parsing/compile/yul-state-constant-access.sol-0.8.16-compact.zip new file mode 100644 index 000000000..121d6c5ec Binary files /dev/null and b/tests/ast-parsing/compile/yul-state-constant-access.sol-0.8.16-compact.zip differ diff --git a/tests/ast-parsing/expected/yul-state-constant-access.sol-0.8.16-compact.json b/tests/ast-parsing/expected/yul-state-constant-access.sol-0.8.16-compact.json new file mode 100644 index 000000000..6c6bc9377 --- /dev/null +++ b/tests/ast-parsing/expected/yul-state-constant-access.sol-0.8.16-compact.json @@ -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" + } +} \ No newline at end of file diff --git a/tests/ast-parsing/yul-state-constant-access.sol b/tests/ast-parsing/yul-state-constant-access.sol new file mode 100644 index 000000000..543d79744 --- /dev/null +++ b/tests/ast-parsing/yul-state-constant-access.sol @@ -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{ + +} \ No newline at end of file diff --git a/tests/test_ast_parsing.py b/tests/test_ast_parsing.py index 14130b428..c783f827f 100644 --- a/tests/test_ast_parsing.py +++ b/tests/test_ast_parsing.py @@ -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: