Skip to content

Fix Vote::Choice variant unhandled in cast_vote match — non-exhaustive match or panic #505

Description

@PrincessnJoy

Description

The Vote enum in contracts/governance/src/types.rs has four variants:

pub enum Vote {
    Yes,
    No,
    Abstain,
    Choice(u32),  // ← multi-choice extension
}

However, the match vote { ... } block inside cast_vote in lib.rs only handles three of them:

match vote {
    Vote::Yes => { ... }
    Vote::No => { ... }
    Vote::Abstain => { ... }
    // Vote::Choice(n) is missing
}

Depending on whether Soroban's Rust target treats this as:

  • A compile error (non-exhaustive pattern match — most likely with #[derive(...)] and Clippy match-wildcard-for-single-variants), or
  • A runtime panic (if a wildcard or default arm is implicitly present)

Either outcome is unacceptable. A caller who submits Vote::Choice(0) will either be rejected at compile time or trigger undefined behavior on-chain.

Root Cause

The Vote::Choice variant was added as part of the multi-choice voting extension (see also #390) but the cast_vote logic was never updated to handle it.

Acceptance Criteria

Dependencies

Priority

High

Estimated Effort

Small

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions