Dussehra::withdraw
can be reentered by a malicious contract if it has been selected as Ram.
Dussehra::withdraw
does not follow the CEI (checks-effects-interactions) pattern.
Consequently, a malicious Ram can reenter the function.
This is demonstrated by the following code:
A malicious contract can witdraw the exact multiple(s) of the intended reward amount (totalAmountByThePeople / 2
) from the Dussehra
contract.
However, there is but a slim possibility for this to happen, as
the malicious contract needs to be selected as Ram for the event, and
the Dussehra
contract needs to have at least twice the indended reward amount on its ETH balance. This can only happen under special circumstances:
-- if users keep calling Dussehra::enterPeopleWhoLikeRam
after Ravan has been killed (Dussehra::KillRavana
successfully executed), and/or
-- users send ETH directly to Dussehra
.
It is very unlikely that enough amount (totalAmountByThePeople / 2
) will be collected this way.
However, if any meaningful amount X
ends up in the contract this way but this X
it is less than totalAmountByThePeople / 2
, the attacker can send an amount oftotalAmountByThePeople / 2 - X
ETH to Dussehra
to extract an extra profit of X
.
Manual review, Foundry.
To prevent possible reentrancy attacks, perform the following modifications in Dussehra
:
The `withdraw` function sends the given amount to Ram. If the attacker calls the `withdraw` function again before the state variable is changed, the function will revert because there are no more funds in the contract. This reentrancy has no impact for the protocol. It is recommended to follow the CEI pattern, but this is informational.
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.