sherlock-2025-07-mellow-m05
[M-05] cancelDepositRequest() always reverts due to modifying FenwickTree with wrong index
Summary
cancelDepositRequest함수로 대기중인 입금 요청을 취소할 수 있다. 펜윅 트리 역시 취소된 만큼 업데이트 되어야 한다. 그런데 펜윅 트리를 업데이트하기 위한 인덱스가 잘못되었다. 트랜잭션이 취소되거나 펜윅 트리가 잘못 업데이트될 수 있다.
Keyword
logic flaw, bug
Vulnerability
cancelDepositRequest를 호출하면 호출자의 대기중인 입금 요청을 취소할 수 있다. 입금 요청을 취소하면 펜윅 트리에 업데이트했던 총 입금액 정보도 업데이트 해야한다.
function cancelDepositRequest() external nonReentrant {
...
@> (bool exists, uint32 timestamp, uint256 index) = $.prices.latestCheckpoint();
...
@> $.requests.modify(index, -int256(assets));
...
}$.prices.latestCheckpoint() 로 조회한 index는 펜윅 트리의 인덱스가 아니라 조회한 가격을 기록한 체크포인트의 인덱스이다. 따라서 잘못된 인덱스의 펜윅 트리를 업데이트 하게 된다. 인덱스가 맞지 않으면 IndexOutOfBounds 에러로 트랜잭션이 취소된다.
Impact
입금 취소 기능을 사용할 수 없음
Mitigation
펜윅 트리의 인덱스를 조회하여 사용한다.
function cancelDepositRequest() external nonReentrant {
...
- (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);
}tags: bughunting, mellow, smart contract, solidity, severity medium, logic flaw