Skip to content

sui: disable_transceiver could remove the last transceiver #695

@johnsaigle

Description

@johnsaigle

disable_transceiver should revert if there is only one remaining transceiver. Otherwise, an admin could accidentally remove the last one, which would disable the protocol.

public fun disable_transceiver<T>(self: &mut State<T>, _: &AdminCap, id: u8) {
self.transceivers.disable_transceiver(id);
// After disabling a transceiver, check if the threshold needs to be reduced
// to ensure it doesn't exceed the number of enabled transceivers
let enabled_count = self.transceivers.get_enabled_transceivers().count_ones();
if (enabled_count < self.threshold) {
self.threshold = enabled_count;
};
check_threshold_invariants(self);
}

/// Check threshold invariants to ensure consistency
fun check_threshold_invariants<T>(state: &State<T>) {
let threshold = state.threshold;
let enabled_count = state.transceivers.get_enabled_transceivers().count_ones();
// Invariant: threshold <= enabled transceivers count
assert!(threshold <= enabled_count, EThresholdTooHigh);
// If there are enabled transceivers, threshold must be > 0
// (If all transceivers are disabled, threshold can be 0)
if (enabled_count > 0) {
assert!(threshold > 0, EZeroThreshold);
}
}

See also

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions