Open sherlock-admin opened 1 year ago
Duplicate with #173 . We don't yet know how to fix it.
Fix, added depositRequest: https://github.com/derbyfinance/derby-yield-optimiser/pull/227
Fix, added depositRequest: derbyfinance/derby-yield-optimiser#227
The change doesn't close the surface: an attacker will make a deposit beforehand (so that depositRequestPeriod
will be fixed in the past as of time of attack) and then wait for the appropriate time to invest at an outdated exchangeRate
when it's profitable as described.
The same looks to be applicable to withdrawalRequest()
just before rebalancing that is known to produce a loss. withdrawalRequest()
will use already outdated exchangeRate
to fix the payout.
hyh
high
Current period profit can be extracted from the Vault by front running state change before exchange rate recalculation
Summary
Every period
exchangeRate
recalculation can be estimated in advance and this can be used to extract funds from the Vault by depositing right before rebalances with big enough positive effects, earning this period profit without taking the risk.Vulnerability Detail
exchangeRate
can be estimated based on the performance of the underlying pools, all of which are public.Since
exchangeRate
is recalculated and stored during rebalancing only and old rate is used for deposits until then, it's possible to extract value from the Vault.Bob the attacker can monitor P&L of the Vault's pools invested and, whenever cumulative realized profit exceeds transaction expenses threshold, do deposit right before rebalancing while
State.Idle
and withdraw the funds right after it. Bob might want to front-run Vault State change or just deposit on observing the accumulated profit.Even if this be paired with some delays, it is still be low risk / big reward operation for Bob as profit is guaranteed, while risk can be controllable (he can limit the attack in size to be able to withdraw immediately) and aren't high overall (say having earned free 10% on his funds he will need to wait until next rebalancing in order to withdraw; most probably this 10% will cover the associated losses of being invested for one rebalancing period, if any).
POC steps for Bob are: 1) Monitor estimated P&L of rebalancing 2) If big enough Deposit just before rebalancing 3) Withdraw immediately after, if possible, otherwise exit on the next rebalancing
Impact
It is free profit for the attacker at the expense of depositors, whose already realized profit can be heavily dilluted this way.
Code Snippet
deposit() before rebalance with current exchangeRate() (which is factually outdated, but used):
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L101-L124
withdraw() right afterwards rebalancing with new exchangeRate() that is incresed by the realized profit:
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L126-L144
New
exchangeRate
is pushed during rebalancing either by XProvider or Guardian:https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L285-L301
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L275-L283
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L426-L433
Tool used
Manual Review
Recommendation
Consider tying the desposits and withdrawals to the next period
exchangeRate
, i.e. gather the requests for both during current period, while processing them all with the updated exchange rate on the next rebalance. Rebalancing period can be somewhat lowered (say to 1 week initialy, then possibly to 3-5 days) to allow for quicker funds turnaround.