Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions contracts/split/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ mod storage_keys;

mod migrations;

mod validation;

use error::ContractError;
use validation::assert_valid_bps;
use soroban_sdk::crypto::bls12_381::{Fr, G1Affine};
Expand Down
19 changes: 19 additions & 0 deletions contracts/split/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ pub fn assert_bps_total(total: u32) -> Result<(), ContractError> {
Ok(())
}

/// Issue #704: Validate that a single basis-point value is within the legal
/// range `[0, BASIS_POINTS_TOTAL]` (i.e. `0..=10_000`).
///
/// Per-invoice options such as `penalty_bps`, `tax_bps`, and
/// `insurance_premium_bps` are stored as `u32` basis points and must never
/// exceed 100%. Callers invoke this guard before writing storage so an
/// out-of-range value is rejected atomically. The three existing call sites
/// use `.expect("… must be ≤ 10000")`, so this returns a `Result` and lets the
/// caller choose how to surface the failure.
///
/// # Errors
/// Returns `Err(ContractError::InvalidRatio)` when `bps > BASIS_POINTS_TOTAL`.
pub fn assert_valid_bps(bps: u32) -> Result<(), ContractError> {
if bps > BASIS_POINTS_TOTAL {
return Err(ContractError::InvalidRatio);
}
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down