Open code423n4 opened 2 years ago
Agreed. This is being changed to:
function _updateDistributableXDEFI() internal returns (int256 changeInDistributableXDEFI_) {
uint256 xdefiBalance = IERC20(xdefi).balanceOf(address(this));
uint256 previousDistributableXDEFI = distributableXDEFI;
unchecked {
uint256 currentDistributableXDEFI = xdefiBalance > totalDepositedXDEFI ? xdefiBalance - totalDepositedXDEFI : uint256(0);
if (currentDistributableXDEFI == previousDistributableXDEFI) return int256(0);
// NOTE: Max XDEFI is 240M (with 18 decimals), so this can never over or underflow.
changeInDistributableXDEFI_ = _toInt256Safe(distributableXDEFI = currentDistributableXDEFI) - _toInt256Safe(previousDistributableXDEFI);
}
}
In release candidate contract, _updateXDEFIBalance
has been more aptly renamed to _updateDistributableXDEFI
, where distributableXDEFI
is not written if currentDistributableXDEFI == previousDistributableXDEFI
.
seems to be resolved, valid finding
Handle
WatchPug
Vulnerability details
Storage writes (
SSTORE
) todistributableXDEFI
may not be needed whenpreviousDistributableXDEFI == currentDistributableXDEFI
, therefore the code can be reorganized to save gas from unnecessary storage writes.https://github.com/XDeFi-tech/xdefi-distribution/blob/3856a42df295183b40c6eee89307308f196612fe/contracts/XDEFIDistribution.sol#L330-L336
Recommendation
Change to: