Skip to content

Commit

Permalink
fix as wei val
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Oct 26, 2023
1 parent 652199e commit ade1031
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,24 +1032,29 @@ def build_IR(self, expr, args, kwargs, context):

denom_divisor = self.get_denomination(expr)
with value.cache_when_complex("value") as (b1, value):
if value.typ in (UINT256_T, UINT8_T):
sub = [
"with",
"ans",
["mul", value, denom_divisor],
[
"seq",
if isinstance(value.typ, IntegerT):
if not value.typ.is_signed:
sub = [
"with",
"ans",
["mul", value, denom_divisor],
[
"assert",
["or", ["eq", ["div", "ans", value], denom_divisor], ["iszero", value]],
"seq",
[
"assert",
[
"or",
["eq", ["div", "ans", value], denom_divisor],
["iszero", value],
],
],
"ans",
],
"ans",
],
]
elif value.typ == INT128_T:
# signed types do not require bounds checks because the
# largest possible converted value will not overflow 2**256
sub = ["seq", ["assert", ["sgt", value, -1]], ["mul", value, denom_divisor]]
]
else:
# signed types do not require bounds checks because the
# largest possible converted value will not overflow 2**256
sub = ["seq", ["assert", ["sgt", value, -1]], ["mul", value, denom_divisor]]
elif value.typ == DecimalT():
sub = [
"seq",
Expand Down

0 comments on commit ade1031

Please sign in to comment.