pub struct BFieldElement(/* private fields */);
Expand description
Base field element ∈ ℤ_{2^64 - 2^32 + 1}.
In Montgomery representation. This implementation follows https://eprint.iacr.org/2022/274.pdf and https://github.com/novifinancial/winterfell/pull/101/files.
Implementations§
Source§impl BFieldElement
impl BFieldElement
pub const BYTES: usize = 8usize
Sourcepub const P: u64 = 18_446_744_069_414_584_321u64
pub const P: u64 = 18_446_744_069_414_584_321u64
The base field’s prime, i.e., 2^64 - 2^32 + 1.
pub const MAX: u64 = 18_446_744_069_414_584_320u64
Sourcepub const MINUS_TWO_INVERSE: BFieldElement = _
pub const MINUS_TWO_INVERSE: BFieldElement = _
-2^-1
pub const fn new(value: u64) -> BFieldElement
pub const fn value(&self) -> u64
Sourcepub const fn power_accumulator<const N: usize, const M: usize>(
base: [BFieldElement; N],
tail: [BFieldElement; N],
) -> [BFieldElement; N]
pub const fn power_accumulator<const N: usize, const M: usize>( base: [BFieldElement; N], tail: [BFieldElement; N], ) -> [BFieldElement; N]
Square the base M times and multiply the result by the tail value
Sourcepub const fn generator() -> BFieldElement
pub const fn generator() -> BFieldElement
Get a generator for the entire field
pub const fn lift(&self) -> XFieldElement
pub fn increment(&mut self)
pub fn decrement(&mut self)
pub const fn mod_pow(&self, exp: u64) -> BFieldElement
Sourcepub fn from_ne_bytes(bytes: &[u8]) -> BFieldElement
👎Deprecated since 0.42.0: endianness must not be platform specific; use <&[u8]>::try_from()
instead
pub fn from_ne_bytes(bytes: &[u8]) -> BFieldElement
<&[u8]>::try_from()
insteadConvert a BFieldElement
from a byte slice in native endianness.
Sourcepub const fn raw_bytes(&self) -> [u8; 8]
pub const fn raw_bytes(&self) -> [u8; 8]
Return the raw bytes or 8-bit chunks of the Montgomery representation, in little-endian byte order
Sourcepub const fn from_raw_bytes(bytes: &[u8; 8]) -> BFieldElement
pub const fn from_raw_bytes(bytes: &[u8; 8]) -> BFieldElement
Take a slice of 8 bytes and interpret it as an integer in little-endian byte order, and cast it to a BFieldElement in Montgomery representation
Sourcepub const fn raw_u16s(&self) -> [u16; 4]
pub const fn raw_u16s(&self) -> [u16; 4]
Return the raw 16-bit chunks of the Montgomery representation, in little-endian chunk order
Sourcepub const fn from_raw_u16s(chunks: &[u16; 4]) -> BFieldElement
pub const fn from_raw_u16s(chunks: &[u16; 4]) -> BFieldElement
Take a slice of 4 16-bit chunks and interpret it as an integer in little-endian chunk order, and cast it to a BFieldElement in Montgomery representation
pub fn raw_u128(&self) -> u128
pub const fn from_raw_u64(e: u64) -> BFieldElement
pub const fn raw_u64(&self) -> u64
pub const fn is_canonical(x: u64) -> bool
Trait Implementations§
Source§impl Add<BFieldElement> for XFieldElement
impl Add<BFieldElement> for XFieldElement
Source§type Output = XFieldElement
type Output = XFieldElement
+
operator.Source§fn add(self, other: BFieldElement) -> XFieldElement
fn add(self, other: BFieldElement) -> XFieldElement
+
operation. Read moreSource§impl Add<XFieldElement> for BFieldElement
impl Add<XFieldElement> for BFieldElement
The bfe + xfe -> xfe
instance belongs to BFieldElement.
Source§type Output = XFieldElement
type Output = XFieldElement
+
operator.Source§fn add(self, other: XFieldElement) -> XFieldElement
fn add(self, other: XFieldElement) -> XFieldElement
+
operation. Read moreSource§impl Add for BFieldElement
impl Add for BFieldElement
Source§type Output = BFieldElement
type Output = BFieldElement
+
operator.Source§fn add(self, rhs: BFieldElement) -> BFieldElement
fn add(self, rhs: BFieldElement) -> BFieldElement
+
operation. Read moreSource§impl AddAssign<BFieldElement> for XFieldElement
impl AddAssign<BFieldElement> for XFieldElement
Source§fn add_assign(&mut self, rhs: BFieldElement)
fn add_assign(&mut self, rhs: BFieldElement)
+=
operation. Read moreSource§impl AddAssign for BFieldElement
impl AddAssign for BFieldElement
Source§fn add_assign(&mut self, rhs: BFieldElement)
fn add_assign(&mut self, rhs: BFieldElement)
+=
operation. Read moreSource§impl<'a> Arbitrary<'a> for BFieldElement
impl<'a> Arbitrary<'a> for BFieldElement
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<BFieldElement, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<BFieldElement, Error>
Self
from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moreSource§impl BFieldCodec for BFieldElement
impl BFieldCodec for BFieldElement
type Error = BFieldCodecError
fn decode( sequence: &[BFieldElement], ) -> Result<Box<BFieldElement>, <BFieldElement as BFieldCodec>::Error>
fn encode(&self) -> Vec<BFieldElement>
Source§fn static_length() -> Option<usize>
fn static_length() -> Option<usize>
Source§impl Clone for BFieldElement
impl Clone for BFieldElement
Source§fn clone(&self) -> BFieldElement
fn clone(&self) -> BFieldElement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl ConstOne for BFieldElement
impl ConstOne for BFieldElement
Source§const ONE: BFieldElement = _
const ONE: BFieldElement = _
Self
, 1
.Source§impl ConstZero for BFieldElement
impl ConstZero for BFieldElement
Source§const ZERO: BFieldElement = _
const ZERO: BFieldElement = _
Self
, 0
.Source§impl CyclicGroupGenerator for BFieldElement
impl CyclicGroupGenerator for BFieldElement
fn get_cyclic_group_elements(&self, max: Option<usize>) -> Vec<BFieldElement>
Source§impl Debug for BFieldElement
impl Debug for BFieldElement
Source§impl Default for BFieldElement
impl Default for BFieldElement
Source§fn default() -> BFieldElement
fn default() -> BFieldElement
Source§impl<'de> Deserialize<'de> for BFieldElement
impl<'de> Deserialize<'de> for BFieldElement
Source§fn deserialize<D>(
deserializer: D,
) -> Result<BFieldElement, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<BFieldElement, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for BFieldElement
impl Display for BFieldElement
Source§impl Div for BFieldElement
impl Div for BFieldElement
Source§type Output = BFieldElement
type Output = BFieldElement
/
operator.Source§fn div(self, other: BFieldElement) -> BFieldElement
fn div(self, other: BFieldElement) -> BFieldElement
/
operation. Read more§impl Evaluable<BFieldElement> for MasterAuxTable
impl Evaluable<BFieldElement> for MasterAuxTable
fn evaluate_initial_constraints( main_row: ArrayView1<'_, BFieldElement>, aux_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges, ) -> Vec<XFieldElement>
fn evaluate_consistency_constraints( main_row: ArrayView1<'_, BFieldElement>, aux_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges, ) -> Vec<XFieldElement>
fn evaluate_transition_constraints( current_main_row: ArrayView1<'_, BFieldElement>, current_aux_row: ArrayView1<'_, XFieldElement>, next_main_row: ArrayView1<'_, BFieldElement>, next_aux_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges, ) -> Vec<XFieldElement>
fn evaluate_terminal_constraints( main_row: ArrayView1<'_, BFieldElement>, aux_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges, ) -> Vec<XFieldElement>
Source§impl FiniteField for BFieldElement
impl FiniteField for BFieldElement
Source§impl From<&NumberOfWords> for BFieldElement
impl From<&NumberOfWords> for BFieldElement
Source§fn from(_: &NumberOfWords) -> BFieldElement
fn from(_: &NumberOfWords) -> BFieldElement
Source§impl From<&OpStackElement> for BFieldElement
impl From<&OpStackElement> for BFieldElement
Source§fn from(_: &OpStackElement) -> BFieldElement
fn from(_: &OpStackElement) -> BFieldElement
Source§impl From<BFieldElement> for [u8; 8]
impl From<BFieldElement> for [u8; 8]
Convert a B-field element to a byte array. The client uses this for its database.
Source§impl From<HashTableMode> for BFieldElement
impl From<HashTableMode> for BFieldElement
Source§fn from(mode: HashTableMode) -> BFieldElement
fn from(mode: HashTableMode) -> BFieldElement
Source§impl From<NumberOfWords> for BFieldElement
impl From<NumberOfWords> for BFieldElement
Source§fn from(num_words: NumberOfWords) -> BFieldElement
fn from(num_words: NumberOfWords) -> BFieldElement
Source§impl From<OpStackElement> for BFieldElement
impl From<OpStackElement> for BFieldElement
Source§fn from(stack_element: OpStackElement) -> BFieldElement
fn from(stack_element: OpStackElement) -> BFieldElement
Source§impl From<i16> for BFieldElement
impl From<i16> for BFieldElement
Source§fn from(value: i16) -> BFieldElement
fn from(value: i16) -> BFieldElement
Source§impl From<i32> for BFieldElement
impl From<i32> for BFieldElement
Source§fn from(value: i32) -> BFieldElement
fn from(value: i32) -> BFieldElement
Source§impl From<i64> for BFieldElement
impl From<i64> for BFieldElement
Source§fn from(value: i64) -> BFieldElement
fn from(value: i64) -> BFieldElement
Source§impl From<i8> for BFieldElement
impl From<i8> for BFieldElement
Source§fn from(value: i8) -> BFieldElement
fn from(value: i8) -> BFieldElement
Source§impl From<isize> for BFieldElement
impl From<isize> for BFieldElement
Source§fn from(value: isize) -> BFieldElement
fn from(value: isize) -> BFieldElement
Source§impl From<u128> for BFieldElement
impl From<u128> for BFieldElement
Source§fn from(value: u128) -> BFieldElement
fn from(value: u128) -> BFieldElement
Source§impl From<u16> for BFieldElement
impl From<u16> for BFieldElement
Source§fn from(value: u16) -> BFieldElement
fn from(value: u16) -> BFieldElement
Source§impl From<u32> for BFieldElement
impl From<u32> for BFieldElement
Source§fn from(value: u32) -> BFieldElement
fn from(value: u32) -> BFieldElement
Source§impl From<u64> for BFieldElement
impl From<u64> for BFieldElement
Source§fn from(value: u64) -> BFieldElement
fn from(value: u64) -> BFieldElement
Source§impl From<u8> for BFieldElement
impl From<u8> for BFieldElement
Source§fn from(value: u8) -> BFieldElement
fn from(value: u8) -> BFieldElement
Source§impl From<usize> for BFieldElement
impl From<usize> for BFieldElement
Source§fn from(value: usize) -> BFieldElement
fn from(value: usize) -> BFieldElement
Source§impl FromStr for BFieldElement
impl FromStr for BFieldElement
Source§type Err = ParseBFieldElementError
type Err = ParseBFieldElementError
Source§fn from_str(s: &str) -> Result<BFieldElement, <BFieldElement as FromStr>::Err>
fn from_str(s: &str) -> Result<BFieldElement, <BFieldElement as FromStr>::Err>
s
to return a value of this type. Read moreSource§impl GetSize for BFieldElement
impl GetSize for BFieldElement
Source§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§impl Hash for BFieldElement
impl Hash for BFieldElement
Source§impl Inverse for BFieldElement
impl Inverse for BFieldElement
fn inverse(&self) -> BFieldElement
fn inverse_or_zero(&self) -> Self
Source§impl ModPowU32 for BFieldElement
impl ModPowU32 for BFieldElement
fn mod_pow_u32(&self, exp: u32) -> BFieldElement
Source§impl ModPowU64 for BFieldElement
impl ModPowU64 for BFieldElement
fn mod_pow_u64(&self, pow: u64) -> BFieldElement
Source§impl Mul<BFieldElement> for XFieldElement
impl Mul<BFieldElement> for XFieldElement
XField * BField means scalar multiplication of the BFieldElement onto each coefficient of the XField.
Source§type Output = XFieldElement
type Output = XFieldElement
*
operator.Source§fn mul(self, other: BFieldElement) -> XFieldElement
fn mul(self, other: BFieldElement) -> XFieldElement
*
operation. Read moreSource§impl<FF, FF2> Mul<Polynomial<'_, FF>> for BFieldElement
impl<FF, FF2> Mul<Polynomial<'_, FF>> for BFieldElement
Source§type Output = Polynomial<'static, FF2>
type Output = Polynomial<'static, FF2>
*
operator.Source§fn mul(
self,
other: Polynomial<'_, FF>,
) -> <BFieldElement as Mul<Polynomial<'_, FF>>>::Output
fn mul( self, other: Polynomial<'_, FF>, ) -> <BFieldElement as Mul<Polynomial<'_, FF>>>::Output
*
operation. Read moreSource§impl Mul<XFieldElement> for BFieldElement
impl Mul<XFieldElement> for BFieldElement
Source§type Output = XFieldElement
type Output = XFieldElement
*
operator.Source§fn mul(self, other: XFieldElement) -> XFieldElement
fn mul(self, other: XFieldElement) -> XFieldElement
*
operation. Read moreSource§impl Mul for BFieldElement
impl Mul for BFieldElement
Source§type Output = BFieldElement
type Output = BFieldElement
*
operator.Source§fn mul(self, rhs: BFieldElement) -> BFieldElement
fn mul(self, rhs: BFieldElement) -> BFieldElement
*
operation. Read moreSource§impl MulAssign<BFieldElement> for XFieldElement
impl MulAssign<BFieldElement> for XFieldElement
Source§fn mul_assign(&mut self, rhs: BFieldElement)
fn mul_assign(&mut self, rhs: BFieldElement)
*=
operation. Read moreSource§impl MulAssign for BFieldElement
impl MulAssign for BFieldElement
Source§fn mul_assign(&mut self, rhs: BFieldElement)
fn mul_assign(&mut self, rhs: BFieldElement)
*=
operation. Read moreSource§impl Neg for BFieldElement
impl Neg for BFieldElement
Source§type Output = BFieldElement
type Output = BFieldElement
-
operator.Source§fn neg(self) -> BFieldElement
fn neg(self) -> BFieldElement
-
operation. Read moreSource§impl One for BFieldElement
impl One for BFieldElement
Source§impl PartialEq for BFieldElement
impl PartialEq for BFieldElement
Source§impl PrimitiveRootOfUnity for BFieldElement
impl PrimitiveRootOfUnity for BFieldElement
fn primitive_root_of_unity(n: u64) -> Option<BFieldElement>
Source§impl Serialize for BFieldElement
impl Serialize for BFieldElement
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl Sub<BFieldElement> for XFieldElement
impl Sub<BFieldElement> for XFieldElement
Source§type Output = XFieldElement
type Output = XFieldElement
-
operator.Source§fn sub(self, other: BFieldElement) -> XFieldElement
fn sub(self, other: BFieldElement) -> XFieldElement
-
operation. Read moreSource§impl Sub<XFieldElement> for BFieldElement
impl Sub<XFieldElement> for BFieldElement
Source§type Output = XFieldElement
type Output = XFieldElement
-
operator.Source§fn sub(self, other: XFieldElement) -> XFieldElement
fn sub(self, other: XFieldElement) -> XFieldElement
-
operation. Read moreSource§impl Sub for BFieldElement
impl Sub for BFieldElement
Source§type Output = BFieldElement
type Output = BFieldElement
-
operator.Source§fn sub(self, rhs: BFieldElement) -> BFieldElement
fn sub(self, rhs: BFieldElement) -> BFieldElement
-
operation. Read moreSource§impl SubAssign<BFieldElement> for XFieldElement
impl SubAssign<BFieldElement> for XFieldElement
Source§fn sub_assign(&mut self, rhs: BFieldElement)
fn sub_assign(&mut self, rhs: BFieldElement)
-=
operation. Read moreSource§impl SubAssign for BFieldElement
impl SubAssign for BFieldElement
Source§fn sub_assign(&mut self, rhs: BFieldElement)
fn sub_assign(&mut self, rhs: BFieldElement)
-=
operation. Read moreSource§impl Sum for BFieldElement
impl Sum for BFieldElement
Source§fn sum<I>(iter: I) -> BFieldElementwhere
I: Iterator<Item = BFieldElement>,
fn sum<I>(iter: I) -> BFieldElementwhere
I: Iterator<Item = BFieldElement>,
Self
from the elements by “summing up”
the items.Source§impl TryFrom<&[u8]> for BFieldElement
impl TryFrom<&[u8]> for BFieldElement
Source§type Error = ParseBFieldElementError
type Error = ParseBFieldElementError
Source§fn try_from(
bytes: &[u8],
) -> Result<BFieldElement, <BFieldElement as TryFrom<&[u8]>>::Error>
fn try_from( bytes: &[u8], ) -> Result<BFieldElement, <BFieldElement as TryFrom<&[u8]>>::Error>
Source§impl Zero for BFieldElement
impl Zero for BFieldElement
impl Copy for BFieldElement
impl Eq for BFieldElement
impl StructuralPartialEq for BFieldElement
Auto Trait Implementations§
impl Freeze for BFieldElement
impl RefUnwindSafe for BFieldElement
impl Send for BFieldElement
impl Sync for BFieldElement
impl Unpin for BFieldElement
impl UnwindSafe for BFieldElement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more