Players transferring eggs to EggVault directly and calling EggVault::depositEgg to register themselves as the depositor without going through EggHuntGame::depositEggToVault are susceptible to frontrunning attack.
There are 2 ways a player can deposit their eggs into the EggVault.
Method 1
Player calls EggstravaganzaNFT::approve, approving EggHuntGame to transfer their eggs
Player calls EggHuntGame::depositEggToVault to transfer their eggs to the EggVault and register themselves as the depositor
Method 2
Player calls EggstravaganzaNFT::transferFrom to transfer their eggs directly to EggVault
Player calls EggVault::depositEgg to register themselves as the depositor
Players unaware of the EggHuntGame::depositEggToVault function will use method 2 to deposit their eggs into the EggVault. Additionally, since EggVault::depositEgg is written to be called by anyone, this also misleads players to use method 2 to deposit their eggs into the EggVault. However, method 2 is vulnerable to frontrunning attack as shown below.
Player calls EggstravaganzaNFT::transferFrom to transfer their eggs directly to EggVault
Attacker calls EggVault::depositEgg to register themselves as the depositor
Player's call to EggVault::depositEgg to register themselves as the depositor will revert
Attacker calls EggVault::withdrawEgg to steal egg out of the EggVault
Impact: High, attacker can steal player's eggs from the vault
Likelihood: Medium, players must deposit eggs directly to Vault by calling EggVault::depositEgg instead of using EggHuntGame::depositEggToVault
Severity: High
Place the following code into EggHuntGameTest.t.sol and run using:
forge test --mt testFrontRunDepositEgg
Manual Review
Limit EggVault::depositEgg to be only callable by EggHuntGame. This will encourage players to deposit eggs using method 1.
Importantly, this will prevent players from depositing eggs using method 2 and prevents an attacker from stealing the eggs.
Front-running depositEgg allows deposit ownership hijacking.
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.