Raisebox Faucet

First Flight #50
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: high
Invalid

A better way to execute `RaiseBoxFaucet:mintFaucetTokens` function

Excessive function interaction may result in consuming more gasses than it could

Description

Since the _to parameter of RaiseBoxFaucet:mintFaucetTokens function will always be the contract itself, we don't need to give a choice to the owner to input any other address

function mintFaucetTokens(address to, uint256 amount) public onlyOwner {
if (to != address(this)) {
revert RaiseBoxFaucet_MiningToNonContractAddressFailed();
}
​
if (balanceOf(address(to)) > 1000 * 10 ** 18) {
revert RaiseBoxFaucet_FaucetNotOutOfTokens();
}
​
_mint(to, amount);
​
emit MintedNewFaucetTokens(to, amount);
}

Recommended Mitigation

If the _to parrameter is removed, we don't need the checks and the custom error of RaiseBoxFaucet_MiningToNonContractAddressFailed, we can also reduced the event emmition of MintedNewFaucetTokens so it only emits the amount

// -----------------------------------------------------------------------
// EVENTS
// -----------------------------------------------------------------------
​
...
​
- event MintedNewFaucetTokens(address indexed user, uint256 amount);
+ event MintedNewFaucetTokens(uint256 amount);
​
​
...
​
// -----------------------------------------------------------------------
// ERRORS
// -----------------------------------------------------------------------
​
...
​
- error RaiseBoxFaucet_MiningToNonContractAddressFailed();
​
...
​
- function mintFaucetTokens(address to, uint256 amount) public onlyOwner {
+ function mintFaucetTokens(uint256 amount) public onlyOwner {
- if (to != address(this)) {
- revert RaiseBoxFaucet_MiningToNonContractAddressFailed();
- }
​
- if (balanceOf(address(to)) > 1000 * 10 ** 18) {
+ if (balanceOf(address(this)) > 1000 * 10 ** 18) {
revert RaiseBoxFaucet_FaucetNotOutOfTokens();
}
​
- _mint(to, amount);
+ _mint(address(this), amount);
​
- emit MintedNewFaucetTokens(to, amount);
+ emit MintedNewFaucetTokens(amount);
}
​
Updates

Lead Judging Commences

inallhonesty Lead Judge 11 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.

Give us feedback!