Added tests for reentrancy read before written

pull/734/head
Natalie Chin 4 years ago
parent dcf1797dc7
commit b8cb7c6dad
  1. 29
      tests/detectors/reentrancy-before-write/reentrancy-write.sol
  2. 823
      tests/detectors/reentrancy-before-write/reentrancy-write.sol.0.4.26.ReentrancyReadBeforeWritten.json
  3. 5
      tests/test_detectors.py

@ -0,0 +1,29 @@
pragma solidity 0.4.26;
contract ReentrancyWrite {
bool notCalled = true;
function bad0() public {
require(notCalled);
if (!(msg.sender.call())) {
revert();
}
notCalled = false;
}
function bad1(address target) public {
require(notCalled);
(bool success) = msg.sender.call();
require(success);
bad0();
}
function good() public {
require(notCalled);
notCalled = true;
if (!(msg.sender.call())) {
revert();
}
}
}

@ -0,0 +1,823 @@
[
[
{
"elements": [
{
"type": "function",
"name": "bad0",
"source_mapping": {
"start": 84,
"length": 153,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
6,
7,
8,
9,
10,
11,
12
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad0()"
}
},
{
"type": "node",
"name": "! (msg.sender.call())",
"source_mapping": {
"start": 149,
"length": 20,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
8
],
"starting_column": 13,
"ending_column": 33
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad0",
"source_mapping": {
"start": 84,
"length": 153,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
6,
7,
8,
9,
10,
11,
12
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad0()"
}
}
},
"additional_fields": {
"underlying_type": "external_calls"
}
},
{
"type": "node",
"name": "notCalled = false",
"source_mapping": {
"start": 213,
"length": 17,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
11
],
"starting_column": 9,
"ending_column": 26
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad0",
"source_mapping": {
"start": 84,
"length": 153,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
6,
7,
8,
9,
10,
11,
12
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad0()"
}
}
},
"additional_fields": {
"underlying_type": "variables_written",
"variable_name": "notCalled"
}
}
],
"description": "Reentrancy in ReentrancyWrite.bad0() (tests/detectors/reentrancy-before-write/reentrancy-write.sol#6-12):\n\tExternal calls:\n\t- ! (msg.sender.call()) (tests/detectors/reentrancy-before-write/reentrancy-write.sol#8)\n\tState variables written after the call(s):\n\t- notCalled = false (tests/detectors/reentrancy-before-write/reentrancy-write.sol#11)\n",
"markdown": "Reentrancy in [ReentrancyWrite.bad0()](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L6-L12):\n\tExternal calls:\n\t- [! (msg.sender.call())](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L8)\n\tState variables written after the call(s):\n\t- [notCalled = false](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L11)\n",
"id": "e078084eca02a4723da5dcb8a78af564de225e53ecc5cb8d98262c19296f7233",
"check": "reentrancy-no-eth",
"impact": "Medium",
"confidence": "Medium"
},
{
"elements": [
{
"type": "function",
"name": "bad1",
"source_mapping": {
"start": 243,
"length": 158,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
14,
15,
16,
17,
18,
19
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad1(address)"
}
},
{
"type": "node",
"name": "success = msg.sender.call()",
"source_mapping": {
"start": 318,
"length": 34,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
16
],
"starting_column": 9,
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad1",
"source_mapping": {
"start": 243,
"length": 158,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
14,
15,
16,
17,
18,
19
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad1(address)"
}
}
},
"additional_fields": {
"underlying_type": "external_calls"
}
},
{
"type": "node",
"name": "bad0()",
"source_mapping": {
"start": 388,
"length": 6,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
18
],
"starting_column": 9,
"ending_column": 15
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad1",
"source_mapping": {
"start": 243,
"length": 158,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
14,
15,
16,
17,
18,
19
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad1(address)"
}
}
},
"additional_fields": {
"underlying_type": "external_calls"
}
},
{
"type": "node",
"name": "! (msg.sender.call())",
"source_mapping": {
"start": 149,
"length": 20,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
8
],
"starting_column": 13,
"ending_column": 33
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad0",
"source_mapping": {
"start": 84,
"length": 153,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
6,
7,
8,
9,
10,
11,
12
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad0()"
}
}
},
"additional_fields": {
"underlying_type": "external_calls_sending_eth"
}
},
{
"type": "node",
"name": "bad0()",
"source_mapping": {
"start": 388,
"length": 6,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
18
],
"starting_column": 9,
"ending_column": 15
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad1",
"source_mapping": {
"start": 243,
"length": 158,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
14,
15,
16,
17,
18,
19
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad1(address)"
}
}
},
"additional_fields": {
"underlying_type": "variables_written",
"variable_name": "notCalled"
}
},
{
"type": "node",
"name": "notCalled = false",
"source_mapping": {
"start": 213,
"length": 17,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
11
],
"starting_column": 9,
"ending_column": 26
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad0",
"source_mapping": {
"start": 84,
"length": 153,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
6,
7,
8,
9,
10,
11,
12
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "ReentrancyWrite",
"source_mapping": {
"start": 25,
"length": 537,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad0()"
}
}
},
"additional_fields": {
"underlying_type": "variables_written",
"variable_name": "notCalled"
}
}
],
"description": "Reentrancy in ReentrancyWrite.bad1(address) (tests/detectors/reentrancy-before-write/reentrancy-write.sol#14-19):\n\tExternal calls:\n\t- success = msg.sender.call() (tests/detectors/reentrancy-before-write/reentrancy-write.sol#16)\n\t- bad0() (tests/detectors/reentrancy-before-write/reentrancy-write.sol#18)\n\t\t- ! (msg.sender.call()) (tests/detectors/reentrancy-before-write/reentrancy-write.sol#8)\n\tState variables written after the call(s):\n\t- bad0() (tests/detectors/reentrancy-before-write/reentrancy-write.sol#18)\n\t\t- notCalled = false (tests/detectors/reentrancy-before-write/reentrancy-write.sol#11)\n",
"markdown": "Reentrancy in [ReentrancyWrite.bad1(address)](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L14-L19):\n\tExternal calls:\n\t- [success = msg.sender.call()](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L16)\n\t- [bad0()](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L18)\n\t\t- [! (msg.sender.call())](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L8)\n\tState variables written after the call(s):\n\t- [bad0()](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L18)\n\t\t- [notCalled = false](tests/detectors/reentrancy-before-write/reentrancy-write.sol#L11)\n",
"id": "2ee9fea9a2fa34c6702dcb539c392ab810468f83a66fb21a2df33a1f3d4747cf",
"check": "reentrancy-no-eth",
"impact": "Medium",
"confidence": "Medium"
}
]
]

@ -53,6 +53,11 @@ def id_test(test_item: Test):
ALL_TESTS = [
Test(
all_detectors.ReentrancyReadBeforeWritten,
"tests/detectors/reentrancy-before-write/reentrancy-write.sol",
"0.4.26",
),
Test(
all_detectors.BooleanEquality,
"tests/detectors/boolean-constant-equality/boolean-constant-equality.sol",

Loading…
Cancel
Save