Skip to content

Commit f71cd48

Browse files
committed
Simplify overflow check for squaring in rpow(x,n,base)
1 parent aaad4df commit f71cd48

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/jug.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ contract Jug is DSNote {
4747
let half := div(b, 2) // for rounding.
4848
for { n := div(n, 2) } n { n := div(n,2) } {
4949
let xx := mul(x, x)
50-
if iszero(eq(div(xx, x), x)) { revert(0,0) }
50+
if shr(128, x) { revert(0,0) }
5151
let xxRound := add(xx, half)
5252
if lt(xxRound, xx) { revert(0,0) }
5353
x := div(xxRound, b)

src/pot.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ contract Pot is DSNote {
8585
let half := div(base, 2) // for rounding.
8686
for { n := div(n, 2) } n { n := div(n,2) } {
8787
let xx := mul(x, x)
88-
if iszero(eq(div(xx, x), x)) { revert(0,0) }
88+
if shr(128, x) { revert(0,0) }
8989
let xxRound := add(xx, half)
9090
if lt(xxRound, xx) { revert(0,0) }
9191
x := div(xxRound, base)

0 commit comments

Comments
 (0)