Skip to content

[Contracts] LoanManager deposit_collateral re-reads the loan after a token transfer, creating a check-then-act gap #17

@grantfox-oss

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

In loan_manager/src/lib.rs deposit_collateral, the loan is loaded and status-checked, then token_client.transfer(&loan.borrower, contract, &amount) runs, and only afterward the loan is re-fetched (expect("loan not found")) and collateral_amount updated. The token transfer (an external call) happens between the read and the write, violating checks-effects-interactions; with a malicious or reentrant token the loan record could change or be removed between the two reads, and the second expect would panic or operate on stale state.

Acceptance criteria

  • Restructure deposit_collateral to compute the new collateral and commit loan state before or atomically with the transfer (CEI), as done in repay/approve_loan
  • Avoid the second storage read after the external transfer, or re-validate status after it
  • Add a test for deposit_collateral interleaving with concurrent loan state changes
  • Ensure the function returns a typed error rather than expect panic if the loan vanishes

Files to touch

  • loan_manager/src/lib.rs

Out of scope

  • Supporting a separate collateral token
  • Collateral valuation oracle

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignbugSomething isn't workinghardAdvanced / high-difficulty issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions