Skip to content

Commit

Permalink
Fix a bug in functions detector
Browse files Browse the repository at this point in the history
  • Loading branch information
Rog3rSm1th committed Oct 10, 2024
1 parent 423ddb1 commit 0f08b40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
22 changes: 13 additions & 9 deletions lib/src/decompiler/decompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &Function> {
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
}
})
}

Expand Down
38 changes: 20 additions & 18 deletions lib/src/detectors/functions_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0f08b40

Please # to comment.