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

1 stars 0 forks source link

less gas using unchecked #162

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Tomio

Vulnerability details

Impact

Cheaper gas using unchecked in MathLib.sol

Proof of Concept

https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/libraries/MathLib.sol#L42

Tools Used

Remix

Recommended Mitigation Steps

example before:

function wDiv(uint256 a, uint256 b) public pure returns (uint256) {
        return ((a * WAD) + (b / 2)) / b;
    }

gas cost 22863

after

function wDiv(uint256 a, uint256 b) public pure returns (uint256) {

        unchecked{
        return ((a * WAD) + (b / 2)) / b;
        }

gas cost 22205

0xean commented 2 years ago

dupe of #177