Improper code pattern in "Game.sol::withdrawWinnings" leading to a re-entrancy vulnerability.
The "Game.sol::withdrawWinnings" function is expected to allow the winner withdraw their winnings.
Howvever, the function is suscpetible to a re-entrancy attack due to not following the CEI pattern and as such, funds are at risk. The code transfers value to the caller first and then updates state, which is bad practice.
Likelihood:
This attack would occur when an attacker interacts with the protocol with a malicious contract that would re-enter the function before state is updated due to the bug.
Impact:
Impact 1 Due to this vulnerability, the protocol funds are at risk.
Impact 2
The below attacker contract shows how an attacker can interact with the game and position for an attack. Also attached is a test case showing how this would happen in real time.
The below code shows the proper implementation of the withdrawWinnings function, where state is first updated before the external interaction involving value.
We only audit the current code in scope. We cannot make speculation with respect to how this codebase will evolve in the future. For now there is a nonReentrant modifier which mitigates any reentrancy. CEI is a good practice, but it's not mandatory. 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.