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

Re-entrancy detector + Control Flow Graph #752

Open
wants to merge 48 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c3a9312
checkpoint
TilakMaddy Sep 27, 2024
ff6cf10
fantasy
TilakMaddy Sep 27, 2024
c689523
checkpoint
TilakMaddy Sep 27, 2024
3ed1d40
checkpoint
TilakMaddy Sep 28, 2024
76f25e5
start and end nodes customized
TilakMaddy Sep 28, 2024
60bf95c
test
TilakMaddy Sep 28, 2024
feeb6a3
test
TilakMaddy Sep 28, 2024
7a9a254
test
TilakMaddy Sep 28, 2024
7a70126
test
TilakMaddy Sep 28, 2024
457c920
sdfsaa
TilakMaddy Sep 28, 2024
724c8ba
safsafas
TilakMaddy Sep 28, 2024
0e2a54e
sfsafasf
TilakMaddy Sep 28, 2024
6af52dc
sdfsfdsafd
TilakMaddy Sep 28, 2024
7fc5960
oiuijkbnbvbncxvzv
TilakMaddy Sep 28, 2024
d6e8a2e
checkpoint
TilakMaddy Sep 28, 2024
de7a451
nbvyeghe
TilakMaddy Sep 28, 2024
688a452
if stmnt checkpoint
TilakMaddy Sep 28, 2024
1e95d49
fix test
TilakMaddy Sep 28, 2024
4b07a83
made if cfg better
TilakMaddy Sep 28, 2024
6e9e2c5
while dont
TilakMaddy Sep 29, 2024
f845ffc
fx
TilakMaddy Sep 29, 2024
0827cd4
for statement done
TilakMaddy Sep 29, 2024
6388099
do while
TilakMaddy Sep 29, 2024
5daabfa
unchecked block
TilakMaddy Sep 29, 2024
866ee2e
wufjfwk
TilakMaddy Sep 30, 2024
235f900
Merge branch 'dev' into feature/control-flow-graphs-plus-re-entrancy-…
TilakMaddy Oct 5, 2024
affcc0c
fmt
TilakMaddy Oct 5, 2024
4a7eef9
clippy
TilakMaddy Oct 5, 2024
ae74394
Make svg creation optional for test to pass
TilakMaddy Oct 5, 2024
c9c7a11
continue, break and return works!
TilakMaddy Oct 6, 2024
4fad54a
cli/reportgen
TilakMaddy Oct 6, 2024
5058353
got rid of constants
TilakMaddy Oct 6, 2024
d05680e
again
TilakMaddy Oct 6, 2024
a343b3b
added try statement as primitive
TilakMaddy Oct 6, 2024
c5edfbc
external calls detector
TilakMaddy Oct 6, 2024
632dc62
cli/reportgen
TilakMaddy Oct 6, 2024
68d3a96
reflection!
TilakMaddy Oct 6, 2024
e73945e
reentrancy detector test works!
TilakMaddy Oct 6, 2024
5ea0d91
cli/reportgen
TilakMaddy Oct 6, 2024
ba94a0b
make fmt
TilakMaddy Oct 6, 2024
a8117c8
state change hint
TilakMaddy Oct 6, 2024
be8cece
better hints
TilakMaddy Oct 6, 2024
e9c41d3
tests moved
TilakMaddy Oct 6, 2024
18ed5c1
re-entrancy low detector
TilakMaddy Oct 7, 2024
117fd9c
test
TilakMaddy Oct 7, 2024
5441dbf
Detector: Use of Incorrect Modifier (#758)
TilakMaddy Oct 8, 2024
30ae055
Merge dev
TilakMaddy Oct 10, 2024
536a72d
Merge branch 'dev' into feature/control-flow-graphs-plus-re-entrancy-…
TilakMaddy Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ jobs:
run: |
git submodule update --init --recursive

- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
cargo test directly -- --nocapture

- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/target
.DS_Store
.venv
debug/
debug/
dot/
!dot/.gitkeep
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aderyn_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ lazy-regex = "3.2.0"
derive_more = "0.99.18"

[dev-dependencies]
petgraph = "0"
serial_test = "3.0.0"
once_cell = "1.19.0"

Expand Down
109 changes: 109 additions & 0 deletions aderyn_core/src/context/browser/external_calls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//! This module helps us detect whether a given AST Node has any external calls inside of it

use super::ExtractMemberAccesses;
use crate::{ast::*, context::workspace_context::ASTNode};

fn is_external_call(ast_node: ASTNode) -> bool {
// This is so we can skip the FunctionCallOptions layer which solidity compiler inserts
// when there are options passed to function calls
for member_access in ExtractMemberAccesses::from(&ast_node).extracted {
// address(..).call("...") pattern
let is_call = member_access.member_name == "call";
if is_call {
return true;
}

// payable(address(..)).transfer(100)
// payable(address(..)).send(100)
// address.sendValue(..) (from openzeppelin)
if member_access.member_name == "transfer"
|| member_access.member_name == "send"
|| member_access.member_name == "sendValue"
{
if let Some(type_description) = member_access.expression.type_descriptions() {
if type_description
.type_string
.as_ref()
.is_some_and(|type_string| type_string.starts_with("address"))
{
return true;
}
}
}

// Any external call
if member_access
.type_descriptions
.type_identifier
.is_some_and(|type_identifier| type_identifier.contains("function_external"))
{
return true;
}
}

false
}

impl FunctionCall {
pub fn is_external_call(&self) -> bool {
is_external_call(self.into())
}
}
impl FunctionCallOptions {
pub fn is_external_call(&self) -> bool {
is_external_call(self.into())
}
}

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

use crate::{
context::browser::ExtractFunctionCalls, detect::test_utils::load_solidity_source_unit,
};

use super::FunctionDefinition;

impl FunctionDefinition {
pub fn makes_external_calls(&self) -> bool {
let func_calls = ExtractFunctionCalls::from(self).extracted;
func_calls.iter().any(|f| f.is_external_call())
}
}

#[test]
#[serial]
fn test_direct_call_on_address() {
let context =
load_solidity_source_unit("../tests/contract-playground/src/ExternalCalls.sol");

let childex = context.find_contract_by_name("ChildEx");

let ext1 = childex.find_function_by_name("ext1");
let ext2 = childex.find_function_by_name("ext2");
let ext3 = childex.find_function_by_name("ext3");
let ext4 = childex.find_function_by_name("ext4");
let ext5 = childex.find_function_by_name("ext5");
let ext6 = childex.find_function_by_name("ext6");
let ext7 = childex.find_function_by_name("ext7");
let ext8 = childex.find_function_by_name("ext8");
let ext9 = childex.find_function_by_name("ext9");

assert!(ext1.makes_external_calls());
assert!(ext2.makes_external_calls());
assert!(ext3.makes_external_calls());
assert!(ext4.makes_external_calls());
assert!(ext5.makes_external_calls());
assert!(ext6.makes_external_calls());
assert!(ext7.makes_external_calls());
assert!(ext8.makes_external_calls());
assert!(ext9.makes_external_calls());

let notext1 = childex.find_function_by_name("notExt1");
let notext2 = childex.find_function_by_name("notExt2");

assert!(!notext1.makes_external_calls());
assert!(!notext2.makes_external_calls());
}
}
1 change: 1 addition & 0 deletions aderyn_core/src/context/browser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod ancestral_line;
mod closest_ancestor;
mod external_calls;
mod extractor;
mod immediate_children;
mod location;
Expand Down
Loading
Loading