3232class YulFunction :
3333 """Represents a parsed Yul function."""
3434
35- def __init__ (self , name : str , signature : str , body : str , full_text : str ):
35+ def __init__ (
36+ self ,
37+ name : str ,
38+ signature : str ,
39+ body : str ,
40+ full_text : str ,
41+ pre_comments : str = "" ,
42+ post_comments : str = "" ,
43+ ):
3644 self .name = name
3745 self .signature = signature # function name(...) -> ...
3846 self .body = body
3947 self .full_text = full_text # Complete function including definition
48+ self .pre_comments = (
49+ pre_comments # Comments before function (e.g., slither-disable-start)
50+ )
51+ self .post_comments = (
52+ post_comments # Comments after function (e.g., slither-disable-end)
53+ )
4054
4155 def __eq__ (self , other ):
4256 if not isinstance (other , YulFunction ):
@@ -111,6 +125,7 @@ def extract_yul_functions(self, assembly_content: str) -> Dict[str, YulFunction]
111125 Extract all Yul function definitions from an assembly block.
112126 Returns dict mapping function name to YulFunction object.
113127 Handles multiline function signatures.
128+ Captures Slither exemption comments before and after functions.
114129 """
115130 functions = {}
116131
@@ -123,6 +138,29 @@ def extract_yul_functions(self, assembly_content: str) -> Dict[str, YulFunction]
123138
124139 # Check if line starts with "function" keyword
125140 if line .strip ().startswith ("function" ):
141+ # Look back for Slither disable comments before the function
142+ # Only capture slither-disable-start or slither-disable-next-line
143+ # Do NOT capture slither-disable-end as that belongs to the previous function
144+ pre_comment_lines = []
145+ j = i - 1
146+ while j >= 0 :
147+ prev_line = lines [j ].strip ()
148+ # Check for slither-disable-start or slither-disable-next-line (not disable-end)
149+ if "slither-disable" in prev_line and prev_line .startswith ("//" ):
150+ if "slither-disable-end" not in prev_line :
151+ # This is a disable-start or disable-next-line, include it
152+ pre_comment_lines .insert (0 , lines [j ])
153+ j -= 1
154+ else :
155+ # This is a disable-end from a previous function, stop here
156+ break
157+ elif prev_line == "" :
158+ # Allow empty lines but don't add them
159+ j -= 1
160+ else :
161+ # Stop when we hit non-comment/non-empty content
162+ break
163+
126164 # Extract function name using simple pattern
127165 func_match = self .function_name_pattern .search (line )
128166
@@ -167,11 +205,39 @@ def extract_yul_functions(self, assembly_content: str) -> Dict[str, YulFunction]
167205 brace_count += lines [i ].count ("{" ) - lines [i ].count ("}" )
168206 i += 1
169207
208+ # Look ahead for Slither disable-end comments after the function
209+ post_comment_lines = []
210+ temp_i = i
211+ while temp_i < len (lines ):
212+ next_line = lines [temp_i ].strip ()
213+ # Check for slither-disable-end
214+ if "slither-disable-end" in next_line and next_line .startswith (
215+ "//"
216+ ):
217+ post_comment_lines .append (lines [temp_i ])
218+ i = temp_i + 1
219+ break
220+ elif next_line == "" :
221+ # Allow empty lines
222+ temp_i += 1
223+ else :
224+ # Stop when we hit any other content (function or non-comment)
225+ break
226+
170227 full_text = "\n " .join (func_lines )
171228 body = "\n " .join (func_lines [len (sig_lines ) :])
229+ pre_comments = "\n " .join (pre_comment_lines ) if pre_comment_lines else ""
230+ post_comments = (
231+ "\n " .join (post_comment_lines ) if post_comment_lines else ""
232+ )
172233
173234 functions [func_name ] = YulFunction (
174- name = func_name , signature = signature , body = body , full_text = full_text
235+ name = func_name ,
236+ signature = signature ,
237+ body = body ,
238+ full_text = full_text ,
239+ pre_comments = pre_comments ,
240+ post_comments = post_comments ,
175241 )
176242 else :
177243 i += 1
@@ -557,7 +623,14 @@ def process_assembly_block(
557623 if imported_functions :
558624 func_lines = []
559625 for func in imported_functions .values ():
626+ # Include pre-comments (e.g., slither-disable-start)
627+ if func .pre_comments :
628+ func_lines .append (func .pre_comments )
629+ # Add the function itself
560630 func_lines .append (func .full_text )
631+ # Include post-comments (e.g., slither-disable-end)
632+ if func .post_comments :
633+ func_lines .append (func .post_comments )
561634
562635 # Add imported functions before other content
563636 return "\n " .join (func_lines ) + "\n " + "\n " .join (result_lines )
0 commit comments