https://github.com/Cyfrin/2024-11-giving-thanks/blob/main/src/CharityRegistry.sol#L27-L30
https://github.com/Cyfrin/2024-11-giving-thanks/blob/main/src/GivingThanks.sol#L22
The function CharityRegistry::isVerified
is intended to check if a charity address has been verified by the CharityRegistry admin. However, a vulnerability exists in this function's logic where it instead checks for resgistered charities. The misleading function is then used in GivingThanks::donate
, which should prevent donors from donating to an unverified charity. Because of this vulnerability, users can register themselves, or a malicious address, and potentially mislead donors into thinking that a charity is verified, when in reality it is not, having that donor donate funds to that malicious address.
The contract CharityRegistry
has two mappings which handle which charity address has been registered, and which charity address has been verified:
Furthermore, any charity/user can register a charity, so that the admin of the CharityRegistry
contract can call on verifyCharity
to verify the given charity.
To check if a charity has been verified, the CharityRegistry
contract has provided a function isVerified
. However a serious vulnerability lies within this function due to a check on the wrong mapping. This function should be using the verifiedCharities
but instead uses registeredCharities
, which is highlighted below:
If a user/charity register themselves and the admin does NOT verify them, the isVerified
function will return true
, despite verifiedCharities[charity]
returning false.
This vulnerability becomes more problematic because of its use in the GivingThanks::donate
function as seen below:
The donate
function SHOULD prevent users from being able to donate to unverified charities, but because CharityRegistry::isVerified
checks the mapping of registeredCharities
and not verifiedCharities
, donors can donate to any "charity" address, so long as they or another user registers that address.
Likelihood: High/Medium
Severity: High/Medium
Because the isVerified
function checks the registeredCharities
and that any user can register themselves or another address, funds from unsuspecting donors could be sent to potentially malicious actors, believing those actors to be verified.
Please add the following test under test/GivingThanks.t.sol
:
And then run the following command:
Manual Review
In order to fix this issue, please change the CharityRegistry::isVerified
function to the following:
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.