Skip to content

Commit 55a2678

Browse files
authored
Merge pull request #842 from crytic/dev-fixes
Multiple minor fixes
2 parents c0bcc84 + c183a36 commit 55a2678

File tree

129 files changed

+28
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+28
-22
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion

scripts/ci_test_dapp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git config --global user.email "[email protected]"
99
git config --global user.name "CI User"
1010

1111
curl https://nixos.org/nix/install | sh
12-
# shellcheck disable=SC1090
12+
# shellcheck disable=SC1090,SC1091
1313
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
1414
nix-env -iA nixpkgs.cachix
1515
cachix use dapp

slither/core/solidity_types/elementary_type.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@
125125

126126
Max_Byte = {k: 2 ** (8 * (i + 1)) - 1 for i, k in enumerate(Byte[2:])}
127127
Max_Byte["bytes"] = None
128+
Max_Byte["string"] = None
128129
Max_Byte["byte"] = 255
129130
Min_Byte = {k: 1 << (4 + 8 * i) for i, k in enumerate(Byte[2:])}
130131
Min_Byte["bytes"] = 0x0
132+
Min_Byte["string"] = None
131133
Min_Byte["byte"] = 0x10
132134

133135
MaxValues = dict(dict(Max_Int, **Max_Uint), **Max_Byte)

slither/slithir/convert.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ def _fits_under_byte(val: Union[int, str]) -> List[str]:
190190
if isinstance(val, int):
191191
hex_val = hex(val)[2:]
192192
size = len(hex_val) // 2
193-
return [f"byte{size}"]
193+
return [f"bytes{size}"]
194194
# val is a str
195195
length = len(val.encode("utf-8"))
196-
return [f"byte{f}" for f in range(length, 32)]
196+
return [f"bytes{f}" for f in range(length, 33)]
197197

198198

199199
def _find_function_from_parameter(ir: Call, candidates: List[Function]) -> Optional[Function]:
@@ -217,28 +217,31 @@ def _find_function_from_parameter(ir: Call, candidates: List[Function]) -> Optio
217217
else:
218218
type_args = [get_type(arg.type)]
219219

220-
if (
221-
isinstance(arg.type, ElementaryType)
222-
and arg.type.type in ElementaryTypeInt + Uint + Byte
223-
):
220+
arg_type = arg.type
221+
if isinstance(
222+
arg_type, ElementaryType
223+
) and arg_type.type in ElementaryTypeInt + Uint + Byte + ["string"]:
224224
if isinstance(arg, Constant):
225225
value = arg.value
226226
can_be_uint = True
227227
can_be_int = True
228228
else:
229-
value = MaxValues[arg.type.type]
229+
value = MaxValues[arg_type.type]
230230
can_be_uint = False
231231
can_be_int = False
232-
if arg.type.type in ElementaryTypeInt:
232+
if arg_type.type in ElementaryTypeInt:
233233
can_be_int = True
234-
elif arg.type.type in Uint:
234+
elif arg_type.type in Uint:
235235
can_be_uint = True
236236

237-
if arg.type.type in ElementaryTypeInt + Uint:
237+
if arg_type.type in ElementaryTypeInt + Uint:
238238
type_args = _fits_under_integer(value, can_be_int, can_be_uint)
239+
elif value is None and arg_type.type in ["bytes", "string"]:
240+
type_args = ["bytes", "string"]
239241
else:
240-
print(value)
241242
type_args = _fits_under_byte(value)
243+
if arg_type.type == "string":
244+
type_args += ["string"]
242245

243246
not_found = True
244247
candidates_kept = []
@@ -247,16 +250,14 @@ def _find_function_from_parameter(ir: Call, candidates: List[Function]) -> Optio
247250
break
248251
candidates_kept = []
249252
for candidate in candidates:
250-
param = str(candidate.parameters[idx].type)
251-
253+
param = get_type(candidate.parameters[idx].type)
252254
if param == type_arg:
253255
not_found = False
254256
candidates_kept.append(candidate)
255257

256258
if len(candidates_kept) == 1:
257259
return candidates_kept[0]
258260
candidates = candidates_kept
259-
260261
if len(candidates) == 1:
261262
return candidates[0]
262263
return None
@@ -1005,7 +1006,9 @@ def convert_to_low_level(ir):
10051006
raise SlithIRError("Incorrect conversion to low level {}".format(ir))
10061007

10071008

1008-
def can_be_solidity_func(ir):
1009+
def can_be_solidity_func(ir) -> bool:
1010+
if not isinstance(ir, HighLevelCall):
1011+
return False
10091012
return ir.destination.name == "abi" and ir.function_name in [
10101013
"encode",
10111014
"encodePacked",

slither/tools/upgradeability/checks/constant.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def _check(self):
4848
state_variables_v2 = contract_v2.state_variables
4949

5050
v2_additional_variables = len(state_variables_v2) - len(state_variables_v1)
51-
if v2_additional_variables < 0:
52-
v2_additional_variables = 0
51+
v2_additional_variables = max(v2_additional_variables, 0)
5352

5453
# We keep two index, because we need to have them out of sync if v2
5554
# has additional non constant variables
@@ -130,8 +129,7 @@ def _check(self):
130129
state_variables_v2 = contract_v2.state_variables
131130

132131
v2_additional_variables = len(state_variables_v2) - len(state_variables_v1)
133-
if v2_additional_variables < 0:
134-
v2_additional_variables = 0
132+
v2_additional_variables = max(v2_additional_variables, 0)
135133

136134
# We keep two index, because we need to have them out of sync if v2
137135
# has additional non constant variables

slither/utils/integer_conversion.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from decimal import Decimal
2+
from typing import Union
23

34
from slither.exceptions import SlitherError
45

56

6-
def convert_string_to_int(val: str) -> int:
7+
def convert_string_to_int(val: Union[str, int]) -> int:
8+
if isinstance(val, int):
9+
return val
710
if val.startswith("0x") or val.startswith("0X"):
811
return int(val, 16)
912

1.75 KB
Binary file not shown.
1.75 KB
Binary file not shown.
1.79 KB
Binary file not shown.
1.81 KB
Binary file not shown.

0 commit comments

Comments
 (0)