Skip to content

Commit

Permalink
Name changes for attack surface
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan committed Mar 6, 2025
1 parent 6ecc6a4 commit f84e734
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
11 changes: 6 additions & 5 deletions aderyn_core/src/audit/auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use strum::{Display, EnumString};

use crate::{
audit::{
attack_surface::AttackSurfaceDetector, entry_points::EntryPointsDetector,
entry_points::EntryPointsDetector,
public_functions_no_sender::PublicFunctionsNoSenderChecksDetector,
raw_calls::RawCallsDetector,
},
context::workspace_context::WorkspaceContext,
};

pub fn get_all_auditor_detectors() -> Vec<Box<dyn AuditorDetector>> {
vec![
Box::<AttackSurfaceDetector>::default(),
Box::<RawCallsDetector>::default(),
Box::<PublicFunctionsNoSenderChecksDetector>::default(),
Box::<EntryPointsDetector>::default(),
]
Expand All @@ -26,7 +27,7 @@ pub fn get_all_auditor_detectors_names() -> Vec<String> {
#[derive(Debug, PartialEq, EnumString, Display)]
#[strum(serialize_all = "kebab-case")]
pub(crate) enum AuditorDetectorNamePool {
AttackSurface,
RawCalls,
NoSenderChecks,
EntryPoints,
// NOTE: `Undecided` will be the default name (for new bots).
Expand All @@ -38,12 +39,12 @@ pub fn get_auditor_detector_by_name(name: &str) -> Box<dyn AuditorDetector> {
// Expects a valid detector_name
let detector_name = AuditorDetectorNamePool::from_str(name).unwrap();
match detector_name {
AuditorDetectorNamePool::AttackSurface => Box::<AttackSurfaceDetector>::default(),
AuditorDetectorNamePool::RawCalls => Box::<RawCallsDetector>::default(),
AuditorDetectorNamePool::NoSenderChecks => {
Box::<PublicFunctionsNoSenderChecksDetector>::default()
}
AuditorDetectorNamePool::EntryPoints => Box::<EntryPointsDetector>::default(),
AuditorDetectorNamePool::Undecided => Box::<AttackSurfaceDetector>::default(),
AuditorDetectorNamePool::Undecided => Box::<RawCallsDetector>::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion aderyn_core/src/audit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod attack_surface;
pub mod auditor;
pub mod entry_points;
pub mod public_functions_no_sender;
pub mod raw_calls;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum AddressSource {
}

#[derive(Clone, Eq, PartialEq)]
pub struct AttackSurfaceInstance {
pub struct RawCallsInstance {
pub contract_name: String,
pub function_name: String,
pub source_code: String,
Expand All @@ -31,7 +31,7 @@ pub struct AttackSurfaceInstance {

use std::cmp::{Ord, Ordering, PartialOrd};

impl Ord for AttackSurfaceInstance {
impl Ord for RawCallsInstance {
fn cmp(&self, other: &Self) -> Ordering {
let by_contract = self.contract_name.cmp(&other.contract_name);
if by_contract != Ordering::Equal {
Expand All @@ -52,7 +52,7 @@ impl Ord for AttackSurfaceInstance {
}
}

impl PartialOrd for AttackSurfaceInstance {
impl PartialOrd for RawCallsInstance {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
Expand All @@ -69,11 +69,11 @@ impl Display for AddressSource {
}

#[derive(Default)]
pub struct AttackSurfaceDetector {
found_instances: BTreeSet<AttackSurfaceInstance>,
pub struct RawCallsDetector {
found_instances: BTreeSet<RawCallsInstance>,
}

impl AuditorDetector for AttackSurfaceDetector {
impl AuditorDetector for RawCallsDetector {
fn detect(&mut self, context: &WorkspaceContext) -> Result<bool, Box<dyn Error>> {
let mut surface_points: BTreeMap<NodeID, AddressSource> = BTreeMap::new();

Expand Down Expand Up @@ -113,15 +113,15 @@ impl AuditorDetector for AttackSurfaceDetector {
}

fn name(&self) -> String {
format!("{}", AuditorDetectorNamePool::AttackSurface)
format!("{}", AuditorDetectorNamePool::RawCalls)
}
}

fn transform_surface_points(
context: &WorkspaceContext,
surface_points: &BTreeMap<NodeID, AddressSource>,
) -> BTreeSet<AttackSurfaceInstance> {
let mut auditor_instances: BTreeSet<AttackSurfaceInstance> = BTreeSet::new();
) -> BTreeSet<RawCallsInstance> {
let mut auditor_instances: BTreeSet<RawCallsInstance> = BTreeSet::new();

for (id, address_storage) in surface_points {
if let Some(ast_node) = context.nodes.get(id) {
Expand All @@ -132,7 +132,7 @@ fn transform_surface_points(
if let Some(source_code) = ast_node.peek(context) {
let contract_name = contract.name.to_string();
let function_name = function.name.to_string();
auditor_instances.insert(AttackSurfaceInstance {
auditor_instances.insert(RawCallsInstance {
contract_name,
function_name,
source_code,
Expand Down Expand Up @@ -203,7 +203,7 @@ fn find_address_source_if_function_call(
mod attack_surface_detector_tests {
use serial_test::serial;

use crate::audit::{attack_surface::AttackSurfaceDetector, auditor::AuditorDetector};
use crate::audit::{auditor::AuditorDetector, raw_calls::RawCallsDetector};

#[test]
#[serial]
Expand All @@ -212,7 +212,7 @@ mod attack_surface_detector_tests {
"../tests/contract-playground/src/auditor_mode/ExternalCalls.sol",
);

let mut detector = AttackSurfaceDetector::default();
let mut detector = RawCallsDetector::default();
let found = detector.detect(&context).unwrap();
// assert that the detector found an issue
assert!(found);
Expand Down

0 comments on commit f84e734

Please sign in to comment.