old borrowing key is used instead of `newBorrowingKey` when adding old loans to the newBorrowing in LiquidityBorrowingManager.takeOverDebt()
In the takeOverDebt function, the old borrowing key was used instead of the newly generated one when associating old loans with the new borrowing. This could cause the wrong borrowing key to be recorded for the old loans' token IDs, leading to incorrect state.
0xMAKEOUTHILL Follow with 0xMaroutis, 0xpep7 and 8 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-10-real-wagmi-judging/issues/53
Found by
0xMAKEOUTHILL, 0xMaroutis, 0xpep7, AuditorPraise, Nyx, ali_shehab, jah, kutugu, p-tsanev, seeques, zraxx
when _addKeysAndLoansInfo() is called within LiquidityBorrowingManager.takeOverDebt(), old Borrowing Key is used and not newBorrowingKey see here
Vulnerability Detail
The old borrowing key credentials are deleted in _removeKeysAndClearStorage(oldBorrowing.borrower, borrowingKey, oldLoans); see here
And a new borrowing key is created with the holdToken, saleToken, and the address of the user who wants to take over the borrowing in the _initOrUpdateBorrowing(). see here
now the old borrowing key whose credentials are already deleted is used to update the old loans in _addKeysAndLoansInfo() instead of the newBorrowingKey generated in _initOrUpdateBorrowing() see here
Impact
wrong borrowing Key is used (i.e the old borrowing key) when adding old loans to newBorrowing
Therefore the wrong borrowing key (i.e the old borrowing key) will be added as borrowing key for tokenId of old Loans in tokenIdToBorrowingKeys in _addKeysAndLoansInfo()
(i.e when the bug of update bool being false, is corrected, devs should understand :))
Code Snippet
Tool used
Manual Review
Recommendation
use newBorrowingKey when calling _addKeysAndLoansInfo() instead of old borrowing key.
Discussion
fann95
This is an inattention error related to the accelerated development of the project. I think we would have fixed this during testing, but thanks for the hint anyway. We will fix it.
fann95
Fixed: https://github.com/RealWagmi/wagmi-leverage/commit/f5860c819eeb5146cc0c5c3b563ee83feb4ab33d
IAm0x52
Fix looks good. Correct variable is used now
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a variable mix-up where the old borrowing key was passed to _addKeysAndLoansInfo instead of the newly created newBorrowingKey.
Impact
The wrong borrowing key (the old one) could be recorded for the old loans' token IDs, potentially causing incorrect tracking of loans.
What the attacker needed
TakeOverDebt function is called
The fix
The code was fixed to use newBorrowingKey when calling _addKeysAndLoansInfo.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A borrowing key is like a unique label for a loan. When someone takes over a loan, a new label should be created and used. The code mistakenly used the old label, which could confuse the system about which loan the items belong to.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.