Merging tranches could make _loanTermination()
accounting incorrect
#69
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
H-01
primary issue
Highest quality submission among a set of duplicates
🤖_12_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/pools/Pool.sol#L516
Vulnerability details
Impact
In the
Pool
contract, when a loan is repaid or liquidated, a call to the Pool is made for accounting. The_loanTermination()
function is eventually invoked. This function uses theloanId
to determine the withdrawal queue to which the loan belongs. If the loan was issued after the last queue, it belongs entirely to the pool, and_outstandingValues
is updated. If not, it updates the queue accounting, queue outstanding values,getTotalReceived
andgetAvailableToWithdraw
.However, the
mergeTranches()
function is permissionless and only requires the merged tranches to be contiguous. Once tranches are merged, theloanId
of the new tranche changes, which can lead to incorrect accounting in thePool
.Proof of Concept
Consider the following scenario:
loanId = 100
, with two tranches, both havinglender = pool_address
.getLastLoanId[1][loan] = 100
, indicating that queue index 1 points to the latest loanId in theloan
contract.mergeTranches()
to merge the two tranches ofloanId = 100
with the same lender, which is the pool address. The newnewLoanId = 101
is used in the new tranche._loanTermination()
function is invoked with_loanId = 101
. The loop returnsi == totalQueues
, making the loan belong entirely to the pool, while it should belong to withdrawal queue index 1.MultiSourceLoan.sol#L1132-L1140
Tools Used
Manual Review
Recommended Mitigation Steps
Limit the ability to call
mergeTranches()
directly to lenders only.Assessed type
Other
The text was updated successfully, but these errors were encountered: