The GivingThanks contract allows donations to charities that are registered but not verified, bypassing the intended verifyCharity requirement. This occurs due to a logic flaw in the isVerified function in CharityRegistry, which incorrectly checks the registeredCharities mapping instead of verifiedCharities.
Root Cause: In the GivingThanks contract, the donate function checks charity verification status via registry.isVerified(charity). However, in CharityRegistry, the isVerified function returns true for any registered charity, even if it’s not verified.
Expected Behavior: Only charities that are both registered and verified should pass the isVerified check in donate.
Current Behavior: Any registered charity (even unverified ones) will pass the isVerified check, allowing donations to potentially untrusted recipients.
This vulnerability enables donations to charities that have not been vetted by the intended verifyCharity process, undermining the verification requirement and allowing unverified charities to receive funds. This could lead to potential misallocation of donated funds or abuse by malicious actors registering as charities without undergoing verification.
Manual code review, Foundry
Update isVerified Logic: Modify isVerified in CharityRegistry to return true only if the charity is verified by checking verifiedCharities[charity]:
Running the line forge test -mt testCannotDonateToUnverifiedCharity with the following set up and test functions:
will output
This test demonstrates that a donor may make a donation to a unregistered charity.
Likelyhood: High, the function returns registered charities instead of verified ones. Impact: High, Any charities can be registered by anyone and will be declared as verified by this function bypassing verification.
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.