sherlock-audit / 2024-06-new-scope-judging

1 stars 1 forks source link

ether_sky - The repayment process in the NFTPositionManager can sometimes be reverted #488

Open sherlock-admin4 opened 2 months ago

sherlock-admin4 commented 2 months ago

ether_sky

Medium

The repayment process in the NFTPositionManager can sometimes be reverted

Summary

Users can supply assets to the pools through the NFTPositionManager to earn rewards in zero tokens. Functions like deposit, withdraw, repay, and borrow should operate normally. However, due to an additional check, repayments might be reverted.

Vulnerability Detail

Here's the relationship between shares (s) and assets (a) in the Pool:

Numerical Example: Suppose there is a pool P where users borrow assets A using the NFTPositionManager.

  DataTypes.SharesType memory repaid = pool.repay(params.asset, params.amount, params.tokenId, params.data);

121:  uint256 currentDebtBalance = pool.getDebt(params.asset, address(this), params.tokenId);

123:  if (previousDebtBalance - currentDebtBalance != repaid.assets) {     revert NFTErrorsLib.BalanceMisMatch();   } }


This example demonstrates a `potential 1 wei mismatch` between `previousDebtBalance` and `currentDebtBalance` due to rounding in the calculations.
## Impact
This check seems to cause a `denial-of-service (DoS)` situation where `repayments` can fail due to small rounding errors. 
This issue can occur with various combinations of `borrow index`, `share amounts`, and `repaid assets`.
## Code Snippet
https://github.com/sherlock-audit/2024-06-new-scope/blob/c8300e73f4d751796daad3dadbae4d11072b3d79/zerolend-one/contracts/core/pool/utils/WadRayMath.sol#L77
https://github.com/sherlock-audit/2024-06-new-scope/blob/c8300e73f4d751796daad3dadbae4d11072b3d79/zerolend-one/contracts/core/pool/utils/WadRayMath.sol#L93
https://github.com/sherlock-audit/2024-06-new-scope/blob/c8300e73f4d751796daad3dadbae4d11072b3d79/zerolend-one/contracts/core/positions/NFTPositionManagerSetters.sol#L119-L125
## Tool used

Manual Review

## Recommendation
Either remove this check or adjust it to allow a `1 wei mismatch` to prevent unnecessary reversion of `repayments`.