diff --git a/aderyn_driver/src/process_auto.rs b/aderyn_driver/src/process_auto.rs index f5f634b94..fbcfe6aea 100644 --- a/aderyn_driver/src/process_auto.rs +++ b/aderyn_driver/src/process_auto.rs @@ -116,56 +116,97 @@ fn create_workspace_context_from_stdout( let mut context = WorkspaceContext::default(); // dbg!(&stdout) - let mut pick_next_line = false; + // let mut pick_next_line = false; let mut src_filepaths = vec![]; - for line in stdout.lines() { - if line.starts_with("======= ") { - let end_marker = line.find(" =======").unwrap(); - let filepath = &PathBuf::from(&line["======= ".len()..end_marker]); - if passes_scope( - scope, - utils::canonicalize(root_path.join(filepath)) - .unwrap() - .as_path(), - absolute_root_path_str, - ) && passes_exclude( - exclude, - utils::canonicalize(root_path.join(filepath)) - .unwrap() - .as_path(), - absolute_root_path_str, - ) && passes_src( - src, - utils::canonicalize(root_path.join(filepath)) - .unwrap() - .as_path(), - ) { - src_filepaths.push(filepath.to_string_lossy().to_string()); - pick_next_line = true; + let lines = stdout.lines().collect::>(); + + let mut idx = 0; + let mut keep_picking = false; + let mut ast_content = String::new(); + + while idx < lines.len() { + let line = lines[idx]; + + let (separation, filename) = + is_demarcation_line(line, scope, exclude, root_path, src, absolute_root_path_str); + + if separation { + if !ast_content.is_empty() { + absorb_ast_content_into_context(&ast_content, root_path, &mut context); + } + ast_content = String::new(); + keep_picking = false; + + if let Some(filepath) = filename { + src_filepaths.push(filepath); + keep_picking = true; } - } else if pick_next_line { - let ast_content = line.to_string(); - let mut source_unit: SourceUnit = serde_json::from_str(&ast_content).unwrap(); - let filepath = source_unit.absolute_path.as_ref().unwrap(); - source_unit.source = std::fs::read_to_string(root_path.join(filepath)).ok(); - // dbg!(&filepath); - source_unit.absolute_path = Some(filepath.to_string()); - // dbg!(&filepath); - - source_unit.accept(&mut context).unwrap_or_else(|err| { - // Exit with a non-zero exit code - eprintln!("Error loading AST into WorkspaceContext"); - eprintln!("{:?}", err); - std::process::exit(1); - }); - - pick_next_line = false; + } else if keep_picking { + ast_content.push_str(line); } + + idx += 1; + } + + if !ast_content.is_empty() { + absorb_ast_content_into_context(&ast_content, root_path, &mut context); } - // println!("{:#?}", context); - // println!("New context !"); context.src_filepaths = src_filepaths; context } + +fn absorb_ast_content_into_context( + ast_content: &str, + root_path: &Path, + context: &mut WorkspaceContext, +) { + let mut source_unit: SourceUnit = serde_json::from_str(ast_content).unwrap(); + let filepath = source_unit.absolute_path.as_ref().unwrap(); + source_unit.source = std::fs::read_to_string(root_path.join(filepath)).ok(); + source_unit.absolute_path = Some(filepath.to_string()); + + source_unit.accept(context).unwrap_or_else(|err| { + // Exit with a non-zero exit code + eprintln!("Error loading AST into WorkspaceContext"); + eprintln!("{:?}", err); + std::process::exit(1); + }); +} + +fn is_demarcation_line( + line: &str, + scope: &Option>, + exclude: &Option>, + root_path: &Path, + src: &Option>, + absolute_root_path_str: &str, +) -> (bool, Option) { + if line.starts_with("======= ") { + let end_marker = line.find(" =======").unwrap(); + let filepath = &PathBuf::from(&line["======= ".len()..end_marker]); + if passes_scope( + scope, + utils::canonicalize(root_path.join(filepath)) + .unwrap() + .as_path(), + absolute_root_path_str, + ) && passes_exclude( + exclude, + utils::canonicalize(root_path.join(filepath)) + .unwrap() + .as_path(), + absolute_root_path_str, + ) && passes_src( + src, + utils::canonicalize(root_path.join(filepath)) + .unwrap() + .as_path(), + ) { + return (true, Some(filepath.to_string_lossy().to_string())); + } + return (true, None); + } + (false, None) +} diff --git a/reports/adhoc-sol-files-report.md b/reports/adhoc-sol-files-report.md index 011d24438..de0b26e38 100644 --- a/reports/adhoc-sol-files-report.md +++ b/reports/adhoc-sol-files-report.md @@ -30,8 +30,8 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | Key | Value | | --- | --- | -| .sol Files | 8 | -| Total nSLOC | 154 | +| .sol Files | 18 | +| Total nSLOC | 206 | ## Files Details @@ -46,7 +46,17 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | inheritance/ExtendedInheritance.sol | 17 | | inheritance/IContractInheritance.sol | 4 | | inheritance/InheritanceBase.sol | 8 | -| **Total** | **154** | +| multiple-versions/0.4/A.sol | 5 | +| multiple-versions/0.4/B.sol | 5 | +| multiple-versions/0.5/A.sol | 5 | +| multiple-versions/0.5/B.sol | 7 | +| multiple-versions/0.6/A.sol | 5 | +| multiple-versions/0.6/B.sol | 5 | +| multiple-versions/0.7/A.sol | 5 | +| multiple-versions/0.7/B.sol | 5 | +| multiple-versions/0.8/A.sol | 5 | +| multiple-versions/0.8/B.sol | 5 | +| **Total** | **206** | ## Issue Summary @@ -116,7 +126,7 @@ The `ecrecover` function is susceptible to signature malleability. This means th Consider using a specific version of Solidity in your contracts instead of a wide version. For example, instead of `pragma solidity ^0.8.0;`, use `pragma solidity 0.8.0;` -
4 Found Instances +
14 Found Instances - Found in Counter.sol [Line: 2](../tests/adhoc-sol-files/Counter.sol#L2) @@ -143,6 +153,66 @@ Consider using a specific version of Solidity in your contracts instead of a wid pragma solidity ^0.8.0; ``` +- Found in multiple-versions/0.4/A.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.4/A.sol#L2) + + ```solidity + pragma solidity ^0.4.0; + ``` + +- Found in multiple-versions/0.4/B.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.4/B.sol#L2) + + ```solidity + pragma solidity ^0.4.0; + ``` + +- Found in multiple-versions/0.5/A.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.5/A.sol#L2) + + ```solidity + pragma solidity ^0.5.0; + ``` + +- Found in multiple-versions/0.5/B.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.5/B.sol#L2) + + ```solidity + pragma solidity ^0.5.0; + ``` + +- Found in multiple-versions/0.6/A.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.6/A.sol#L2) + + ```solidity + pragma solidity ^0.6.0; + ``` + +- Found in multiple-versions/0.6/B.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.6/B.sol#L2) + + ```solidity + pragma solidity ^0.6.0; + ``` + +- Found in multiple-versions/0.7/A.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.7/A.sol#L2) + + ```solidity + pragma solidity ^0.7.0; + ``` + +- Found in multiple-versions/0.7/B.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.7/B.sol#L2) + + ```solidity + pragma solidity ^0.7.0; + ``` + +- Found in multiple-versions/0.8/A.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.8/A.sol#L2) + + ```solidity + pragma solidity ^0.8.0; + ``` + +- Found in multiple-versions/0.8/B.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.8/B.sol#L2) + + ```solidity + pragma solidity ^0.8.0; + ``` +
@@ -238,7 +308,7 @@ Index event fields make the field more quickly accessible to off-chain tools tha Solc compiler version 0.8.20 switches the default target EVM version to Shanghai, which means that the generated bytecode will include PUSH0 opcodes. Be sure to select the appropriate EVM version in case you intend to deploy on a chain other than mainnet like L2 chains that may not support PUSH0, otherwise deployment of your contracts will fail. -
6 Found Instances +
8 Found Instances - Found in Counter.sol [Line: 2](../tests/adhoc-sol-files/Counter.sol#L2) @@ -277,6 +347,18 @@ Solc compiler version 0.8.20 switches the default target EVM version to Shanghai pragma solidity ^0.8.0; ``` +- Found in multiple-versions/0.8/A.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.8/A.sol#L2) + + ```solidity + pragma solidity ^0.8.0; + ``` + +- Found in multiple-versions/0.8/B.sol [Line: 2](../tests/adhoc-sol-files/multiple-versions/0.8/B.sol#L2) + + ```solidity + pragma solidity ^0.8.0; + ``` +
@@ -308,7 +390,7 @@ Solc compiler version 0.8.20 switches the default target EVM version to Shanghai Consider removing empty blocks. -
1 Found Instances +
2 Found Instances - Found in OnceModifierExample.sol [Line: 10](../tests/adhoc-sol-files/OnceModifierExample.sol#L10) @@ -317,6 +399,12 @@ Consider removing empty blocks. function perform() external onlyOnce { ``` +- Found in multiple-versions/0.5/B.sol [Line: 8](../tests/adhoc-sol-files/multiple-versions/0.5/B.sol#L8) + + ```solidity + function emptyBlockCatchMe() external { + ``` +
diff --git a/tests/adhoc-sol-files/multiple-versions/0.4/A.sol b/tests/adhoc-sol-files/multiple-versions/0.4/A.sol new file mode 100644 index 000000000..dcf669f88 --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.4/A.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.4.0; + +contract Constants { + address public constant MY_ADDRESS = address(0); + uint256 public constant MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.4/B.sol b/tests/adhoc-sol-files/multiple-versions/0.4/B.sol new file mode 100644 index 000000000..8f00a217d --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.4/B.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.4.0; + +contract Vars { + address public MY_ADDRESS = address(0); + uint256 public MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.5/A.sol b/tests/adhoc-sol-files/multiple-versions/0.5/A.sol new file mode 100644 index 000000000..d42d75b9d --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.5/A.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.5.0; + +contract Constants { + address public constant MY_ADDRESS = address(0); + uint256 public constant MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.5/B.sol b/tests/adhoc-sol-files/multiple-versions/0.5/B.sol new file mode 100644 index 000000000..197705d17 --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.5/B.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.5.0; + +contract Vars { + address public MY_ADDRESS = address(0); + uint256 public MY_UINT = 134131; + + function emptyBlockCatchMe() external { + + } +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.6/A.sol b/tests/adhoc-sol-files/multiple-versions/0.6/A.sol new file mode 100644 index 000000000..07c658fd8 --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.6/A.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.0; + +contract Constants { + address public constant MY_ADDRESS = address(0); + uint256 public constant MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.6/B.sol b/tests/adhoc-sol-files/multiple-versions/0.6/B.sol new file mode 100644 index 000000000..5dbf1a95f --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.6/B.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.0; + +contract Vars { + address public MY_ADDRESS = address(0); + uint256 public MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.7/A.sol b/tests/adhoc-sol-files/multiple-versions/0.7/A.sol new file mode 100644 index 000000000..16e58b516 --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.7/A.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Constants { + address public constant MY_ADDRESS = address(0); + uint256 public constant MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.7/B.sol b/tests/adhoc-sol-files/multiple-versions/0.7/B.sol new file mode 100644 index 000000000..6235cbc1a --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.7/B.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Vars { + address public MY_ADDRESS = address(0); + uint256 public MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.8/A.sol b/tests/adhoc-sol-files/multiple-versions/0.8/A.sol new file mode 100644 index 000000000..c1c1acc0e --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.8/A.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract Constants { + address public constant MY_ADDRESS = address(0); + uint256 public constant MY_UINT = 134131; +} diff --git a/tests/adhoc-sol-files/multiple-versions/0.8/B.sol b/tests/adhoc-sol-files/multiple-versions/0.8/B.sol new file mode 100644 index 000000000..03a29e9bf --- /dev/null +++ b/tests/adhoc-sol-files/multiple-versions/0.8/B.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract Vars { + address public MY_ADDRESS = address(0); + uint256 public MY_UINT = 134131; +}