Submitted by Toshii, also found by immeas and 0xDING99YA.
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L282 https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L82 https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L329-L331 https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L87
When a user calls closePosition(..) -> _repay(..) on the Position contract, the function borrowBalanceOfPos(..) is used to calculate the amount that the user needs to repay. This repayment amount is equivalent to the amount the user borrowed (_borrowedAmount) plus their interest (_interest). To calculate this interest portion, the function multiplies the current borrowRate by the difference in number of blocks between when the user created the position and the current block timestamp. The issue arises because the borrowRate over the entire duration of the borrow is defined as: rate = CTokenInterface(bathToken).borrowRatePerBlock();. However, borrowRatePerBlock() is a function of total borrows and total supply for the cToken; thus, is not required to be the same over the entire duration of when the user takes it out of their position. This means the calculated repayment amount can potentially overshoot/undershoot the actual amount.
Steps:
This results in excess asset being swapped to quote, rather than what is needed for repayment.
Potentially keep track of changes in the supply/borrow state. However, this might not be worth the tradeoff in increased gas.
daoio (Rubicon) confirmed
HickupHH3 (judge) increased severity to High and commented:
