code-423n4 / 2022-07-fractional-findings

0 stars 0 forks source link

`div by 0` if user got all the fractions #564

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-07-fractional/blob/8f2697ae727c60c93ea47276f8fa128369abfe51/src/modules/Migration.sol#L175-L214 https://github.com/code-423n4/2022-07-fractional/blob/8f2697ae727c60c93ea47276f8fa128369abfe51/src/modules/Migration.sol#L430-L482 https://github.com/code-423n4/2022-07-fractional/blob/8f2697ae727c60c93ea47276f8fa128369abfe51/src/modules/Migration.sol#L520-L529

Vulnerability details

Impact

If you got all the fractions you got a div 0 when _calculateContribution in the commit and migrateFractions functions

Tools Used

Manual Review

Recommended Mitigation Steps

Add if that returns _totalEth if _totalFractions == _lastTotalSupply

    function _calculateTotal(
        uint256 _scalar,
        uint256 _lastTotalSupply,
        uint256 _totalEth,
        uint256 _totalFractions
    ) private pure returns (uint256) {
        if (_totalFractions == _lastTotalSupply) {
            return _totalEth;
        }
        return
            (_totalEth * _scalar) /
            (_scalar - ((_totalFractions * _scalar) / _lastTotalSupply));
    }
mehtaculous commented 2 years ago

Duplicate of #155