Vault vulnerable to inflation attack risking depositors losing their deposits #295
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-848
grade-b
Q-86
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
satisfactory
satisfies C4 submission criteria; eligible for awards
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Lines of code
https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultERC4626.sol#L202
https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultV2.sol#L359
Vulnerability details
Impact
The current vault implementation
ReaperVaultERC4626
is vulnerable to inflation attacks [0] risking depositors losing their deposits.Proof of Concept
We demonstrate the attack using an empty vault with a TVL cap of 100 ether. A malicious depositor deposits 1 wei of the underlying to the vault to mint 1 share.
While observing the mempool for a large deposit of a legitimate user, the attacker transfers the same amount of the underlying token directly to the vault before the legitimate user deposits.
Once the legitimate user deposits and the vault calculates the amount of shares, the transfer of the attacker will have inflated the share price effectively rendering the legitimate users' deposit worthless because the number of shares a user gets is rounded down.
See [1] for a detailed breakdown of the attack and proposed mitigations.
POC https://gist.github.com/alpeware/52f27b1de2dfd648ac6232925d0c18e6#file-inflationattack-t-sol
Snippet -
Logs https://gist.github.com/alpeware/52f27b1de2dfd648ac6232925d0c18e6#file-log-txt
Tools Used
Foundry
ERC4626 Property Tests
Recommended Mitigation Steps
Use virtual shares and assets to mitigate inflation attacks as originally pioneered by YieldBox [2].
See OZ implementation for an example implementation -
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol
QA feedback
ReaperVaultERC4626
implementation does not comply with theEIP-4626
spec [3] sinceassets
andshares
are approximate values due to loss of precision when they should be exact.withdraw
sends exactly assets of underlying tokensmint
Mints exactly shares Vault sharesReferrences
[0] OpenZeppelin/openzeppelin-contracts#3706
[1] https://gist.github.com/Amxx/ec7992a21499b6587979754206a48632
[2] https://github.com/boringcrypto/YieldBox/blob/107eb8cb9d0bc686181b842d8c74659913603937/contracts/YieldBoxRebase.sol
[3] https://eips.ethereum.org/EIPS/eip-4626
The text was updated successfully, but these errors were encountered: