Closed code423n4 closed 2 years ago
Tomio
Cheaper gas using unchecked in MathLib.sol
https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/libraries/MathLib.sol#L42
Remix
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
dupe of #177
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:
gas cost 22863
after
gas cost 22205