solve-score 0.1.0

Independent implementation of SOLVE v0.5 (Scoring Obstacle Levels in Vulnerabilities & Exploits), a rubric for scoring vulnerability-discovery and exploit-development difficulty. Reproduces the 16 published calibration assessments. Not affiliated with or endorsed by Irregular.
Documentation
//! The specification's appendices: weakness classes, exploit techniques, expertise domains.
//!
//! Only the *counts* of CWEs and techniques feed the arithmetic. These types exist so an
//! assessment records which ones were counted, which is what makes a score auditable.

use core::fmt;

/// A MITRE CWE identifier.
///
/// Appendix A is deliberately a hand-picked subset of MITRE's catalogue, not a closed set —
/// the specification expects it to grow. Any identifier is representable; [`Cwe::in_appendix_a`]
/// reports whether it is one the specification currently names.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct Cwe(pub u16);

macro_rules! appendix_a {
    ($($konst:ident = $num:literal, $name:literal;)*) => {
        impl Cwe {
            $(
                #[doc = $name]
                pub const $konst: Self = Self($num);
            )*
        }

        /// Every CWE named in Appendix A, paired with its short description.
        pub const APPENDIX_A: &[(Cwe, &str)] = &[$((Cwe($num), $name)),*];
    };
}

appendix_a! {
    PATH_TRAVERSAL = 22, "Path traversal";
    SQL_INJECTION = 89, "SQL injection";
    CODE_INJECTION = 94, "Code injection";
    OUT_OF_BOUNDS_READ = 125, "Out-of-bounds read";
    FORMAT_STRING = 134, "Attacker-controlled format string";
    UNICODE_HANDLING = 176, "Improper handling of Unicode";
    URL_ENCODING = 177, "Improper handling of URL encoding";
    INCORRECT_REGEX = 185, "Incorrect regex";
    OFF_BY_ONE = 193, "Off-by-one";
    INFO_LEAK = 200, "Info leak";
    TIMING_DIFFERENCE = 208, "Observable timing difference";
    PARAMETER_HANDLING = 233, "Improper handling of parameters";
    UNNECESSARY_PRIVILEGES = 250, "Execution with unnecessary privileges";
    PLAINTEXT_PASSWORD = 256, "Plaintext storage of password";
    NONCE_REUSE = 323, "Nonce/key-pair reuse";
    WEAK_ENCRYPTION_STRENGTH = 326, "Inadequate encryption strength";
    BROKEN_CRYPTO_ALGORITHM = 327, "Broken or risky cryptographic algorithm";
    WEAK_HASH = 328, "Weak hash";
    WEAK_PRNG_SEED = 335, "Weak PRNG seed";
    WEAK_PRNG_ALGORITHM = 338, "Weak PRNG algorithm";
    PREDICTABLE_RANDOM_IDS = 340, "Predictable random IDs";
    BAD_ORIGIN_VALIDATION = 346, "Bad origin validation";
    RACE_CONDITION = 362, "Race condition";
    USE_AFTER_FREE = 416, "Use after free";
    UNRESTRICTED_UPLOAD = 434, "Unrestricted upload of dangerous file type";
    UNINITIALIZED_VARIABLE = 457, "Uninitialized variable";
    UNSAFE_DESERIALIZATION = 502, "Deserialization of untrusted data";
    SENSITIVE_CACHE = 524, "Use of cache containing sensitive information";
    OUT_OF_BOUNDS_WRITE = 787, "Out-of-bounds write";
    DANGLING_POINTER = 825, "Dangling pointer";
    MISSING_MINIMUM_RANGE_CHECK = 839, "Numeric range check without minimum";
    TYPE_CONFUSION = 843, "Type confusion";
    MISSING_AUTHORIZATION = 862, "Missing authorization";
    NOSQL_INJECTION = 943, "Data query injection";
    WRONG_COMPARISON_FACTORS = 1025, "Comparison using wrong factors";
    WEAK_PASSWORD = 1391, "Weak password";
}

impl Cwe {
    /// A weakness that was counted but not classified.
    ///
    /// Only the number of distinct weaknesses feeds the arithmetic, so an assessment can be
    /// scored before its classes are pinned down. Such an assessment is not auditable, and
    /// [`Cwe::in_appendix_a`] reports `false` for it.
    pub const UNSPECIFIED: Self = Self(0);

    /// The Appendix A description, if this identifier is one the specification names.
    #[must_use]
    pub fn name(self) -> Option<&'static str> {
        APPENDIX_A
            .iter()
            .find_map(|&(cwe, name)| (cwe == self).then_some(name))
    }

    /// Whether the specification currently names this identifier.
    #[must_use]
    pub fn in_appendix_a(self) -> bool {
        self.name().is_some()
    }
}

impl fmt::Display for Cwe {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "CWE-{}", self.0)
    }
}

/// An exploitation technique, per Appendix B.
///
/// The specification describes this list as "far from comprehensive" and intends it to become a
/// CAPEC- or ATT&CK-style taxonomy, so [`Technique::Other`] carries anything not yet named.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Technique {
    /// Mitigation bypass, such as ROP.
    MitigationBypass,
    /// Leaking memory layout or content needed by a later stage.
    MemoryLeak,
    /// Memory shaping, such as advanced heap grooming.
    MemoryShaping,
    /// Timing-sensitive or probabilistic attacks, and probability-enhancing tricks.
    ProbabilisticAttack,
    /// Use of deep OS internals.
    OsSpecific,
    /// Architecture-specific effects, such as speculative execution.
    ArchSpecific,
    /// Cryptographic work needing non-trivial compute.
    CryptographicCompute,
    /// A technique that was counted but not classified.
    Unspecified,
    /// A technique outside the current appendix.
    Other(String),
}

/// A domain of expertise, per Appendix C.
///
/// A domain is general knowledge that is neither classical vulnerability-research skill nor
/// knowledge of the specific system under attack. See [`NON_DOMAINS`] for categories the
/// specification considered and rejected.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Domain {
    /// Advanced web technologies such as OAuth, passkeys, or CORS bypasses — not XSS basics.
    Web,
    /// Network infrastructure and protocols.
    ComputerNetworks,
    /// Binary exploitation lore: kernel and ABI internals, standard library and compiler
    /// internals, memory-safety mitigations, and hardware or CPU issues.
    LowLevel,
    /// Cloud service platforms.
    Cloud,
    /// Special or niche systems, from ICS and automotive to legacy operating systems.
    SpecialSystems,
    /// Cryptography, excluding cryptocurrency.
    Cryptography,
    /// Data storage, media encodings, and intricate container formats.
    DataAndFormats,
    /// Machine learning implementation and algorithms.
    MachineLearning,
    /// A domain outside the current appendix.
    Other(String),
}

/// Categories the specification considered as domains of expertise and rejected.
///
/// Each was rejected on the grounds that there is no body of lore to have studied — the work
/// only demands skill. Scoring one of these as expert knowledge inflates a SOLVE score.
pub const NON_DOMAINS: &[&str] = &[
    "Hypervisors",
    "Browsers",
    "VMs and sandboxed execution environments",
    "Cryptocurrency",
    "Difficult code analysis",
    "Reverse engineering in general",
    "Databases, excluding the data storage part",
];