Initial vault deposits can be frontrun allowing attacker to steal entire deposit #360
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-848
grade-b
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
Lines of code
https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperVaultV2.sol#L331-L335
Vulnerability details
Impact
Attacker can steal initial deposits into the
ReaperVaultV2
contract by frontrunning.Proof of Concept
The first deposit (or any deposit where the
totalSupply
is 0) in aReaperVaultV2
contract mints shares equivalent to the amount of tokens being deposited. Every other deposit will mint according to:(_amount * totalSupply()) / freeFunds
.An attacker can take advantage of this logic as follows:
freeFunds
is also 101e18.100e18 * 1 / 101e18 = 0.9900990099009901
which is rounded down to 0.Although this logic is simplified to interacting with the deposit method directly, which is gated via
_atLeastRole(DEPOSITOR)
, this attack is still possible via opening troves.Opening a trove results in sending collateral to
ActivePool
:Which triggers a rebalance:
Which then makes a deposit into the vault:
As we can see, we can perform the above example in an indirect manner by observing troves to be opened in the mempool and frontrunning them by opening our own troves with 1 wei of collateral and sending a larger amount of collateral than the victims deposit directly to the vault contract.
It is further possible for the attacker to continue to steal additional deposits so long as they have the capital to maintain a vault contract balance greater than the current victim deposit, stealing every deposit until an
emergencyShutdown
is enacted.Recommended Mitigation Steps
There are two possible mitigation strategies which can be taken:
require(shares != 0, "No vault tokens minted")
.The text was updated successfully, but these errors were encountered: