Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan committed Jul 29, 2024
2 parents babda66 + 25a368c commit c1605ea
Show file tree
Hide file tree
Showing 74 changed files with 5,494 additions and 132 deletions.
14 changes: 0 additions & 14 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,15 +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
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: 3 additions & 3 deletions aderyn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[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"
Expand Down
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),
}
}
}
7 changes: 7 additions & 0 deletions aderyn_core/src/ast/impls/node/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ impl Node for ExpressionStatement {
fn accept(&self, visitor: &mut impl ASTConstVisitor) -> Result<()> {
if visitor.visit_expression_statement(self)? {
self.expression.accept(visitor)?;
self.accept_metadata(visitor)?;
}
visitor.end_visit_expression_statement(self)
}
fn accept_metadata(&self, visitor: &mut impl ASTConstVisitor) -> Result<()> {
if let Some(child_id) = self.expression.get_node_id() {
visitor.visit_immediate_children(self.id, vec![child_id])?;
}
Ok(())
}
}

impl Node for VariableDeclarationStatement {
Expand Down
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

0 comments on commit c1605ea

Please sign in to comment.