Sparkn

CodeFox Inc.
DeFiFoundryProxy
15,000 USDC
View results
Submission Details
Severity: low
Valid

Skip sending token if percentage[i] is 0

Summary

There is no need to send an amount=0 token to an address. Check if the percentage[i] is 0 first, and if it is, skip sending tokens and it can save some gas.

Vulnerability Details

https://github.com/Cyfrin/2023-08-sparkn/blob/main/src/Distributor.sol#L146

uint256 winnersLength = winners.length; // cache length
for (uint256 i; i < winnersLength;) {
uint256 amount = totalAmount * percentages[i] / BASIS_POINTS; // Here check if percentages[i] is 0 and if it is, skip sending tokens
erc20.safeTransfer(winners[i], amount);
unchecked {
++i;
}
}

Impact

Waste gas

Tools Used

Manual review

Recommendations

Check if the percentage[i] is 0 first, and if it is, skip sending tokens and it can save some gas.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.