Skip to content

Commit

Permalink
chore(clippy): make clippy happy (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker authored Dec 30, 2023
1 parent fc356fa commit 94aabc9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
5 changes: 4 additions & 1 deletion common/src/ether/evm/ext/exec/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
26 changes: 22 additions & 4 deletions common/src/utils/range_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ impl RangeMap {
}

fn range_collides(incoming: &Range<usize>, incumbent: &Range<usize>) -> 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)
}
}

Expand Down Expand Up @@ -229,4 +231,20 @@ mod tests {

assert_eq!(actual_byte_tracker, expected_byte_tracker);
}

#[test]
fn test_range_collides() {
let range: Range<usize> = Range { start: 0, end: 10 };
let incumbent: Range<usize> = Range { start: 5, end: 15 };

assert!(RangeMap::range_collides(&range, &incumbent));
}

#[test]
fn test_range_does_not_collide() {
let range: Range<usize> = Range { start: 0, end: 10 };
let incumbent: Range<usize> = Range { start: 11, end: 15 };

assert!(!RangeMap::range_collides(&range, &incumbent));
}
}
6 changes: 1 addition & 5 deletions core/src/decompile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};
Expand Down
6 changes: 3 additions & 3 deletions core/src/decompile/out/postprocessers/solidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/src/decompile/out/postprocessers/yul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/snapshot/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/snapshot/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub async fn resolve_signatures(
async fn resolve_function_signatures(
matched_resolved_functions: &mut Vec<ResolvedFunction>,
snapshot: &mut Snapshot,
snapshot_progress: &mut ProgressBar,
snapshot_progress: &ProgressBar,
default: bool,
func_analysis_trace: &u32,
trace: &mut TraceFactory,
Expand Down Expand Up @@ -250,7 +250,7 @@ async fn resolve_function_signatures(
async fn resolve_error_signatures(
snapshot: &mut Snapshot,
all_resolved_errors: &mut HashMap<String, ResolvedError>,
snapshot_progress: &mut ProgressBar,
snapshot_progress: &ProgressBar,
resolved_counter: &mut i32,
default: bool,
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -308,7 +308,7 @@ async fn resolve_error_signatures(
async fn resolve_event_signatures(
snapshot: &mut Snapshot,
all_resolved_events: &mut HashMap<String, ResolvedLog>,
snapshot_progress: &mut ProgressBar,
snapshot_progress: &ProgressBar,
resolved_counter: &mut i32,
default: bool,
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down

0 comments on commit 94aabc9

Please sign in to comment.