pub struct Scalar<E>where
E: Environment,{ /* private fields */ }Implementations§
Source§impl<E> Scalar<E>where
E: Environment,
impl<E> Scalar<E>where
E: Environment,
Sourcepub fn from_field_lossy(field: &Field<E>) -> Scalar<E>
pub fn from_field_lossy(field: &Field<E>) -> Scalar<E>
Casts a scalar from a base field, with lossy truncation.
This method is commonly used by hash-to-scalar algorithms, where the hash output does not need to preserve the full base field.
Trait Implementations§
Source§impl<E> Add for Scalar<E>where
E: Environment,
impl<E> Add for Scalar<E>where
E: Environment,
Source§impl<E> AddAssign<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> AddAssign<&Scalar<E>> for Scalar<E>where
E: Environment,
Source§fn add_assign(&mut self, other: &Scalar<E>)
fn add_assign(&mut self, other: &Scalar<E>)
+= operation. Read moreSource§impl<E> AddAssign for Scalar<E>where
E: Environment,
impl<E> AddAssign for Scalar<E>where
E: Environment,
Source§fn add_assign(&mut self, other: Scalar<E>)
fn add_assign(&mut self, other: Scalar<E>)
+= operation. Read moreSource§impl<E> Cast<Address<E>> for Scalar<E>where
E: Environment,
impl<E> Cast<Address<E>> for Scalar<E>where
E: Environment,
Source§fn cast(&self) -> Address<E>
fn cast(&self) -> Address<E>
Casts a Scalar to an Address.
This operation converts the scalar to a field element, and then attempts to recover the group element by treating the field element as an x-coordinate. The group element is then converted to an address.
To cast arbitrary scalars to addresses, use Scalar::cast_lossy.
Source§impl<E, I> Cast<Integer<E, I>> for Scalar<E>where
E: Environment,
I: IntegerType,
impl<E, I> Cast<Integer<E, I>> for Scalar<E>where
E: Environment,
I: IntegerType,
Source§impl<E, I> Cast<Scalar<E>> for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> Cast<Scalar<E>> for Integer<E, I>where
E: Environment,
I: IntegerType,
Source§impl<E> Cast for Scalar<E>where
E: Environment,
impl<E> Cast for Scalar<E>where
E: Environment,
Source§impl<E> CastLossy<Address<E>> for Scalar<E>where
E: Environment,
impl<E> CastLossy<Address<E>> for Scalar<E>where
E: Environment,
Source§fn cast_lossy(&self) -> Address<E>
fn cast_lossy(&self) -> Address<E>
Casts a Scalar to an Address.
This operation converts the scalar into a field element, and then attempts to recover
the group element to construct the address. See the documentation of Field::cast_lossy
on the Group type for more details.
Source§impl<E> CastLossy<Boolean<E>> for Scalar<E>where
E: Environment,
impl<E> CastLossy<Boolean<E>> for Scalar<E>where
E: Environment,
Source§fn cast_lossy(&self) -> Boolean<E>
fn cast_lossy(&self) -> Boolean<E>
Casts a Scalar to a Boolean, with lossy truncation.
This operation returns the least significant bit of the scalar.
Source§impl<E> CastLossy<Field<E>> for Scalar<E>where
E: Environment,
impl<E> CastLossy<Field<E>> for Scalar<E>where
E: Environment,
Source§fn cast_lossy(&self) -> Field<E>
fn cast_lossy(&self) -> Field<E>
Casts a Scalar to a Field.
This operation is always lossless.
Source§impl<E> CastLossy<Group<E>> for Scalar<E>where
E: Environment,
impl<E> CastLossy<Group<E>> for Scalar<E>where
E: Environment,
Source§fn cast_lossy(&self) -> Group<E>
fn cast_lossy(&self) -> Group<E>
Casts a Scalar to a Group.
This operation converts the scalar into a field element, and then attempts to recover
the group element. See the documentation of Field::cast_lossy on the Group type
for more details.
Source§impl<E, I> CastLossy<Integer<E, I>> for Scalar<E>where
E: Environment,
I: IntegerType,
impl<E, I> CastLossy<Integer<E, I>> for Scalar<E>where
E: Environment,
I: IntegerType,
Source§fn cast_lossy(&self) -> Integer<E, I>
fn cast_lossy(&self) -> Integer<E, I>
Casts a Scalar to an Integer, with lossy truncation.
Source§impl<E> CastLossy<Scalar<E>> for Boolean<E>where
E: Environment,
impl<E> CastLossy<Scalar<E>> for Boolean<E>where
E: Environment,
Source§fn cast_lossy(&self) -> Scalar<E>
fn cast_lossy(&self) -> Scalar<E>
Casts a Boolean to a Scalar.
This is safe because casting from a boolean to any other type is always lossless.
Source§impl<E> CastLossy<Scalar<E>> for Field<E>where
E: Environment,
impl<E> CastLossy<Scalar<E>> for Field<E>where
E: Environment,
Source§fn cast_lossy(&self) -> Scalar<E>
fn cast_lossy(&self) -> Scalar<E>
Casts a Field to a Scalar, with lossy truncation.
This operation truncates the field to a scalar.
Source§impl<E, I> CastLossy<Scalar<E>> for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> CastLossy<Scalar<E>> for Integer<E, I>where
E: Environment,
I: IntegerType,
Source§fn cast_lossy(&self) -> Scalar<E>
fn cast_lossy(&self) -> Scalar<E>
Casts an Integer to a Scalar.
This is safe because casting from an integer to a scalar is always lossless.
Source§impl<E> CastLossy for Scalar<E>where
E: Environment,
impl<E> CastLossy for Scalar<E>where
E: Environment,
Source§fn cast_lossy(&self) -> Scalar<E>
fn cast_lossy(&self) -> Scalar<E>
Casts a Scalar to a Scalar.
This is an identity cast, so it is always lossless.
Source§impl<E> Compare for Scalar<E>where
E: Environment,
impl<E> Compare for Scalar<E>where
E: Environment,
Source§fn is_less_than(&self, other: &Scalar<E>) -> <Scalar<E> as Compare>::Output
fn is_less_than(&self, other: &Scalar<E>) -> <Scalar<E> as Compare>::Output
Returns true if self is less than other.
Source§fn is_greater_than(&self, other: &Scalar<E>) -> <Scalar<E> as Compare>::Output
fn is_greater_than(&self, other: &Scalar<E>) -> <Scalar<E> as Compare>::Output
Returns true if self is greater than other.
Source§fn is_less_than_or_equal(
&self,
other: &Scalar<E>,
) -> <Scalar<E> as Compare>::Output
fn is_less_than_or_equal( &self, other: &Scalar<E>, ) -> <Scalar<E> as Compare>::Output
Returns true if self is less than or equal to other.
Source§fn is_greater_than_or_equal(
&self,
other: &Scalar<E>,
) -> <Scalar<E> as Compare>::Output
fn is_greater_than_or_equal( &self, other: &Scalar<E>, ) -> <Scalar<E> as Compare>::Output
Returns true if self is greater than or equal to other.
type Output = Boolean<E>
Source§impl<E> Debug for Scalar<E>where
E: Environment,
impl<E> Debug for Scalar<E>where
E: Environment,
Source§impl<E> Display for Scalar<E>where
E: Environment,
impl<E> Display for Scalar<E>where
E: Environment,
Source§impl<E> Eject for Scalar<E>where
E: Environment,
impl<E> Eject for Scalar<E>where
E: Environment,
Source§fn eject_mode(&self) -> Mode
fn eject_mode(&self) -> Mode
Ejects the mode of the scalar.
Source§fn eject_value(&self) -> <Scalar<E> as Eject>::Primitive
fn eject_value(&self) -> <Scalar<E> as Eject>::Primitive
Ejects the scalar circuit as a console scalar.
type Primitive = Scalar<<E as Environment>::Network>
Source§fn eject(&self) -> (Mode, Self::Primitive)
fn eject(&self) -> (Mode, Self::Primitive)
Source§fn is_constant(&self) -> bool
fn is_constant(&self) -> bool
true if the circuit is a constant.Source§fn is_private(&self) -> bool
fn is_private(&self) -> bool
true if the circuit is a private.Source§impl<E> Equal for Scalar<E>where
E: Environment,
impl<E> Equal for Scalar<E>where
E: Environment,
Source§impl<E> From<&Scalar<E>> for LinearCombination<<E as Environment>::BaseField>where
E: Environment,
impl<E> From<&Scalar<E>> for LinearCombination<<E as Environment>::BaseField>where
E: Environment,
Source§fn from(scalar: &Scalar<E>) -> LinearCombination<<E as Environment>::BaseField>
fn from(scalar: &Scalar<E>) -> LinearCombination<<E as Environment>::BaseField>
Source§impl<E> From<Scalar<E>> for LinearCombination<<E as Environment>::BaseField>where
E: Environment,
impl<E> From<Scalar<E>> for LinearCombination<<E as Environment>::BaseField>where
E: Environment,
Source§fn from(scalar: Scalar<E>) -> LinearCombination<<E as Environment>::BaseField>
fn from(scalar: Scalar<E>) -> LinearCombination<<E as Environment>::BaseField>
Source§impl<E> FromBits for Scalar<E>where
E: Environment,
impl<E> FromBits for Scalar<E>where
E: Environment,
Source§fn from_bits_le(bits_le: &[<Scalar<E> as FromBits>::Boolean]) -> Scalar<E>
fn from_bits_le(bits_le: &[<Scalar<E> as FromBits>::Boolean]) -> Scalar<E>
Initializes a new scalar field element from a list of little-endian bits.
- If
bits_leis longer thanE::ScalarField::size_in_bits(), the excess bits are enforced to be0s. - If
bits_leis shorter thanE::ScalarField::size_in_bits(), it is padded with0s up to scalar field size.
Source§fn from_bits_be(bits_be: &[<Scalar<E> as FromBits>::Boolean]) -> Scalar<E>
fn from_bits_be(bits_be: &[<Scalar<E> as FromBits>::Boolean]) -> Scalar<E>
Initializes a new scalar field element from a list of big-endian bits without leading zeros.
type Boolean = Boolean<E>
Source§impl<E> FromField for Scalar<E>where
E: Environment,
impl<E> FromField for Scalar<E>where
E: Environment,
Source§fn from_field(field: <Scalar<E> as FromField>::Field) -> Scalar<E>
fn from_field(field: <Scalar<E> as FromField>::Field) -> Scalar<E>
Casts a scalar from a base field element.
This method guarantees the following:
- If the field element is larger than the scalar field modulus, then the operation will fail.
- If the field element is smaller than the scalar field modulus, then the operation will succeed.
- This is particularly useful for the case where a user called,
Scalar::from_field(scalar.to_field()), and the scalar bit representation is betweensize_in_data_bits < bits.len() < size_in_bits.
- This is particularly useful for the case where a user called,
type Field = Field<E>
Source§impl<E> FromStr for Scalar<E>where
E: Environment,
impl<E> FromStr for Scalar<E>where
E: Environment,
Source§impl<E> Inject for Scalar<E>where
E: Environment,
impl<E> Inject for Scalar<E>where
E: Environment,
Source§impl<E> MulAssign<&Scalar<E>> for Group<E>where
E: Environment,
impl<E> MulAssign<&Scalar<E>> for Group<E>where
E: Environment,
Source§fn mul_assign(&mut self, other: &Scalar<E>)
fn mul_assign(&mut self, other: &Scalar<E>)
*= operation. Read moreSource§impl<E> MulAssign<Scalar<E>> for Group<E>where
E: Environment,
impl<E> MulAssign<Scalar<E>> for Group<E>where
E: Environment,
Source§fn mul_assign(&mut self, other: Scalar<E>)
fn mul_assign(&mut self, other: Scalar<E>)
*= operation. Read moreSource§impl<E> One for Scalar<E>where
E: Environment,
impl<E> One for Scalar<E>where
E: Environment,
Source§impl<E> OutputMode<dyn Add<Scalar<E>, Output = Scalar<E>>> for Scalar<E>where
E: Environment,
impl<E> OutputMode<dyn Add<Scalar<E>, Output = Scalar<E>>> for Scalar<E>where
E: Environment,
Source§impl<E> Parser for Scalar<E>where
E: Environment,
impl<E> Parser for Scalar<E>where
E: Environment,
Source§impl<E> Ternary for Scalar<E>where
E: Environment,
impl<E> Ternary for Scalar<E>where
E: Environment,
Source§impl<E> ToBits for &Scalar<E>where
E: Environment,
impl<E> ToBits for &Scalar<E>where
E: Environment,
Source§fn write_bits_le(&self, vec: &mut Vec<<&Scalar<E> as ToBits>::Boolean>)
fn write_bits_le(&self, vec: &mut Vec<<&Scalar<E> as ToBits>::Boolean>)
Outputs the little-endian bit representation of self without trailing zeros.
Source§fn write_bits_be(&self, vec: &mut Vec<<&Scalar<E> as ToBits>::Boolean>)
fn write_bits_be(&self, vec: &mut Vec<<&Scalar<E> as ToBits>::Boolean>)
Outputs the big-endian bit representation of self without leading zeros.
type Boolean = Boolean<E>
Source§fn to_bits_le(&self) -> Vec<Self::Boolean>
fn to_bits_le(&self) -> Vec<Self::Boolean>
Source§fn to_bits_be(&self) -> Vec<Self::Boolean>
fn to_bits_be(&self) -> Vec<Self::Boolean>
Source§impl<E> ToBits for Scalar<E>where
E: Environment,
impl<E> ToBits for Scalar<E>where
E: Environment,
Source§fn write_bits_le(&self, vec: &mut Vec<<Scalar<E> as ToBits>::Boolean>)
fn write_bits_le(&self, vec: &mut Vec<<Scalar<E> as ToBits>::Boolean>)
Outputs the little-endian bit representation of self without trailing zeros.
Source§fn write_bits_be(&self, vec: &mut Vec<<Scalar<E> as ToBits>::Boolean>)
fn write_bits_be(&self, vec: &mut Vec<<Scalar<E> as ToBits>::Boolean>)
Outputs the big-endian bit representation of self without leading zeros.
type Boolean = Boolean<E>
Source§fn to_bits_le(&self) -> Vec<Self::Boolean>
fn to_bits_le(&self) -> Vec<Self::Boolean>
Source§fn to_bits_be(&self) -> Vec<Self::Boolean>
fn to_bits_be(&self) -> Vec<Self::Boolean>
Source§impl<E> ToField for Scalar<E>where
E: Environment,
impl<E> ToField for Scalar<E>where
E: Environment,
Source§impl<E> ToFields for Scalar<E>where
E: Environment,
impl<E> ToFields for Scalar<E>where
E: Environment,
Source§impl<E> TypeName for Scalar<E>where
E: Environment,
impl<E> TypeName for Scalar<E>where
E: Environment,
Source§impl<E> Zero for Scalar<E>where
E: Environment,
impl<E> Zero for Scalar<E>where
E: Environment,
impl<E> GroupTrait<Scalar<E>> for Group<E>where
E: Environment,
impl<E> ScalarTrait for Scalar<E>where
E: Environment,
Auto Trait Implementations§
impl<E> !Freeze for Scalar<E>
impl<E> !RefUnwindSafe for Scalar<E>
impl<E> Send for Scalar<E>
impl<E> !Sync for Scalar<E>
impl<E> Unpin for Scalar<E>
impl<E> UnwindSafe for Scalar<E>
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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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