sherlock-audit / 2023-12-arcadia-judging

19 stars 15 forks source link

anya - Insufficient Allowance Handling in withdraw Function and redeem in Tranche.sol #210

Closed sherlock-admin closed 9 months ago

sherlock-admin commented 9 months ago

anya

medium

Insufficient Allowance Handling in withdraw Function and redeem in Tranche.sol

Summary

The withdraw function in the provided code snippet does not explicitly check if the user's allowance is sufficient to cover the desired withdrawal amount before proceeding. This could lead to vulnerabilities and unexpected behaviour if the allowance is less than the requested shares.

Vulnerability Detail

function withdraw(uint256 assets, address receiver, address owner_)
          {
        ...
            uint256 allowed = allowance[owner_][msg.sender];

            if (allowed != type(uint256).max) allowance[owner_][msg.sender] = allowed - shares;
        }

    }

Impact

Code Snippet

https://github.com/sherlock-audit/2023-12-arcadia/blob/main/lending-v2/src/Tranche.sol#L208-L230

https://github.com/sherlock-audit/2023-12-arcadia/blob/main/lending-v2/src/Tranche.sol#L239-L260

Tool used

Manual Review

Recommendation

function redeem(uint256 shares, address receiver, address owner_)
    public
    override
    notLocked
    notDuringAuction
    returns (uint256 assets)
{
    if (msg.sender != owner_) {
        uint256 allowed = allowance[owner_][msg.sender];

        // Check for insufficient allowance
        if (allowed < shares) revert TrancheErrors.InsufficientAllowance();

        // Update allowance (preventing negative values)
        allowance[owner_][msg.sender] = allowed - shares;
    }

    // ... 
}
sherlock-admin2 commented 9 months ago

1 comment(s) were left on this issue during the judging contest.

takarez commented:

invalid

nevillehuang commented 9 months ago

Invalid, if insufficient allowance is assigned to user withdrawing, allowed-shares will underflow and revert, no explicit checks required