`MultiInvoker` and `Manager` orders execution can be DOS in key moments if AAVE/Compound utilization is at 100%
The protocol's DSU wrapper relies on AAVE/Compound reserves, which can be fully utilized, causing withdrawals to revert. This blocks MultiInvoker and Manager orders that require unwrapping DSU to USDC, allowing an attacker to delay stop-loss or take-profit execution and cause user losses.
Source: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/16
Found by
panprog
Summary
Perennial contracts rely on the DSU token, which is essentially a wrapper for the USDC token. There are 2 in-scope implementations of DSU wrappers (reserve) which use part of the protocol reserves to deposit into external protocols (AAVE and Compound). Any time the protocol tries to unwrap (redeem) from the reserve (basically convert DSU to USDC), some funds are withdrawn from the AAVE or Compound.
The issue is that both AAVE and Compound allow to withdraw only the difference between the pool's supply and debt. This means that the withdrawal operation might revert in case of 100% utilization (supply ~= debt). This can happen by itself (and has happened in the past during some periods) or be intentionally forced by anyone by temporarily taking out all available AAVE/Compound funds as a debt, and then later repaying it to DOS certain operations to Perennial users.
In particular, all MultiInvoker and Manager withdrawals with unwrap flag set are vulnerable to this DOS. Each MultiInvoker or Manager action charges interfaceFee by withdrawing it from user's market balance and if unwrap flag is set, it's converted to USDC via batcher or reserve (if batcher is not set or empty). Since this conversion to USDC will revert in reserve, entire MultiInvoker or Manager transaction will revert as well. The most impactful operation seems to be the stop loss or take profit orders execution - attacker can monitor the MultiInvoker and Manager limit orders and when the stop loss price is near, execute this attack to delay the execution of these orders until the price becomes much worse, thus users will lose funds due to delay in their orders execution, getting much worse price than what they could get if not for the attack.
Root Cause
MultiInvoker charges interface fee in _update:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial-extensions/contracts/MultiInvoker.sol#L241-L242
_chargeFee unwraps DSU if unwrap is set to true:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial-extensions/contracts/MultiInvoker.sol#L310
_unwrap redeems from reserve:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial-extensions/contracts/MultiInvoker.sol#L370
redeem allocates:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/emptyset-mono/packages/emptyset-reserve/contracts/reserve/ReserveBase.sol#L81
_allocate calls _update to allocate/deallocate to match allocated amount to target amount according to strategy:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/emptyset-mono/packages/emptyset-reserve/contracts/reserve/ReserveBase.sol#L137
reserve withdraws from AAVE when allocating:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/emptyset-mono/packages/emptyset-reserve/contracts/reserve/strategy/AaveV3FiatReserve.sol#L66-L67
reserve withdraws from Compound when allocating:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/emptyset-mono/packages/emptyset-reserve/contracts/reserve/strategy/CompoundV3FiatReserve.sol#L61-L62
The same happens in Manager:
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial-order/contracts/Manager.sol#L196
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial-order/contracts/Manager.sol#L218
Internal pre-conditions
- Reserve uses either AAVE or Compound strategy
Reserve.allocationis not 0- User has created a
MultiInvokerorManagerorder withinterfaceFee.unwraporinterfaceFee2.unwrapset to true.
External pre-conditions Market price is within the order's execution range
Attack Path
- Attacker empties the
batcherif it's set inMultiInvokerandManagerand not empty. Exact steps depend on the batcher implementation which is out of scope, but should be possible according to current implementation (depositing large amount of USDC tobatcher, then immediately withdrawing it). Alternatively (if not possible), this should be additional pre-condition (nobatcherset orbatcheris empty). - Attacker deposits some token other than
USDCinto AAVE/Compound and takes outUSDCdebt to make AAVE/CompoundUSDCbalance almost 0. Alternatively, this can happen by itself (and has happened in the past), in such case this is additional external pre-condition. - Attacker waits for some time, taking out more debt if needed to keep AAVE/Compound
USDCbalance close to 0. - All this time
MultiInvokerandManagerorders execution is blocked - Once the price is far enough from where it was, attacker repays the debt and withdraws amount supplied to AAVE/Compound
Impact
- User order is executed at a much worse price
- Or position is liquidated (in case the order was a stop-loss and price moved beyound liquidation price)
- Or user order is not executed (in case the order is take profit and the price had moved away from the execution range)
In all 3 cases user losses funds.
This attack can be intentionally caused by attacker, or can happen by itself (but much less probable). If it is caused by attacker, this is then mostly a griefing attack as there is no profit for the attacker, although the attacker might be a maker and want to avoid closure of the large position which has an order in MultiInvoker.
The same issue also causes all user attempts to exit DSU to USDC revert for some time, including MultiInvoker withdrawal orders (but probably less severe as not as time-critical as positional orders execution).
PoC Not needed
Mitigation
It's probably impossible to do anything in such circumstances to convert DSU to USDC, however it's still possible to keep orders execution, keeping all funds in DSU. So one possible mitigation is to force all interface fee to be in DSU only (so remove the unwrap field from interface fee). Alternatively, if some interfaces only support USDC, maybe accumulate their fee in DSU and let them manually claim USDC if needed (so that it's not time-critical and can be done when unwrapping is available again)
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/461
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the protocol's withdrawal logic depends on external lending pools that can be fully utilized, causing reverts when trying to unwrap DSU to USDC.
Impact
User orders may execute at a much worse price, positions could be liquidated, or orders may not execute at all, causing financial loss; the attack is mostly griefing with no direct profit for the attacker.
What the attacker needed
Reserve uses AAVE or Compound strategy; Reserve allocation is not zero; User order has unwrap flag set; Market price within execution range
The fix
The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/461
How it was found
- Attacker empties the batcher if it is set and not empty.
- Attacker deposits a non-USDC token into AAVE/Compound and borrows USDC to make the USDC balance almost zero.
- Attacker waits, taking more debt if needed to keep the USDC balance near zero.
- During this time, MultiInvoker and Manager orders execution is blocked.
- Once the price moves far enough, attacker repays the debt and withdraws the supplied amount.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The protocol keeps some of its stablecoin in lending pools like AAVE and Compound to earn interest. If those pools have no free funds (because everything is lent out), the protocol cannot take its money back when needed. An attacker can borrow all available funds to make this happen, blocking users from executing important trades.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.