triton_vm::prelude

Struct BFieldElement

Source
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

Source

pub const BYTES: usize = 8usize

Source

pub const P: u64 = 18_446_744_069_414_584_321u64

The base field’s prime, i.e., 2^64 - 2^32 + 1.

Source

pub const MAX: u64 = 18_446_744_069_414_584_320u64

Source

pub const MINUS_TWO_INVERSE: BFieldElement = _

-2^-1

Source

pub const fn new(value: u64) -> BFieldElement

Source

pub const fn value(&self) -> u64

Source

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

Source

pub const fn generator() -> BFieldElement

Get a generator for the entire field

Source

pub const fn lift(&self) -> XFieldElement

Source

pub fn increment(&mut self)

Source

pub fn decrement(&mut self)

Source

pub const fn mod_pow(&self, exp: u64) -> BFieldElement

Source

pub fn from_ne_bytes(bytes: &[u8]) -> BFieldElement

👎Deprecated since 0.42.0: endianness must not be platform specific; use <&[u8]>::try_from() instead

Convert a BFieldElement from a byte slice in native endianness.

Source

pub const fn montyred(x: u128) -> u64

Montgomery reduction

Source

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

Source

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

Source

pub const fn raw_u16s(&self) -> [u16; 4]

Return the raw 16-bit chunks of the Montgomery representation, in little-endian chunk order

Source

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

Source

pub fn raw_u128(&self) -> u128

Source

pub const fn from_raw_u64(e: u64) -> BFieldElement

Source

pub const fn raw_u64(&self) -> u64

Source

pub const fn is_canonical(x: u64) -> bool

Trait Implementations§

Source§

impl Add<BFieldElement> for XFieldElement

Source§

type Output = XFieldElement

The resulting type after applying the + operator.
Source§

fn add(self, other: BFieldElement) -> XFieldElement

Performs the + operation. Read more
Source§

impl Add<XFieldElement> for BFieldElement

The bfe + xfe -> xfe instance belongs to BFieldElement.

Source§

type Output = XFieldElement

The resulting type after applying the + operator.
Source§

fn add(self, other: XFieldElement) -> XFieldElement

Performs the + operation. Read more
Source§

impl Add for BFieldElement

Source§

type Output = BFieldElement

The resulting type after applying the + operator.
Source§

fn add(self, rhs: BFieldElement) -> BFieldElement

Performs the + operation. Read more
Source§

impl AddAssign<BFieldElement> for XFieldElement

Source§

fn add_assign(&mut self, rhs: BFieldElement)

Performs the += operation. Read more
Source§

impl AddAssign for BFieldElement

Source§

fn add_assign(&mut self, rhs: BFieldElement)

Performs the += operation. Read more
Source§

impl<'a> Arbitrary<'a> for BFieldElement

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<BFieldElement, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl BFieldCodec for BFieldElement

Source§

type Error = BFieldCodecError

Source§

fn decode( sequence: &[BFieldElement], ) -> Result<Box<BFieldElement>, <BFieldElement as BFieldCodec>::Error>

Source§

fn encode(&self) -> Vec<BFieldElement>

Source§

fn static_length() -> Option<usize>

Returns the length in number of BFieldElements if it is known at compile-time. Otherwise, None.
Source§

impl Clone for BFieldElement

Source§

fn clone(&self) -> BFieldElement

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConstOne for BFieldElement

Source§

const ONE: BFieldElement = _

The multiplicative identity element of Self, 1.
Source§

impl ConstZero for BFieldElement

Source§

const ZERO: BFieldElement = _

The additive identity element of Self, 0.
Source§

impl CyclicGroupGenerator for BFieldElement

Source§

impl Debug for BFieldElement

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for BFieldElement

Source§

fn default() -> BFieldElement

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for BFieldElement

Source§

fn deserialize<D>( deserializer: D, ) -> Result<BFieldElement, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for BFieldElement

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Div for BFieldElement

Source§

type Output = BFieldElement

The resulting type after applying the / operator.
Source§

fn div(self, other: BFieldElement) -> BFieldElement

Performs the / operation. Read more
§

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

Source§

fn batch_inversion(input: Vec<Self>) -> Vec<Self>

Montgomery Batch Inversion
Source§

fn square(self) -> Self

Source§

impl From<&NumberOfWords> for BFieldElement

Source§

fn from(_: &NumberOfWords) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<&OpStackElement> for BFieldElement

Source§

fn from(_: &OpStackElement) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<BFieldElement> for [u8; 8]

Convert a B-field element to a byte array. The client uses this for its database.

Source§

fn from(bfe: BFieldElement) -> [u8; 8]

Converts to this type from the input type.
Source§

impl From<HashTableMode> for BFieldElement

Source§

fn from(mode: HashTableMode) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<NumberOfWords> for BFieldElement

Source§

fn from(num_words: NumberOfWords) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<OpStackElement> for BFieldElement

Source§

fn from(stack_element: OpStackElement) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<i16> for BFieldElement

Source§

fn from(value: i16) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<i32> for BFieldElement

Source§

fn from(value: i32) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<i64> for BFieldElement

Source§

fn from(value: i64) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<i8> for BFieldElement

Source§

fn from(value: i8) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<isize> for BFieldElement

Source§

fn from(value: isize) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<u128> for BFieldElement

Source§

fn from(value: u128) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<u16> for BFieldElement

Source§

fn from(value: u16) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<u32> for BFieldElement

Source§

fn from(value: u32) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<u64> for BFieldElement

Source§

fn from(value: u64) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<u8> for BFieldElement

Source§

fn from(value: u8) -> BFieldElement

Converts to this type from the input type.
Source§

impl From<usize> for BFieldElement

Source§

fn from(value: usize) -> BFieldElement

Converts to this type from the input type.
Source§

impl FromStr for BFieldElement

Source§

type Err = ParseBFieldElementError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<BFieldElement, <BFieldElement as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl GetSize for BFieldElement

Source§

fn get_stack_size() -> usize

Determines how may bytes this object occupies inside the stack. Read more
Source§

fn get_heap_size(&self) -> usize

Determines how many bytes this object occupies inside the heap. Read more
Source§

fn get_size(&self) -> usize

Determines the total size of the object. Read more
Source§

impl Hash for BFieldElement

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Inverse for BFieldElement

Source§

impl ModPowU32 for BFieldElement

Source§

impl ModPowU64 for BFieldElement

Source§

impl Mul<BFieldElement> for XFieldElement

XField * BField means scalar multiplication of the BFieldElement onto each coefficient of the XField.

Source§

type Output = XFieldElement

The resulting type after applying the * operator.
Source§

fn mul(self, other: BFieldElement) -> XFieldElement

Performs the * operation. Read more
Source§

impl<FF, FF2> Mul<Polynomial<'_, FF>> for BFieldElement
where FF: FiniteField<Output = FF2> + Mul<BFieldElement>, FF2: 'static + FiniteField,

Source§

type Output = Polynomial<'static, FF2>

The resulting type after applying the * operator.
Source§

fn mul( self, other: Polynomial<'_, FF>, ) -> <BFieldElement as Mul<Polynomial<'_, FF>>>::Output

Performs the * operation. Read more
Source§

impl Mul<XFieldElement> for BFieldElement

Source§

type Output = XFieldElement

The resulting type after applying the * operator.
Source§

fn mul(self, other: XFieldElement) -> XFieldElement

Performs the * operation. Read more
Source§

impl Mul for BFieldElement

Source§

type Output = BFieldElement

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: BFieldElement) -> BFieldElement

Performs the * operation. Read more
Source§

impl MulAssign<BFieldElement> for XFieldElement

Source§

fn mul_assign(&mut self, rhs: BFieldElement)

Performs the *= operation. Read more
Source§

impl MulAssign for BFieldElement

Source§

fn mul_assign(&mut self, rhs: BFieldElement)

Performs the *= operation. Read more
Source§

impl Neg for BFieldElement

Source§

type Output = BFieldElement

The resulting type after applying the - operator.
Source§

fn neg(self) -> BFieldElement

Performs the unary - operation. Read more
Source§

impl One for BFieldElement

Source§

fn one() -> BFieldElement

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

impl PartialEq for BFieldElement

Source§

fn eq(&self, other: &BFieldElement) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PrimitiveRootOfUnity for BFieldElement

Source§

impl Serialize for BFieldElement

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<BFieldElement> for XFieldElement

Source§

type Output = XFieldElement

The resulting type after applying the - operator.
Source§

fn sub(self, other: BFieldElement) -> XFieldElement

Performs the - operation. Read more
Source§

impl Sub<XFieldElement> for BFieldElement

Source§

type Output = XFieldElement

The resulting type after applying the - operator.
Source§

fn sub(self, other: XFieldElement) -> XFieldElement

Performs the - operation. Read more
Source§

impl Sub for BFieldElement

Source§

type Output = BFieldElement

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: BFieldElement) -> BFieldElement

Performs the - operation. Read more
Source§

impl SubAssign<BFieldElement> for XFieldElement

Source§

fn sub_assign(&mut self, rhs: BFieldElement)

Performs the -= operation. Read more
Source§

impl SubAssign for BFieldElement

Source§

fn sub_assign(&mut self, rhs: BFieldElement)

Performs the -= operation. Read more
Source§

impl Sum for BFieldElement

Source§

fn sum<I>(iter: I) -> BFieldElement
where I: Iterator<Item = BFieldElement>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl TryFrom<&[u8]> for BFieldElement

Source§

type Error = ParseBFieldElementError

The type returned in the event of a conversion error.
Source§

fn try_from( bytes: &[u8], ) -> Result<BFieldElement, <BFieldElement as TryFrom<&[u8]>>::Error>

Performs the conversion.
Source§

impl TryFrom<[u8; 8]> for BFieldElement

Source§

type Error = ParseBFieldElementError

The type returned in the event of a conversion error.
Source§

fn try_from( array: [u8; 8], ) -> Result<BFieldElement, <BFieldElement as TryFrom<[u8; 8]>>::Error>

Performs the conversion.
Source§

impl Zero for BFieldElement

Source§

fn zero() -> BFieldElement

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl Copy for BFieldElement

Source§

impl Eq for BFieldElement

Source§

impl StructuralPartialEq for BFieldElement

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> LinalgScalar for T
where T: One<Output = T> + Add<Output = T> + Sub<Output = T> + 'static + Mul + Copy + Div<Output = T> + Zero,