From 6ebfbc58f108f1b1ca97670d04be4732b651db95 Mon Sep 17 00:00:00 2001 From: Yhtyyar Sahatov Date: Mon, 3 Jun 2024 08:32:51 +0300 Subject: [PATCH] ignore libs --- slitherin/detectors/event_setter.py | 38 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/slitherin/detectors/event_setter.py b/slitherin/detectors/event_setter.py index addb7b1..e8b2697 100644 --- a/slitherin/detectors/event_setter.py +++ b/slitherin/detectors/event_setter.py @@ -10,22 +10,25 @@ 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 @@ -33,13 +36,18 @@ 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