snarkvm_fields/traits/
field_parameters.rs

1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use crate::traits::{FftParameters, PoseidonDefaultParameters};
17
18use core::{fmt::Debug, hash::Hash};
19
20/// A trait that defines parameters for a prime field.
21pub trait FieldParameters:
22    'static + FftParameters + PoseidonDefaultParameters + Copy + Clone + Debug + Default + PartialEq + Eq + Hash
23{
24    /// The modulus of the field.
25    const MODULUS: Self::BigInteger;
26
27    /// The number of bits needed to represent the `Self::MODULUS`.
28    const MODULUS_BITS: u32;
29
30    /// The number of bits that must be shaved from the beginning of
31    /// the representation when randomly sampling.
32    const REPR_SHAVE_BITS: u32;
33
34    /// R = 2^256 % Self::MODULUS
35    const R: Self::BigInteger;
36
37    /// R2 = R^2 % Self::MODULUS
38    const R2: Self::BigInteger;
39
40    /// INV = -(MODULUS^{-1} mod MODULUS) mod MODULUS
41    const INV: u64;
42
43    /// A multiplicative generator that is also a quadratic nonresidue.
44    /// `Self::GENERATOR` is an element having multiplicative order
45    /// `Self::MODULUS - 1`.
46    /// There also does not exist `x` such that `Self::GENERATOR = x^2 %
47    /// Self::MODULUS`
48    const GENERATOR: Self::BigInteger;
49
50    /// The number of bits that can be reliably stored.
51    /// (Should equal `SELF::MODULUS_BITS - 1`)
52    const CAPACITY: u32;
53
54    /// t for 2^s * t = MODULUS - 1
55    const T: Self::BigInteger;
56
57    /// (t - 1) / 2
58    const T_MINUS_ONE_DIV_TWO: Self::BigInteger;
59
60    /// (Self::MODULUS - 1) / 2
61    const MODULUS_MINUS_ONE_DIV_TWO: Self::BigInteger;
62}