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

bug: make_setter is incorrect for complex types when RHS references LHS with a function call #3503

Closed
tserg opened this issue Jul 17, 2023 · 0 comments · Fixed by #4037
Closed

Comments

@tserg
Copy link
Collaborator

tserg commented Jul 17, 2023

Version Information

  • vyper Version (output of vyper --version): 9e3b9a2
  • OS: linux
  • Python Version (output of python --version): 3.10.4

What's your issue about?

#2418 described a bug where, during an assignment, if the right-hand side refers to the left-hand side, part of the data to be copied may get overwritten before being copied.

Although #3410 fixed the issue in most of the cases, it can still happen with function calls as shown in the examples below.

In this example, a call to foo() returns [2, 2] when it should return [2, 1].

a:DynArray[uint256,2]

@external
def foo() -> DynArray[uint256,2]:
    # Initial value
    self.a = [1,2]
    self.a = [self.bar(1), self.bar(0)]
    return self.a #returns [2,2]

@internal
def bar(i:uint256)->uint256:
    return self.a[i]

In this example, boo() temporarily assigns values to self.a before emptying it. The values stored in self.a are however still readable from foo() as a fall to foo() here returns [11, 12, 3, 4].

a: DynArray[uint256, 10]

@external
    def foo()->DynArray[uint256, 10]:
    self.a = [1, 2, self.boo(), 4]
    return self.a # returns [11, 12, 3, 4]

@internal
def boo() -> uint256:
    self.a = [11, 12, 13, 14, 15, 16]
    self.a = []
    # it should now be impossible to read any of [11, 12, 13, 14, 15, 16]
    return 3

h/t @trocher

How can it be fixed?

Fill this in if you know how to fix it.

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 a pull request may close this issue.

1 participant