From 7061ea95a46e2e5700d61d52b4c2d3d86cc989f8 Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Sat, 19 Oct 2019 22:11:00 +0300 Subject: [PATCH] Simplify overflow check for squaring in rpow(x,n,base) --- src/jug.sol | 2 +- src/pot.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jug.sol b/src/jug.sol index 3d4e7207..44a6d22a 100644 --- a/src/jug.sol +++ b/src/jug.sol @@ -47,7 +47,7 @@ contract Jug is DSNote { let half := div(b, 2) // for rounding. for { n := div(n, 2) } n { n := div(n,2) } { let xx := mul(x, x) - if iszero(eq(div(xx, x), x)) { revert(0,0) } + if shr(x, 128) { revert(0,0) } let xxRound := add(xx, half) if lt(xxRound, xx) { revert(0,0) } x := div(xxRound, b) diff --git a/src/pot.sol b/src/pot.sol index 3df066ea..e8c31016 100644 --- a/src/pot.sol +++ b/src/pot.sol @@ -85,7 +85,7 @@ contract Pot is DSNote { let half := div(base, 2) // for rounding. for { n := div(n, 2) } n { n := div(n,2) } { let xx := mul(x, x) - if iszero(eq(div(xx, x), x)) { revert(0,0) } + if shr(x, 128) { revert(0,0) } let xxRound := add(xx, half) if lt(xxRound, xx) { revert(0,0) } x := div(xxRound, base)