vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.82k stars 790 forks source link

fix[codegen]: fix `make_setter` overlap in `dynarray_append` #4059

Closed charles-cooper closed 1 month ago

charles-cooper commented 1 month ago

What I did

fix https://github.com/vyperlang/vyper/issues/4056, which is another make_setter overlap bug

variant of #4037 and https://github.com/vyperlang/vyper/pull/3410

additionally adds an internal assertion to prevent future variants

How I did it

How to verify it

Commit message

`make_setter` can potentially run into overlap when called from
`dynarray_append`; this commit copies to a temporary intermediate buffer
(as is done in `AnnAssign`) before copying to the destination if the
condition is detected.

this is a variant of the bugs fixed in ad9c10b0b98e2d and 1c8349e867b2b.

this commit also adds a util function to detect overlap, and adds an
assertion directly in `make_setter` so that future variants panic
instead of generating bad code.

Description for the changelog

Cute Animal Picture

![Put a link to a cute animal picture inside the parenthesis-->]()

cyberthirst commented 1 month ago

currently we don't handle ann_assign well

this will panic

interface Bar:
    def bar() -> Bytes[2]: payable

@external
def foo() -> Bytes[2]:
    x: Bytes[2] = extcall Bar(self).bar()
    return x
cyberthirst commented 1 month ago

also this due to the internal buffer variable on lhs

BLUEPRINT: immutable(address)

@deploy
def __init__(blueprint_address: address):
    BLUEPRINT = blueprint_address

@external
def test(code_ofst: uint256) -> address:
    return create_from_blueprint(BLUEPRINT, code_offset=code_ofst)
codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 19.04762% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 55.21%. Comparing base (dcec257) to head (74d1b85).

:exclamation: Current head 74d1b85 differs from pull request most recent head 2b93d79

Please upload reports for the commit 2b93d79 to get more accurate results.

Files Patch % Lines
vyper/codegen/core.py 33.33% 4 Missing and 4 partials :warning:
vyper/codegen/expr.py 0.00% 8 Missing :warning:
vyper/codegen/stmt.py 0.00% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #4059 +/- ## =========================================== - Coverage 91.23% 55.21% -36.03% =========================================== Files 108 107 -1 Lines 15499 15466 -33 Branches 3404 3401 -3 =========================================== - Hits 14141 8540 -5601 - Misses 927 6304 +5377 - Partials 431 622 +191 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.