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[ux]: catch state modifying functions in range expr and loop iterator #3884

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Mar 23, 2024

What I did

Fix #3172, #3504, #3867. Closes #3188.

How I did it

Check for modifying member and contract functions in a range call and as loop iterator.

How to verify it

See tests.

Commit message

fix[ux]: catch state modifying functions in range expr and loop iterator

This commit catches state-modifying functions in the iterator and range
expression of a for loop, and throws a StateAccessViolation exception.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.06%. Comparing base (dd5a3d9) to head (fc76404).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3884      +/-   ##
==========================================
- Coverage   92.06%   92.06%   -0.01%     
==========================================
  Files         120      120              
  Lines       17335    17352      +17     
  Branches     2935     2940       +5     
==========================================
+ Hits        15960    15975      +15     
- Misses        957      958       +1     
- Partials      418      419       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

interesting that we don't need (as much) analysis anymore. but i'm not sure this works for side effecting expressions which aren't marked with extcall (e.g. raw_call, internal calls which result in state changes, etc). i think a more robust solution is going to be to pass around a context variable with the current scope's modifiability information

@charles-cooper
Copy link
Member

this is a dup of #3546 no?

@cyberthirst
Copy link
Collaborator

interface I:
    def bar() -> DynArray[uint256, 10]: nonpayable

@external
def bar(t: address):
    for i: uint256 in extcall I(t).bar():
        pass
vyper.exceptions.CodegenPanic: unhandled exception typechecker missed this, parse_ExtCall

  contract "tests/custom/test4.vy:6", function "bar", line 6:22 
       5 def bar(t: address):
  ---> 6     for i: uint256 in extcall I(t).bar():
  -----------------------------^
       7         pass


This is an unhandled internal compiler error. Please create an issue on Github to notify the developers!
https://github.com/vyperlang/vyper/issues/new?template=bug.md

@tserg tserg changed the title fix: catch extcalls in range expr fix: catch extcalls in range expr and loop iterator Oct 11, 2024
@tserg tserg changed the title fix: catch extcalls in range expr and loop iterator fix[ux]: catch extcalls in range expr and loop iterator Oct 11, 2024
@tserg tserg changed the title fix[ux]: catch extcalls in range expr and loop iterator fix[ux]: catch state modifying functions in range expr and loop iterator Dec 30, 2024
@@ -614,6 +614,19 @@ def foo(_addr: address):
(
"""
@external
def foo(a: address):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a test for raw call because it has its own analysis in its build_IR function. Can I move these syntax tests to tests/functional/syntax/test_raw_call.py?

Copy link
Member

Choose a reason for hiding this comment

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

yea

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!

@tserg tserg requested a review from charles-cooper December 31, 2024 05:19
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.

State can be modified in a range expression using pop
4 participants