cancelDepositRequest() always reverts due to modifying FenwickTree with wrong index
The cancelDepositRequest function uses the latest price checkpoint index instead of the request's timestamp index when modifying the Fenwick tree, causing an out-of-bounds revert. This prevents users from cancelling their pending deposits.
Source: https://github.com/sherlock-audit/2025-07-mellow-flexible-vaults-judging/issues/246
Found by
0rpse, 0x23r0, 0xDLG, 0xRaz, 0xShoonya, 0xc0ffEE, 0xfocusNode, 8olidity, Arav, Cybrid, Pexy, Sabit97, algiz, blockace, boredpukar, ccvascocc, d4r3_w0lf, dimulski, freeking, hunt1, jah, kazan, komane007, lodelux, maigadoh, sheep, tedox, teoslaf1
Summary
In DepositQueue:cancelDepositRequest() , the code uses the latest price checkpoint instead of index when attempting to remove a user’s pending deposit from the Fenwick tree.
Because the timestamp-based request array has length < price, the index is out of bounds and the function always reverts, making it impossible for depositors to cancel their queued deposits.
Root Cause
The DepositQueue:cancelDepositRequest() calls:
(bool exists, uint32 timestamp, uint256 index) = $.prices.latestCheckpoint(); //@audit index is actually the price
..
$.requests.modify(index, -int256(assets)); //@audit priceD18 instead of index will result in IndexOutOfBounds error
Here, $.prices is the oracle-price checkpoint trace, not the timestamp trace that indexes the $.requests Fenwick tree. As a result, the retrieved index does not corresponds to a valid slot in the $.requests, causing modify() to revert with IndexOutOfBounds.
Internal Pre-conditions
- At least one price report has been processed
- A user has a pending deposit and the request is still non-claimable
External Pre-conditions
None.
Attack Path
- User submits
deposit(..)and their funds are locked and recorded in$.requestOfand Fenwick tree - User calls
cancelDepositRequest(), but the function reverts and the user cannot cancel their deposit
Impact
Medium severity
- Users can’t cancel their own pending deposits, undermining basic UX and expected behaviour.
- Core cancellation functionality is broken, but funds aren’t stolen, just stuck until the queue processes.
PoC
- Add the following test to the
DepositQueue.t.sol:
function testPoC_CancelDepositRequest_WrongIndex_Reverts() external {
Deployment memory deployment = createVault(vaultAdmin, vaultProxyAdmin, assetsDefault);
DepositQueue queue = DepositQueue(addDepositQueue(deployment, vaultProxyAdmin, asset));
IOracle.SecurityParams memory securityParams = deployment.oracle.securityParams();
/// @dev push a report to set the initial price
// Just pushing a price is not enough, since the report can't be accepted. We need to warp the time to set a valid initial price.
vm.warp(block.timestamp + Math.max(securityParams.timeout, securityParams.redeemInterval));
pushReport(deployment.oracle, IOracle.Report({asset: asset, priceD18: 1e18}));
address user1 = vm.createWallet("user").addr;
uint256 amount1 = 5 ether;
makeDeposit(user1, amount1, queue);
assertEq(queue.claimableOf(user1), 0, "Claimable amount should be zero before deposit");
(, uint256 assets1) = queue.requestOf(user1);
assertEq(assets1, amount1, "Assets should match the deposited amount");
vm.prank(user1);
vm.expectRevert("IndexOutOfBounds()");
queue.cancelDepositRequest();
}
- Execute with:
forge test --mt testPoC_CancelDepositRequest_WrongIndex_Reverts --fork-url https://eth-mainnet.g.alchemy.com/public --gas-limit 10000000000000000 --fork-block-number 22730425 -vvv
Mitigation
Instead of using the index returned from the prices.latestCheckpoint(), use the index that corresponds to the user's request timestamp.
This could be achieved by modifying the cancelDepositRequest():
function cancelDepositRequest() external nonReentrant {
address caller = _msgSender();
DepositQueueStorage storage $ = _depositQueueStorage();
Checkpoints.Checkpoint224 memory request = $.requestOf[caller];
uint256 assets = request._value;
if (assets == 0) {
revert NoPendingRequest();
}
address asset_ = asset();
- (bool exists, uint32 timestamp, uint256 index) = $.pric- es.latestCheckpoint();
+ (bool exists, uint32 timestamp, ) = $.prices.lates+ tCheckpoint();
if (exists && timestamp >= request._key) {
revert ClaimableRequestExists();
}
delete $.requestOf[caller];
IVaultModule(vault()).riskManager().modifyPendingAssets(asset_, -int256(uint256(assets)));
+ uint256 index = _timestamps().lowerLookup(reque+ st._key);
$.requests.modify(index, -int256(assets));
TransferLibrary.sendAssets(asset_, caller, assets);
emit DepositRequestCanceled(caller, assets, request._key);
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/mellow-finance/flexible-vaults/pull/7/files
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
The code retrieves the index from the price checkpoint trace instead of the timestamp trace that indexes the requests Fenwick tree, leading to an invalid index.
Impact
Users cannot cancel their pending deposits, breaking core cancellation functionality, though funds are not stolen and remain stuck until the queue processes.
What the attacker needed
At least one price report processed; User has a pending deposit; Request is not yet claimable
The fix
The protocol team fixed this issue by using the index corresponding to the user's request timestamp instead of the price checkpoint index.
How it was found
- User submits a deposit, locking funds and recording the request in the Fenwick tree.
- User calls cancelDepositRequest, but the function reverts due to an out-of-bounds index.
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 smart contract lets users queue deposits and later cancel them. The cancel function mistakenly uses a number from the price history instead of the correct position in the queue, so it always fails and users cannot cancel.
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.