Complexity rank: 10 of 15
Priority: Medium
Selection criteria satisfied: 2 (correctness under real deployment)
Scope tier: Standard
Description:
contracts/atomic_swap/src/lib.rs:1512-1562 (claim_insurance) computes actual_payout = if pool >= payout { payout } else { pool }, paying out of a single shared InsurancePool(token) balance with no reservation or escrow carved out per policy at issuance time. Two independently valid, already-issued policies on the same token can be claimed in sequence; the second claimant silently receives a partial payout (or zero) with no distinct error from "nothing was owed to you" — the contract cannot tell the difference between "your claim is invalid" and "someone else's claim drained the pool first." This is a correctness gap under real concurrent usage, not a premium-calculation dispute: the pool accounting itself doesn't guarantee a policy's coverage amount is actually available when a valid claim against it is filed. No test exercises two claims racing the same pool balance.
Tasks:
- At policy issuance (wherever
InsurancePool premiums are credited), reserve/escrow each policy's coverageAmount against the pool rather than leaving the full pool balance fungible across all outstanding policies.
- Change
claim_insurance to pay from a policy's own reservation rather than the shared pool remainder, and return a distinct error (not a silent partial amount) if the pool is genuinely under-collateralized relative to outstanding reservations.
- Add an admin/queryable view of total outstanding reservations versus actual pool balance so under-collateralization is observable before it causes a failed payout.
- Add a test proving two policies issued against the same pool can each be claimed in full, in either order, without one starving the other, when the pool is adequately collateralized.
- Add a test proving a claim against an under-collateralized pool returns a distinct "insufficient reserve" error rather than a silently reduced payout.
- Preserve the existing premium calculation, risk-factor, and tiering logic unchanged.
- Confirm
docs/api-reference.md's insurance section describes the reservation model.
Complexity rank: 10 of 15
Priority: Medium
Selection criteria satisfied: 2 (correctness under real deployment)
Scope tier: Standard
Description:
contracts/atomic_swap/src/lib.rs:1512-1562(claim_insurance) computesactual_payout = if pool >= payout { payout } else { pool }, paying out of a single sharedInsurancePool(token)balance with no reservation or escrow carved out per policy at issuance time. Two independently valid, already-issued policies on the same token can be claimed in sequence; the second claimant silently receives a partial payout (or zero) with no distinct error from "nothing was owed to you" — the contract cannot tell the difference between "your claim is invalid" and "someone else's claim drained the pool first." This is a correctness gap under real concurrent usage, not a premium-calculation dispute: the pool accounting itself doesn't guarantee a policy's coverage amount is actually available when a valid claim against it is filed. No test exercises two claims racing the same pool balance.Tasks:
InsurancePoolpremiums are credited), reserve/escrow each policy'scoverageAmountagainst the pool rather than leaving the full pool balance fungible across all outstanding policies.claim_insuranceto pay from a policy's own reservation rather than the shared pool remainder, and return a distinct error (not a silent partial amount) if the pool is genuinely under-collateralized relative to outstanding reservations.docs/api-reference.md's insurance section describes the reservation model.