Updated mutators

pull/2278/head
Vishnuram Rajkumar 10 months ago
parent 5fb5f69b8e
commit 71f970f051
  1. 2
      slither/tools/mutator/README.md
  2. 2
      slither/tools/mutator/__main__.py
  3. 3
      slither/tools/mutator/mutators/AOR.py
  4. 3
      slither/tools/mutator/mutators/ASOR.py
  5. 3
      slither/tools/mutator/mutators/BOR.py
  6. 3
      slither/tools/mutator/mutators/CR.py
  7. 3
      slither/tools/mutator/mutators/FHR.py
  8. 3
      slither/tools/mutator/mutators/LIR.py
  9. 3
      slither/tools/mutator/mutators/LOR.py
  10. 3
      slither/tools/mutator/mutators/MIA.py
  11. 3
      slither/tools/mutator/mutators/MVIE.py
  12. 3
      slither/tools/mutator/mutators/MVIV.py
  13. 3
      slither/tools/mutator/mutators/MWA.py
  14. 3
      slither/tools/mutator/mutators/ROR.py
  15. 4
      slither/tools/mutator/mutators/RR.py
  16. 3
      slither/tools/mutator/mutators/SBR.py
  17. 3
      slither/tools/mutator/mutators/UOR.py
  18. 24
      slither/tools/mutator/mutators/abstract_mutator.py
  19. 13
      slither/tools/mutator/utils/command_line.py

@ -6,6 +6,8 @@
`slither-mutate <codebase> --test-cmd <test-command> <options>`
To view the list of mutators available `slither-mutate --list-mutators`
### CLI Interface
```

@ -118,7 +118,7 @@ class ListMutators(argparse.Action): # pylint: disable=too-few-public-methods
def __call__(
self, parser: Any, *args: Any, **kwargs: Any
) -> None: # pylint: disable=signature-differs
checks = _get_mutators()
checks = _get_mutators(None)
output_mutators(checks)
parser.exit()

@ -1,7 +1,7 @@
from typing import Dict
from slither.slithir.operations import Binary, BinaryType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
from slither.core.expressions.unary_operation import UnaryOperation
arithmetic_operators = [
@ -15,7 +15,6 @@ arithmetic_operators = [
class AOR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "AOR"
HELP = "Arithmetic operator replacement"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,6 +1,6 @@
from typing import Dict
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
from slither.core.expressions.assignment_operation import AssignmentOperationType, AssignmentOperation
assignment_operators = [
@ -20,7 +20,6 @@ assignment_operators = [
class ASOR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "ASOR"
HELP = "Assignment Operator Replacement"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,7 +1,7 @@
from typing import Dict
from slither.slithir.operations import Binary, BinaryType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
bitwise_operators = [
BinaryType.AND,
@ -14,7 +14,6 @@ bitwise_operators = [
class BOR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "BOR"
HELP = "Bitwise Operator Replacement"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,13 +1,12 @@
from typing import Dict
from slither.core.cfg.node import NodeType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
class CR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "CR"
HELP = 'Comment Replacement'
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,6 +1,6 @@
from typing import Dict
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
import re
function_header_replacements = [
@ -13,7 +13,6 @@ function_header_replacements = [
class FHR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "FHR"
HELP = 'Function Header Replacement'
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,7 +1,7 @@
from typing import Dict
from slither.core.expressions import Literal
from slither.core.variables.variable import Variable
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.core.solidity_types import ElementaryType
@ -10,7 +10,6 @@ literal_replacements = []
class LIR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "LIR"
HELP = "Literal Interger Replacement"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,7 +1,7 @@
from typing import Dict
from slither.slithir.operations import Binary, BinaryType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
logical_operators = [
BinaryType.OROR,
@ -11,7 +11,6 @@ logical_operators = [
class LOR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "LOR"
HELP = "Logical Operator Replacement"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,13 +1,12 @@
from typing import Dict
from slither.core.cfg.node import NodeType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
from slither.core.expressions.unary_operation import UnaryOperationType, UnaryOperation
class MIA(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "MIA"
HELP = '"if" construct around statement'
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,13 +1,12 @@
from typing import Dict
from slither.core.expressions import Literal
from slither.core.variables.variable import Variable
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
from slither.tools.mutator.utils.patch import create_patch_with_line
class MVIE(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "MVIE"
HELP = "variable initialization using an expression"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,13 +1,12 @@
from typing import Dict
from slither.core.expressions import Literal
from slither.core.variables.variable import Variable
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
from slither.tools.mutator.utils.patch import create_patch_with_line
class MVIV(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "MVIV"
HELP = "variable initialization using a value"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,13 +1,12 @@
from typing import Dict
from slither.core.cfg.node import NodeType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
from slither.core.expressions.unary_operation import UnaryOperationType, UnaryOperation
class MWA(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "MWA"
HELP = '"while" construct around statement'
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,7 +1,7 @@
from typing import Dict
from slither.slithir.operations import Binary, BinaryType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
relational_operators = [
BinaryType.LESS,
@ -15,7 +15,6 @@ relational_operators = [
class ROR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "ROR"
HELP = "Relational Operator Replacement"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,13 +1,11 @@
from typing import Dict
from slither.core.cfg.node import NodeType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
class RR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "RR"
HELP = 'Revert Replacement'
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,7 +1,7 @@
from typing import Dict
from slither.core.cfg.node import NodeType
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
import re
from slither.core.variables.variable import Variable
@ -47,7 +47,6 @@ solidity_rules = [
class SBR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "SBR"
HELP = 'Solidity Based Replacement'
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:

@ -1,7 +1,7 @@
from typing import Dict
from slither.core.expressions.unary_operation import UnaryOperationType, UnaryOperation
from slither.tools.mutator.utils.patch import create_patch_with_line
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator
unary_operators = [
UnaryOperationType.PLUSPLUS_PRE,
@ -14,7 +14,6 @@ unary_operators = [
class UOR(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "UOR"
HELP = "Unary Operator Replacement"
FAULTNATURE = FaultNature.Missing
def _mutate(self) -> Dict:
result: Dict = {}

@ -1,6 +1,5 @@
import abc
import logging
from enum import Enum
from typing import Optional, Dict, Tuple, List
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.formatters.utils.patches import apply_patch, create_diff
@ -12,22 +11,10 @@ logger = logging.getLogger("Slither-Mutate")
class IncorrectMutatorInitialization(Exception):
pass
class FaultNature(Enum):
Missing = 0
Wrong = 1
Extraneous = 2
Undefined = 100
# not executed - can be detected by replacing with revert
# has no effect - can be detected by removing a line / comment
# can have valid mutant
# can't have valid mutant
class AbstractMutator(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-methods
NAME = ""
HELP = ""
FAULTNATURE = FaultNature.Undefined
VALID_MUTANTS_COUNT = 0
INVALID_MUTANTS_COUNT = 0
@ -69,11 +56,6 @@ class AbstractMutator(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-
f"HELP is not initialized {self.__class__.__name__}"
)
if self.FAULTNATURE == FaultNature.Undefined:
raise IncorrectMutatorInitialization(
f"FAULTNATURE is not initialized {self.__class__.__name__}"
)
if rate < 0 or rate > 100:
raise IncorrectMutatorInitialization(
f"rate must be between 0 and 100 {self.__class__.__name__}"
@ -115,8 +97,4 @@ class AbstractMutator(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-
# add valid mutant patches to a output file
with open(self.output_folder + "/patches_file.txt", 'a') as patches_file:
patches_file.write(diff + '\n')
return (self.VALID_MUTANTS_COUNT, self.INVALID_MUTANTS_COUNT, self.dont_mutate_line)
return (self.VALID_MUTANTS_COUNT, self.INVALID_MUTANTS_COUNT, self.dont_mutate_line)

@ -7,14 +7,13 @@ def output_mutators(mutators_classes: List[Type[AbstractMutator]]) -> None:
for detector in mutators_classes:
argument = detector.NAME
help_info = detector.HELP
fault_nature = detector.FAULTNATURE.name
mutators_list.append((argument, help_info, fault_nature))
table = MyPrettyTable(["Num", "Name", "What it Does", "Fault Nature"])
mutators_list.append((argument, help_info))
table = MyPrettyTable(["Num", "Name", "What it Does"])
# Sort by class, nature, name
mutators_list = sorted(mutators_list, key=lambda element: (element[2], element[0]))
# Sort by class
mutators_list = sorted(mutators_list, key=lambda element: (element[0]))
idx = 1
for (argument, help_info, fault_nature) in mutators_list:
table.add_row([str(idx), argument, help_info, fault_nature])
for (argument, help_info) in mutators_list:
table.add_row([str(idx), argument, help_info])
idx = idx + 1
print(table)

Loading…
Cancel
Save