Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: major crates refactor / rewrite #372

Merged
merged 19 commits into from
May 6, 2024
Merged

Conversation

Jon-Becker
Copy link
Owner

@Jon-Becker Jon-Becker commented Mar 19, 2024

No description provided.

@Jon-Becker Jon-Becker changed the title [WIP] meta: major crates refactor [WIP] meta: major crates refactor / rewrite Mar 19, 2024
@Jon-Becker Jon-Becker marked this pull request as draft March 19, 2024 13:22
@Jon-Becker Jon-Becker marked this pull request as ready for review May 6, 2024 22:18
@Jon-Becker Jon-Becker enabled auto-merge (squash) May 6, 2024 22:18

/// The [`AnalyzedFunction`] struct represents a function that has been analyzed by the decompiler.
#[derive(Clone, Debug)]
pub struct AnalyzedFunction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: struct `AnalyzedFunction` is never constructed
  --> crates/cfg/src/interfaces/function.rs:11:12
   |
11 | pub struct AnalyzedFunction {
   |            ^^^^^^^^^^^^^^^^
   |
   = note: `AnalyzedFunction` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis
   = note: `#[warn(dead_code)]` on by default

}

#[derive(Clone, Debug)]
pub struct StorageFrame {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: struct `StorageFrame` is never constructed
  --> crates/cfg/src/interfaces/function.rs:59:12
   |
59 | pub struct StorageFrame {
   |            ^^^^^^^^^^^^
   |
   = note: `StorageFrame` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis

}

#[derive(Clone, Debug)]
pub struct CalldataFrame {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: struct `CalldataFrame` is never constructed
  --> crates/cfg/src/interfaces/function.rs:65:12
   |
65 | pub struct CalldataFrame {
   |            ^^^^^^^^^^^^^
   |
   = note: `CalldataFrame` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis

H160::default(),
H160::default(),
0,
u128::max_value(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: usage of a legacy numeric method
  --> crates/cfg/src/core/mod.rs:76:15
   |
76 |         u128::max_value(),
   |               ^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
   = note: `#[warn(clippy::legacy_numeric_constants)]` on by default
help: use the associated constant instead
   |
76 |         u128::MAX,
   |               ~~~


/// The [`AnalyzedFunction`] struct represents a function that has been analyzed by the decompiler.
#[derive(Clone, Debug)]
pub struct AnalyzedFunction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: field `entry_point` is never read
  --> crates/decompile/src/interfaces/function.rs:19:9
   |
13 | pub struct AnalyzedFunction {
   |            ---------------- field in this struct
...
19 |     pub entry_point: u128,
   |         ^^^^^^^^^^^
   |
   = note: `AnalyzedFunction` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis
   = note: `#[warn(dead_code)]` on by default

.join(", ");

// add the event emission to the function's logic
match analyzer_state.analyzer_type {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: you seem to be trying to use `match` for an equality check. Consider using `if`
  --> crates/decompile/src/utils/heuristics/events.rs:35:9
   |
35 | /         match analyzer_state.analyzer_type {
36 | |             AnalyzerType::Solidity => {
37 | |                 function.logic.push(format!(
38 | |                     "emit Event_{}({}{});{}",
...  |
72 | |             _ => {}
73 | |         }
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
   = note: `#[warn(clippy::single_match)]` on by default
help: try
   |
35 ~         if analyzer_state.analyzer_type == AnalyzerType::Solidity {
36 +             function.logic.push(format!(
37 +                 "emit Event_{}({}{});{}",
38 +                 &event
39 +                     .topics
40 +                     .first()
41 +                     .unwrap_or(&U256::from(0))
42 +                     .encode_hex()
43 +                     .replacen("0x", "", 1)[0..8],
44 +                 event
45 +                     .topics
46 +                     .get(1..)
47 +                     .map(|topics| {
48 +                         if !event.data.is_empty() && !topics.is_empty() {
49 +                             let mut solidified_topics: Vec = Vec::new();
50 +                             for (i, _) in topics.iter().enumerate() {
51 +                                 solidified_topics.push(
52 +                                     state.last_instruction.input_operations[i + 3].solidify(),
53 +                                 );
54 +                             }
55 +                             format!("{}, ", solidified_topics.join(", "))
56 +                         } else {
57 +                             let mut solidified_topics: Vec = Vec::new();
58 +                             for (i, _) in topics.iter().enumerate() {
59 +                                 solidified_topics.push(
60 +                                     state.last_instruction.input_operations[i + 3].solidify(),
61 +                                 );
62 +                             }
63 +                             solidified_topics.join(", ")
64 +                         }
65 +                     })
66 +                     .unwrap_or("".to_string()),
67 +                 data_mem_ops_solidified,
68 +                 if anonymous { " // anonymous event" } else { "" }
69 +             ));
70 +         }
   |

@@ -1,9 +1,13 @@
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Error: {0}")]
#[error("{0}")]
Generic(String),
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: variant name ends with the enum's name
 --> crates/cli/src/error.rs:6:5
  |
6 |     IOError(#[from] std::io::Error),
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names
  = note: `#[warn(clippy::enum_variant_names)]` on by default

@@ -1,9 +1,13 @@
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Error: {0}")]
#[error("{0}")]
Generic(String),
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
#[error("Serde error: {0}")]
SerdeError(#[from] serde_json::Error),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: variant name ends with the enum's name
 --> crates/cli/src/error.rs:8:5
  |
8 |     SerdeError(#[from] serde_json::Error),
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names

Generic(String),
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
#[error("Serde error: {0}")]
SerdeError(#[from] serde_json::Error),
#[error("Decompile error: {0}")]
DecompileError(#[from] heimdall_core::heimdall_decompiler::Error),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: variant name ends with the enum's name
  --> crates/cli/src/error.rs:10:5
   |
10 |     DecompileError(#[from] heimdall_core::heimdall_decompiler::Error),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names

#[error("Decompile error: {0}")]
DecompileError(#[from] heimdall_core::heimdall_decompiler::Error),
#[error("Disassemble error: {0}")]
DisassembleError(#[from] heimdall_core::heimdall_disassembler::Error),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: variant name ends with the enum's name
  --> crates/cli/src/error.rs:12:5
   |
12 |     DisassembleError(#[from] heimdall_core::heimdall_disassembler::Error),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names

@Jon-Becker Jon-Becker disabled auto-merge May 6, 2024 22:23
@Jon-Becker Jon-Becker merged commit 1278d63 into main May 6, 2024
7 checks passed
@Jon-Becker Jon-Becker changed the title [WIP] meta: major crates refactor / rewrite meta: major crates refactor / rewrite May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant