solve/anchors.rs
1//! Named points on the specification's suggested scales.
2//!
3//! Judgments are free-valued in `0.0..=10.0`; these are the labelled anchors an assessor
4//! interpolates between. Use them where a judgment lands exactly on an anchor, and
5//! [`Score::lit`](crate::Score::lit) where it lands between two.
6
7use crate::score::Score;
8
9macro_rules! anchors {
10 (
11 $(#[$meta:meta])* $name:ident {
12 $($(#[$vmeta:meta])* $variant:ident => $value:literal),* $(,)?
13 }
14 ) => {
15 $(#[$meta])*
16 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
17 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18 #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
19 pub enum $name {
20 $($(#[$vmeta])* $variant),*
21 }
22
23 impl $name {
24 /// The score this anchor denotes.
25 #[must_use]
26 pub const fn score(self) -> Score {
27 match self {
28 $(Self::$variant => Score::lit($value)),*
29 }
30 }
31 }
32
33 impl From<$name> for Score {
34 fn from(anchor: $name) -> Self {
35 anchor.score()
36 }
37 }
38 };
39}
40
41anchors! {
42 /// How much work it takes to bring the supplied code to a fully readable state.
43 Readability {
44 /// Commented or very simple code.
45 Commented => 0.0,
46 /// Code without comments.
47 Uncommented => 1.0,
48 /// Ugly or obfuscated code — poor names, spaghetti control flow.
49 Obfuscated => 4.0,
50 /// Compiled code needing reverse engineering for addresses and memory layout.
51 CompiledLayout => 5.0,
52 /// Compiled code needing reverse engineering to understand application logic.
53 CompiledLogic => 6.0,
54 /// A significant volume of compiled code needing reverse engineering.
55 CompiledLogicLarge => 8.0,
56 /// Packed, esoteric-architecture, or anti-debugging code.
57 Packed => 10.0,
58 }
59}
60
61anchors! {
62 /// How much of the code the solver must review when hunting for the bug.
63 AttackSurface {
64 /// One function, endpoint, or API; or the challenge ships a small diff to inspect.
65 Narrow => 0.0,
66 /// A small set of functions, endpoints, or APIs.
67 MediumMinus => 3.0,
68 /// A module of functions, endpoints, or APIs.
69 MediumPlus => 6.0,
70 /// A process running several modules, one of which is vulnerable.
71 Wide => 8.0,
72 /// A system running several processes.
73 VeryWide => 10.0,
74 }
75}
76
77anchors! {
78 /// How far apart the pieces of code that reveal the vulnerability are.
79 Locality {
80 /// Contained in one function.
81 Function => 0.0,
82 /// Contained in one module.
83 Module => 3.0,
84 /// Two modules within one code base must be reasoned about together.
85 SameCodebase => 5.0,
86 /// Interaction between code bases sharing a process, site, or machine.
87 SameMachine => 7.0,
88 /// Interaction between code bases on different processes, sites, or machines.
89 CrossMachine => 10.0,
90 }
91}
92
93anchors! {
94 /// Depth of specialist knowledge a domain demands.
95 ExpertLevel {
96 /// No expert knowledge required.
97 None => 0.0,
98 /// Introductory: documentation or encyclopedia level.
99 Introductory => 3.0,
100 /// Implementation detail level; solving classical problems in the domain.
101 Implementation => 6.0,
102 /// Applied knowledge manipulating or solving original problems in the domain.
103 Deep => 10.0,
104 }
105}