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

Vyper compiler fails to compile long unsafe expression #3316

Closed
pcaversaccio opened this issue Mar 8, 2023 · 1 comment · Fixed by #3318
Closed

Vyper compiler fails to compile long unsafe expression #3316

pcaversaccio opened this issue Mar 8, 2023 · 1 comment · Fixed by #3318

Comments

@pcaversaccio
Copy link
Collaborator

Version Information

  • vyper Version (output of vyper --version): 0.3.7+commit.6020b8b
  • OS: linux
  • Python Version (output of python --version): 3.9.2

What's your issue about?

The Vyper compiler fails to compile the following function (waited for around 10mins without success):

@external
@pure
def wad_exp(x: int256) -> uint256:
    value: int256 = x
    if (x <= -42139678854452767551):
        return empty(uint256)

    assert x < 135305999368893231589, "Math: wad_exp overflow"

    value = unsafe_div(shift(x, 78), 5 ** 18)
    k: int256 = shift(unsafe_add(unsafe_div(shift(value, 96), 54916777467707473351141471128), 2 ** 95), -96)
    value = unsafe_sub(value, unsafe_mul(k, 54916777467707473351141471128))

    y: int256 = unsafe_add(shift(unsafe_mul(unsafe_add(value, 1346386616545796478920950773328), value), -96), 57155421227552351082224309758442)
    p: int256 = unsafe_add(unsafe_mul(unsafe_add(shift(unsafe_mul(unsafe_sub(unsafe_add(y, value), 94201549194550492254356042504812), y), -96), 28719021644029726153956944680412240), value), shift(4385272521454847904659076985693276, 96))

    q: int256 = unsafe_add(shift(unsafe_mul(unsafe_sub\
                (shift(unsafe_mul(unsafe_add(shift(unsafe_mul\
                (unsafe_sub(shift(unsafe_mul(unsafe_add(shift(unsafe_mul\
                (unsafe_sub(value, convert(2855989394907223263936484059900, int256)),\
                value), convert(-96, int256)), convert(50020603652535783019961831881945,\
                int256)), value), convert(-96, int256)), convert(533845033583426703283633433725380, int256)),\
                value), convert(-96, int256)), convert(3604857256930695427073651918091429, int256)), value),\
                convert(-96, int256)), convert(14423608567350463180887372962807573, int256)), value),\
                convert(-96, int256)), convert(26449188498355588339934803723976023, int256))

    r: int256 = unsafe_div(p, q)

    return convert(shift(unsafe_mul(r, 3822833074963236453042738258902158003155416615667), -unsafe_sub(195, k)), uint256)

How can it be fixed?

The Vyper compiler should be able to successfully compile the above or similar long unsafe expressions.

@pcaversaccio
Copy link
Collaborator Author

Tagging @michwill: maybe you can share your example with the same issue?

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