-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Borrowers can steal lenders funds #4
Comments
alcueca marked the issue as primary issue |
alcueca marked issue #28 as primary and marked this issue as a duplicate of 28 |
alcueca marked the issue as satisfactory |
hello @alcueca Pls, note this sentence from report: |
I think that in this case these issues can be separate. |
In same way it's not fair to me. In this case it would be fair to leave it as 1 report. @alcueca I have explained exactly how it works in one case and another one is exactly same(same problem). I don't see the need to explain it separately. And the problem is indeed same, position random is not checked. |
hey @alcueca |
Lines of code
https://github.com/code-423n4/2024-04-lavarage/blob/main/libs/smart-contracts/programs/lavarage/src/processor/swap.rs#L98-L103
Vulnerability details
Proof of Concept
When trader borrows sol from trading pool, then position account is created. Pls, note, that
random_account_as_id
field that is provided by trader is used to create PDA. This is needed, because same trader can have several position with same trading pool.borrow
function checks that there will beadd_collateral
instruction later in transaction and only after that it borrows sol to the trader. This is becauseadd_collateral
should check that trader has provided tokens as collateral. Alsoborrow
function storesrandom_account_as_id
to the position, so we know which random was used to derive position account.add_collateral
function checks that position account is now funded with enough amount of tokens to cover borrowed funds.add_collateral
function is provided with context, where position account is provided withrandom_account_as_id
as well.The problem is that trader can provide another position, which is already collateralized. In that case trader will be able to steal all borrowed funds.
Pls, note that there is same problem inside
swapback.rs
, which allows to steal tokens from position without repaying sol on it.Impact
Funds can be stolen.
Tools Used
VsCode
Recommended Mitigation Steps
In the function that is responsible for the check of final instruction you should check that position account provided is same.
Assessed type
Error
The text was updated successfully, but these errors were encountered: