The EggVault.depositEgg
function can be front-run by a malicious actor to steal NFTs that users intend to deposit, by designating themselves as the depositor.
The depositEgg
function in EggVault.sol
is declared public
and takes a depositor
address as an argument:
The intended deposit flow is via the EggHuntGame.depositEggToVault
function, which atomically transfers the NFT to the vault and then calls EggVault.depositEgg
. However, a user might mistakenly first transfer their NFT directly to the EggVault
contract and then call EggVault.depositEgg
themselves.
This two-step process (transfer then call depositEgg
) opens a window for a front-running attack:
A legitimate user transfers their NFT (e.g., tokenId 123) to the EggVault
contract address.
The user then submits a transaction calling depositEgg(123, userAddress)
.
An attacker observing the mempool sees this transaction.
The attacker copies the transaction data, replaces userAddress
with attackerAddress
, and submits their own transaction calling depositEgg(123, attackerAddress)
with a higher gas price.
The attacker's transaction is mined first, registering the attacker as the eggDepositor
for tokenId 123.
The attacker can now call withdrawEgg(123)
to transfer the NFT to themselves.
Users can permanently lose their NFTs if they attempt to deposit them directly into the vault instead of using the EggHuntGame.depositEggToVault
function, due to this front-running vulnerability.
Manual Review
Restrict the depositEgg
function so that it can only be called by the EggHuntGame
contract. This ensures that deposits only happen through the intended, secure EggHuntGame::depositEggToVault
flow.
Add a state variable in EggVault
to store the EggHuntGame
contract address. This should ideally be set immutably in the constructor or with a dedicated setter function with appropriate access control.
Add an inline require statement at the beginning of the depositEgg
function to check the caller:
This change enforces that only the EggHuntGame
contract can dictate the depositor, eliminating the front-running vulnerability.
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.