Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enum.max/min when enum in other contract #2051

Merged
merged 4 commits into from
Sep 15, 2023
Merged

Conversation

smonicas
Copy link
Collaborator

Fix #2020 #1602
In slithir it will look as if the enum used is always the local one however the correct enum is used, that's because Enum str prints only the name it could be fixed by printing the canonical_name but then even when the enum is local you would have the contract name.
Slithir of the test:

	Function D.a() (*)
		Expression: uint256(type()(E).max)
		IRs:
			TMP_0(type(E)) = SOLIDITY_CALL type()(E)
			TMP_1(uint256) := 2(uint256)
			TMP_2 = CONVERT TMP_1 to uint256
			RETURN TMP_2
	Function D.b() (*)
		Expression: uint256(type()(Q.E).max)
		IRs:
			TMP_3(type(E)) = SOLIDITY_CALL type()(E)
			TMP_4(uint256) := 0(uint256)
			TMP_5 = CONVERT TMP_4 to uint256
			RETURN TMP_5
	Function D.c() (*)
		Expression: uint256(type()(Z.E).max)
		IRs:
			TMP_6(type(E)) = SOLIDITY_CALL type()(E)
			TMP_7(uint256) := 1(uint256)
			TMP_8 = CONVERT TMP_7 to uint256
			RETURN TMP_8

@@ -523,6 +536,10 @@ def _post_member_access(self, expression: MemberAccess) -> None:
if expression.member_name in expr.custom_errors_as_dict:
set_val(expression, expr.custom_errors_as_dict[expression.member_name])
return
# Lookup enums when in a different contract e.g. C.E
if str(expression) in expr.enums_as_dict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be expression.member_name instead of str(expression)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expression.member_name has only the enum name e.g. with C.E it's E but the fully qualified name is needed and that's the expression

@0xalpharush
Copy link
Contributor

0xalpharush commented Jul 24, 2023

Can we make this an IR test that checks the value of the constant (min/max) instead of a parsing test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants