diff --git a/aderyn_core/src/context/graph/mod.rs b/aderyn_core/src/context/callgraph/mod.rs similarity index 100% rename from aderyn_core/src/context/graph/mod.rs rename to aderyn_core/src/context/callgraph/mod.rs diff --git a/aderyn_core/src/context/graph/traits.rs b/aderyn_core/src/context/callgraph/traits.rs similarity index 100% rename from aderyn_core/src/context/graph/traits.rs rename to aderyn_core/src/context/callgraph/traits.rs diff --git a/aderyn_core/src/context/graph/workspace_callgraph.rs b/aderyn_core/src/context/callgraph/workspace_callgraph.rs similarity index 100% rename from aderyn_core/src/context/graph/workspace_callgraph.rs rename to aderyn_core/src/context/callgraph/workspace_callgraph.rs diff --git a/aderyn_core/src/context/investigator/standard.rs b/aderyn_core/src/context/investigator/standard.rs index 70329a92..dfdb4332 100644 --- a/aderyn_core/src/context/investigator/standard.rs +++ b/aderyn_core/src/context/investigator/standard.rs @@ -11,7 +11,7 @@ use crate::{ ast::{NodeID, NodeType}, context::{ browser::{ExtractReferencedDeclarations, GetClosestAncestorOfTypeX}, - graph::WorkspaceCallGraph, + callgraph::WorkspaceCallGraph, workspace_context::{ASTNode, WorkspaceContext}, }, }; diff --git a/aderyn_core/src/context/mod.rs b/aderyn_core/src/context/mod.rs index ca73f66c..b8e331f8 100644 --- a/aderyn_core/src/context/mod.rs +++ b/aderyn_core/src/context/mod.rs @@ -1,6 +1,6 @@ pub mod browser; +pub mod callgraph; pub mod capturable; -pub mod graph; pub mod investigator; pub mod macros; pub mod meta_workspace; diff --git a/aderyn_core/src/context/workspace_context.rs b/aderyn_core/src/context/workspace_context.rs index 5cd2cdb4..1dd2f149 100644 --- a/aderyn_core/src/context/workspace_context.rs +++ b/aderyn_core/src/context/workspace_context.rs @@ -3,8 +3,8 @@ use std::cmp::Ordering; use std::collections::HashMap; use super::browser::GetImmediateParent; +use super::callgraph::WorkspaceCallGraph; use super::capturable::Capturable; -use super::graph::WorkspaceCallGraph; pub use crate::ast::ASTNode; #[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] diff --git a/aderyn_core/src/detect/test_utils/load_source_unit.rs b/aderyn_core/src/detect/test_utils/load_source_unit.rs index c52a15f2..3a9448f9 100644 --- a/aderyn_core/src/detect/test_utils/load_source_unit.rs +++ b/aderyn_core/src/detect/test_utils/load_source_unit.rs @@ -7,9 +7,9 @@ use std::{ use crate::{ ast::SourceUnit, - context::{graph::traits::Transpose, workspace_context::WorkspaceContext}, + context::{callgraph::traits::Transpose, workspace_context::WorkspaceContext}, }; -use crate::{context::graph::WorkspaceCallGraph, visitor::ast_visitor::Node}; +use crate::{context::callgraph::WorkspaceCallGraph, visitor::ast_visitor::Node}; use super::ensure_valid_solidity_file; diff --git a/aderyn_driver/src/driver.rs b/aderyn_driver/src/driver.rs index 3abef9b3..a9af0960 100644 --- a/aderyn_driver/src/driver.rs +++ b/aderyn_driver/src/driver.rs @@ -2,9 +2,9 @@ use crate::{ config_helpers::{append_from_foundry_toml, derive_from_aderyn_toml}, ensure_valid_root_path, process_auto, }; -use aderyn_core::context::graph::traits::Transpose; +use aderyn_core::context::callgraph::traits::Transpose; use aderyn_core::{ - context::{graph::WorkspaceCallGraph, workspace_context::WorkspaceContext}, + context::{callgraph::WorkspaceCallGraph, workspace_context::WorkspaceContext}, detect::detector::{get_all_issue_detectors, IssueDetector, IssueSeverity}, fscloc, report::{ diff --git a/tests/contract-playground/src/CallsInsideLoop.sol b/tests/contract-playground/src/CallsInsideLoop.sol new file mode 100644 index 00000000..cce0c501 --- /dev/null +++ b/tests/contract-playground/src/CallsInsideLoop.sol @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity 0.8.19; + +contract HighLevelCallsInLoop { + address payable[] destinations; + + function bad() external { + // BAD for loop (the fallback may revert causing DoS) + for (uint i = 0; i < destinations.length; i++) { + destinations[i].transfer(i); + } + } + + function bad2() external { + // BAD for loop (the fallback may revert causing DoS) + for (uint i = 0; i < destinations.length; i++) { + facilitateTransfer(i, i * 2); + } + } + + function facilitateTransfer(uint256 index, uint256 money) internal { + destinations[index].transfer(money); + } + + function bad3() external view { + // BAD for loop + for (uint i = 0; i < destinations.length; i++) { + SimplyRevert(destinations[i]).sayHello(); + } + } + + function goodButTreatedAsBad() external view { + // BAD for loop + for (uint i = 0; i < destinations.length; i++) { + SimplyRevert(destinations[i]).innocent(); + } + } +} + +contract SimplyRevert { + error HellNo(string); + + function sayHello() external pure { + revert(); + } + + function innocent() external pure {} +} \ No newline at end of file