The WeatherNftSol::requestMintWeatherNFT
function is marked payable and collects ETH from users as minting fees. However, the contract provides no mechanism for the owner (or any authorized party) to withdraw the accumulated ETH. As a result, all ETH sent to the contract remains permanently locked, preventing the project from accessing its minting revenue.
Missing Withdrawal Mechanism: Although the contract accepts ETH via a payable function, there is no owner-only withdrawal function.
No Fallback/Receive Handler: The contract lacks a fallback() or receive() function that could facilitate ETH recovery or forwarding.
Lost Revenue: Minting fees accumulate indefinitely with no way to retrieve them.
Operational Risk: Inability to withdraw funds undermines project sustainability and damages user trust.
This issue was found by using Aderyn and Slither.
Add a secure, owner-only withdrawal function that adheres to the checks-effects-interactions pattern. It should:
Verify that the contract’s balance is positive.
(If applicable) Update any relevant state variables before transferring funds.
Transfer ETH using a low-level call and revert on failure.
Emit an event for auditability.
Implement the withdrawEther function in WeatherNft.sol
and the corresponding EtherWithdrawn event in WeatherNftStore.sol
file.
To ensure that only the contract’s owner can withdraw Ether, follow these steps:
Declare and initialize the owner
Define a private owner
variable and set it to msg.sender
in the constructor so that the deployer becomes the owner.
Create the onlyOwner
modifier
Implement a modifier that checks require(msg.sender == owner, "Caller is not the owner");
and then runs the rest of the function.
Protect withdrawEther
Simply add onlyOwner
to the withdrawEther
function signature. This guarantees that any attempt to call it from a non-owner address will revert..
The contract collects funds for minting a WeatherNFT, but there is no function that allows the owner to withdraw these funds.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.