Skip to content

Commit

Permalink
cli/reportgen
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Sep 2, 2024
1 parent b4fcd7c commit d9b81ce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 119 deletions.
16 changes: 13 additions & 3 deletions aderyn_core/src/detect/low/state_variable_could_be_constant.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::collections::{BTreeMap, HashSet};
use std::error::Error;

use crate::ast::{Mutability, NodeID};
use crate::ast::{FunctionCallKind, Mutability, NodeID};

use crate::capture;
use crate::context::browser::ExtractFunctionCalls;
use crate::detect::detector::IssueDetectorNamePool;
use crate::{
context::workspace_context::WorkspaceContext,
detect::detector::{IssueDetector, IssueSeverity},
};
use eyre::Result;

#[derive(Default)]
pub struct StateVariableCouldBeConstantDetector {
Expand All @@ -33,11 +33,21 @@ impl IssueDetector for StateVariableCouldBeConstantDetector {
continue;
}

if let Some(rhs_value) = variable.value.as_ref() {
let function_calls = ExtractFunctionCalls::from(rhs_value).extracted;
if function_calls
.iter()
.any(|f| f.kind == FunctionCallKind::FunctionCall)
{
continue;
}
}

if variable.mutability() == Some(&Mutability::Immutable) {
continue;
}

// Do not report it if it's a struct / mapping / contract type
// Do not report it if it's a struct / mapping
if variable
.type_descriptions
.type_string
Expand Down
30 changes: 0 additions & 30 deletions reports/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -5781,42 +5781,12 @@
"src": "123:21",
"src_char": "123:21"
},
{
"contract_path": "src/FunctionInitializingState.sol",
"line_no": 6,
"src": "108:21",
"src_char": "108:21"
},
{
"contract_path": "src/FunctionInitializingState.sol",
"line_no": 7,
"src": "176:17",
"src_char": "176:17"
},
{
"contract_path": "src/FunctionInitializingState.sol",
"line_no": 8,
"src": "199:21",
"src_char": "199:21"
},
{
"contract_path": "src/FunctionInitializingState.sol",
"line_no": 9,
"src": "267:21",
"src_char": "267:21"
},
{
"contract_path": "src/FunctionInitializingState.sol",
"line_no": 10,
"src": "294:22",
"src_char": "294:22"
},
{
"contract_path": "src/FunctionInitializingState.sol",
"line_no": 11,
"src": "322:23",
"src_char": "322:23"
},
{
"contract_path": "src/FunctionInitializingState.sol",
"line_no": 58,
Expand Down
32 changes: 1 addition & 31 deletions reports/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -5883,7 +5883,7 @@ solc versions below 0.5.9 contain a compiler bug leading to unexpected behavior

State variables that are not updated following deployment should be declared constant to save gas. Add the `constant` attribute to state variables that never change.

<details><summary>39 Found Instances</summary>
<details><summary>34 Found Instances</summary>


- Found in src/CostlyOperationsInsideLoops.sol [Line: 6](../tests/contract-playground/src/CostlyOperationsInsideLoops.sol#L6)
Expand All @@ -5892,42 +5892,12 @@ State variables that are not updated following deployment should be declared con
uint loop_count = 100;
```

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

```solidity
uint public v = set(); // Initialize from function (sets to 77)
```

- Found in src/FunctionInitializingState.sol [Line: 7](../tests/contract-playground/src/FunctionInitializingState.sol#L7)

```solidity
uint public w = 5;
```

- Found in src/FunctionInitializingState.sol [Line: 8](../tests/contract-playground/src/FunctionInitializingState.sol#L8)

```solidity
uint public x = set(); // Initialize from function (sets to 88)
```

- Found in src/FunctionInitializingState.sol [Line: 9](../tests/contract-playground/src/FunctionInitializingState.sol#L9)

```solidity
uint public f = tes();
```

- Found in src/FunctionInitializingState.sol [Line: 10](../tests/contract-playground/src/FunctionInitializingState.sol#L10)

```solidity
uint public h = okay();
```

- Found in src/FunctionInitializingState.sol [Line: 11](../tests/contract-playground/src/FunctionInitializingState.sol#L11)

```solidity
uint public m = okay2();
```

- Found in src/FunctionInitializingState.sol [Line: 58](../tests/contract-playground/src/FunctionInitializingState.sol#L58)

```solidity
Expand Down
55 changes: 0 additions & 55 deletions reports/report.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -9546,17 +9546,6 @@
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "src/FunctionInitializingState.sol"
},
"region": {
"byteLength": 21,
"byteOffset": 108
}
}
},
{
"physicalLocation": {
"artifactLocation": {
Expand All @@ -9568,50 +9557,6 @@
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "src/FunctionInitializingState.sol"
},
"region": {
"byteLength": 21,
"byteOffset": 199
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "src/FunctionInitializingState.sol"
},
"region": {
"byteLength": 21,
"byteOffset": 267
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "src/FunctionInitializingState.sol"
},
"region": {
"byteLength": 22,
"byteOffset": 294
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "src/FunctionInitializingState.sol"
},
"region": {
"byteLength": 23,
"byteOffset": 322
}
}
},
{
"physicalLocation": {
"artifactLocation": {
Expand Down

0 comments on commit d9b81ce

Please sign in to comment.