Christmas Dinner

First Flight #31
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

`ChristmasDinner.getHost` function is unecessary

Description: The ChristmasDinner::getHost function is completely unecessary due to the fact that the ChristmasDinner::host statate variable is public and can be accessed by the contract directly ChristmasDinner::host. Also the dev comments say its primarily for testing, that's a bad practice and should be avoided. Don't put unecessary code in your contract just for "testing". Additionally the function also has a parameter address _host which is not used.

The same problem can be said about the function ChristmasDinner.getParticipationStatus, it is only being used once in the contract in ChristmasDinner::deposit and can be easily replaced just by using the ChristmasDinner::participant mapping.

Impact: Gas fees and messy code base

Proof of Concept:

None

Recommendation: Remove the function ChristmasDinner::getHost completely and just use the getter ChristmasDinner:this.host() or ChristmasDinner:host directly. Additionally the function is only used once in withdraw, usually only want to add a helper function when its used more than once in the contract.

function withdraw() external onlyHost {
- address _host = getHost();
+ address _host = this.host();
i_WETH.safeTransfer(_host, i_WETH.balanceOf(address(this)));
i_WBTC.safeTransfer(_host, i_WBTC.balanceOf(address(this)));
i_USDC.safeTransfer(_host, i_USDC.balanceOf(address(this)));
}
function deposit(address _token, uint256 _amount) external beforeDeadline {
if(!whitelisted[_token]) {
revert NotSupportedToken();
}
if(participant[msg.sender]){
balances[msg.sender][_token] += _amount;
IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount);
emit GenerousAdditionalContribution(msg.sender, _amount);
} else {
participant[msg.sender] = true;
balances[msg.sender][_token] += _amount;
IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount);
- emit NewSignup(msg.sender, _amount, getParticipationStatus(msg.sender));
+ emit NewSignup(msg.sender, _amount, participant[msg.sender]);
}
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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