Skip to content

Commit

Permalink
Simplify overflow check for squaring in rpow(x,n,base)
Browse files Browse the repository at this point in the history
  • Loading branch information
k06a committed Oct 19, 2019
1 parent aaad4df commit f71cd48
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/jug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(128, x) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, b)
Expand Down
2 changes: 1 addition & 1 deletion src/pot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(128, x) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, base)
Expand Down

0 comments on commit f71cd48

Please sign in to comment.