Assessment reports>Pyth Governance>Discussion>Avoid using default case

Avoid using default case in validate match statement

The validate function is used to determine the level of risk a particular set of positions present. As part of this, total_exposure, max_target_exposure, and governance_exposure parameters are determined by iterating over the collection of targets and their exposures.

As it stands, targets can only be of type VOTING or STAKING, however if future target types were added in the future, the default pattern used in this match statement would automatically assume a strategy for assessing risk for the new kind of target.

Given the critical nature of validate, we suggest to avoid using the default _ => ... pattern and instead explicitly match against all the possibilities in the enum variant. If future target types were added, this would result in a compiler error rather than a silently accepted default exposure calculation.

An example is provided:

for (target, exposure) in &current_exposures {
    match target {
        Target::VOTING => { /* voting exposure calc */ }
        Target::STAKING { .. } => { /* staking exposure calc */ }
    }
}
Zellic © 2024Back to top ↑