The withdraw()
function doesn't implement CEI (Check-Effect-Interaction) pattern, causing the function vulnerable to Reentrancy Attack.
Once Ram
is selected, the function killRavana()
is now accessible, and once the Ravana
dies, the chosen Ram
can then proceed to take the money presented to him in the totalAmountGivenToRam
.
The withdraw()
implements CIE, which could let an attacker call it multiple times while inside the receive() or fallback() function inside the attacking contract, making it always stop on every successful transfer then repeat the function call and won't change the totalAmountGivenToRam
variable.
The money that the Dussehra.sol contract holds could be drained by the attack.
Manual Analysis
Slightly modify the pattern to use a best practice of CEI, like the code below.
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.