The setEggNFT() function in the EggVault contract can be called at any time by the vault owner, allowing them to change the NFT contract address even after eggs have been deposited.
The setEggNFT() function has insufficient access controls:
This function can be called by the vault owner at any time to change the NFT contract address. This presents several serious issues:
The owner can point the vault to a malicious NFT contract after users have deposited eggs
This could enable the owner to steal all deposited NFTs by redirecting withdrawals
There's no initialization flag to prevent changing the NFT after the vault is in use
Impact: High. This vulnerability enables:
Complete theft of all NFTs by the vault owner
Ability to bypass all security measures in the system
No guarantee that deposited eggs remain linked to their original contract
Manual code review and "Proof of Code" conducted with the testNFTAddressChangeAttack() function:
Here's the recommended code for the setEggNFT function to fix the access control vulnerability:
The key improvements in this implementation:
Added an initialized boolean flag to ensure the function can only be called once
Added an event to provide transparency when the NFT address is set
Added a clear error message when attempting to initialize twice
This pattern, known as the "initialization pattern," ensures that critical parameters can only be set once, preventing the vault owner from changing the NFT contract after users have deposited their eggs. This is a simple but effective way to protect users from the vulnerability without introducing complex upgrade patterns.
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.