Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan committed Aug 5, 2024
2 parents a3acce3 + 155a9d6 commit 1be413e
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 18 deletions.
5 changes: 5 additions & 0 deletions aderyn/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

> ⚠️ **Installing via crates is no longer fully supported. `cyfrinup` is the preferred installation method.**.
>
> For the best experience, please remove the legacy crate installation by running `cargo uninstall aderyn`, and use `cyfrinup` instead.
>
> Full install instructions are [here](#installation).
<p align="center">
<br />
Expand Down
9 changes: 3 additions & 6 deletions aderyn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,12 @@ pub fn aderyn_is_currently_running_newest_version() -> Result<bool, reqwest::Err
.build()?;

let latest_version_checker = client
.get("https://crates.io/api/v1/crates?q=aderyn&per_page=1")
.get("https://api.github.com/repos/Cyfrin/aderyn/releases/latest")
.send()?;

let data = latest_version_checker.json::<Value>()?;

let newest_version = data["crates"][0]["newest_version"].to_string();
let newest_version = &newest_version[1..newest_version.len() - 1];

let newest = Version::parse(newest_version).unwrap();
let newest =
Version::parse(data["tag_name"].as_str().unwrap().replace("v", "").as_str()).unwrap();
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();

Ok(current >= newest)
Expand Down
4 changes: 1 addition & 3 deletions aderyn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ fn main() {
if let Ok(yes) = aderyn_is_currently_running_newest_version() {
if !yes {
println!();
println!(
"NEW VERSION OF ADERYN AVAILABLE! Please run `cargo install aderyn` to fully upgrade the current version"
);
println!("NEW VERSION OF ADERYN AVAILABLE! Please run `cyfrinup` to upgrade.");
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions aderyn_core/src/detect/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub fn get_all_issue_detectors() -> Vec<Box<dyn IssueDetector>> {
Box::<PreDeclaredLocalVariableUsageDetector>::default(),
Box::<DeletionNestedMappingDetector>::default(),
Box::<ConstantFunctionContainsAssemblyDetector>::default(),
Box::<BooleanEqualityDetector>::default(),
Box::<TxOriginUsedForAuthDetector>::default(),
Box::<MsgValueUsedInLoopDetector>::default(),
Box::<ContractLocksEtherDetector>::default(),
Expand Down Expand Up @@ -149,6 +150,7 @@ pub(crate) enum IssueDetectorNamePool {
PreDeclaredLocalVariableUsage,
DeleteNestedMapping,
ConstantFunctionsAssembly,
BooleanEquality,
TxOriginUsedForAuth,
MsgValueInLoop,
ContractLocksEther,
Expand Down Expand Up @@ -313,6 +315,7 @@ pub fn request_issue_detector_by_name(detector_name: &str) -> Option<Box<dyn Iss
IssueDetectorNamePool::ConstantFunctionsAssembly => {
Some(Box::<ConstantFunctionContainsAssemblyDetector>::default())
}
IssueDetectorNamePool::BooleanEquality => Some(Box::<BooleanEqualityDetector>::default()),
IssueDetectorNamePool::TxOriginUsedForAuth => {
Some(Box::<TxOriginUsedForAuthDetector>::default())
}
Expand Down
50 changes: 50 additions & 0 deletions aderyn_core/src/detect/low/boolean_equality.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::detect::helpers::is_constant_boolean;
use crate::issue_detector;
use eyre::Result;

issue_detector! {
BooleanEqualityDetector;

severity: Low,
title: "Boolean equality is not required.",
desc: "If `x` is a boolean, there is no need to do `if(x == true)` or `if(x == false)`. Just use `if(x)` and `if(!x)` respectively.",
name: BooleanEquality,

|context| {
for binary_operation in context.binary_operations() {
if binary_operation.operator == "=="
&& [
binary_operation.left_expression.as_ref(),
binary_operation.right_expression.as_ref(),
]
.iter()
.any(|&operand| is_constant_boolean(context, operand))
{
grab!(binary_operation);
}
}
}

}

#[cfg(test)]
mod boolean_equality_tests {
use serial_test::serial;

use crate::detect::{detector::IssueDetector, low::boolean_equality::BooleanEqualityDetector};

#[test]
#[serial]
fn test_boolean_equality_by_loading_contract_directly() {
let context = crate::detect::test_utils::load_solidity_source_unit(
"../tests/contract-playground/src/BooleanEquality.sol",
);

let mut detector = BooleanEqualityDetector::default();
let found = detector.detect(&context).unwrap();
// assert that the detector found an issue
assert!(found);
// assert that the detector found the correct number of instances
assert_eq!(detector.instances().len(), 4);
}
}
2 changes: 2 additions & 0 deletions aderyn_core/src/detect/low/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub(crate) mod boolean_equality;
pub(crate) mod centralization_risk;
pub(crate) mod constant_funcs_assembly;
pub(crate) mod constants_instead_of_literals;
Expand Down Expand Up @@ -25,6 +26,7 @@ pub(crate) mod useless_modifier;
pub(crate) mod useless_public_function;
pub(crate) mod zero_address_check;

pub use boolean_equality::BooleanEqualityDetector;
pub use centralization_risk::CentralizationRiskDetector;
pub use constant_funcs_assembly::ConstantFunctionContainsAssemblyDetector;
pub use constants_instead_of_literals::ConstantsInsteadOfLiteralsDetector;
Expand Down
78 changes: 75 additions & 3 deletions reports/report.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files_summary": {
"total_source_units": 78,
"total_sloc": 2251
"total_source_units": 79,
"total_sloc": 2278
},
"files_details": {
"files_details": [
Expand All @@ -21,6 +21,10 @@
"file_path": "src/AssemblyExample.sol",
"n_sloc": 9
},
{
"file_path": "src/BooleanEquality.sol",
"n_sloc": 27
},
{
"file_path": "src/CallGraphTests.sol",
"n_sloc": 49
Expand Down Expand Up @@ -321,7 +325,7 @@
},
"issue_count": {
"high": 36,
"low": 26
"low": 27
},
"high_issues": {
"issues": [
Expand Down Expand Up @@ -2580,6 +2584,42 @@
"description": "If the same constant literal value is used multiple times, create a constant state variable and reference it throughout the contract.",
"detector_name": "constants-instead-of-literals",
"instances": [
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 6,
"src": "170:3",
"src_char": "170:3"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 13,
"src": "330:3",
"src_char": "330:3"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 15,
"src": "360:3",
"src_char": "360:3"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 20,
"src": "492:3",
"src_char": "492:3"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 27,
"src": "653:3",
"src_char": "653:3"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 29,
"src": "683:3",
"src_char": "683:3"
},
{
"contract_path": "src/Casting.sol",
"line_no": 16,
Expand Down Expand Up @@ -4086,6 +4126,37 @@
"src_char": "934:98"
}
]
},
{
"title": "Boolean equality is not required.",
"description": "If `x` is a boolean, there is no need to do `if(x == true)` or `if(x == false)`. Just use `if(x)` and `if(!x)` respectively.",
"detector_name": "boolean-equality",
"instances": [
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 5,
"src": "133:14",
"src_char": "133:14"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 12,
"src": "292:15",
"src_char": "292:15"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 19,
"src": "454:15",
"src_char": "454:15"
},
{
"contract_path": "src/BooleanEquality.sol",
"line_no": 26,
"src": "614:16",
"src_char": "614:16"
}
]
}
]
},
Expand Down Expand Up @@ -4149,6 +4220,7 @@
"pre-declared-local-variable-usage",
"delete-nested-mapping",
"constant-functions-assembly",
"boolean-equality",
"tx-origin-used-for-auth",
"msg-value-in-loop",
"contract-locks-ether"
Expand Down
83 changes: 78 additions & 5 deletions reports/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati
- [L-24: Redundant statements have no effect.](#l-24-redundant-statements-have-no-effect)
- [L-25: Public variables of a contract read in an external context (using `this`).](#l-25-public-variables-of-a-contract-read-in-an-external-context-using-this)
- [L-26: Functions declared `pure` / `view` but contains assembly](#l-26-functions-declared-pure--view-but-contains-assembly)
- [L-27: Boolean equality is not required.](#l-27-boolean-equality-is-not-required)


# Summary
Expand All @@ -79,8 +80,8 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati

| Key | Value |
| --- | --- |
| .sol Files | 78 |
| Total nSLOC | 2251 |
| .sol Files | 79 |
| Total nSLOC | 2278 |


## Files Details
Expand All @@ -91,6 +92,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati
| src/AdminContract.sol | 11 |
| src/ArbitraryTransferFrom.sol | 37 |
| src/AssemblyExample.sol | 9 |
| src/BooleanEquality.sol | 27 |
| src/CallGraphTests.sol | 49 |
| src/Casting.sol | 126 |
| src/CompilerBugStorageSignedIntegerArray.sol | 13 |
Expand Down Expand Up @@ -165,15 +167,15 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati
| src/reused_contract_name/ContractB.sol | 7 |
| src/uniswap/UniswapV2Swapper.sol | 50 |
| src/uniswap/UniswapV3Swapper.sol | 150 |
| **Total** | **2251** |
| **Total** | **2278** |


## Issue Summary

| Category | No. of Issues |
| --- | --- |
| High | 36 |
| Low | 26 |
| Low | 27 |


# High Issues
Expand Down Expand Up @@ -2611,9 +2613,45 @@ Instead of marking a function as `public`, consider marking it as `external` if

If the same constant literal value is used multiple times, create a constant state variable and reference it throughout the contract.

<details><summary>38 Found Instances</summary>
<details><summary>44 Found Instances</summary>


- Found in src/BooleanEquality.sol [Line: 6](../tests/contract-playground/src/BooleanEquality.sol#L6)

```solidity
return 100;
```

- Found in src/BooleanEquality.sol [Line: 13](../tests/contract-playground/src/BooleanEquality.sol#L13)

```solidity
return 200;
```

- Found in src/BooleanEquality.sol [Line: 15](../tests/contract-playground/src/BooleanEquality.sol#L15)

```solidity
return 130;
```

- Found in src/BooleanEquality.sol [Line: 20](../tests/contract-playground/src/BooleanEquality.sol#L20)

```solidity
return 100;
```

- Found in src/BooleanEquality.sol [Line: 27](../tests/contract-playground/src/BooleanEquality.sol#L27)

```solidity
return 200;
```

- Found in src/BooleanEquality.sol [Line: 29](../tests/contract-playground/src/BooleanEquality.sol#L29)

```solidity
return 130;
```

- Found in src/Casting.sol [Line: 16](../tests/contract-playground/src/Casting.sol#L16)

```solidity
Expand Down Expand Up @@ -4179,3 +4217,38 @@ If the assembly code contains bugs or unintended side effects, it can lead to in



## L-27: Boolean equality is not required.

If `x` is a boolean, there is no need to do `if(x == true)` or `if(x == false)`. Just use `if(x)` and `if(!x)` respectively.

<details><summary>4 Found Instances</summary>


- Found in src/BooleanEquality.sol [Line: 5](../tests/contract-playground/src/BooleanEquality.sol#L5)

```solidity
if (isEven == true) {
```

- Found in src/BooleanEquality.sol [Line: 12](../tests/contract-playground/src/BooleanEquality.sol#L12)

```solidity
if (isEven == !true) {
```

- Found in src/BooleanEquality.sol [Line: 19](../tests/contract-playground/src/BooleanEquality.sol#L19)

```solidity
if (isEven == false) {
```

- Found in src/BooleanEquality.sol [Line: 26](../tests/contract-playground/src/BooleanEquality.sol#L26)

```solidity
if (isEven == !false) {
```

</details>



Loading

0 comments on commit 1be413e

Please sign in to comment.