You are building an ERC-4626 yield vault. What design and security issues do you consider?
What the interviewer wants to hear
- Share price inflation or donation attack on empty vaults; virtual shares or seed deposit
- Rounding always in favour of the vault
- Accurate totalAssets that cannot be manipulated, including strategy losses
- Token quirks: fee-on-transfer, rebasing, decimals
- Strategy risk, withdrawal limits, reentrancy, and invariant tests
Model answer
The first issue is the inflation or donation attack: an attacker deposits 1 wei, donates a large amount, and later depositors receive zero shares. I use OpenZeppelin's virtual shares with a decimals offset, and also seed the vault with an initial deposit. Rounding must always favour the vault, so deposit and redeem round down for the user, and mint and withdraw round up. totalAssets must be accurate and hard to manipulate: if it reads a pool spot price or a balance anyone can donate to, the share price can be pushed. I handle strategy losses honestly instead of hiding them, and set withdrawal limits through maxWithdraw when liquidity is locked. I decide which tokens are supported and block fee-on-transfer or rebasing ones if not handled. Finally I add reentrancy guards around external strategy calls and write invariant tests, such as "shares never become worth more than the assets backing them".
Can you answer it under time pressure?
Take a timed hard round and get scored on every answer.
More hard Blockchain Developer questions
- You are designing a new lending protocol. What are the biggest security risks and how do you address them?
- Why have cross-chain bridges been a common target for large hacks, and how would you design a safer cross-chain system?
- What is MEV, and how would you protect your protocol's users from harmful MEV?
- How do you prepare a codebase for a security audit, and what happens after the audit?
- How do you decide what logic and data should live on chain versus off chain in a dApp?
- Your protocol is being exploited right now on mainnet. What do you do in the first hour and afterwards?
- How does EIP-7702 change assumptions that smart contracts and dApps make about EOAs, and what would you change in your code?
- How do you make sure an upgrade to a proxy-based contract does not corrupt storage or break the system?
- Your team wants to deploy the same protocol to five EVM chains, including L2s. What can go wrong and how do you prepare?