From 0fbde5f0dcd50cf0e530f6d7e08b39c4f7a3e684 Mon Sep 17 00:00:00 2001 From: Jon-Becker Date: Sat, 30 Dec 2023 11:06:41 -0600 Subject: [PATCH] chore(clippy): make clippy happy --- common/src/ether/evm/ext/exec/util.rs | 5 +++- common/src/utils/range_map.rs | 26 ++++++++++++++++--- core/src/decompile/mod.rs | 6 +---- .../decompile/out/postprocessers/solidity.rs | 6 ++--- core/src/decompile/out/postprocessers/yul.rs | 2 +- core/src/snapshot/analyze.rs | 2 +- core/src/snapshot/mod.rs | 2 +- core/src/snapshot/resolve.rs | 6 ++--- 8 files changed, 36 insertions(+), 19 deletions(-) diff --git a/common/src/ether/evm/ext/exec/util.rs b/common/src/ether/evm/ext/exec/util.rs index 122d1b38..aae9bc1c 100644 --- a/common/src/ether/evm/ext/exec/util.rs +++ b/common/src/ether/evm/ext/exec/util.rs @@ -196,7 +196,10 @@ pub fn historical_diffs_approximately_equal(stack: &Stack, historical_stacks: &[ } // check if all stack diffs are the same - if !stack_diffs.iter().all(|diff| diff.get(0) == stack_diffs.get(0).unwrap_or(&vec![]).get(0)) { + if !stack_diffs + .iter() + .all(|diff| diff.first() == stack_diffs.first().unwrap_or(&vec![]).first()) + { return false } diff --git a/common/src/utils/range_map.rs b/common/src/utils/range_map.rs index a30d4356..d8e0f643 100644 --- a/common/src/utils/range_map.rs +++ b/common/src/utils/range_map.rs @@ -107,10 +107,12 @@ impl RangeMap { } fn range_collides(incoming: &Range, incumbent: &Range) -> bool { - (incoming.start <= incumbent.start && incoming.end >= incumbent.end) || - (incoming.start <= incumbent.start && incoming.end >= incumbent.start) || - (incoming.start <= incumbent.end && incoming.end >= incumbent.end) || - (incoming.start > incumbent.start && incoming.end < incumbent.end) + !(incoming.start <= incumbent.start && + incoming.end < incumbent.end && + incoming.end < incumbent.start || + incoming.start > incumbent.start && + incoming.end >= incumbent.end && + incoming.start > incumbent.end) } } @@ -229,4 +231,20 @@ mod tests { assert_eq!(actual_byte_tracker, expected_byte_tracker); } + + #[test] + fn test_range_collides() { + let range: Range = Range { start: 0, end: 10 }; + let incumbent: Range = Range { start: 5, end: 15 }; + + assert!(RangeMap::range_collides(&range, &incumbent)); + } + + #[test] + fn test_range_does_not_collide() { + let range: Range = Range { start: 0, end: 10 }; + let incumbent: Range = Range { start: 11, end: 15 }; + + assert!(!RangeMap::range_collides(&range, &incumbent)); + } } diff --git a/core/src/decompile/mod.rs b/core/src/decompile/mod.rs index 06158803..e0a6c983 100644 --- a/core/src/decompile/mod.rs +++ b/core/src/decompile/mod.rs @@ -267,11 +267,7 @@ pub async fn decompile( ) { Some(map) => map, None => { - trace.add_error( - func_analysis_trace, - line!(), - &format!("symbolic execution timed out!"), - ); + trace.add_error(func_analysis_trace, line!(), "symbolic execution timed out!"); (VMTrace::default(), 0) } }; diff --git a/core/src/decompile/out/postprocessers/solidity.rs b/core/src/decompile/out/postprocessers/solidity.rs index 6c1c51f2..53806912 100644 --- a/core/src/decompile/out/postprocessers/solidity.rs +++ b/core/src/decompile/out/postprocessers/solidity.rs @@ -232,7 +232,7 @@ fn simplify_parentheses(line: &str, paren_index: usize) -> String { let paren_end = paren_end + nth_paren_index; // if a match was found, check if the parens are unnecessary - if let true = found_match { + if found_match { // get the logical expression including the char before the parentheses (to detect casts) let logical_expression = match paren_start { 0 => match cleaned.get(paren_start..paren_end + 1) { @@ -299,7 +299,7 @@ fn convert_access_to_variable(line: &str) -> String { // since the regex is greedy, match the memory brackets let matched_loc = find_balanced_encapsulator(memory_access, ('[', ']')); - if let true = matched_loc.2 { + if matched_loc.2 { let mut mem_map = MEM_LOOKUP_MAP.lock().unwrap(); // safe to unwrap since we know these indices exist @@ -338,7 +338,7 @@ fn convert_access_to_variable(line: &str) -> String { // since the regex is greedy, match the memory brackets let matched_loc = find_balanced_encapsulator(storage_access, ('[', ']')); - if let true = matched_loc.2 { + if matched_loc.2 { let mut stor_map = STORAGE_LOOKUP_MAP.lock().unwrap(); // safe to unwrap since we know these indices exist diff --git a/core/src/decompile/out/postprocessers/yul.rs b/core/src/decompile/out/postprocessers/yul.rs index 9134766c..066127dd 100644 --- a/core/src/decompile/out/postprocessers/yul.rs +++ b/core/src/decompile/out/postprocessers/yul.rs @@ -215,7 +215,7 @@ fn simplify_parentheses(line: &str, paren_index: usize) -> String { let paren_end = paren_end + nth_paren_index; // if a match was found, check if the parens are unnecessary - if let true = found_match { + if found_match { // get the logical expression including the char before the parentheses (to detect casts) let logical_expression = match paren_start { 0 => match cleaned.get(paren_start..paren_end + 1) { diff --git a/core/src/snapshot/analyze.rs b/core/src/snapshot/analyze.rs index 2ece3594..e4197f79 100644 --- a/core/src/snapshot/analyze.rs +++ b/core/src/snapshot/analyze.rs @@ -531,7 +531,7 @@ pub fn snapshot_trace( } // recurse into the children of the VMTrace map - for (_, child) in vm_trace.children.iter().enumerate() { + for child in vm_trace.children.iter() { snapshot = snapshot_trace(child, snapshot, trace, trace_parent); } diff --git a/core/src/snapshot/mod.rs b/core/src/snapshot/mod.rs index 69c5e2c0..cacc4e76 100644 --- a/core/src/snapshot/mod.rs +++ b/core/src/snapshot/mod.rs @@ -273,7 +273,7 @@ async fn get_snapshots( trace.add_error( func_analysis_trace, line!(), - &format!("symbolic execution timed out, skipping snapshotting."), + "symbolic execution timed out, skipping snapshotting.", ); continue } diff --git a/core/src/snapshot/resolve.rs b/core/src/snapshot/resolve.rs index 3b248a02..3770a2cc 100644 --- a/core/src/snapshot/resolve.rs +++ b/core/src/snapshot/resolve.rs @@ -195,7 +195,7 @@ pub async fn resolve_signatures( async fn resolve_function_signatures( matched_resolved_functions: &mut Vec, snapshot: &mut Snapshot, - snapshot_progress: &mut ProgressBar, + snapshot_progress: &ProgressBar, default: bool, func_analysis_trace: &u32, trace: &mut TraceFactory, @@ -250,7 +250,7 @@ async fn resolve_function_signatures( async fn resolve_error_signatures( snapshot: &mut Snapshot, all_resolved_errors: &mut HashMap, - snapshot_progress: &mut ProgressBar, + snapshot_progress: &ProgressBar, resolved_counter: &mut i32, default: bool, ) -> Result<(), Box> { @@ -308,7 +308,7 @@ async fn resolve_error_signatures( async fn resolve_event_signatures( snapshot: &mut Snapshot, all_resolved_events: &mut HashMap, - snapshot_progress: &mut ProgressBar, + snapshot_progress: &ProgressBar, resolved_counter: &mut i32, default: bool, ) -> Result<(), Box> {