-
Notifications
You must be signed in to change notification settings - Fork 59
/
double_entry_token_possibility.py
56 lines (39 loc) · 2 KB
/
double_entry_token_possibility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
class DoubleEntryTokenPossiblity(AbstractDetector):
"""
Sees if contract contains a function which is vulnurable to double-entry tokens attack
"""
ARGUMENT = 'pess-double-entry-token-alert' # slither will launch the detector with slither.py --detect mydetector
HELP = 'The function might be sensitive to double entry token usage'
IMPACT = DetectorClassification.HIGH
CONFIDENCE = DetectorClassification.LOW
WIKI = 'https://github.com/pessimistic-io/slitherin/blob/master/docs/double_entry_token_possibility.md'
WIKI_TITLE = 'Double-entry token'
WIKI_DESCRIPTION = "Double-entry token related attack might be possible"
WIKI_EXPLOIT_SCENARIO = '-'
WIKI_RECOMMENDATION = 'Project contract must be sustainable to a token which has two pointing addresses'
def get_tokens_as_params(self, fun):
res = [] # параметры функции
for p in fun.parameters:
if len(p._name) and str(p.type) in ['IERC20[]', 'address[]']:
res.append(p)
return res
def do_have_token_interaction(self, fun, token):
for n in fun.nodes:
if str(token) in str(n.expression):
if '.transfer' in str(n.expression): return True
if '.balanceOf' in str(n.expression): return True
return False
def _detect(self):
res = []
for contract in self.compilation_unit.contracts_derived:
for f in contract.functions:
tokens = self.get_tokens_as_params(f)
if len(tokens)>0:
for t in tokens:
if self.do_have_token_interaction(f, t):
res.append(self.generate_result([
f.contract_declarer.name, ' ',
f, ' might be vulnerable to double-entry token exploit',
'\n']))
return res