MorenaBarboni / SuMo-SOlidity-MUtator

A mutation testing tool for Solidity Smart Contracts
GNU General Public License v3.0
73 stars 10 forks source link

Fix block comments collisions for CBD, CSC, CCD, OLFD, ORFD and OMD mutations #9

Closed web3skeptic closed 1 year ago

web3skeptic commented 1 year ago

Summary

This pull request addresses an issue where certain mutations in the library use block comments to disable specific block of code, resulting in collusions with block comments within the commented block. This collision leads to compilation errors and stillborn mutants as a result.

The issue is valid for the next mutation types:

Description

For example, consider the code snippet before Conditional Statement Change (CSC) mutation:

if (true) {
    // some code
} else {
    /*
        block comment
    */
    // another code
}

After the mutation, the code becomes:

if (true) {
    // some code
} /* else {
    /*
        block comment
    */
    // another code
} */

Consequently, the compilation fails due to the presence of nested block comments, which is not allowed in Solidity. Any mutation that leads to failed compilation is considered a stillborn mutant.

To calculate the mutation score, the following formula is used:

mutationScore = killed / (survived + killed)

However, stillborn mutants are not considered in the mutation score calculation. This pull request proposes a fix that will enable the recognition of previously stillborn mutants as either "killed" or "survived," thereby increasing the precision and correctness of the mutation score.

Note: There is an alternative option to replace block comments with line comments. However, this method affects the code execution speed, particularly for large blocks of code.