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

Fixes issue #336 #371

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Fixes issue #336 #371

wants to merge 5 commits into from

Conversation

pcjordan
Copy link
Contributor

Requesting bug bounty :-)

opshin/type_inference.py Show resolved Hide resolved
opshin/type_inference.py Show resolved Hide resolved
@nielstron
Copy link
Contributor

Hey, thanks for participating in the bug bounty (for #336). Please share your payment address / ada handle while I will review your contribution and provide feedback. Payments will be done if the PR results in a merge. More details as usual can be found in the bug bounty documentation.

Copy link
Contributor

@nielstron nielstron left a comment

Choose a reason for hiding this comment

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

Please incorporate the noted changes. Please also run the code on two example contracts and provide the output with that (I think creating a proper unit test for logged warnings would be beyond the scope of this PR)

warn_assert_msg = f" (see assert with message '{node.msg.value}')"
except Exception:
warn_assert_msg = ""
if isinstance(ta.test.args[0], Constant) and ta.test.args[0].value is None:
Copy link
Contributor

@nielstron nielstron Apr 26, 2024

Choose a reason for hiding this comment

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

If I understand correctly you are trying to cover two cases here: either the line is assert None or the line is assert foo() where foo returns None.

I think it is good to explicitly cover the foo case and provide a more specific error message for it. However the handling would be more generic if after that check we check for the type of the whole expression (I.e. ta.test.args[0].typ or ta.test.typ)

opshin/type_inference.py Outdated Show resolved Hide resolved
@pcjordan
Copy link
Contributor Author

pcjordan commented Jul 9, 2024

Picking up on this again, I made the Exception more specific, and added two examples which give the following warnings:

  1. python3 -m opshin compile spending examples/smart_contracts/assert_none.py gives WARNING for examples/smart_contracts/assert_none.py:6 Asserting 'None' (see assert with message 'Always fails!') is equivalent to asserting False, which always fails.
  2. python3 -m opshin compile spending examples/smart_contracts/assert_foo_none.py gives WARNING for examples/smart_contracts/assert_foo_none.py:10 Asserting 'None' (see assert with message 'Always fails!') is likely to stem from a procedure already doing internal assertions and returning 'None'. Asserting this is equivalent to asserting False, which always fails (likely unintended).

Regarding your comment on more generic handling: I'm not sure if I understand what you mean by the ta.test.args[0].value.typ thing. If the line is assert None, then ta.test.args[0].value is None and there is no attribute typ. If the line is assert foo() where foo returns None, then ta.test.args[0] is a Call object which has no attribute value.

@OpShin OpShin deleted a comment from codereviewbot-ai bot Jul 9, 2024
@OpShin OpShin deleted a comment from codereviewbot-ai bot Jul 9, 2024
@OpShin OpShin deleted a comment from codereviewbot-ai bot Jul 9, 2024
@OpShin OpShin deleted a comment from codereviewbot-ai bot Jul 9, 2024
@OpShin OpShin deleted a comment from codereviewbot-ai bot Jul 9, 2024
@OpShin OpShin deleted a comment from codereviewbot-ai bot Jul 9, 2024
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.

2 participants