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

v0.1.8 Staging #608

Merged
merged 13 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 1 addition & 16 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ jobs:
useLockFile: false
working-directory: tests/2024-05-Sablier/v2-core

- uses: bahmutov/npm-install@v1
with:
useLockFile: false
working-directory: tests/2024-07-templegold/

- uses: bahmutov/npm-install@v1
with:
useLockFile: false
Expand Down Expand Up @@ -213,16 +208,6 @@ jobs:
cat ./reports/prb-math-report-workflow.md
diff ./reports/prb-math-report.md ./reports/prb-math-report-workflow.md


- name: Generate 2024-07-templegold-report-workflow.md
run: |
cargo run -- ./tests/2024-07-templegold/protocol -o ./reports/2024-07-templegold-report-workflow.md --skip-update-check

- name: Check 2024-07-templegold-report.md vs 2024-07-templegold-report-workflow.md
run: |
cat ./reports/2024-07-templegold-report-workflow.md
diff ./reports/templegold-report.md ./reports/2024-07-templegold-report-workflow.md


# Verify report.json

Expand Down Expand Up @@ -287,4 +272,4 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
args: -- -D warnings
9 changes: 5 additions & 4 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ resolver="1"
exclude = [
"bot_ci_cd",
"foundry",
]
]

[profile.release]
codegen-units = 1
lto = true
9 changes: 4 additions & 5 deletions aderyn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
[package]
name = "aderyn"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["Alex Roan <alex@cyfrin.io>"]
authors = ["Cyfrin <aderyn@cyfrin.io>"]
description = "Rust based Solidity AST analyzer"
license = "MIT"
default-run = "aderyn"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aderyn_driver = { path = "../aderyn_driver", version = "0.1.7" }
aderyn_driver = { path = "../aderyn_driver", version = "0.1.8" }
clap = { version = "4.4.6", features = ["derive"] }
reqwest = { version = "0.12.2", default-features = false, features = ["blocking", "json", "rustls-tls"] }
semver = "1.0.22"
serde = { version = "1.0.160", features = ["derive"] }
serde_json = { version = "1.0.96", features = ["preserve_order"] }
strum = { version = "0.26", features = ["derive"] }
notify-debouncer-full = "0.3.1"
cyfrin-foundry-compilers = { version = "0.3.20-aderyn", features = ["svm-solc"] }

cyfrin-foundry-compilers = { version = "0.3.20-aderyn", features = ["svm-solc"] }
5 changes: 3 additions & 2 deletions aderyn_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "aderyn_core"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["Alex Roan <alex@cyfrin.io>"]
authors = ["Cyfrin <aderyn@cyfrin.io>"]
description = "Rust based Solidity AST analyzer backend"
license = "MIT"

Expand All @@ -23,6 +23,7 @@ serde_repr = "0.1.12"
strum = { version = "0.26", features = ["derive"] }
toml = "0.8.2"
cyfrin-foundry-compilers = { version = "0.3.20-aderyn", features = ["svm-solc"] }
derive_more = "0.99.18"

[dev-dependencies]
serial_test = "3.0.0"
Expand Down
66 changes: 66 additions & 0 deletions aderyn_core/src/ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,69 @@ impl From<&YulLiteral> for ASTNode {
ASTNode::YulLiteral(value.clone())
}
}

impl From<&Expression> for ASTNode {
fn from(value: &Expression) -> Self {
match value {
Expression::Literal(literal) => ASTNode::Literal(literal.clone()),
Expression::Identifier(identifier) => ASTNode::Identifier(identifier.clone()),
Expression::UnaryOperation(unary_operation) => {
ASTNode::UnaryOperation(unary_operation.clone())
}
Expression::BinaryOperation(binary_operation) => {
ASTNode::BinaryOperation(binary_operation.clone())
}
Expression::Conditional(conditional) => ASTNode::Conditional(conditional.clone()),
Expression::Assignment(assignment) => ASTNode::Assignment(assignment.clone()),
Expression::FunctionCall(function_call) => ASTNode::FunctionCall(function_call.clone()),
Expression::FunctionCallOptions(function_call_ops) => {
ASTNode::FunctionCallOptions(function_call_ops.clone())
}
Expression::IndexAccess(index_access) => ASTNode::IndexAccess(index_access.clone()),
Expression::IndexRangeAccess(index_range_access) => {
ASTNode::IndexRangeAccess(index_range_access.clone())
}
Expression::MemberAccess(member_access) => ASTNode::MemberAccess(member_access.clone()),
Expression::ElementaryTypeNameExpression(elementary_type_name_expression) => {
ASTNode::ElementaryTypeNameExpression(elementary_type_name_expression.clone())
}
Expression::TupleExpression(tuple_expression) => {
ASTNode::TupleExpression(tuple_expression.clone())
}
Expression::NewExpression(new_expression) => {
ASTNode::NewExpression(new_expression.clone())
}
}
}
}

impl From<Expression> for ASTNode {
fn from(value: Expression) -> Self {
match value {
Expression::Literal(literal) => ASTNode::Literal(literal),
Expression::Identifier(identifier) => ASTNode::Identifier(identifier),
Expression::UnaryOperation(unary_operation) => ASTNode::UnaryOperation(unary_operation),
Expression::BinaryOperation(binary_operation) => {
ASTNode::BinaryOperation(binary_operation)
}
Expression::Conditional(conditional) => ASTNode::Conditional(conditional),
Expression::Assignment(assignment) => ASTNode::Assignment(assignment),
Expression::FunctionCall(function_call) => ASTNode::FunctionCall(function_call),
Expression::FunctionCallOptions(function_call_ops) => {
ASTNode::FunctionCallOptions(function_call_ops)
}
Expression::IndexAccess(index_access) => ASTNode::IndexAccess(index_access),
Expression::IndexRangeAccess(index_range_access) => {
ASTNode::IndexRangeAccess(index_range_access)
}
Expression::MemberAccess(member_access) => ASTNode::MemberAccess(member_access),
Expression::ElementaryTypeNameExpression(elementary_type_name_expression) => {
ASTNode::ElementaryTypeNameExpression(elementary_type_name_expression)
}
Expression::TupleExpression(tuple_expression) => {
ASTNode::TupleExpression(tuple_expression)
}
Expression::NewExpression(new_expression) => ASTNode::NewExpression(new_expression),
}
}
}
2 changes: 1 addition & 1 deletion aderyn_core/src/audit/public_functions_no_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl AuditorDetector for PublicFunctionsNoSenderChecksDetector {
});
// Check if the function has a `msg.sender` BinaryOperation check
let has_msg_sender_binary_operation =
has_msg_sender_binary_operation(function_definition);
has_msg_sender_binary_operation(&((*function_definition).into()));
// TODO Check if the function has a hasRole identifier with msg.sender as an arg
does_not_have_an_owner_modifier && !has_msg_sender_binary_operation
});
Expand Down
37 changes: 37 additions & 0 deletions aderyn_core/src/context/browser/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,40 @@ impl ASTConstVisitor for ExtractImmediateChildrenIDs {
Ok(())
}
}

// Extract Reference Declaration IDs
#[derive(Default)]
pub struct ExtractReferencedDeclarations {
pub extracted: Vec<NodeID>,
}

impl ExtractReferencedDeclarations {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractReferencedDeclarations = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}

impl ASTConstVisitor for ExtractReferencedDeclarations {
fn visit_member_access(&mut self, node: &MemberAccess) -> Result<bool> {
if let Some(referenced_id) = node.referenced_declaration {
self.extracted.push(referenced_id);
}
Ok(true)
}
fn visit_identifier(&mut self, node: &Identifier) -> Result<bool> {
if let Some(referenced_id) = node.referenced_declaration {
self.extracted.push(referenced_id);
}
Ok(true)
}
fn visit_identifier_path(&mut self, node: &IdentifierPath) -> Result<bool> {
self.extracted.push(node.referenced_declaration as i64);
Ok(true)
}
fn visit_user_defined_type_name(&mut self, node: &UserDefinedTypeName) -> Result<bool> {
self.extracted.push(node.referenced_declaration);
Ok(true)
}
}
32 changes: 32 additions & 0 deletions aderyn_core/src/context/graph/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub mod traits;
mod workspace_callgraph;

pub use workspace_callgraph::*;

use derive_more::From;

pub type Result<T> = core::result::Result<T, Error>;

#[derive(Debug, From)]
pub enum Error {
#[from]
Custom(String),

// region: -- standard::* errors
WorkspaceCallGraphDFSError,
// endregion
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}

impl From<&str> for Error {
fn from(value: &str) -> Self {
Error::Custom(value.to_string())
}
}

impl std::error::Error for Error {}
4 changes: 4 additions & 0 deletions aderyn_core/src/context/graph/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Trait to support reversing of callgraph. (Because, direct impl is not allowed on Foreign Types)
pub trait Transpose {
fn reverse(&self) -> Self;
}
Loading
Loading