From 71adcf3e3151b9e7979d30ebf1e128db9cc10703 Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Wed, 31 Jul 2024 20:36:40 +0530 Subject: [PATCH 1/5] done --- aderyn_core/src/context/browser/extractor.rs | 178 ++++++++++++++++++ .../src/StateVariablesWritten.sol | 148 +++++++++++++++ 2 files changed, 326 insertions(+) create mode 100644 tests/contract-playground/src/StateVariablesWritten.sol diff --git a/aderyn_core/src/context/browser/extractor.rs b/aderyn_core/src/context/browser/extractor.rs index cece1c871..ea7f68aab 100644 --- a/aderyn_core/src/context/browser/extractor.rs +++ b/aderyn_core/src/context/browser/extractor.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use crate::{ ast::*, visitor::ast_visitor::{ASTConstVisitor, Node}, @@ -125,3 +127,179 @@ impl ASTConstVisitor for ExtractReferencedDeclarations { Ok(true) } } + +// Extract Reference Declaration IDs +#[derive(Default)] +pub struct ExtractWrittenStateVariablesIDs { + pub deleted: HashSet, + pub assigned: HashSet, + pub pushed: HashSet, + pub popped: HashSet, +} + +impl ExtractWrittenStateVariablesIDs { + pub fn get_all_node_ids(&self) -> Vec { + let mut all_nodes = [ + self.deleted.clone().into_iter().collect::>(), + self.assigned.clone().into_iter().collect::>(), + self.pushed.clone().into_iter().collect::>(), + self.popped.clone().into_iter().collect::>(), + ] + .concat(); + // Some state variables can undergo more than 1 of the above operation. + // Hence, we should deduplicate it + all_nodes.dedup(); + all_nodes + } + + pub fn from(node: &T) -> Self { + let mut extractor: ExtractWrittenStateVariablesIDs = Self::default(); + node.accept(&mut extractor).unwrap_or_default(); + extractor + } +} + +impl ASTConstVisitor for ExtractWrittenStateVariablesIDs { + fn visit_unary_operation(&mut self, node: &UnaryOperation) -> Result { + // Catch delete operations + if node.operator == "delete" { + if let Some(id) = find_referenced_declaration_for_identifier_or_indexed_identifier( + node.sub_expression.as_ref(), + ) { + self.deleted.insert(id); + } + } + Ok(true) + } + + fn visit_member_access(&mut self, member: &MemberAccess) -> Result { + if let Some(id) = find_referenced_declaration_for_identifier_or_indexed_identifier( + member.expression.as_ref(), + ) { + if member.member_name == "push" { + self.pushed.insert(id); + } else if member.member_name == "pop" { + self.popped.insert(id); + } + } + Ok(true) + } + + fn visit_assignment(&mut self, assignment: &Assignment) -> Result { + if let Some(id) = find_referenced_declaration_for_identifier_or_indexed_identifier( + assignment.left_hand_side.as_ref(), + ) { + self.assigned.insert(id); + } + Ok(true) + } +} + +fn find_referenced_declaration_for_identifier_or_indexed_identifier( + expr: &Expression, +) -> Option { + match expr { + Expression::Identifier(Identifier { + referenced_declaration: Some(id), + .. + }) => { + return Some(*id); + } + Expression::IndexAccess(IndexAccess { + base_expression, .. + }) => { + return find_referenced_declaration_for_identifier_or_indexed_identifier( + base_expression.as_ref(), + ); + } + _ => (), + }; + None +} + +#[cfg(test)] +mod written_state_variables_tests { + use crate::detect::test_utils::load_solidity_source_unit; + + use super::ExtractWrittenStateVariablesIDs; + + #[test] + fn has_variable_declarations() { + let context = + load_solidity_source_unit("../tests/contract-playground/src/StateVariablesWritten.sol"); + + assert!(!context.variable_declarations().is_empty()); + } + + #[test] + fn can_capture_deletes() { + let context = + load_solidity_source_unit("../tests/contract-playground/src/StateVariablesWritten.sol"); + + let mut total_state_variables_deleted = 0; + + for contract in context.contract_definitions() { + let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + println!("{} - {}", contract.name, state_variables_info.deleted.len()); + println!("{:?}", state_variables_info.deleted); + total_state_variables_deleted += state_variables_info.deleted.len(); + } + + assert_eq!(total_state_variables_deleted, 5); + } + + #[test] + fn can_capture_pushes() { + let context = + load_solidity_source_unit("../tests/contract-playground/src/StateVariablesWritten.sol"); + + let mut total_state_variables_pushed_to = 0; + + for contract in context.contract_definitions() { + let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + println!("{} - {}", contract.name, state_variables_info.pushed.len()); + println!("{:?}", state_variables_info.pushed); + total_state_variables_pushed_to += state_variables_info.pushed.len(); + } + + assert_eq!(total_state_variables_pushed_to, 2); + } + + #[test] + fn can_capture_pops() { + let context = + load_solidity_source_unit("../tests/contract-playground/src/StateVariablesWritten.sol"); + + let mut total_state_variables_popped = 0; + + for contract in context.contract_definitions() { + let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + println!("{} - {}", contract.name, state_variables_info.popped.len()); + println!("{:?}", state_variables_info.popped); + total_state_variables_popped += state_variables_info.popped.len(); + } + + assert_eq!(total_state_variables_popped, 1); + } + + #[test] + fn can_capture_assignments() { + let context = + load_solidity_source_unit("../tests/contract-playground/src/StateVariablesWritten.sol"); + + let mut total_state_variables_assigned = 0; + + for contract in context.contract_definitions() { + let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + println!( + "{} - {}", + contract.name, + state_variables_info.assigned.len() + ); + println!("{:?}", state_variables_info.assigned); + total_state_variables_assigned += state_variables_info.assigned.len(); + } + + assert_eq!(total_state_variables_assigned, 10); + } +} diff --git a/tests/contract-playground/src/StateVariablesWritten.sol b/tests/contract-playground/src/StateVariablesWritten.sol new file mode 100644 index 000000000..357187b57 --- /dev/null +++ b/tests/contract-playground/src/StateVariablesWritten.sol @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract StorageManipulationExamples { + // Simple state variables + uint256 public simpleUint; + int256 public simpleInt; + bool public simpleBool; + address public simpleAddress; + string public simpleString; + + // Array of uint256 + uint256[] public numbersArray; + + // Mapping from address to uint256 + mapping(address => uint256) public balanceOf; + + // Define a mapping from an address to another mapping, which maps an uint256 to an array of int64 + mapping(address => mapping(uint256 => int64[])) private userNestedValues; + + // Struct example + struct Person { + string name; + uint256 age; + } + Person public person; + + // Nested mapping + mapping(address => mapping(uint256 => bool)) public nestedMapping; + + // Function to add a value to the array associated with a specific address and identifier + function addValue(address _user, uint256 _id, int64 _value) public { + userNestedValues[_user][_id].push(_value); + } + + // Simple function to update uint256 + function setSimpleUint(uint256 _value) external { + simpleUint = _value; + } + + // Function to update int256 + function setSimpleInt(int256 _value) external { + simpleInt = _value; + } + + // Function to delete the array for a specific address and identifier + function deleteValues(address _user, uint256 _id) public { + delete userNestedValues[_user][_id]; + } + + // Function to update bool + function setSimpleBool(bool _value) external { + simpleBool = _value; + } + + // Function to update address + function setSimpleAddress(address _value) external { + simpleAddress = _value; + } + + // Function to update string + function setSimpleString(string calldata _value) external { + simpleString = _value; + } + + // Function to add an element to the array + function addNumber(uint256 _number) external { + numbersArray.push(_number); + } + + // Function to remove an element from the array by index + function removeNumber(uint256 _index) external { + require(_index < numbersArray.length, "Index out of bounds"); + for (uint256 i = _index; i < numbersArray.length - 1; i++) { + numbersArray[i] = numbersArray[i + 1]; + } + numbersArray.pop(); // Remove the last element which is now duplicated + } + + // Function to set balance for an address + function setBalance(address _account, uint256 _amount) external { + balanceOf[_account] = _amount; + } + + // Function to delete balance for an address + function deleteBalance(address _account) external { + delete balanceOf[_account]; + } + + // Function to update Person struct + function setPerson(string calldata _name, uint256 _age) external { + person = Person(_name, _age); + } + + // Function to delete Person struct + function deletePerson() external { + delete person; + } + + // Function to set value in nested mapping + function setNestedMapping( + address _account, + uint256 _key, + bool _value + ) external { + nestedMapping[_account][_key] = _value; + } + + // Function to delete value from nested mapping + function deleteNestedMapping(address _account, uint256 _key) external { + delete nestedMapping[_account][_key]; + } + + // Function to retrieve a value from the nested mapping + function getNestedMapping( + address _account, + uint256 _key + ) external view returns (bool) { + return nestedMapping[_account][_key]; + } +} + +contract FixedSizeArrayExamples { + // Constant-sized array of uint256 with 5 elements + uint256[5] public fixedSizeArray; + + // Function to set values in the fixed-size array + function setFixedSizeArray(uint256[5] calldata _values) external { + fixedSizeArray = _values; + } + + // Function to update a specific element in the fixed-size array + function updateElement(uint256 _index, uint256 _value) external { + require(_index < fixedSizeArray.length, "Index out of bounds"); + fixedSizeArray[_index] = _value; + } + + // Function to get a specific element from the fixed-size array + function getElement(uint256 _index) external view returns (uint256) { + require(_index < fixedSizeArray.length, "Index out of bounds"); + return fixedSizeArray[_index]; + } + + // Function to reset the fixed-size array to default values + function resetArray() external { + delete fixedSizeArray; // Resets all elements to 0 + } +} From 43824a2d9c9e938ba1fd1ba93bba925d68895346 Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Wed, 31 Jul 2024 20:37:06 +0530 Subject: [PATCH 2/5] change name --- aderyn_core/src/context/browser/extractor.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/aderyn_core/src/context/browser/extractor.rs b/aderyn_core/src/context/browser/extractor.rs index ea7f68aab..48ea3ade5 100644 --- a/aderyn_core/src/context/browser/extractor.rs +++ b/aderyn_core/src/context/browser/extractor.rs @@ -130,14 +130,14 @@ impl ASTConstVisitor for ExtractReferencedDeclarations { // Extract Reference Declaration IDs #[derive(Default)] -pub struct ExtractWrittenStateVariablesIDs { +pub struct ExtractManipulatedStateVariablesIDs { pub deleted: HashSet, pub assigned: HashSet, pub pushed: HashSet, pub popped: HashSet, } -impl ExtractWrittenStateVariablesIDs { +impl ExtractManipulatedStateVariablesIDs { pub fn get_all_node_ids(&self) -> Vec { let mut all_nodes = [ self.deleted.clone().into_iter().collect::>(), @@ -153,13 +153,13 @@ impl ExtractWrittenStateVariablesIDs { } pub fn from(node: &T) -> Self { - let mut extractor: ExtractWrittenStateVariablesIDs = Self::default(); + let mut extractor: ExtractManipulatedStateVariablesIDs = Self::default(); node.accept(&mut extractor).unwrap_or_default(); extractor } } -impl ASTConstVisitor for ExtractWrittenStateVariablesIDs { +impl ASTConstVisitor for ExtractManipulatedStateVariablesIDs { fn visit_unary_operation(&mut self, node: &UnaryOperation) -> Result { // Catch delete operations if node.operator == "delete" { @@ -221,7 +221,7 @@ fn find_referenced_declaration_for_identifier_or_indexed_identifier( mod written_state_variables_tests { use crate::detect::test_utils::load_solidity_source_unit; - use super::ExtractWrittenStateVariablesIDs; + use super::ExtractManipulatedStateVariablesIDs; #[test] fn has_variable_declarations() { @@ -239,7 +239,7 @@ mod written_state_variables_tests { let mut total_state_variables_deleted = 0; for contract in context.contract_definitions() { - let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + let state_variables_info = ExtractManipulatedStateVariablesIDs::from(contract); println!("{} - {}", contract.name, state_variables_info.deleted.len()); println!("{:?}", state_variables_info.deleted); total_state_variables_deleted += state_variables_info.deleted.len(); @@ -256,7 +256,7 @@ mod written_state_variables_tests { let mut total_state_variables_pushed_to = 0; for contract in context.contract_definitions() { - let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + let state_variables_info = ExtractManipulatedStateVariablesIDs::from(contract); println!("{} - {}", contract.name, state_variables_info.pushed.len()); println!("{:?}", state_variables_info.pushed); total_state_variables_pushed_to += state_variables_info.pushed.len(); @@ -273,7 +273,7 @@ mod written_state_variables_tests { let mut total_state_variables_popped = 0; for contract in context.contract_definitions() { - let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + let state_variables_info = ExtractManipulatedStateVariablesIDs::from(contract); println!("{} - {}", contract.name, state_variables_info.popped.len()); println!("{:?}", state_variables_info.popped); total_state_variables_popped += state_variables_info.popped.len(); @@ -290,7 +290,7 @@ mod written_state_variables_tests { let mut total_state_variables_assigned = 0; for contract in context.contract_definitions() { - let state_variables_info = ExtractWrittenStateVariablesIDs::from(contract); + let state_variables_info = ExtractManipulatedStateVariablesIDs::from(contract); println!( "{} - {}", contract.name, From 28f6329643d2c360c9c39e69b5e52e881455bd2b Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Wed, 31 Jul 2024 20:40:31 +0530 Subject: [PATCH 3/5] cli/reportgen --- reports/report.json | 38 ++++++++++++++++++++++++++++-- reports/report.md | 45 ++++++++++++++++++++++++++++++------ reports/report.sarif | 55 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 9 deletions(-) diff --git a/reports/report.json b/reports/report.json index 3380ece53..dc2a2534e 100644 --- a/reports/report.json +++ b/reports/report.json @@ -1,7 +1,7 @@ { "files_summary": { - "total_source_units": 73, - "total_sloc": 1996 + "total_source_units": 74, + "total_sloc": 2089 }, "files_details": { "files_details": [ @@ -161,6 +161,10 @@ "file_path": "src/StateVariables.sol", "n_sloc": 58 }, + { + "file_path": "src/StateVariablesWritten.sol", + "n_sloc": 93 + }, { "file_path": "src/StorageConditionals.sol", "n_sloc": 59 @@ -2061,6 +2065,12 @@ "src": "32:23", "src_char": "32:23" }, + { + "contract_path": "src/StateVariablesWritten.sol", + "line_no": 2, + "src": "32:23", + "src_char": "32:23" + }, { "contract_path": "src/UncheckedSend.sol", "line_no": 2, @@ -2128,6 +2138,12 @@ "src": "2121:14", "src_char": "2121:14" }, + { + "contract_path": "src/StateVariablesWritten.sol", + "line_no": 58, + "src": "1706:22", + "src_char": "1706:22" + }, { "contract_path": "src/ZeroAddressCheck.sol", "line_no": 43, @@ -2213,6 +2229,18 @@ "src": "2539:25", "src_char": "2539:25" }, + { + "contract_path": "src/StateVariablesWritten.sol", + "line_no": 32, + "src": "931:8", + "src_char": "931:8" + }, + { + "contract_path": "src/StateVariablesWritten.sol", + "line_no": 47, + "src": "1387:12", + "src_char": "1387:12" + }, { "contract_path": "src/UninitializedStateVariable.sol", "line_no": 17, @@ -2807,6 +2835,12 @@ "src": "32:23", "src_char": "32:23" }, + { + "contract_path": "src/StateVariablesWritten.sol", + "line_no": 2, + "src": "32:23", + "src_char": "32:23" + }, { "contract_path": "src/StorageConditionals.sol", "line_no": 2, diff --git a/reports/report.md b/reports/report.md index d6af919d3..56e894669 100644 --- a/reports/report.md +++ b/reports/report.md @@ -74,8 +74,8 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | Key | Value | | --- | --- | -| .sol Files | 73 | -| Total nSLOC | 1996 | +| .sol Files | 74 | +| Total nSLOC | 2089 | ## Files Details @@ -121,6 +121,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | src/SendEtherNoChecks.sol | 58 | | src/StateShadowing.sol | 17 | | src/StateVariables.sol | 58 | +| src/StateVariablesWritten.sol | 93 | | src/StorageConditionals.sol | 59 | | src/StorageParameters.sol | 16 | | src/T11sTranferer.sol | 8 | @@ -155,7 +156,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | src/reused_contract_name/ContractB.sol | 7 | | src/uniswap/UniswapV2Swapper.sol | 50 | | src/uniswap/UniswapV3Swapper.sol | 150 | -| **Total** | **1996** | +| **Total** | **2089** | ## Issue Summary @@ -2008,7 +2009,7 @@ ERC20 functions may not behave as expected. For example: return values are not a 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;` -
19 Found Instances +
20 Found Instances - Found in src/CompilerBugStorageSignedIntegerArray.sol [Line: 2](../tests/contract-playground/src/CompilerBugStorageSignedIntegerArray.sol#L2) @@ -2077,6 +2078,12 @@ Consider using a specific version of Solidity in your contracts instead of a wid pragma solidity ^0.4.0; ``` +- Found in src/StateVariablesWritten.sol [Line: 2](../tests/contract-playground/src/StateVariablesWritten.sol#L2) + + ```solidity + pragma solidity ^0.8.0; + ``` + - Found in src/UncheckedSend.sol [Line: 2](../tests/contract-playground/src/UncheckedSend.sol#L2) ```solidity @@ -2133,7 +2140,7 @@ Consider using a specific version of Solidity in your contracts instead of a wid Check for `address(0)` when assigning values to address state variables. -
6 Found Instances +
7 Found Instances - Found in src/ArbitraryTransferFrom.sol [Line: 12](../tests/contract-playground/src/ArbitraryTransferFrom.sol#L12) @@ -2148,6 +2155,12 @@ Check for `address(0)` when assigning values to address state variables. addr = newAddr; ``` +- Found in src/StateVariablesWritten.sol [Line: 58](../tests/contract-playground/src/StateVariablesWritten.sol#L58) + + ```solidity + simpleAddress = _value; + ``` + - Found in src/ZeroAddressCheck.sol [Line: 43](../tests/contract-playground/src/ZeroAddressCheck.sol#L43) ```solidity @@ -2180,7 +2193,7 @@ Check for `address(0)` when assigning values to address state variables. Instead of marking a function as `public`, consider marking it as `external` if it is not used internally. -
23 Found Instances +
25 Found Instances - Found in src/ArbitraryTransferFrom.sol [Line: 28](../tests/contract-playground/src/ArbitraryTransferFrom.sol#L28) @@ -2237,6 +2250,18 @@ Instead of marking a function as `public`, consider marking it as `external` if function setNonEmptyAlteredNumbers( ``` +- Found in src/StateVariablesWritten.sol [Line: 32](../tests/contract-playground/src/StateVariablesWritten.sol#L32) + + ```solidity + function addValue(address _user, uint256 _id, int64 _value) public { + ``` + +- Found in src/StateVariablesWritten.sol [Line: 47](../tests/contract-playground/src/StateVariablesWritten.sol#L47) + + ```solidity + function deleteValues(address _user, uint256 _id) public { + ``` + - Found in src/UninitializedStateVariable.sol [Line: 17](../tests/contract-playground/src/UninitializedStateVariable.sol#L17) ```solidity @@ -2774,7 +2799,7 @@ Using `ERC721::_mint()` can mint ERC721 tokens to addresses which don't support 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. -
28 Found Instances +
29 Found Instances - Found in src/AdminContract.sol [Line: 2](../tests/contract-playground/src/AdminContract.sol#L2) @@ -2843,6 +2868,12 @@ Solc compiler version 0.8.20 switches the default target EVM version to Shanghai pragma solidity 0.8.20; ``` +- Found in src/StateVariablesWritten.sol [Line: 2](../tests/contract-playground/src/StateVariablesWritten.sol#L2) + + ```solidity + pragma solidity ^0.8.0; + ``` + - Found in src/StorageConditionals.sol [Line: 2](../tests/contract-playground/src/StorageConditionals.sol#L2) ```solidity diff --git a/reports/report.sarif b/reports/report.sarif index c60ae1436..2452bf8ed 100644 --- a/reports/report.sarif +++ b/reports/report.sarif @@ -3068,6 +3068,17 @@ } } }, + { + "physicalLocation": { + "artifactLocation": { + "uri": "src/StateVariablesWritten.sol" + }, + "region": { + "byteLength": 23, + "byteOffset": 32 + } + } + }, { "physicalLocation": { "artifactLocation": { @@ -3187,6 +3198,17 @@ } } }, + { + "physicalLocation": { + "artifactLocation": { + "uri": "src/StateVariablesWritten.sol" + }, + "region": { + "byteLength": 22, + "byteOffset": 1706 + } + } + }, { "physicalLocation": { "artifactLocation": { @@ -3339,6 +3361,28 @@ } } }, + { + "physicalLocation": { + "artifactLocation": { + "uri": "src/StateVariablesWritten.sol" + }, + "region": { + "byteLength": 8, + "byteOffset": 931 + } + } + }, + { + "physicalLocation": { + "artifactLocation": { + "uri": "src/StateVariablesWritten.sol" + }, + "region": { + "byteLength": 12, + "byteOffset": 1387 + } + } + }, { "physicalLocation": { "artifactLocation": { @@ -4405,6 +4449,17 @@ } } }, + { + "physicalLocation": { + "artifactLocation": { + "uri": "src/StateVariablesWritten.sol" + }, + "region": { + "byteLength": 23, + "byteOffset": 32 + } + } + }, { "physicalLocation": { "artifactLocation": { From f86b440dfe1057935d861ebebd0f543aff68227e Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Wed, 31 Jul 2024 21:20:51 +0530 Subject: [PATCH 4/5] added support struct.prop = value --- aderyn_core/src/context/browser/extractor.rs | 7 ++++++- tests/contract-playground/src/StateVariablesWritten.sol | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/aderyn_core/src/context/browser/extractor.rs b/aderyn_core/src/context/browser/extractor.rs index 48ea3ade5..bc6956c90 100644 --- a/aderyn_core/src/context/browser/extractor.rs +++ b/aderyn_core/src/context/browser/extractor.rs @@ -212,6 +212,11 @@ fn find_referenced_declaration_for_identifier_or_indexed_identifier( base_expression.as_ref(), ); } + Expression::MemberAccess(MemberAccess { expression, .. }) => { + return find_referenced_declaration_for_identifier_or_indexed_identifier( + expression.as_ref(), + ); + } _ => (), }; None @@ -300,6 +305,6 @@ mod written_state_variables_tests { total_state_variables_assigned += state_variables_info.assigned.len(); } - assert_eq!(total_state_variables_assigned, 10); + assert_eq!(total_state_variables_assigned, 11); } } diff --git a/tests/contract-playground/src/StateVariablesWritten.sol b/tests/contract-playground/src/StateVariablesWritten.sol index 357187b57..cca9e9a73 100644 --- a/tests/contract-playground/src/StateVariablesWritten.sol +++ b/tests/contract-playground/src/StateVariablesWritten.sol @@ -24,6 +24,7 @@ contract StorageManipulationExamples { uint256 age; } Person public person; + Person public person2; // Nested mapping mapping(address => mapping(uint256 => bool)) public nestedMapping; @@ -92,6 +93,12 @@ contract StorageManipulationExamples { person = Person(_name, _age); } + // Function to update Person struct + function setPerson2Name(string calldata _name, uint256 _age) external { + person2.name = _name; + person2.age = _age; + } + // Function to delete Person struct function deletePerson() external { delete person; From 2932410f3d802a562fcb0145537df6237e442156 Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Wed, 31 Jul 2024 21:21:27 +0530 Subject: [PATCH 5/5] cli/reportgen --- reports/report.json | 22 +++++++++++----------- reports/report.md | 12 ++++++------ reports/report.sarif | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/reports/report.json b/reports/report.json index dc2a2534e..a0cd94a4c 100644 --- a/reports/report.json +++ b/reports/report.json @@ -1,7 +1,7 @@ { "files_summary": { "total_source_units": 74, - "total_sloc": 2089 + "total_sloc": 2094 }, "files_details": { "files_details": [ @@ -163,7 +163,7 @@ }, { "file_path": "src/StateVariablesWritten.sol", - "n_sloc": 93 + "n_sloc": 98 }, { "file_path": "src/StorageConditionals.sol", @@ -2140,9 +2140,9 @@ }, { "contract_path": "src/StateVariablesWritten.sol", - "line_no": 58, - "src": "1706:22", - "src_char": "1706:22" + "line_no": 59, + "src": "1733:22", + "src_char": "1733:22" }, { "contract_path": "src/ZeroAddressCheck.sol", @@ -2231,15 +2231,15 @@ }, { "contract_path": "src/StateVariablesWritten.sol", - "line_no": 32, - "src": "931:8", - "src_char": "931:8" + "line_no": 33, + "src": "958:8", + "src_char": "958:8" }, { "contract_path": "src/StateVariablesWritten.sol", - "line_no": 47, - "src": "1387:12", - "src_char": "1387:12" + "line_no": 48, + "src": "1414:12", + "src_char": "1414:12" }, { "contract_path": "src/UninitializedStateVariable.sol", diff --git a/reports/report.md b/reports/report.md index 56e894669..ef795c423 100644 --- a/reports/report.md +++ b/reports/report.md @@ -75,7 +75,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | Key | Value | | --- | --- | | .sol Files | 74 | -| Total nSLOC | 2089 | +| Total nSLOC | 2094 | ## Files Details @@ -121,7 +121,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | src/SendEtherNoChecks.sol | 58 | | src/StateShadowing.sol | 17 | | src/StateVariables.sol | 58 | -| src/StateVariablesWritten.sol | 93 | +| src/StateVariablesWritten.sol | 98 | | src/StorageConditionals.sol | 59 | | src/StorageParameters.sol | 16 | | src/T11sTranferer.sol | 8 | @@ -156,7 +156,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | src/reused_contract_name/ContractB.sol | 7 | | src/uniswap/UniswapV2Swapper.sol | 50 | | src/uniswap/UniswapV3Swapper.sol | 150 | -| **Total** | **2089** | +| **Total** | **2094** | ## Issue Summary @@ -2155,7 +2155,7 @@ Check for `address(0)` when assigning values to address state variables. addr = newAddr; ``` -- Found in src/StateVariablesWritten.sol [Line: 58](../tests/contract-playground/src/StateVariablesWritten.sol#L58) +- Found in src/StateVariablesWritten.sol [Line: 59](../tests/contract-playground/src/StateVariablesWritten.sol#L59) ```solidity simpleAddress = _value; @@ -2250,13 +2250,13 @@ Instead of marking a function as `public`, consider marking it as `external` if function setNonEmptyAlteredNumbers( ``` -- Found in src/StateVariablesWritten.sol [Line: 32](../tests/contract-playground/src/StateVariablesWritten.sol#L32) +- Found in src/StateVariablesWritten.sol [Line: 33](../tests/contract-playground/src/StateVariablesWritten.sol#L33) ```solidity function addValue(address _user, uint256 _id, int64 _value) public { ``` -- Found in src/StateVariablesWritten.sol [Line: 47](../tests/contract-playground/src/StateVariablesWritten.sol#L47) +- Found in src/StateVariablesWritten.sol [Line: 48](../tests/contract-playground/src/StateVariablesWritten.sol#L48) ```solidity function deleteValues(address _user, uint256 _id) public { diff --git a/reports/report.sarif b/reports/report.sarif index 2452bf8ed..c9de6ea11 100644 --- a/reports/report.sarif +++ b/reports/report.sarif @@ -3205,7 +3205,7 @@ }, "region": { "byteLength": 22, - "byteOffset": 1706 + "byteOffset": 1733 } } }, @@ -3368,7 +3368,7 @@ }, "region": { "byteLength": 8, - "byteOffset": 931 + "byteOffset": 958 } } }, @@ -3379,7 +3379,7 @@ }, "region": { "byteLength": 12, - "byteOffset": 1387 + "byteOffset": 1414 } } },