From bf5d6d64459297a2f1104fa559b6095f271acba7 Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 18 Sep 2024 15:18:25 +0200 Subject: [PATCH 1/5] Add assert information for echidna --- slither/printers/guidance/echidna.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/slither/printers/guidance/echidna.py b/slither/printers/guidance/echidna.py index 0c47fa0f98..9b97d0b737 100644 --- a/slither/printers/guidance/echidna.py +++ b/slither/printers/guidance/echidna.py @@ -138,17 +138,13 @@ def _extract_assert(contracts: List[Contract]) -> Dict[str, Dict[str, List[Dict] """ ret: Dict[str, Dict[str, List[Dict]]] = {} for contract in contracts: - functions_using_assert = [] # Dict[str, List[Dict]] = defaultdict(list) + functions_using_assert: Dict[str, List[Dict]] = defaultdict(list) for f in contract.functions_entry_points: - for v in f.all_solidity_calls(): - if v == SolidityFunction("assert(bool)"): - functions_using_assert.append(_get_name(f)) + for node in f.all_node(): + if SolidityFunction("assert(bool)") in node.solidity_calls and node.source_mapping: + func_name = _get_name(f) + functions_using_assert[func_name].append(node.source_mapping.to_json()) break - # Revert https://github.com/crytic/slither/pull/2105 until format is supported by echidna. - # for node in f.all_nodes(): - # if SolidityFunction("assert(bool)") in node.solidity_calls and node.source_mapping: - # func_name = _get_name(f) - # functions_using_assert[func_name].append(node.source_mapping.to_json()) if functions_using_assert: ret[contract.name] = functions_using_assert return ret From 4de824bac7af0236a3bf82e09bf6e9b9bb3d4e7b Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 18 Sep 2024 15:22:47 +0200 Subject: [PATCH 2/5] Fix function name --- slither/printers/guidance/echidna.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slither/printers/guidance/echidna.py b/slither/printers/guidance/echidna.py index 9b97d0b737..4b2526b1be 100644 --- a/slither/printers/guidance/echidna.py +++ b/slither/printers/guidance/echidna.py @@ -140,7 +140,7 @@ def _extract_assert(contracts: List[Contract]) -> Dict[str, Dict[str, List[Dict] for contract in contracts: functions_using_assert: Dict[str, List[Dict]] = defaultdict(list) for f in contract.functions_entry_points: - for node in f.all_node(): + for node in f.all_nodes(): if SolidityFunction("assert(bool)") in node.solidity_calls and node.source_mapping: func_name = _get_name(f) functions_using_assert[func_name].append(node.source_mapping.to_json()) From fdf1db3382e4d3b52d7d7e3122a0a84058d9a92c Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 18 Sep 2024 15:27:31 +0200 Subject: [PATCH 3/5] Lint --- slither/printers/guidance/echidna.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slither/printers/guidance/echidna.py b/slither/printers/guidance/echidna.py index 4b2526b1be..c3fb5561ff 100644 --- a/slither/printers/guidance/echidna.py +++ b/slither/printers/guidance/echidna.py @@ -152,7 +152,7 @@ def _extract_assert(contracts: List[Contract]) -> Dict[str, Dict[str, List[Dict] # Create a named tuple that is serialization in json def json_serializable(cls): - # pylint: disable=unnecessary-comprehension + # pylint: disable=unnecessary-comprehension,unnecessary-dunder-call # TODO: the next line is a quick workaround to prevent pylint from crashing # It can be removed once https://github.com/PyCQA/pylint/pull/3810 is merged my_super = super From 1bbc13b3086100f20180017851680fb0cfdda313 Mon Sep 17 00:00:00 2001 From: Simone Date: Thu, 24 Oct 2024 13:11:47 +0200 Subject: [PATCH 4/5] Use the new API --- slither/printers/guidance/echidna.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slither/printers/guidance/echidna.py b/slither/printers/guidance/echidna.py index c3cb16a56c..07ca3427f2 100644 --- a/slither/printers/guidance/echidna.py +++ b/slither/printers/guidance/echidna.py @@ -141,10 +141,10 @@ def _extract_assert(contracts: List[Contract]) -> Dict[str, Dict[str, List[Dict] for contract in contracts: functions_using_assert: Dict[str, List[Dict]] = defaultdict(list) for f in contract.functions_entry_points: - for node in f.all_nodes(): - if SolidityFunction("assert(bool)") in node.solidity_calls and node.source_mapping: + for ir in f.all_solidity_calls(): + if ir.function == SolidityFunction("assert(bool)") and ir.node.source_mapping: func_name = _get_name(f) - functions_using_assert[func_name].append(node.source_mapping.to_json()) + functions_using_assert[func_name].append(ir.node.source_mapping.to_json()) break if functions_using_assert: ret[contract.name] = functions_using_assert From 537ee273c28096c1147a3ed31109bab0dcdc7c1e Mon Sep 17 00:00:00 2001 From: Simone Date: Thu, 24 Oct 2024 13:24:55 +0200 Subject: [PATCH 5/5] Extract multiple assert in a single function --- slither/printers/guidance/echidna.py | 1 - 1 file changed, 1 deletion(-) diff --git a/slither/printers/guidance/echidna.py b/slither/printers/guidance/echidna.py index 07ca3427f2..48e40a90f3 100644 --- a/slither/printers/guidance/echidna.py +++ b/slither/printers/guidance/echidna.py @@ -145,7 +145,6 @@ def _extract_assert(contracts: List[Contract]) -> Dict[str, Dict[str, List[Dict] if ir.function == SolidityFunction("assert(bool)") and ir.node.source_mapping: func_name = _get_name(f) functions_using_assert[func_name].append(ir.node.source_mapping.to_json()) - break if functions_using_assert: ret[contract.name] = functions_using_assert return ret