Skip to content
Business logic Audit finding Intermediate

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.

Afriaudit Follow with DMoore, Varun_05 and 4 others

Originally disclosed on Sherlock

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:

  1. The 'owner' deposits tokens into the vault, receiving vault shares in return.
  2. The 'owner' then delegates the allowance of all their vault shares to another user.
  3. When epochId == 1, this user executes The requestRedeem , specifying the 'owner''s address as owner, the user's address as receiver, and the 'owner''s share balance as shares.
  4. The internal function _createRedeemRequest is invoked, incrementing epochs[epochId].redeemRequestBalance[receiver] by the amount of shares, and setting lastRedeemRequestId[owner] = epochId.
  5. At epochId == 2, the user calls claimRedeem, which in turn calls the internal function _claimRedeem, with owner set to _msgSender() (i.e., the user's address) and receiver also set to the user's address.
  6. In this scenario, lastRequestId remains zero because lastRedeemRequestId[owner] == 0 (here, owner refers 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 :

Solidity
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 :

  1. Copy the above code and paste it into TestClaimDeposit.t.sol
  2. 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 :

Diff
-        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.

The original report as published on Sherlock, by Afriaudit. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. The owner deposits tokens into the vault and receives shares.
  2. The owner approves another user to spend all their vault shares.
  3. The user calls requestRedeem with the owner as owner, themselves as receiver, and the owner's share balance.
  4. The internal _createRedeemRequest increments redeemRequestBalance for the receiver but sets lastRedeemRequestId for the owner.
  5. After the epoch settles, the user calls claimRedeem, but lastRedeemRequestId for the user is zero, so no assets are claimed.
  6. 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.

More by Afriaudit

View all

2 more disclosed reports, best first.

More from Amphor

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.