-
Notifications
You must be signed in to change notification settings - Fork 62
/
event_setter.py
53 lines (47 loc) · 2.09 KB
/
event_setter.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
from typing import List
from slither.utils.output import Output
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from slither.core.declarations import Function
from slither.slithir.operations.event_call import EventCall
class EventSetter(AbstractDetector):
"""
Sees if contract setters do not emit events
"""
ARGUMENT = "pess-event-setter" # slither will launch the detector with slither.py --detect mydetector
HELP = "Contract function does not emit event after the value is set"
IMPACT = DetectorClassification.LOW
CONFIDENCE = DetectorClassification.MEDIUM
WIKI = (
"https://github.com/pessimistic-io/slitherin/blob/master/docs/event_setter.md"
)
WIKI_TITLE = "Missing Event Setter"
WIKI_DESCRIPTION = "Setter-functions must emit events"
WIKI_EXPLOIT_SCENARIO = "N/A"
WIKI_RECOMMENDATION = "Emit events in setter functions"
def _emits_event(self, fun: Function) -> bool:
"""Checks if function has multiple storage read"""
if isinstance(fun, Function): # check for a correct function type
if any(
ir for node in fun.nodes for ir in node.irs if isinstance(ir, EventCall)
):
return True
return False
def _detect(self) -> List[Output]:
"""Main function"""
res = []
for contract in self.compilation_unit.contracts_derived:
if not contract.is_interface and not contract.is_library:
for f in contract.functions_and_modifiers_declared:
if f.name.startswith("set"):
x = self._emits_event(f)
if not x:
res.append(
self.generate_result(
[
"Setter function ",
f,
" does not emit an event" "\n",
]
)
)
return res