Struct triton_vm::prelude::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 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

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 fn raw_u64(&self) -> u64

Trait Implementations§

source§

impl Add<BFieldElement> for XFieldElement

§

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.

§

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

§

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

§

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 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

§

type Output = BFieldElement

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Evaluable<BFieldElement> for MasterExtTable

source§

fn evaluate_initial_constraints( base_row: ArrayView1<'_, BFieldElement>, ext_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges ) -> Vec<XFieldElement>

The code for this method must be generated by running cargo run --bin constraint-evaluation-generator
source§

fn evaluate_consistency_constraints( base_row: ArrayView1<'_, BFieldElement>, ext_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges ) -> Vec<XFieldElement>

The code for this method must be generated by running cargo run --bin constraint-evaluation-generator
source§

fn evaluate_transition_constraints( current_base_row: ArrayView1<'_, BFieldElement>, current_ext_row: ArrayView1<'_, XFieldElement>, next_base_row: ArrayView1<'_, BFieldElement>, next_ext_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges ) -> Vec<XFieldElement>

The code for this method must be generated by running cargo run --bin constraint-evaluation-generator
source§

fn evaluate_terminal_constraints( base_row: ArrayView1<'_, BFieldElement>, ext_row: ArrayView1<'_, XFieldElement>, challenges: &Challenges ) -> Vec<XFieldElement>

The code for this method must be generated by running cargo run --bin constraint-evaluation-generator
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(num_words: &NumberOfWords) -> Self

Converts to this type from the input type.
source§

impl From<&OpStackElement> for BFieldElement

source§

fn from(stack_element: &OpStackElement) -> Self

Converts to this type from the input type.
source§

impl From<[u8; 8]> for BFieldElement

source§

fn from(array: [u8; 8]) -> 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) -> Self

Converts to this type from the input type.
source§

impl From<NumberOfWords> for BFieldElement

source§

fn from(num_words: NumberOfWords) -> Self

Converts to this type from the input type.
source§

impl From<OpStackElement> for BFieldElement

source§

fn from(stack_element: OpStackElement) -> Self

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<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 FromStr for BFieldElement

§

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 MasterTable<BFieldElement> for MasterBaseTable

source§

fn trace_domain(&self) -> ArithmeticDomain

source§

fn randomized_trace_domain(&self) -> ArithmeticDomain

source§

fn quotient_domain(&self) -> ArithmeticDomain

source§

fn fri_domain(&self) -> ArithmeticDomain

source§

fn trace_table(&self) -> ArrayView2<'_, BFieldElement>

Presents underlying trace data, excluding trace randomizers and randomizer polynomials.
source§

fn trace_table_mut(&mut self) -> ArrayViewMut2<'_, BFieldElement>

Mutably presents underlying trace data, excluding trace randomizers and randomizer polynomials.
source§

fn randomized_trace_table(&self) -> ArrayView2<'_, BFieldElement>

source§

fn randomized_trace_table_mut(&mut self) -> ArrayViewMut2<'_, BFieldElement>

source§

fn quotient_domain_table(&self) -> ArrayView2<'_, BFieldElement>

The low-degree extended randomized trace data over the quotient domain. Includes randomizer polynomials. Requires having called low_degree_extend_all_columns first.
source§

fn fri_domain_table(&self) -> ArrayView2<'_, BFieldElement>

The low-degree extended randomized trace data over the FRI domain. Includes randomizer polynomials. Requires having called low_degree_extend_all_columns first.
source§

fn memoize_low_degree_extended_table( &mut self, low_degree_extended_columns: Array2<BFieldElement> )

Not intended for direct use, but through Self::low_degree_extend_all_columns.
source§

fn low_degree_extended_table(&self) -> ArrayView2<'_, BFieldElement>

Requires having called low_degree_extend_all_columns first.
source§

fn memoize_interpolation_polynomials( &mut self, interpolation_polynomials: Array1<Polynomial<BFieldElement>> )

Memoize the polynomials interpolating the columns. Not intended for direct use, but through Self::low_degree_extend_all_columns.
source§

fn interpolation_polynomials(&self) -> ArrayView1<'_, Polynomial<XFieldElement>>

Requires having called low_degree_extend_all_columns first.
source§

fn row(&self, row_index: XFieldElement) -> Array1<XFieldElement>

Get one row of the table at an arbitrary index. Notably, the index does not have to be in any of the domains. In other words, can be used to compute out-of-domain rows. Requires having called low_degree_extend_all_columns first. Does not include randomizer polynomials.
source§

fn hash_one_row(row: ArrayView1<'_, BFieldElement>) -> Digest

source§

fn randomize_trace(&mut self)

Set all rows not part of the actual (padded) trace to random values.
source§

fn low_degree_extend_all_columns(&mut self)

Low-degree extend all columns of the randomized trace domain table. The resulting low-degree extended columns can be accessed using quotient_domain_table and fri_domain_table.
source§

fn merkle_tree( &self, maybe_profiler: &mut Option<TritonProfiler> ) -> MerkleTree<Tip5>

Compute a Merkle tree of the FRI domain table. Every row gives one leaf in the tree. The function hash_row is used to hash each row.
source§

fn hash_all_fri_domain_rows(&self) -> Vec<Digest>

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.

§

type Output = XFieldElement

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<XFieldElement> for BFieldElement

§

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

§

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

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

§

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

§

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

§

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>,

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl TryFrom<&BFieldElement> for NumberOfWords

§

type Error = NumberOfWordsError

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

fn try_from(index: &BFieldElement) -> Result<Self, NumberOfWordsError>

Performs the conversion.
source§

impl TryFrom<BFieldElement> for Instruction

§

type Error = InstructionError

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

fn try_from(opcode: BFieldElement) -> Result<Self, InstructionError>

Performs the conversion.
source§

impl TryFrom<BFieldElement> for NumberOfWords

§

type Error = NumberOfWordsError

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

fn try_from(index: BFieldElement) -> Result<Self, NumberOfWordsError>

Performs the conversion.
source§

impl TryFrom<BFieldElement> for OpStackElement

§

type Error = OpStackElementError

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

fn try_from(stack_index: BFieldElement) -> Result<Self, OpStackElementError>

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> 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.
§

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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,