Skip to content

Commit

Permalink
Fix TempleDao repo issues (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan authored Jul 11, 2024
1 parent 79f6dc4 commit 840b12e
Show file tree
Hide file tree
Showing 9 changed files with 8,398 additions and 44 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
- uses: pnpm/action-setup@v3
with:
version: 8

- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'

- name: Make
run: |
Expand Down Expand Up @@ -215,6 +220,19 @@ 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
uses: actions-rs/cargo@v1
with:
command: run
args: -- ./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

- name: Generate report-workflow.json
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "tests/prb-math"]
path = tests/prb-math
url = https://github.com/PaulRBerg/prb-math
[submodule "tests/2024-07-templegold"]
path = tests/2024-07-templegold
url = https://github.com/Cyfrin/2024-07-templegold.git
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ setup:
yarn install && forge build
cd tests/prb-math/;\
npm install && forge build

cd tests/2024-07-templegold/;\
yarn

# Check for tests to pass
.PHONY: test
Expand Down
10 changes: 5 additions & 5 deletions aderyn_core/src/ast/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ impl VariableDeclaration {
/// Returns the mutability of the variable that was declared.
///
/// This is a helper to check variable mutability across Solidity versions.
pub fn mutability(&self) -> &Mutability {
pub fn mutability(&self) -> Option<&Mutability> {
if let Some(mutability) = &self.mutability {
mutability
Some(mutability)
} else if self.constant {
&Mutability::Constant
Some(&Mutability::Constant)
} else if self.state_variable {
&Mutability::Mutable
Some(&Mutability::Mutable)
} else {
unreachable!()
None
}
}
}
Expand Down
65 changes: 28 additions & 37 deletions aderyn_core/src/context/workspace_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,46 +1661,37 @@ impl WorkspaceContext {
let absolute_path = source_unit.absolute_path.as_ref().unwrap().clone();
let source_line = node
.src()
.map(|src| source_unit.source_line(src).unwrap_or(0)) // If `src` is `Some`, get the line number, else return 0
.unwrap_or(0); // If `src` is `None`, default to 0
.map(|src| source_unit.source_line(src).unwrap_or(0))
.unwrap_or(0);

// If the node is one of these, and it has a `name_location`, use that instead of the full `src`
let src_location = match node {
ASTNode::ContractDefinition(node) => {
if let Some(name_location) = &node.name_location {
name_location
} else {
&node.src
}
}
ASTNode::FunctionDefinition(node) => {
if let Some(name_location) = &node.name_location {
name_location
} else {
&node.src
}
}
ASTNode::ModifierDefinition(node) => {
if let Some(name_location) = &node.name_location {
name_location
} else {
&node.src
}
}
ASTNode::VariableDeclaration(node) => {
if let Some(name_location) = &node.name_location {
name_location
} else {
&node.src
}
}
_ => node.src().unwrap_or(""),
ASTNode::ContractDefinition(contract_node) => contract_node
.name_location
.as_ref()
.filter(|loc| !loc.contains("-1"))
.map_or_else(|| contract_node.src.clone(), |loc| loc.clone()),
ASTNode::FunctionDefinition(function_node) => function_node
.name_location
.as_ref()
.filter(|loc| !loc.contains("-1"))
.map_or_else(|| function_node.src.clone(), |loc| loc.clone()),
ASTNode::ModifierDefinition(modifier_node) => modifier_node
.name_location
.as_ref()
.filter(|loc| !loc.contains("-1"))
.map_or_else(|| modifier_node.src.clone(), |loc| loc.clone()),
ASTNode::VariableDeclaration(variable_node) => variable_node
.name_location
.as_ref()
.filter(|loc| !loc.contains("-1"))
.map_or_else(|| variable_node.src.clone(), |loc| loc.clone()),
_ => node.src().unwrap_or("").to_string(),
};
let chopped_location = match src_location.rfind(':') {
Some(index) => &src_location[..index],
None => src_location, // No colon found, return the original string
}
.to_string();

let chopped_location = src_location
.rfind(':')
.map(|index| src_location[..index].to_string())
.unwrap_or(src_location);

(absolute_path, source_line, chopped_location)
}
Expand Down
2 changes: 1 addition & 1 deletion aderyn_core/src/detect/low/zero_address_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl IssueDetector for ZeroAddressCheckDetector {
.iter()
.filter_map(|&var_decl| {
if !var_decl.constant
&& matches!(var_decl.mutability(), Mutability::Mutable)
&& matches!(var_decl.mutability(), Some(Mutability::Mutable))
&& var_decl.state_variable
&& (var_decl
.type_descriptions
Expand Down
3 changes: 3 additions & 0 deletions cli/reportgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ FOUNDRY_PROFILE=uniswap cargo run tests/contract-playground/ -o ./reports/uniswa
# PRB Math (uses new solidity features)
cargo run -- tests/prb-math -o reports/prb-math-report.md --skip-update-check &

# TempleGold
cargo run -- tests/2024-07-templegold/protocol -o reports/templegold-report.md --skip-update-check &

##### JSON REPORTS ########

# Basic report.json
Expand Down
Loading

0 comments on commit 840b12e

Please sign in to comment.