From 0f08b40595914a1acd390cfa57edbe708ca74a19 Mon Sep 17 00:00:00 2001 From: Rog3rSm1th Date: Thu, 10 Oct 2024 15:41:13 +0200 Subject: [PATCH] Fix a bug in functions detector --- lib/src/decompiler/decompiler.rs | 22 ++++++++------ lib/src/detectors/functions_detector.rs | 38 +++++++++++++------------ 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/src/decompiler/decompiler.rs b/lib/src/decompiler/decompiler.rs index 3f33b9e..9897d0a 100644 --- a/lib/src/decompiler/decompiler.rs +++ b/lib/src/decompiler/decompiler.rs @@ -127,15 +127,19 @@ impl<'a> Decompiler<'a> { /// From : https://github.com/crytic/caracal/blob/2267d5d514530e8a187732f1ca3e249c2997b6b6/src/core/compilation_unit.rs#L52 pub fn user_defined_functions(&self) -> impl Iterator { self.functions.iter().filter(|f| { - matches!( - f.function_type.clone().unwrap(), - FunctionType::Constructor - | FunctionType::External - | FunctionType::View - | FunctionType::Private - | FunctionType::L1Handler - | FunctionType::Loop - ) + if let Some(function_type) = &f.function_type { + matches!( + function_type, + FunctionType::Constructor + | FunctionType::External + | FunctionType::View + | FunctionType::Private + | FunctionType::L1Handler + | FunctionType::Loop + ) + } else { + false + } }) } diff --git a/lib/src/detectors/functions_detector.rs b/lib/src/detectors/functions_detector.rs index 60124bb..8ae9ede 100644 --- a/lib/src/detectors/functions_detector.rs +++ b/lib/src/detectors/functions_detector.rs @@ -51,24 +51,26 @@ impl Detector for FunctionsDetector { if let Some(first_space_index) = stripped_prototype.find(' ') { let function_name = &stripped_prototype[..first_space_index]; - // Put the function type in the output - let function_type = match function.function_type { - Some(FunctionType::External) => "External", - Some(FunctionType::View) => "View", - Some(FunctionType::Private) => "Private", - Some(FunctionType::Constructor) => "Constructor", - Some(FunctionType::Event) => "Event", - Some(FunctionType::Storage) => "Storage", - Some(FunctionType::Wrapper) => "Wrapper", - Some(FunctionType::Core) => "Core", - Some(FunctionType::AbiCallContract) => "AbiCallContract", - Some(FunctionType::AbiLibraryCall) => "AbiLibraryCall", - Some(FunctionType::L1Handler) => "L1Handler", - Some(FunctionType::Loop) => "Loop", - None => "", - }; - - result += &format!("{} : {}", function_type, function_name); + // Put the function type in the output if it exists + if let Some(function_type) = &function.function_type { + let function_type_str = match function_type { + FunctionType::External => "External", + FunctionType::View => "View", + FunctionType::Private => "Private", + FunctionType::Constructor => "Constructor", + FunctionType::Event => "Event", + FunctionType::Storage => "Storage", + FunctionType::Wrapper => "Wrapper", + FunctionType::Core => "Core", + FunctionType::AbiCallContract => "AbiCallContract", + FunctionType::AbiLibraryCall => "AbiLibraryCall", + FunctionType::L1Handler => "L1Handler", + FunctionType::Loop => "Loop", + }; + result += &format!("{} : {}", function_type_str, function_name); + } else { + result += function_name; + } } // Add a newline if it's not the last function if index < total_functions - 1 {