Skip to content

ContestationPeriod Num instance can panic via (-) / negate #2707

Description

@noonio

Description

(-) and negate over Natural throw Underflow on negative results. fromInteger 0 correctly rejects zero, but 1 - 2 :: ContestationPeriod silently produces a runtime exception rather than a typed failure. The on-chain protocol assumes cp > 0; the type intends to enforce this but exposes ways to violate it that panic instead of returning Maybe.

Location: hydra-tx/src/Hydra/Tx/ContestationPeriod.hs:28-38.

Verification

Read the Num instance; both operators delegate to Natural which throws on underflow.

Suggested fix

Remove the Num instance, or implement (-) and negate as error "use fromNominalDiffTime". Only legitimate constructors are fromInteger >0 and fromNominalDiffTime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    claudeissues discovered by claudegood first issueHighlight opportunities for people to contribute to the project

    Type

    Projects

    Status
    Triage 🏥

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions