Open c4-bot-8 opened 7 months ago
alcueca marked the issue as duplicate of #4
alcueca marked the issue as not a duplicate
alcueca marked the issue as primary issue
alcueca marked the issue as selected for report
piske-alex (sponsor) confirmed
alcueca marked the issue as satisfactory
Lines of code
https://github.com/code-423n4/2024-04-lavarage/blob/9e8295b542fb71b2ba9b4693e25619585266d19e/libs/smart-contracts/programs/lavarage/src/processor/swapback.rs#L43-L77
Vulnerability details
Impact
Users can bypass the repayment of their loans when claiming their collateral, which can be abused in order to drain any trading pool
Proof of Concept
The
borrow_collateral
function located inside theswapback.rs
file lacks a crucial instruction validation check - a check for verifying that therandom_account_as_id
value passed in to therepay_sol
instruction context is not the same as that passed in to theborrow_collateral
instruction context. What this effectively means is that users can pass in an instruction that callsrepay_sol
with aposition_account
value that is different than the one passed in toborrow_collateral
. This can be abused in order to claim the collateral for one position, while repaying the borrowed SOL for another (even if that one was already repaid), making it possible to claim back collateral while repaying practically nothing, if the repayed position is one with a dust amount borrowed.The following coded PoC demonstrates the issue at question. To run it, paste it at the bottom of the
lavarage
describe block in thelavarage.spec.ts
test file and then runanchor test
inlibs/smart-contracts
. The tests insidelavarage.spec.ts
are stateful, so the order in which they are executed does matter.Tools Used
Manual review
Recommended Mitigation Steps
Replace the current verrification checks with a single one for the
position_account
value:Assessed type
Invalid Validation