Skip to content

[Feature] V2: implement credit accrual and owner-authorized withdrawal #70

Description

@collinsezedike

Summary

Implement the withdrawal step that turns settled Credit(id, address) entitlements (see #69) into actual token transfers, and its reentrancy guard.

What to build

withdraw(owner: Address, id: u64, destination: Address)

  • Requires owner's authorization.
  • Reduces Credit(id, owner) and the dispute's outstanding liability, and increases its withdrawn total, before making the outgoing token transfer (effects before interactions).
  • If the token transfer fails, atomically roll back all three of the above; the credit is not consumed by a failed transfer.
  • The owner may specify any destination address, so a token that rejects transfers to owner directly can't permanently strand funds, the owner can route around it.

Reentrancy guard on incoming deposits (this affects registration in #66 as well, call it out there too if not already handled): a position must not become usable, by a permissionless cutoff transition or by a settlement callback, while its funding token transfer is still executing. Enter the guard before the external call; roll it back with the transaction on transfer failure. A position only becomes active as part of a successfully completed funding operation.

Invariant to test explicitly: total withdrawals and credits for one dispute must never exceed its funded positions, even under a hostile token contract that tries to call back into Tholos mid-transfer.

Depends on

#69 (credit must be accrued by settlement before it can be withdrawn).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmediumModerate scope or risk

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions