Skip to content

Commit

Permalink
Improve function lookup for bytes (#1163)
Browse files Browse the repository at this point in the history
* Improve function lookup for bytes

* Update dapp test

* black
  • Loading branch information
montyly committed Apr 10, 2022
1 parent 644f5e5 commit 741fc06
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/ci_test_dapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dapp init
slither . --detect external-function

# TODO: make more elaborate test
if [ $? -eq 3 ]
if [ $? -eq 4 ]
then
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion slither/slithir/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _fits_under_byte(val: Union[int, str]) -> List[str]:
return [f"bytes{size}"]
# val is a str
length = len(val.encode("utf-8"))
return [f"bytes{f}" for f in range(length, 33)]
return [f"bytes{f}" for f in range(length, 33)] + ["bytes"]


def _find_function_from_parameter(ir: Call, candidates: List[Function]) -> Optional[Function]:
Expand Down
17 changes: 17 additions & 0 deletions tests/ast-parsing/bytes_call.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
contract Log{
// Check that we can parse string/bytes
function f(bytes calldata) external{
}

function f(bytes4) external{
}
}

contract A{

Log l;
function test() internal{
l.f("TESTA");
}
}

Binary file not shown.
9 changes: 9 additions & 0 deletions tests/ast-parsing/expected/bytes_call.sol-0.8.12-compact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Log": {
"f(bytes)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n}\n",
"f(bytes4)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n}\n"
},
"A": {
"test()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}
1 change: 1 addition & 0 deletions tests/test_ast_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> List[str]:
Test("complex_imports/import_aliases/test.sol", VERSIONS_08),
# 0.8.9 crashes on our testcase
Test("user_defined_types.sol", ["0.8.8"] + make_version(8, 10, 12)),
Test("bytes_call.sol", ["0.8.12"]),
]
# create the output folder if needed
try:
Expand Down

0 comments on commit 741fc06

Please sign in to comment.