Skip to content

Commit

Permalink
Merge branch 'dev' into fix-unicode-src-mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Feb 24, 2025
2 parents e7c791b + 88fdafb commit 260b744
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 17 deletions.
29 changes: 14 additions & 15 deletions slither/solc_parsing/yul/parse_yul.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,27 +798,12 @@ def parse_yul_identifier(root: YulScope, _node: YulNode, ast: Dict) -> Optional[
if name in builtins:
return Identifier(YulBuiltin(name))

# check function-scoped variables
parent_func = root.parent_func
if parent_func:
local_variable = parent_func.get_local_variable_from_name(name)
if local_variable:
return Identifier(local_variable)

if isinstance(parent_func, FunctionContract):
# 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)

# check yul-scoped variable
variable = root.get_yul_local_variable_from_name(name)
if variable:
return Identifier(variable.underlying)

# check yul-scoped function

func = root.get_yul_local_function_from_name(name)
if func:
return Identifier(func.underlying)
Expand All @@ -840,6 +825,20 @@ def parse_yul_identifier(root: YulScope, _node: YulNode, ast: Dict) -> Optional[
if func:
return Identifier(func.underlying)

# check function-scoped variables
parent_func = root.parent_func
if parent_func:
local_variable = parent_func.get_local_variable_from_name(name)
if local_variable:
return Identifier(local_variable)

if isinstance(parent_func, FunctionContract):
# 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)

magic_suffix = _parse_yul_magic_suffixes(name, root)
if magic_suffix:
return magic_suffix
Expand Down
3 changes: 2 additions & 1 deletion slither/tools/read_storage/read_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,12 @@ def _find_struct_var_slot(
slot = int.from_bytes(slot_as_bytes, "big")
offset = 0
type_to = ""
size = 0
for var in elems:
var_type = var.type
if isinstance(var_type, ElementaryType):
size = var_type.size
if offset >= 256:
if size > (256 - offset):
slot += 1
offset = 0
if struct_var == var.name:
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/solc_parsing/test_data/assembly-functions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ contract A {
}
}
}

// Issue https://github.com/crytic/slither/issues/2655
contract B {
function test(int256 a) internal {
assembly {
function a() {}
function b() { a() }
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"foo.asm_0.w.a()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n}\n",
"foo.asm_0.w.b()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n",
"foo.asm_0.g()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
},
"B": {
"test(int256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: END INLINE ASM 2\n\"];\n}\n",
"test.asm_0.a()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n}\n",
"test.asm_0.b()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"A": {
"foo()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: END INLINE ASM 2\n\"];\n}\n"
},
"B": {
"test(int256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: END INLINE ASM 2\n\"];\n}\n"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"foo.asm_0.w.a()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n}\n",
"foo.asm_0.w.b()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n",
"foo.asm_0.g()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
},
"B": {
"test(int256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: END INLINE ASM 2\n\"];\n}\n",
"test.asm_0.a()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n}\n",
"test.asm_0.b()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"A": {
"foo()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: END INLINE ASM 2\n\"];\n}\n"
},
"B": {
"test(int256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: END INLINE ASM 2\n\"];\n}\n"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"foo.asm_0.w.a()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n}\n",
"foo.asm_0.w.b()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n",
"foo.asm_0.g()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
},
"B": {
"test(int256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: END INLINE ASM 2\n\"];\n}\n",
"test.asm_0.a()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n}\n",
"test.asm_0.b()": "digraph{\n0[label=\"Node Type: INLINE ASM 0\n\"];\n0->1;\n1[label=\"Node Type: ENTRY_POINT 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}
2 changes: 1 addition & 1 deletion tests/tools/read-storage/test_data/StorageLayout.bin

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/tools/read-storage/test_data/StorageLayout.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ contract StorageLayout {
uint[][] multidimensionalArray;
PackedStruct[] dynamicArrayOfStructs;
PackedStruct[3] fixedArrayOfStructs;
struct BiggerStruct {
uint64 x;
uint256 y;
}
BiggerStruct big;

function store() external {
require(_address == address(0));
Expand Down Expand Up @@ -71,5 +76,6 @@ contract StorageLayout {

mappingDynamicArrayOfStructs[_address].push(dynamicArrayOfStructs[0]);
mappingDynamicArrayOfStructs[_address].push(dynamicArrayOfStructs[1]);
big = BiggerStruct(10,100);
}
}
28 changes: 28 additions & 0 deletions tests/tools/read-storage/test_data/TEST_storage_layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,5 +572,33 @@
}
}
}
},
"big": {
"name": "big",
"type_string": "StorageLayout.BiggerStruct",
"slot": 21,
"size": 512,
"offset": 0,
"value": "000000000000000000000000000000000000000000000000000000000000000a",
"elems": {
"x": {
"name": "big.x",
"type_string": "uint64",
"slot": 21,
"size": 64,
"offset": 0,
"value": 10,
"elems": {}
},
"y": {
"name": "big.y",
"type_string": "uint256",
"slot": 22,
"size": 256,
"offset": 0,
"value": 100,
"elems": {}
}
}
}
}

0 comments on commit 260b744

Please sign in to comment.