DeFiFoundrySolidity
16,653 OP
View results
Submission Details
Severity: high
Invalid

Critical Vulnerabilities in redeem Function: Division by Zero and Insufficient Balance Validation

1. Summary

The redeem function in the YieldTokenMock contract contains two critical vulnerabilities:

  1. A division by zero error in the price() function.

  2. Missing balance validation, allowing users to redeem more tokens than they own, potentially draining the contract's funds.


2. Vulnerability Details

  1. Division by Zero in price() Function

    • The price() function returns 0 when totalSupply() is 0.

    • This causes a division by zero in the _burn() calculation within the redeem function, leading to a runtime error that halts the transaction.

  2. Lack of Balance Validation in redeem

    • The redeem function does not validate whether the user has sufficient shares to redeem the requested _amount.

    • This allows users to redeem more than their proportional share of the underlying tokens, leading to a potential drain of the contract's funds.


3. Impact

  1. Division by Zero Impact:

    • The redeem function fails when price() returns 0, disrupting user operations.

  2. Balance Validation Impact:

    • Malicious users can exploit this lack of validation to withdraw more than their entitled share of the underlying asset, resulting in:

      • Financial loss for other users.

      • Complete depletion of the contract's funds.


4. Tools Used

  • Manual code review to analyze the logic of the redeem function and the price() function.

  • Test cases in a local development environment to confirm the behavior of the vulnerabilities.


5. Recommendations

  1. Fix Division by Zero in price() Function:

    • Update the price() function to revert if totalSupply() is 0:

      function price() public view returns (uint256) {
      require(totalSupply() > 0, "No tokens available to redeem");
      return (totalValue() * 10**decimals()) / totalSupply();
      }
  2. Add Balance Validation in redeem:

    • Ensure users can only redeem if they have enough shares to cover the _amount:

      function redeem(uint256 _amount, address _recipient) external {
      uint256 sharesToBurn = (_amount * 10**decimals()) / price();
      require(balanceOf(msg.sender) >= sharesToBurn, "Insufficient balance to redeem");
      _burn(msg.sender, sharesToBurn);
      underlying.safeTransfer(_recipient, _amount);
      }
Updates

Appeal created

inallhonesty Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.