-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2051 from crytic/dev-fix-enum-max-min
Fix enum.max/min when enum in other contract
- Loading branch information
Showing
7 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.24 KB
tests/e2e/solc_parsing/test_data/compile/enum-max-min.sol-0.8.19-compact.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
library Q { | ||
enum E {a} | ||
} | ||
|
||
contract Z { | ||
enum E {a,b} | ||
} | ||
|
||
contract D { | ||
enum E {a,b,c} | ||
|
||
function a() public returns(uint){ | ||
return uint(type(E).max); | ||
} | ||
|
||
function b() public returns(uint){ | ||
return uint(type(Q.E).max); | ||
} | ||
|
||
function c() public returns(uint){ | ||
return uint(type(Z.E).max); | ||
} | ||
|
||
function d() public returns(uint){ | ||
return uint(type(E).min); | ||
} | ||
|
||
function e() public returns(uint){ | ||
return uint(type(Q.E).min); | ||
} | ||
|
||
function f() public returns(uint){ | ||
return uint(type(Z.E).min); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
tests/e2e/solc_parsing/test_data/expected/enum-max-min.sol-0.8.19-compact.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Q": {}, | ||
"Z": {}, | ||
"D": { | ||
"a()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n", | ||
"b()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n", | ||
"c()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n", | ||
"d()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n", | ||
"e()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n", | ||
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
library Q { | ||
enum E {a} | ||
} | ||
|
||
contract Z { | ||
enum E {a,b} | ||
} | ||
|
||
contract D { | ||
enum E {a,b,c} | ||
|
||
function a() public returns(uint){ | ||
return uint(type(E).max); | ||
} | ||
|
||
function b() public returns(uint){ | ||
return uint(type(Q.E).max); | ||
} | ||
|
||
function c() public returns(uint){ | ||
return uint(type(Z.E).max); | ||
} | ||
|
||
function d() public returns(uint){ | ||
return uint(type(E).min); | ||
} | ||
|
||
function e() public returns(uint){ | ||
return uint(type(Q.E).min); | ||
} | ||
|
||
function f() public returns(uint){ | ||
return uint(type(Z.E).min); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from pathlib import Path | ||
from slither import Slither | ||
from slither.slithir.operations import Assignment | ||
from slither.slithir.variables import Constant | ||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" | ||
|
||
|
||
def test_enum_max_min(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.8.19") | ||
slither = Slither(Path(TEST_DATA_DIR, "enum_max_min.sol").as_posix(), solc=solc_path) | ||
|
||
contract = slither.get_contract_from_name("D")[0] | ||
|
||
f = contract.get_function_from_full_name("a()") | ||
# TMP_1(uint256) := 2(uint256) | ||
assignment = f.slithir_operations[1] | ||
assert ( | ||
isinstance(assignment, Assignment) | ||
and isinstance(assignment.rvalue, Constant) | ||
and assignment.rvalue.value == 2 | ||
) | ||
|
||
f = contract.get_function_from_full_name("b()") | ||
# TMP_4(uint256) := 0(uint256) | ||
assignment = f.slithir_operations[1] | ||
assert ( | ||
isinstance(assignment, Assignment) | ||
and isinstance(assignment.rvalue, Constant) | ||
and assignment.rvalue.value == 0 | ||
) | ||
|
||
f = contract.get_function_from_full_name("c()") | ||
# TMP_7(uint256) := 1(uint256) | ||
assignment = f.slithir_operations[1] | ||
assert ( | ||
isinstance(assignment, Assignment) | ||
and isinstance(assignment.rvalue, Constant) | ||
and assignment.rvalue.value == 1 | ||
) | ||
|
||
f = contract.get_function_from_full_name("d()") | ||
# TMP_10(uint256) := 0(uint256) | ||
assignment = f.slithir_operations[1] | ||
assert ( | ||
isinstance(assignment, Assignment) | ||
and isinstance(assignment.rvalue, Constant) | ||
and assignment.rvalue.value == 0 | ||
) | ||
|
||
f = contract.get_function_from_full_name("e()") | ||
# TMP_13(uint256) := 0(uint256) | ||
assignment = f.slithir_operations[1] | ||
assert ( | ||
isinstance(assignment, Assignment) | ||
and isinstance(assignment.rvalue, Constant) | ||
and assignment.rvalue.value == 0 | ||
) | ||
|
||
f = contract.get_function_from_full_name("f()") | ||
# TMP_16(uint256) := 0(uint256) | ||
assignment = f.slithir_operations[1] | ||
assert ( | ||
isinstance(assignment, Assignment) | ||
and isinstance(assignment.rvalue, Constant) | ||
and assignment.rvalue.value == 0 | ||
) |