stark_curve/
constants.rs

1//! Stark curve constants
2
3use crate::core::{field_element::FieldElementCore, W};
4use crate::FieldElement;
5
6/// Internal bytes representation of defined constants.
7///
8/// See the tests below which ensure that specified internal bytes repr
9/// indeed matches constant defined in the specs
10mod internal_bytes_repr {
11    pub const EQUATION_A: [u64; 4] = [
12        18446744073709551585,
13        18446744073709551615,
14        18446744073709551615,
15        576460752303422960,
16    ];
17    pub const EQUATION_B: [u64; 4] = [
18        3863487492851900874,
19        7432612994240712710,
20        12360725113329547591,
21        88155977965380735,
22    ];
23    pub const GENERATOR_X: [u64; 4] = [
24        14484022957141291997,
25        5884444832209845738,
26        299981207024966779,
27        232005955912912577,
28    ];
29    pub const GENERATOR_Y: [u64; 4] = [
30        6241159653446987914,
31        664812301889158119,
32        18147424675297964973,
33        405578048423154473,
34    ];
35}
36
37/// Coefficient $\alpha$ of curve equation
38///
39/// $\alpha = 1$
40pub const EQUATION_A: FieldElement = W::new(FieldElementCore::from_internal_repr(
41    internal_bytes_repr::EQUATION_A,
42));
43
44/// Coefficient $\beta$ of curve equation
45///
46/// $\beta = 3141592653589793238462643383279502884197169399375105820974944592307816406665$
47pub const EQUATION_B: FieldElement = W::new(FieldElementCore::from_internal_repr(
48    internal_bytes_repr::EQUATION_B,
49));
50
51/// Curve generator coordinates $(x, y)$
52///
53/// * $x = 874739451078007766457464989774322083649278607533249481151382481072868806602$
54/// * $y = 152666792071518830868575557812948353041420400780739481342941381225525861407$
55pub const GENERATOR: (FieldElement, FieldElement) = (
56    W::new(FieldElementCore::from_internal_repr(
57        internal_bytes_repr::GENERATOR_X,
58    )),
59    W::new(FieldElementCore::from_internal_repr(
60        internal_bytes_repr::GENERATOR_Y,
61    )),
62);
63
64#[cfg(test)]
65mod tests {
66    use hex_literal::hex;
67
68    use crate::FieldElement;
69
70    #[test]
71    fn defined_cosntants_align_with_specs() {
72        // Hex-encoded constants can be found here:
73        // https://github.com/starkware-libs/starkex-resources/blob/844ac3dcb1f735451457f7eecc6e37cd96d1cb2d/crypto/starkware/crypto/signature/signature.js#L38-L50
74
75        let a = FieldElement::ONE;
76        let b = FieldElement::from_be_bytes(
77            hex!("06f21413 efbe40de 150e596d 72f7a8c5 609ad26c 15c915c1 f4cdfcb9 9cee9e89").into(),
78        )
79        .unwrap();
80
81        let g_x = FieldElement::from_be_bytes(
82            hex!("01ef15c18599971b7beced415a40f0c7deacfd9b0d1819e03d723d8bc943cfca").into(),
83        )
84        .unwrap();
85        let g_y = FieldElement::from_be_bytes(
86            hex!("005668060aa49730b7be4801df46ec62de53ecd11abe43a32873000c36e8dc1f").into(),
87        )
88        .unwrap();
89
90        assert_eq!(super::EQUATION_A, a, "{:?}", a.internal_repr());
91        assert_eq!(super::EQUATION_B, b, "{:?}", b.internal_repr());
92        assert_eq!(super::GENERATOR.0, g_x, "{:?}", g_x.internal_repr());
93        assert_eq!(super::GENERATOR.1, g_y, "{:?}", g_y.internal_repr());
94    }
95}