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

Double Eval in experimental codegen without optimization #4072

Closed
ritzdorf opened this issue May 31, 2024 · 6 comments · Fixed by #4149
Closed

Double Eval in experimental codegen without optimization #4072

ritzdorf opened this issue May 31, 2024 · 6 comments · Fixed by #4149
Assignees
Labels
bug - type 1 bug which results in incorrect codegen sev - low

Comments

@ritzdorf
Copy link
Contributor

Version Information

  • vyper Version (output of vyper --version OR linkable commit hash vyperlang/vyper@commitish): 0.4.0rc6+commit.33719560

Issue description

In version 0.4.0rc6 it seems that #4030 fixed the issue #4071 for all tested compilation settings EXCEPT when compiling with experimental_codegen and no optimization. For that compilation setting incorrect bytecode with double evaluation is still being generated.

PoC

m: HashMap[uint256, String[33]]

@external
def foo() -> uint256:
    x: DynArray[uint256, 32] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    self.m[x.pop()] = "Hello world"
    return len(x)

And compile with

vyper --experimental-codegen -O none example.vy

Returns 30, but should return 31.

@cyberthirst cyberthirst transferred this issue from another repository May 31, 2024
@charles-cooper charles-cooper transferred this issue from another repository May 31, 2024
@charles-cooper charles-cooper added sev - medium bug - type 1 bug which results in incorrect codegen sev - low and removed sev - low sev - medium labels May 31, 2024
harkal added a commit to harkal/vyper that referenced this issue Jun 12, 2024
harkal added a commit to harkal/vyper that referenced this issue Jun 12, 2024
@harkal
Copy link
Collaborator

harkal commented Jun 12, 2024

It appears that the latest master (commit 21f7172) fails to compile the above example. I have created a test case for it in #4130 to investigate for venom, but it seems to be a general issue.

@trocher
Copy link
Contributor

trocher commented Jun 12, 2024

It appears that the latest master (commit 21f7172) fails to compile the above example. I have created a test case for it in #4130 to investigate for venom, but it seems to be a general issue.

I think master failing to compile is expected given that #3514/#4071 have not been fixed yet, only a fence was added (#4030) to prevent incorrect bytecode generation by having the compiler fail, but the underlying issue is not fixed

@harkal
Copy link
Collaborator

harkal commented Jun 12, 2024

so #4030 is not actually fixing the issue, instead it asserts to abort from producing erroneous bytecode?

@trocher
Copy link
Contributor

trocher commented Jun 14, 2024

Exact, #4030, together with #3835 it extend the usage of unique_symbol to more expressions that are known to have side effects. They make the compiler fail if the tagged node gets evaluated more than once by using unique_symbol:

Concerned (IR) nodes are:

  • CALL (used in send, raw_call or regular external calls)
  • CREATE/CREATE2 (used in all relevant builtin)
  • SELFDESTRUCT
  • LOGK (in raw_log)
  • all STORE done by append and pop (storage, transient or mem)
  • all TSTORE and SSTORE
  • all internal calls

This means that for now, the compiler relies on that list to be exhaustive not to perform any double evaluation of the dst of an assignment that would lead to visible side effects

@charles-cooper
Copy link
Member

yea we can probably demote this to "type 0" bug (panic instead of producing bad code). but we should still investigate since it indicates some kind of deeper issue

@charles-cooper charles-cooper added bug - type 0 compiler halts or panics instead of generating code bug - type 1 bug which results in incorrect codegen and removed bug - type 1 bug which results in incorrect codegen bug - type 0 compiler halts or panics instead of generating code labels Jun 14, 2024
@charles-cooper
Copy link
Member

ah never mind, i see what's happening -- -Onone --experimental-codegen bypasses the unique symbols check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - type 1 bug which results in incorrect codegen sev - low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants