-
-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
_abi_decode() validation (#3626)
`_abi_decode()` does not validate input when it is nested in certain
expressions. the following example gets correctly validated (bounds
checked):
```vyper
x: uint8 = _abi_decode(slice(msg.data, 4, 32), uint8)
```
however, the following example is not bounds checked:
```vyper
@external
def abi_decode(x: uint256) -> uint256:
a: uint256 = convert(
_abi_decode(
slice(msg.data, 4, 32),
(uint8)
),
uint256
)
return a # abi_decode(256) returns: 256
```
the issue is caused because the `ABIDecode()` builtin tags its output
with `encoding=Encoding.ABI`, but this does not result in validation
until that itself is passed to `make_setter` (which is called for
instance when generating an assignment or return statement).
the issue can be triggered by constructing an example where the output
of `ABIDecode()` is not internally passed to `make_setter` or other
input validating routine.
this commit fixes the issue by calling `make_setter` in `ABIDecode()`
before returning the output buffer, which causes validation to be
performed. note that this causes a performance regression in the common
(and majority of) cases where `make_setter` is immediately called on the
result of `ABIDecode()` because a redundant memory copy ends up being
generated (like in the aforementioned examples: in a plain assignment or
return statement). however, fixing this performance regression is left
to future work in the optimizer.- Loading branch information
1 parent
e5c323a
commit d438d92
Showing
2 changed files
with
52 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters