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

0 stars 0 forks source link

Unused named returns #144

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

Unused named returns increase contract size and gas usage at deployment.

https://github.com/XDeFi-tech/xdefi-distribution/blob/3856a42df295183b40c6eee89307308f196612fe/contracts/XDEFIDistribution.sol#L330-L335

function _updateXDEFIBalance() internal returns (int256 newFundsTokenBalance_) {
    uint256 previousDistributableXDEFI = distributableXDEFI;
    uint256 currentDistributableXDEFI = distributableXDEFI = IERC20(XDEFI).balanceOf(address(this)) - totalDepositedXDEFI;

    return _toInt256Safe(currentDistributableXDEFI) - _toInt256Safe(previousDistributableXDEFI);
}

newFundsTokenBalance_ is redundant as is never used.

Other examples include:

https://github.com/XDeFi-tech/xdefi-distribution/blob/3856a42df295183b40c6eee89307308f196612fe/contracts/XDEFIDistribution.sol#L337-L345

function _withdrawableGiven(uint96 units_, uint88 depositedXDEFI_, int256 pointsCorrection_) internal view returns (uint256 withdrawableXDEFI_) {
    return
        (
            _toUint256Safe(
                _toInt256Safe(_pointsPerUnit * uint256(units_)) +
                pointsCorrection_
            ) / _pointsMultiplier
        ) + uint256(depositedXDEFI_);
}

https://github.com/XDeFi-tech/xdefi-distribution/blob/3856a42df295183b40c6eee89307308f196612fe/contracts/XDEFIDistribution.sol#L156-L159

function withdrawableOf(uint256 tokenId_) public view returns (uint256 withdrawableXDEFI_) {
    Position storage position = positionOf[tokenId_];
    return _withdrawableGiven(position.units, position.depositedXDEFI, position.pointsCorrection);
}

https://github.com/XDeFi-tech/xdefi-distribution/blob/3856a42df295183b40c6eee89307308f196612fe/contracts/XDEFIDistribution.sol#L288-L291

function _toUint256Safe(int256 x_) internal pure returns (uint256 y_) {
    assert(x_ >= int256(0));
    return uint256(x_);
}
deluca-mike commented 2 years ago

Yup, good point. We will go with the option to assign return variables in order to keep the function prototype pattern/style consistent. However, this is not a gas optimization, but rather just informational.

deluca-mike commented 2 years ago

Duplicate #2