Skip to content

Commit

Permalink
Relax fixed pragma constraints on library contract files (#740)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Roan <[email protected]>
  • Loading branch information
TilakMaddy and alexroan authored Oct 3, 2024
1 parent 9207635 commit ceee00e
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 180 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ jobs:
run: |
git submodule update --init --recursive
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
cargo test _by_loading_contract_directly
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
Expand Down
34 changes: 31 additions & 3 deletions aderyn_core/src/detect/low/unspecific_solidity_pragma.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::{collections::BTreeMap, error::Error};

use crate::{
ast::NodeID,
ast::{ContractKind, NodeID, NodeType},
capture,
context::workspace_context::WorkspaceContext,
context::{
browser::{ExtractContractDefinitions, GetClosestAncestorOfTypeX},
workspace_context::WorkspaceContext,
},
detect::detector::{IssueDetector, IssueDetectorNamePool, IssueSeverity},
};
use eyre::Result;
Expand All @@ -18,8 +21,20 @@ pub struct UnspecificSolidityPragmaDetector {
impl IssueDetector for UnspecificSolidityPragmaDetector {
fn detect(&mut self, context: &WorkspaceContext) -> Result<bool, Box<dyn Error>> {
for pragma_directive in context.pragma_directives() {
let Some(source_unit) =
pragma_directive.closest_ancestor_of_type(context, NodeType::SourceUnit)
else {
continue;
};
let contracts_in_source_unit = ExtractContractDefinitions::from(source_unit).extracted;
if contracts_in_source_unit
.iter()
.any(|c| c.kind == ContractKind::Library)
{
continue;
}
for literal in &pragma_directive.literals {
if literal.contains('^') || literal.contains('>') {
if literal.contains('^') || literal.contains('>') || literal.contains('<') {
capture!(self, context, pragma_directive);
break;
}
Expand Down Expand Up @@ -88,4 +103,17 @@ mod unspecific_solidity_pragma_tests {
)
);
}

#[test]
#[serial]
fn test_unspecific_solidity_pragma_detector_by_loading_contract_directly_on_library() {
let context = crate::detect::test_utils::load_solidity_source_unit(
"../tests/contract-playground/src/OnlyLibrary.sol",
);

let mut detector = UnspecificSolidityPragmaDetector::default();
let found = detector.detect(&context).unwrap();
// assert that the detector found an abi encode packed
assert!(!found);
}
}
38 changes: 1 addition & 37 deletions reports/ccip-functions-report.md

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

20 changes: 1 addition & 19 deletions reports/prb-math-report.md

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

20 changes: 12 additions & 8 deletions reports/report.json

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

23 changes: 12 additions & 11 deletions reports/report.md

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

22 changes: 11 additions & 11 deletions reports/report.sarif

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

32 changes: 1 addition & 31 deletions reports/sablier-aderyn-toml-nested-root.md

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

Loading

0 comments on commit ceee00e

Please sign in to comment.