Section 5 of 18

Build
+15 Lynx

Vault: Deposit and First-Depositor Defense

What You Are Building

Two things in one section. The public deposit() flow that lets users put underlying into the vault. And the override of _issueSharesForAmount and _shareValue from section 4 that closes the first-depositor inflation attack at the math layer.

The deposit flow is mostly bookkeeping: validate inputs, compute shares from the math, mint, update totalIdle, pull tokens. The interesting part is the order. Pull tokens last, after every state change. The interesting fix is the override: virtual-offset shares, the modern best practice that Yearn V3 inherited from OpenZeppelin's ERC-4626.

Your Code

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

Sign up free — keep reading + earn 15 Lynx

Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.

Sign up free to continue

Already have an account? Log in