Calling `requestRedeem` with `_msgSender() != owner` will lead to user's shares being locked in the vault forever
The requestRedeem function allows a user to redeem on behalf of another user who has granted allowance, but the internal _createRedeemRequest incorrectly updates lastRedeemRequestId for the owner instead of the receiver. This causes the shares to be permanently locked, as neither the owner nor the user can claim the redeemed assets.
Source: https://github.com/sherlock-audit/2024-03-amphor-judging/issues/85
Found by
Afriaudit, DMoore, Varun_05, den_sosnovskyi, fugazzi, sammy, zzykxx
Summary
The requestRedeem function in AsyncSynthVault.sol can be invoked by a user on behalf of another user, referred to as 'owner', provided that the user has been granted sufficient allowance by the 'owner'. However, this action results in a complete loss of balance.
Vulnerability Detail
The _createRedeemRequest function contains a discrepancy; it fails to update the lastRedeemRequestId for the user eligible to claim the shares upon maturity. Instead, it updates this identifier for the 'owner' who delegated their shares to the user. As a result, the shares become permanently locked in the vault, rendering them unclaimable by either the 'owner' or the user.
This issue unfolds as follows:
- The 'owner' deposits tokens into the vault, receiving vault shares in return.
- The 'owner' then delegates the allowance of all their vault shares to another user.
- When
epochId == 1, this user executes TherequestRedeem, specifying the 'owner''s address asowner, the user's address asreceiver, and the 'owner''s share balance asshares. - The internal function
_createRedeemRequestis invoked, incrementingepochs[epochId].redeemRequestBalance[receiver]by the amount ofshares, and settinglastRedeemRequestId[owner] = epochId. - At
epochId == 2, the user callsclaimRedeem, which in turn calls the internal function_claimRedeem, withownerset to_msgSender()(i.e., the user's address) andreceiveralso set to the user's address. - In this scenario,
lastRequestIdremains zero becauselastRedeemRequestId[owner] == 0(here,ownerrefers to the user's address). Consequently,epochs[lastRequestId].redeemRequestBalance[owner]is also zero. Therefore, no shares are minted to the user.
Proof of Code :
The following test demonstrates the claim made above :
function test_poc() external {
// set token balances
deal(vaultTested.asset(), user1.addr, 20); // owner
vm.startPrank(user1.addr);
IERC20Metadata(vaultTested.asset()).approve(address(vaultTested), 20);
// owner deposits tokens when vault is open and receives vault shares
vaultTested.deposit(20, user1.addr);
// owner delegates shares balance to user
IERC20Metadata(address(vaultTested)).approve(
user2.addr,
vaultTested.balanceOf(user1.addr)
);
vm.stopPrank();
// vault is closed
vm.prank(vaultTested.owner());
vaultTested.close();
// epoch = 1
vm.startPrank(user2.addr);
// user requests a redeem on behlaf of owner
vaultTested.requestRedeem(
vaultTested.balanceOf(user1.addr),
user2.addr,
user1.addr,
""
);
// user checks the pending redeem request amount
assertEq(vaultTested.pendingRedeemRequest(user2.addr), 20);
vm.stopPrank();
vm.startPrank(vaultTested.owner());
IERC20Metadata(vaultTested.asset()).approve(
address(vaultTested),
type(uint256).max
);
vaultTested.settle(23); // an epoch goes by
vm.stopPrank();
// epoch = 2
vm.startPrank(user2.addr);
// user tries to claim the redeem
vaultTested.claimRedeem(user2.addr);
assertEq(IERC20Metadata(vaultTested.asset()).balanceOf(user2.addr), 0);
// however, token balance of user is still empty
vm.stopPrank();
vm.startPrank(user1.addr);
// owner also tries to claim the redeem
vaultTested.claimRedeem(user1.addr);
assertEq(IERC20Metadata(vaultTested.asset()).balanceOf(user1.addr), 0);
// however, token balance of owner is still empty
vm.stopPrank();
// all the balances of owner and user are zero, indicating loss of funds
assertEq(vaultTested.balanceOf(user1.addr), 0);
assertEq(IERC20Metadata(vaultTested.asset()).balanceOf(user1.addr), 0);
assertEq(vaultTested.balanceOf(user2.addr), 0);
assertEq(IERC20Metadata(vaultTested.asset()).balanceOf(user2.addr), 0);
}
To run the test :
- Copy the above code and paste it into
TestClaimDeposit.t.sol - Run
forge test --match-test test_poc --ffi
Impact
The shares are locked in the vault forever with no method for recovery by the user or the 'owner'.
Code Snippet
Tool used
Manual Review Foundry
Recommendation
Modify _createRedeemRequest as follows :
- lastRedeemRequestId[owner] = epochId;
+ lastRedeemRequestid[receiver] = epochId;
Discussion
sherlock-admin3
1 comment(s) were left on this issue during the judging contest.
takarez commented:
invalid
sherlock-admin4
The protocol team fixed this issue in the following PRs/commits: https://github.com/AmphorProtocol/asynchronous-vault/pull/103
sherlock-admin3
The Lead Senior Watson signed off on the fix.
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
Impact
The shares are locked in the vault forever with no method for recovery by the user or the owner.
What the attacker needed
Owner has vault shares; owner approves another user to spend shares; vault is closed for deposits; epochs progress
The fix
The protocol team fixed this issue by updating lastRedeemRequestId for the receiver instead of the owner.
How it was found
- The owner deposits tokens into the vault and receives shares.
- The owner approves another user to spend all their vault shares.
- The user calls requestRedeem with the owner as owner, themselves as receiver, and the owner's share balance.
- The internal _createRedeemRequest increments redeemRequestBalance for the receiver but sets lastRedeemRequestId for the owner.
- After the epoch settles, the user calls claimRedeem, but lastRedeemRequestId for the user is zero, so no assets are claimed.
- The owner also calls claimRedeem, but their lastRedeemRequestId points to the epoch, yet the redeemRequestBalance for the owner is zero, so no assets are claimed.
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.
In a vault, users can let others act on their behalf. Here, when one user requests a redemption for another, the system records the request under the wrong person. Later, when trying to claim the redeemed assets, the system looks in the wrong place and finds nothing, so the shares are stuck forever.
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.