Skip to content

Commit

Permalink
ignore libs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yhtiyar committed Jun 3, 2024
1 parent 80d8669 commit 6ebfbc5
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions slitherin/detectors/event_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,44 @@ 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'
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 = (
"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'
WIKI_EXPLOIT_SCENARIO = "N/A"
WIKI_RECOMMENDATION = "Emit events in setter functions"


def _emits_event(self, fun: Function) -> bool:
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)):
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:
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']))
res.append(
self.generate_result(
[
"Setter function ",
f,
" does not emit an event" "\n",
]
)
)
return res

0 comments on commit 6ebfbc5

Please sign in to comment.