Skip to content

Commit

Permalink
Fix multiplication overflow throw because of non-existing short-circu…
Browse files Browse the repository at this point in the history
…it boolean expressions evaluation in Solidity Assembly
  • Loading branch information
k06a committed Oct 19, 2019
1 parent 7061ea9 commit 8724783
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/jug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ contract Jug is DSNote {
x := div(xxRound, b)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
if iszero(iszero(x)) {
if iszero(eq(div(zx, x), z)) { revert(0,0) }
}
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, b)
Expand Down
4 changes: 3 additions & 1 deletion src/pot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ contract Pot is DSNote {
x := div(xxRound, base)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
if iszero(iszero(x)) {
if iszero(eq(div(zx, x), z)) { revert(0,0) }
}
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, base)
Expand Down

0 comments on commit 8724783

Please sign in to comment.