From 4ed2a56df577af8c4e5d7bfd741a40038a07c139 Mon Sep 17 00:00:00 2001 From: Alex Roan Date: Thu, 12 Dec 2024 18:54:09 +0000 Subject: [PATCH] Linting fix (#782) --- aderyn_core/src/context/browser/extractor.rs | 2 +- aderyn_core/src/context/browser/storage_vars.rs | 4 ++-- aderyn_core/src/context/graph/callgraph_tests.rs | 2 +- .../src/detect/high/const_func_change_state.rs | 2 +- .../src/detect/high/delegate_call_no_address_check.rs | 2 +- .../src/detect/high/incorrect_erc20_interface.rs | 2 +- .../src/detect/high/incorrect_erc721_interface.rs | 2 +- .../src/detect/high/nested_struct_in_mapping.rs | 2 +- .../src/detect/high/state_variable_shadowing.rs | 2 +- aderyn_core/src/detect/low/assert_state_change.rs | 2 +- aderyn_core/src/detect/low/cache_array_length.rs | 2 +- .../src/detect/low/costly_operations_inside_loops.rs | 2 +- aderyn_core/src/detect/low/deprecated_oz_functions.rs | 4 ++-- .../src/detect/low/function_init_state_vars.rs | 2 +- aderyn_core/src/detect/low/missing_inheritance.rs | 4 ++-- aderyn_core/src/detect/low/return_bomb.rs | 2 +- .../detect/low/state_variable_could_be_constant.rs | 2 +- aderyn_core/src/detect/low/unsafe_oz_erc721_mint.rs | 2 +- aderyn_core/src/fscloc/util.rs | 6 +----- aderyn_core/src/report/json_printer.rs | 11 ----------- 20 files changed, 22 insertions(+), 37 deletions(-) diff --git a/aderyn_core/src/context/browser/extractor.rs b/aderyn_core/src/context/browser/extractor.rs index 2d30d0e49..350f0a854 100644 --- a/aderyn_core/src/context/browser/extractor.rs +++ b/aderyn_core/src/context/browser/extractor.rs @@ -147,7 +147,7 @@ impl<'a> ExtractReferencedDeclarationsConditionally<'a> { } } -impl<'a> ASTConstVisitor for ExtractReferencedDeclarationsConditionally<'a> { +impl ASTConstVisitor for ExtractReferencedDeclarationsConditionally<'_> { fn visit_member_access(&mut self, node: &MemberAccess) -> Result { if !self.condition.as_ref()(node.id, self.context) { return Ok(true); diff --git a/aderyn_core/src/context/browser/storage_vars.rs b/aderyn_core/src/context/browser/storage_vars.rs index e49b1dde5..a7ebf5890 100644 --- a/aderyn_core/src/context/browser/storage_vars.rs +++ b/aderyn_core/src/context/browser/storage_vars.rs @@ -61,7 +61,7 @@ impl<'a> Add> for ApproximateStorageChangeFin } } -impl<'a> Debug for ApproximateStorageChangeFinder<'a> { +impl Debug for ApproximateStorageChangeFinder<'_> { // Do not print context. Hence, debug is custom derived for this struct fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "Manipulated directly: {:?}", self.directly_manipulated_state_variables)?; @@ -213,7 +213,7 @@ impl<'a> ApproximateStorageChangeFinder<'a> { } } -impl<'a> ASTConstVisitor for ApproximateStorageChangeFinder<'a> { +impl ASTConstVisitor for ApproximateStorageChangeFinder<'_> { fn visit_unary_operation(&mut self, node: &UnaryOperation) -> Result { // WRITE HEURISTICS // Catch unary operations that manipulate variables diff --git a/aderyn_core/src/context/graph/callgraph_tests.rs b/aderyn_core/src/context/graph/callgraph_tests.rs index 2855e79ef..3d4c5bfeb 100644 --- a/aderyn_core/src/context/graph/callgraph_tests.rs +++ b/aderyn_core/src/context/graph/callgraph_tests.rs @@ -157,7 +157,7 @@ mod callgraph_test_functions { outward_side_effects_modifier_definitions_names: Vec, } - impl<'a> Tracker<'a> { + impl Tracker<'_> { fn new(context: &WorkspaceContext) -> Tracker { Tracker { context, diff --git a/aderyn_core/src/detect/high/const_func_change_state.rs b/aderyn_core/src/detect/high/const_func_change_state.rs index 007277d40..c45f8c5d7 100644 --- a/aderyn_core/src/detect/high/const_func_change_state.rs +++ b/aderyn_core/src/detect/high/const_func_change_state.rs @@ -74,7 +74,7 @@ struct StateVariableChangeTracker<'a> { context: &'a WorkspaceContext, } -impl<'a> CallGraphVisitor for StateVariableChangeTracker<'a> { +impl CallGraphVisitor for StateVariableChangeTracker<'_> { fn visit_any(&mut self, node: &crate::ast::ASTNode) -> eyre::Result<()> { if self.state_var_has_changed { return Ok(()); diff --git a/aderyn_core/src/detect/high/delegate_call_no_address_check.rs b/aderyn_core/src/detect/high/delegate_call_no_address_check.rs index 358066770..e77d57ee8 100644 --- a/aderyn_core/src/detect/high/delegate_call_no_address_check.rs +++ b/aderyn_core/src/detect/high/delegate_call_no_address_check.rs @@ -71,7 +71,7 @@ struct DelegateCallNoAddressChecksTracker<'a> { context: &'a WorkspaceContext, } -impl<'a> CallGraphVisitor for DelegateCallNoAddressChecksTracker<'a> { +impl CallGraphVisitor for DelegateCallNoAddressChecksTracker<'_> { fn visit_any(&mut self, node: &crate::context::workspace_context::ASTNode) -> eyre::Result<()> { if !self.has_address_checks && helpers::has_binary_checks_on_some_address(node) { self.has_address_checks = true; diff --git a/aderyn_core/src/detect/high/incorrect_erc20_interface.rs b/aderyn_core/src/detect/high/incorrect_erc20_interface.rs index c466aeb78..4b527266a 100644 --- a/aderyn_core/src/detect/high/incorrect_erc20_interface.rs +++ b/aderyn_core/src/detect/high/incorrect_erc20_interface.rs @@ -113,7 +113,7 @@ mod erc_matching_function_signature_helper { } // Helps with checking if a function definition satisifed a signature matcher - impl<'a> SignatureMatcher<'a> { + impl SignatureMatcher<'_> { fn satisfies(&self, func: &FunctionDefinition) -> Option { if func.name != self.name { return Some(false); diff --git a/aderyn_core/src/detect/high/incorrect_erc721_interface.rs b/aderyn_core/src/detect/high/incorrect_erc721_interface.rs index f15dc1f40..f87cfe677 100644 --- a/aderyn_core/src/detect/high/incorrect_erc721_interface.rs +++ b/aderyn_core/src/detect/high/incorrect_erc721_interface.rs @@ -127,7 +127,7 @@ mod erc721_matching_function_signature_helper { } // Helps with checking if a function definition satisifed a signature matcher - impl<'a> SignatureMatcher<'a> { + impl SignatureMatcher<'_> { fn satisfies(&self, func: &FunctionDefinition) -> bool { if func.name != self.name { return false; diff --git a/aderyn_core/src/detect/high/nested_struct_in_mapping.rs b/aderyn_core/src/detect/high/nested_struct_in_mapping.rs index d18d8fb3a..fed71f735 100644 --- a/aderyn_core/src/detect/high/nested_struct_in_mapping.rs +++ b/aderyn_core/src/detect/high/nested_struct_in_mapping.rs @@ -29,7 +29,7 @@ fn version_req_allows_below_0_5_0(version_req: &VersionReq) -> bool { } let comparator = &version_req.comparators[0]; - comparator.major == 0 && comparator.minor.map_or(false, |m| m < 5) + comparator.major == 0 && comparator.minor.is_some_and(|m| m < 5) } impl IssueDetector for NestedStructInMappingDetector { diff --git a/aderyn_core/src/detect/high/state_variable_shadowing.rs b/aderyn_core/src/detect/high/state_variable_shadowing.rs index 3d13c5fb8..f8792fca6 100644 --- a/aderyn_core/src/detect/high/state_variable_shadowing.rs +++ b/aderyn_core/src/detect/high/state_variable_shadowing.rs @@ -107,7 +107,7 @@ fn allows_below_0_6_0(version_req: &VersionReq) -> bool { } let comparator = &version_req.comparators[0]; - comparator.major == 0 && comparator.minor.map_or(false, |m| m < 6) + comparator.major == 0 && comparator.minor.is_some_and(|m| m < 6) } impl IssueDetector for StateVariableShadowingDetector { diff --git a/aderyn_core/src/detect/low/assert_state_change.rs b/aderyn_core/src/detect/low/assert_state_change.rs index 80b262b04..d3d8b20a8 100644 --- a/aderyn_core/src/detect/low/assert_state_change.rs +++ b/aderyn_core/src/detect/low/assert_state_change.rs @@ -69,7 +69,7 @@ mod assert_state_change_tracker { context: &'a WorkspaceContext, } - impl<'a> CallGraphVisitor for StateVariableChangeTracker<'a> { + impl CallGraphVisitor for StateVariableChangeTracker<'_> { fn visit_any(&mut self, node: &crate::ast::ASTNode) -> eyre::Result<()> { if self.has_some_state_variable_changed { return Ok(()); diff --git a/aderyn_core/src/detect/low/cache_array_length.rs b/aderyn_core/src/detect/low/cache_array_length.rs index 8c2dfccdf..cf941c0f0 100644 --- a/aderyn_core/src/detect/low/cache_array_length.rs +++ b/aderyn_core/src/detect/low/cache_array_length.rs @@ -160,7 +160,7 @@ mod loop_investigation_helper { changes: Option>, } - impl<'a> CallGraphVisitor for StateVariableChangeTracker<'a> { + impl CallGraphVisitor for StateVariableChangeTracker<'_> { fn visit_any(&mut self, node: &ASTNode) -> eyre::Result<()> { let changes = ApproximateStorageChangeFinder::from(self.context, node); if self.changes.is_none() { diff --git a/aderyn_core/src/detect/low/costly_operations_inside_loops.rs b/aderyn_core/src/detect/low/costly_operations_inside_loops.rs index 7341afd01..88803422d 100644 --- a/aderyn_core/src/detect/low/costly_operations_inside_loops.rs +++ b/aderyn_core/src/detect/low/costly_operations_inside_loops.rs @@ -80,7 +80,7 @@ struct StateVariableChangeTracker<'a> { context: &'a WorkspaceContext, } -impl<'a> CallGraphVisitor for StateVariableChangeTracker<'a> { +impl CallGraphVisitor for StateVariableChangeTracker<'_> { fn visit_any(&mut self, node: &crate::ast::ASTNode) -> eyre::Result<()> { if self.state_var_has_changed { return Ok(()); diff --git a/aderyn_core/src/detect/low/deprecated_oz_functions.rs b/aderyn_core/src/detect/low/deprecated_oz_functions.rs index 11e00e097..003902d40 100644 --- a/aderyn_core/src/detect/low/deprecated_oz_functions.rs +++ b/aderyn_core/src/detect/low/deprecated_oz_functions.rs @@ -31,7 +31,7 @@ impl IssueDetector for DeprecatedOZFunctionsDetector { directive .absolute_path .as_ref() - .map_or(false, |path| path.contains("openzeppelin")) + .is_some_and(|path| path.contains("openzeppelin")) }) && identifier.name == "_setupRole" { capture!(self, context, identifier); @@ -51,7 +51,7 @@ impl IssueDetector for DeprecatedOZFunctionsDetector { directive .absolute_path .as_ref() - .map_or(false, |path| path.contains("openzeppelin")) + .is_some_and(|path| path.contains("openzeppelin")) }) && member_access.member_name == "safeApprove" { capture!(self, context, member_access); diff --git a/aderyn_core/src/detect/low/function_init_state_vars.rs b/aderyn_core/src/detect/low/function_init_state_vars.rs index de6ad3ec7..b030de046 100644 --- a/aderyn_core/src/detect/low/function_init_state_vars.rs +++ b/aderyn_core/src/detect/low/function_init_state_vars.rs @@ -93,7 +93,7 @@ impl<'a> NonConstantStateVariableReferenceDeclarationTracker<'a> { } } -impl<'a> CallGraphVisitor for NonConstantStateVariableReferenceDeclarationTracker<'a> { +impl CallGraphVisitor for NonConstantStateVariableReferenceDeclarationTracker<'_> { fn visit_any(&mut self, node: &ASTNode) -> eyre::Result<()> { // We already know the condition is satisifed if self.makes_a_reference { diff --git a/aderyn_core/src/detect/low/missing_inheritance.rs b/aderyn_core/src/detect/low/missing_inheritance.rs index cca19ec73..5399b19ec 100644 --- a/aderyn_core/src/detect/low/missing_inheritance.rs +++ b/aderyn_core/src/detect/low/missing_inheritance.rs @@ -74,7 +74,7 @@ impl IssueDetector for MissingInheritanceDetector { continue; } if let Some(ASTNode::ContractDefinition(c)) = context.nodes.get(contract_id) { - if c.kind != ContractKind::Contract || c.is_abstract.map_or(false, identity) { + if c.kind != ContractKind::Contract || c.is_abstract.is_some_and(identity) { continue; } } @@ -100,7 +100,7 @@ impl IssueDetector for MissingInheritanceDetector { if let Some(ASTNode::ContractDefinition(c)) = context.nodes.get(potentially_missing_inheritance) { - if c.kind == ContractKind::Interface || c.is_abstract.map_or(false, identity) { + if c.kind == ContractKind::Interface || c.is_abstract.is_some_and(identity) { // Check that the contract is compatible with the missing inheritance if missing_function_selectors.iter().all(|s| contract_selectors.contains(s)) { diff --git a/aderyn_core/src/detect/low/return_bomb.rs b/aderyn_core/src/detect/low/return_bomb.rs index bf1483fff..0d9585913 100644 --- a/aderyn_core/src/detect/low/return_bomb.rs +++ b/aderyn_core/src/detect/low/return_bomb.rs @@ -130,7 +130,7 @@ struct CallNoAddressChecksTracker<'a> { context: &'a WorkspaceContext, } -impl<'a> CallGraphVisitor for CallNoAddressChecksTracker<'a> { +impl CallGraphVisitor for CallNoAddressChecksTracker<'_> { fn visit_any(&mut self, node: &crate::context::workspace_context::ASTNode) -> eyre::Result<()> { if !self.has_address_checks && helpers::has_binary_checks_on_some_address(node) { self.has_address_checks = true; diff --git a/aderyn_core/src/detect/low/state_variable_could_be_constant.rs b/aderyn_core/src/detect/low/state_variable_could_be_constant.rs index dba18ccdc..b69c48121 100644 --- a/aderyn_core/src/detect/low/state_variable_could_be_constant.rs +++ b/aderyn_core/src/detect/low/state_variable_could_be_constant.rs @@ -142,7 +142,7 @@ mod function_state_changes_finder_helper { changes: Option>, } - impl<'a> CallGraphVisitor for StateVariableChangeTracker<'a> { + impl CallGraphVisitor for StateVariableChangeTracker<'_> { fn visit_any(&mut self, node: &ASTNode) -> eyre::Result<()> { let changes = ApproximateStorageChangeFinder::from(self.context, node); if self.changes.is_none() { diff --git a/aderyn_core/src/detect/low/unsafe_oz_erc721_mint.rs b/aderyn_core/src/detect/low/unsafe_oz_erc721_mint.rs index d63da7438..dfce8626b 100644 --- a/aderyn_core/src/detect/low/unsafe_oz_erc721_mint.rs +++ b/aderyn_core/src/detect/low/unsafe_oz_erc721_mint.rs @@ -31,7 +31,7 @@ impl IssueDetector for UnsafeERC721MintDetector { directive .absolute_path .as_ref() - .map_or(false, |path| path.contains("openzeppelin")) + .is_some_and(|path| path.contains("openzeppelin")) }) && identifier.name == "_mint" { let this_contract_definition = identifier diff --git a/aderyn_core/src/fscloc/util.rs b/aderyn_core/src/fscloc/util.rs index c9263a0a7..58b01ead0 100644 --- a/aderyn_core/src/fscloc/util.rs +++ b/aderyn_core/src/fscloc/util.rs @@ -50,10 +50,6 @@ impl FromStr for CodeIterator { type Err = usize; fn from_str(code: &str) -> Result::Err> { - return Ok(CodeIterator { - content: code.chars().collect::>(), - curr_pos: 0, - line_no: 1, - }); + Ok(CodeIterator { content: code.chars().collect::>(), curr_pos: 0, line_no: 1 }) } } diff --git a/aderyn_core/src/report/json_printer.rs b/aderyn_core/src/report/json_printer.rs index e742a7e6d..4169c744d 100644 --- a/aderyn_core/src/report/json_printer.rs +++ b/aderyn_core/src/report/json_printer.rs @@ -24,17 +24,6 @@ pub struct JsonContent { pub struct JsonPrinter; -/** - * JSON should mimick MD - { - "files_summary": {...}, - "files_details": {...}, - "issue_summary": {...}, - "high_issues": {...}, - ... - } -*/ - impl ReportPrinter<()> for JsonPrinter { fn print_report( &self,