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

broken clamps in initcode #2456

Closed
Tracked by #2471
charles-cooper opened this issue Sep 14, 2021 · 1 comment
Closed
Tracked by #2471

broken clamps in initcode #2456

charles-cooper opened this issue Sep 14, 2021 · 1 comment
Assignees
Labels
bug Bug that shouldn't change language semantics when fixed.

Comments

@charles-cooper
Copy link
Member

charles-cooper commented Sep 14, 2021

Version Information

  • vyper Version (output of vyper --version): v0.2.16

What's your issue about?

Clampers for __init__ bytestrings use calldata (which is always 0 for constructors). In other words, they always validate the constructor arguments even if they are borked.

Example contract:

foo: Bytes[20]

@external
def __init__(x: Bytes[20]):
    self.foo = x

Constructor LLL:

  [codecopy, 320, ~codelen, 32],
  [codecopy, 352, [add, ~codelen, [codeload, ~codelen]], 52],
  [assert, [le, [calldataload, [add, 4, [codeload, ~codelen]]], 20]], # BYTESTRING CLAMP IS HERE - always returns true
  # Line 6
  [with,
    _pos,
    352 <x>,
    /* copy byte slice src: _pos dst: 0 <self.foo> */ 
    [with,
      _pos,
      _pos,
      [with,
        _opos,
        0 <self.foo>,
        [with,
          _actual_len,
          [add, [mload, _pos], 32],
          [repeat,
            288,
            0,
            2,
            [seq,
              [if, [gt, [mul, 32, [mload, 288]], _actual_len], break],
              [sstore,
                [add, _opos, [mload, 288]],
                [mload, [add, _pos, [mul, 32, [mload, 288]]]]]]]]]]],

How can it be fixed?

Fill this in if you know how to fix it.

@charles-cooper charles-cooper self-assigned this Sep 14, 2021
@charles-cooper charles-cooper added the bug Bug that shouldn't change language semantics when fixed. label Sep 14, 2021
@charles-cooper
Copy link
Member Author

fixed in #2447

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that shouldn't change language semantics when fixed.
Projects
None yet
Development

No branches or pull requests

1 participant