code-423n4 / 2021-10-union-findings

0 stars 0 forks source link

Lack of precision in wadDiv #109

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

pants

Vulnerability details

The function : function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) { uint256 halfB = b / 2;

    return (halfB + a * WAD) / b;
}

could be:

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

That is more numeric precise and gas efficient.

GalloDaSballo commented 3 years ago

Agreed as you always wanna run division last to avoid integer rounding