Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/halmos/bitvec.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ def addmod(
assert size == modulus.size

if self.is_concrete and other.is_concrete and modulus.is_concrete:
if modulus.value == 0:
return modulus
return HalmosBitVec((self.value + other.value) % modulus.value, size=size)

# to avoid add overflow; and to be a multiple of 8-bit
Expand Down Expand Up @@ -762,6 +764,8 @@ def mulmod(
assert size == modulus.size

if self.is_concrete and other.is_concrete and modulus.is_concrete:
if modulus.value == 0:
return modulus
return HalmosBitVec((self.value * other.value) % modulus.value, size=size)

# to avoid mul overflow
Expand Down
2 changes: 2 additions & 0 deletions tests/test_sevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def byte_of(i, x):
(o(EVM.SMOD), [x, BV(0)], BV(0)),
(o(EVM.SMOD), [x, BV(1)], BV(0)),
(o(EVM.ADDMOD), [BV(4), BV(1), BV(3)], BV(2)),
(o(EVM.ADDMOD), [BV(4), BV(1), BV(0)], BV(0)),
(o(EVM.ADDMOD), [x, y, BV(0)], BV(0)),
(o(EVM.ADDMOD), [x, y, BV(1)], BV(0)),
(
Expand Down Expand Up @@ -229,6 +230,7 @@ def byte_of(i, x):
BV(1),
),
(o(EVM.MULMOD), [BV(5), BV(1), BV(3)], BV(2)),
(o(EVM.MULMOD), [BV(5), BV(1), BV(0)], BV(0)),
(o(EVM.MULMOD), [x, y, BV(0)], BV(0)),
(o(EVM.MULMOD), [x, y, BV(1)], BV(0)),
(
Expand Down