code-423n4 / 2022-01-elasticswap-findings

1 stars 0 forks source link

Shift rather than dividing with a power of 2 #92

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

0x0x0x

Vulnerability details

It costs less gas to shift than division. So rather than dividing by a power of 2, right shift can be used to save gas.

Occurrences


./libraries/MathLib.sol:43:        return ((a * WAD) + (b / 2)) / b;
./libraries/MathLib.sol:55:        return ((a + (n / 2)) / n) * n;
./libraries/MathLib.sol:67:        return ((a * b) + (WAD / 2)) / WAD;
./libraries/MathLib.sol:85:            uint256 x = y / 2 + 1;
./libraries/MathLib.sol:88:                x = (y / x + x) / 2;
0xean commented 2 years ago

dupe of #100