proof_of_sql/base/scalar/
scalar.rs

1#![expect(clippy::module_inception)]
2
3use crate::base::{encode::VarInt, ref_into::RefInto, scalar::ScalarConversionError};
4use alloc::string::String;
5use bnum::types::U256;
6use core::ops::Sub;
7use num_bigint::BigInt;
8
9/// A trait for the scalar field used in Proof of SQL.
10pub trait Scalar:
11    Clone
12    + core::fmt::Debug
13    + core::fmt::Display
14    + PartialEq
15    + Default
16    + for<'a> From<&'a str>
17    + Sync
18    + Send
19    + num_traits::One
20    + core::iter::Sum
21    + core::iter::Product
22    + Sub<Output = Self>
23    + Copy
24    + core::ops::MulAssign
25    + core::ops::AddAssign
26    + num_traits::Zero
27    + for<'a> core::convert::From<&'a Self> // Required for `Column` to implement `MultilinearExtension`
28    + for<'a> core::convert::From<&'a bool> // Required for `Column` to implement `MultilinearExtension`
29    + for<'a> core::convert::From<&'a i8> // Required for `Column` to implement `MultilinearExtension`
30    + for<'a> core::convert::From<&'a i16> // Required for `Column` to implement `MultilinearExtension`
31    + for<'a> core::convert::From<&'a i32> // Required for `Column` to implement `MultilinearExtension`
32    + for<'a> core::convert::From<&'a i64> // Required for `Column` to implement `MultilinearExtension`
33    + for<'a> core::convert::From<&'a i128> // Required for `Column` to implement `MultilinearExtension`
34    + for<'a> core::convert::From<&'a u8> // Required for `Column` to implement `MultilinearExtension`
35    + for<'a> core::convert::From<&'a u64> // Required for `Column` to implement `MultilinearExtension`
36    + core::convert::TryInto <bool>
37    + core::convert::TryInto <u8>
38    + core::convert::TryInto <i8>
39    + core::convert::TryInto <i16>
40    + core::convert::TryInto <i32>
41    + core::convert::TryInto <i64>
42    + core::convert::TryInto <i128>
43    + core::convert::Into<[u64; 4]>
44    + core::convert::From<[u64; 4]>
45    + core::convert::From<u8>
46    + core::cmp::Ord
47    + core::ops::Neg<Output = Self>
48    + num_traits::Zero
49    + core::ops::AddAssign
50    + ark_serialize::CanonicalSerialize //This enables us to put `Scalar`s on the transcript
51    + ark_std::UniformRand //This enables us to get `Scalar`s as challenges from the transcript
52    + num_traits::Inv<Output = Option<Self>> // Note: `inv` should return `None` exactly when the element is zero.
53    + core::ops::SubAssign
54    + RefInto<[u64; 4]>
55    + for<'a> core::convert::From<&'a String>
56    + VarInt
57    + core::convert::From<String>
58    + core::convert::From<i128>
59    + core::convert::From<i64>
60    + core::convert::From<i32>
61    + core::convert::From<i16>
62    + core::convert::From<i8>
63    + core::convert::From<u64>
64    + core::convert::From<bool>
65    + core::convert::Into<BigInt>
66    + TryFrom<BigInt, Error = ScalarConversionError>
67{
68    /// The value (p - 1) / 2. This is "mid-point" of the field - the "six" on the clock.
69    /// It is the largest signed value that can be represented in the field with the natural embedding.
70    const MAX_SIGNED: Self;
71    /// The 0 (additive identity) element of the field.
72    const ZERO: Self;
73    /// The 1 (multiplicative identity) element of the field.
74    const ONE: Self;
75    /// 1 + 1
76    const TWO: Self;
77    /// 2 + 2 + 2 + 2 + 2
78    const TEN: Self;
79    /// 2^64
80    const TWO_POW_64: Self;
81    /// The value to mask the challenge with to ensure it is in the field.
82    /// This one less than the largest power of 2 that is less than the field modulus.
83    const CHALLENGE_MASK: U256;
84    /// The largest n such that 2^n <=p
85    const MAX_BITS: u8;
86    /// A U256 representation of the largest signed value in the field.
87    const MAX_SIGNED_U256: U256;
88}