1
- from functools import total_ordering
2
1
from decimal import Decimal
2
+ from functools import total_ordering
3
3
4
- from slither .slithir .variables .variable import SlithIRVariable
5
- from slither .slithir .exceptions import SlithIRError
6
4
from slither .core .solidity_types .elementary_type import ElementaryType , Int , Uint
5
+ from slither .slithir .variables .variable import SlithIRVariable
7
6
from slither .utils .arithmetic import convert_subdenomination
7
+ from slither .utils .integer_conversion import convert_string_to_int
8
8
9
9
10
10
@total_ordering
@@ -25,26 +25,7 @@ def __init__(
25
25
assert isinstance (constant_type , ElementaryType )
26
26
self ._type = constant_type
27
27
if constant_type .type in Int + Uint + ["address" ]:
28
- if val .startswith ("0x" ) or val .startswith ("0X" ):
29
- self ._val = int (val , 16 )
30
- else :
31
- if "e" in val or "E" in val :
32
- base , expo = val .split ("e" ) if "e" in val else val .split ("E" )
33
- base , expo = Decimal (base ), int (expo )
34
- # The resulting number must be < 2**256-1, otherwise solc
35
- # Would not be able to compile it
36
- # 10**77 is the largest exponent that fits
37
- # See https://github.com/ethereum/solidity/blob/9e61f92bd4d19b430cb8cb26f1c7cf79f1dff380/libsolidity/ast/Types.cpp#L1281-L1290
38
- if expo > 77 :
39
- if base != Decimal (0 ):
40
- raise SlithIRError (
41
- f"{ base } e{ expo } is too large to fit in any Solidity integer size"
42
- )
43
- self ._val = 0
44
- else :
45
- self ._val = int (Decimal (base ) * Decimal (10 ** expo ))
46
- else :
47
- self ._val = int (Decimal (val ))
28
+ self ._val = convert_string_to_int (val )
48
29
elif constant_type .type == "bool" :
49
30
self ._val = (val == "true" ) | (val == "True" )
50
31
else :
0 commit comments