Add tests for the divide-before-multiply detector

pull/858/head
Michael Colburn 4 years ago
parent 327a95246c
commit 7b94b576f1
  1. 5
      tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol
  2. 127
      tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol.0.4.25.DivideBeforeMultiply.json
  3. 5
      tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol
  4. 127
      tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol.0.5.16.DivideBeforeMultiply.json
  5. 5
      tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol
  6. 127
      tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol.0.6.11.DivideBeforeMultiply.json
  7. 5
      tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol
  8. 127
      tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol.0.7.6.DivideBeforeMultiply.json
  9. 20
      tests/test_detectors.py

@ -0,0 +1,5 @@
contract A {
function f(uint a, uint b, uint c) public returns (uint) {
return (a / b) * c;
}
}

@ -0,0 +1,127 @@
[
[
{
"elements": [
{
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
},
{
"type": "node",
"name": "(a / b) * c",
"source_mapping": {
"start": 81,
"length": 18,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
3
],
"starting_column": 9,
"ending_column": 27
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
}
}
}
],
"description": "A.f(uint256,uint256,uint256) (tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#2-4) performs a multiplication on the result of a division:\n\t-(a / b) * c (tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#3)\n",
"markdown": "[A.f(uint256,uint256,uint256)](tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#L2-L4) performs a multiplication on the result of a division:\n\t-[(a / b) * c](tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#L3)\n",
"first_markdown_element": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#L2-L4",
"id": "fe40e2f72824d1270402b09af057ec7364af1ad2f8c48ef4df72fc27012b3186",
"check": "divide-before-multiply",
"impact": "Medium",
"confidence": "Medium"
}
]
]

@ -0,0 +1,5 @@
contract A {
function f(uint a, uint b, uint c) public returns (uint) {
return (a / b) * c;
}
}

@ -0,0 +1,127 @@
[
[
{
"elements": [
{
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
},
{
"type": "node",
"name": "(a / b) * c",
"source_mapping": {
"start": 81,
"length": 18,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
3
],
"starting_column": 9,
"ending_column": 27
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
}
}
}
],
"description": "A.f(uint256,uint256,uint256) (tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol#2-4) performs a multiplication on the result of a division:\n\t-(a / b) * c (tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol#3)\n",
"markdown": "[A.f(uint256,uint256,uint256)](tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol#L2-L4) performs a multiplication on the result of a division:\n\t-[(a / b) * c](tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol#L3)\n",
"first_markdown_element": "tests/detectors/divide-before-multiply/0.5.16/divide_before_multiply.sol#L2-L4",
"id": "a484421df5c9ebf3dc3d8bcec6701ab3065e03b21e294c4972142c4503f2fccb",
"check": "divide-before-multiply",
"impact": "Medium",
"confidence": "Medium"
}
]
]

@ -0,0 +1,5 @@
contract A {
function f(uint a, uint b, uint c) public returns (uint) {
return (a / b) * c;
}
}

@ -0,0 +1,127 @@
[
[
{
"elements": [
{
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
},
{
"type": "node",
"name": "(a / b) * c",
"source_mapping": {
"start": 81,
"length": 18,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
3
],
"starting_column": 9,
"ending_column": 27
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
}
}
}
],
"description": "A.f(uint256,uint256,uint256) (tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol#2-4) performs a multiplication on the result of a division:\n\t-(a / b) * c (tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol#3)\n",
"markdown": "[A.f(uint256,uint256,uint256)](tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol#L2-L4) performs a multiplication on the result of a division:\n\t-[(a / b) * c](tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol#L3)\n",
"first_markdown_element": "tests/detectors/divide-before-multiply/0.6.11/divide_before_multiply.sol#L2-L4",
"id": "9010aa3fdf8f7689d4c4d4ea0bcd771668212100e5427e48644ed7337de03a6d",
"check": "divide-before-multiply",
"impact": "Medium",
"confidence": "Medium"
}
]
]

@ -0,0 +1,5 @@
contract A {
function f(uint a, uint b, uint c) public returns (uint) {
return (a / b) * c;
}
}

@ -0,0 +1,127 @@
[
[
{
"elements": [
{
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
},
{
"type": "node",
"name": "(a / b) * c",
"source_mapping": {
"start": 81,
"length": 18,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
3
],
"starting_column": 9,
"ending_column": 27
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
}
}
}
],
"description": "A.f(uint256,uint256,uint256) (tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol#2-4) performs a multiplication on the result of a division:\n\t-(a / b) * c (tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol#3)\n",
"markdown": "[A.f(uint256,uint256,uint256)](tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol#L2-L4) performs a multiplication on the result of a division:\n\t-[(a / b) * c](tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol#L3)\n",
"first_markdown_element": "tests/detectors/divide-before-multiply/0.7.6/divide_before_multiply.sol#L2-L4",
"id": "9bc6cb85ece6cd57fa946707784180957080ad5f9575abc17af218f0d2801f77",
"check": "divide-before-multiply",
"impact": "Medium",
"confidence": "Medium"
}
]
]

@ -1199,6 +1199,26 @@ ALL_TESTS = [
"deprecated_calls.sol",
"0.4.25",
),
Test(
all_detectors.DivideBeforeMultiply,
"divide_before_multiply.sol",
"0.4.25",
),
Test(
all_detectors.DivideBeforeMultiply,
"divide_before_multiply.sol",
"0.5.16",
),
Test(
all_detectors.DivideBeforeMultiply,
"divide_before_multiply.sol",
"0.6.11",
),
Test(
all_detectors.DivideBeforeMultiply,
"divide_before_multiply.sol",
"0.7.6",
),
]
GENERIC_PATH = "/GENERIC_PATH"

Loading…
Cancel
Save