From 86d7017dbe5060a6c78aa2feaff4ac50227848c7 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 12 Sep 2023 17:22:34 -0400 Subject: [PATCH] inline wrap256 --- boa/vyper/ir_executor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/boa/vyper/ir_executor.py b/boa/vyper/ir_executor.py index e7b62b1a..571274d6 100644 --- a/boa/vyper/ir_executor.py +++ b/boa/vyper/ir_executor.py @@ -405,6 +405,9 @@ def executor(cls): def _wrap256(x): return x % 2**256 +def wrap256(x_str): + return f"(({x_str}) % 2**256)" + def _as_signed(x): return unsigned_to_signed(x, 256, strict=True) @@ -421,12 +424,12 @@ def funcname(self): return self._op.__module__ + "." + self._op.__name__ def _compile(self, x, y): - return f"_wrap256({self.funcname}({x}, {y}))" + return wrap256(f"{self.funcname}({x}, {y})") class SignedBinopExecutor(UnsignedBinopExecutor): def _compile(self, x, y): - return f"_wrap256({self.funcname}(_as_signed({x}), _as_signed({y})))" + return wrap256(f"{self.funcname}(_as_signed({x}), _as_signed({y}))") # for binops, just use routines from vyper optimizer @@ -455,7 +458,7 @@ class Sar(IRExecutor): def _compile(self, bits, val): # wrap256 to get back into unsigned land - return f"_wrap256(_as_signed({val}) >> {bits})" + return wrap256(f"_as_signed({val}) >> {bits}") @executor @@ -465,7 +468,7 @@ class Shl(IRExecutor): _type: type = int def _compile(self, bits, val): - return f"_wrap256({val} << {bits})" + return wrap256(f"{val} << {bits}") @executor