Skip to content

[bug] liquidity-pool: borrow due_at = now + duration_secs uses raw u64 addition — no overflow guard produces immediately-overdue loans #731

Description

@gboigwe

Summary

borrow computes the loan due date with a raw u64 addition:

due_at: now + duration_secs, // ❌ no overflow guard

If duration_secs is set close to u64::MAX, the addition wraps to a small past value. The BorrowPosition.due_at field would indicate the loan is immediately overdue upon creation. Although the current contract has no on-chain enforcement of the due date (no auto-liquidation), any off-chain system or future contract upgrade that checks due_at < now would incorrectly treat the loan as overdue from the moment it was created.

Location

contracts/liquidity-pool/src/lib.rs, borrow

due_at: now + duration_secs, // ❌

Fix

due_at: now.checked_add(duration_secs)
    .expect("loan due_at timestamp overflows u64"),

Also add a reasonable upper bound on duration_secs (e.g., one year) to prevent unreasonably long-dated loans that effectively become permanent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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