Skip to content

Commit

Permalink
fix: order of evaluation for some builtins
Browse files Browse the repository at this point in the history
ecadd, ecmul, addmod, mulmod

in the case that the arguments have side effects, they could be
evaluated out of order

chainsec june 2023 review 5.1
  • Loading branch information
charles-cooper committed Sep 2, 2023
1 parent 2c21eab commit 021b7ab
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ def build_IR(self, expr, args, kwargs, context):
typ=SArrayT(UINT256_T, 2),
location=MEMORY,
)
return b2.resolve(b1.resolve(o))
return b1.resolve(b2.resolve(o))


class ECMul(BuiltinFunction):
Expand Down Expand Up @@ -844,7 +844,7 @@ def build_IR(self, expr, args, kwargs, context):
typ=SArrayT(UINT256_T, 2),
location=MEMORY,
)
return b2.resolve(b1.resolve(o))
return b1.resolve(b2.resolve(o))


def _generic_element_getter(op):
Expand Down Expand Up @@ -1525,13 +1525,14 @@ def evaluate(self, node):

@process_inputs
def build_IR(self, expr, args, kwargs, context):
c = args[2]

with c.cache_when_complex("c") as (b1, c):
ret = IRnode.from_list(
["seq", ["assert", c], [self._opcode, args[0], args[1], c]], typ=UINT256_T
)
return b1.resolve(ret)
x, y, z = args
with x.cache_when_complex("x") as (b1, x):
with y.cache_when_complex("y") as (b2, y):
with z.cache_when_complex("z") as (b3, z):
ret = IRnode.from_list(
["seq", ["assert", z], [self._opcode, x, y, z]], typ=UINT256_T
)
return b1.resolve(b2.resolve(b3.resolve(ret)))


class AddMod(_AddMulMod):
Expand Down

0 comments on commit 021b7ab

Please sign in to comment.