The donate function serves a crucial role in facilitating the donation process while providing donors with a tangible reward for their contribution.
In the current donate function, the interaction with the charity (sending Ether) happens before the state is updated:
solidity
Problem: When a smart contract makes an external call (e.g., sending Ether) before completing state changes, the receiving contract can call back the original contract before it finishes its execution.
Consequence: An attacker can repeatedly invoke the function, leading to unintended or unauthorized operations, such as multiple Ether withdrawals.
Problem: Updating the state after performing an external interaction can lead to state inconsistencies if the external call fails.
Consequence: The contract's state may not reflect the actual transaction status, potentially causing logical errors.
Problem: Failing to follow the CEI pattern can expose the contract to various security vulnerabilities, potentially undermining user trust in the system.
Consequence: Loss of user trust and potential financial losses.
manual review
Here’s how you can refactor the function to follow the CEI pattern:
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.