You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vyper Version (output of vyper --version): commit 4b4e188ba83d28b5dd6ff66479e7448e5b925030
Issue description
When a bound is specified, the range() built-in checks at runtime
that ["assert", [le, start, end]]. However, if the type of the loop
iterator, is a signed integer, the check is not always correct as le
here performs an unsigned integer comparison and not a signed one. This
means that:
If the iterator type is int256 it is possible to overflow 256 bits
while looping if end is negative and start is positive.
POC
For example, calling the function foo in the following contract
returns [57896044618658097711785492504343953926634992332820282019728792003956564819967, -57896044618658097711785492504343953926634992332820282019728792003956564819968, -57896044618658097711785492504343953926634992332820282019728792003956564819967]
Version Information
vyper --version
): commit4b4e188ba83d28b5dd6ff66479e7448e5b925030
Issue description
When a
bound
is specified, therange()
built-in checks at runtimethat
["assert", [le, start, end]]
. However, if the type of the loopiterator, is a signed integer, the check is not always correct as
le
here performs an unsigned integer comparison and not a signed one. This
means that:
If the iterator type is
int256
it is possible to overflow 256 bitswhile looping if
end
is negative andstart
is positive.POC
For example, calling the function
foo
in the following contractreturns
[57896044618658097711785492504343953926634992332820282019728792003956564819967, -57896044618658097711785492504343953926634992332820282019728792003956564819968, -57896044618658097711785492504343953926634992332820282019728792003956564819967]
credits: @trocher
The text was updated successfully, but these errors were encountered: