Skip to main content

ScalarChallenge

Struct ScalarChallenge 

Source
pub struct ScalarChallenge<F>(F);
Expand description

A challenge which is used as a scalar on a group element in the verifier.

This wraps a field element that will be converted to an “effective” scalar using the curve endomorphism for efficient scalar multiplication.

See ScalarChallenge::to_field for how the conversion works.

Tuple Fields§

§0: F

Implementations§

Source§

impl<F> ScalarChallenge<F>

Source

pub const fn new(challenge: F) -> Self

Creates a ScalarChallenge from a field element.

§Deprecation

This constructor will be deprecated in favor of Self::from_limbs, which enforces the 128-bit constraint at construction.

The field element is assumed to contain at most 128 bits of data (i.e., only the two lowest 64-bit limbs are set). This is the case when the value comes from FqSponge::challenge.

Source§

impl<F: PrimeField> ScalarChallenge<F>

Source

pub fn from_limbs(limbs: [u64; 2]) -> Self

Creates a ScalarChallenge from exactly 128 bits (2 limbs).

This is the preferred constructor as it enforces the 128-bit constraint required by Self::to_field.

§Panics

Panics if the 128-bit value cannot be represented as a field element (unreachable for fields with modulus > 2^128).

Source

pub const fn inner(&self) -> F

Get the inner value

Source

pub fn to_field_with_length(&self, length_in_bits: usize, endo_coeff: &F) -> F

Converts a scalar challenge to an “effective” scalar using endomorphism decomposition.

§Background

For curves with an endomorphism φ(P) = [λ]P, we can represent any scalar k as:

k = a·λ + b

This allows efficient scalar multiplication because:

[k]P = [a·λ + b]P = [a]·φ(P) + [b]·P

Since φ(P) = (ξ·x, y) is essentially free (one field multiplication), we reduce the scalar multiplication cost by processing two scalar multiplications of half the size instead of one full-size multiplication.

§Algorithm

Starting with a = b = 2, the challenge bits are processed in pairs (r_{2i}, r_{2i+1}) from MSB to LSB. For each pair:

  1. Double both a and b
  2. Add ±1 to either a or b based on the bit pair:
r_{2i}r_{2i+1}Action
00b += -1
10b += +1
01a += -1
11a += +1

The result is: a·λ + b

§Parameters
  • length_in_bits: Number of bits to process from the challenge
  • endo_coeff: The scalar λ such that φ(P) = [λ]P
§Returns

The effective scalar k = a·λ + b

§References
Source

pub fn to_field(&self, endo_coeff: &F) -> F

Converts a scalar challenge to an effective scalar.

This is a convenience wrapper around Self::to_field_with_length using the default challenge length (128 bits).

See Self::to_field_with_length for details on the algorithm.

Trait Implementations§

Source§

impl<F: Clone> Clone for ScalarChallenge<F>

Source§

fn clone(&self) -> ScalarChallenge<F>

Returns a duplicate 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<F: Debug> Debug for ScalarChallenge<F>

Source§

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

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

impl<F, CamlF> From<CamlScalarChallenge<CamlF>> for ScalarChallenge<F>
where CamlF: Into<F>,

Source§

fn from(caml_sc: CamlScalarChallenge<CamlF>) -> Self

Converts to this type from the input type.
Source§

impl<F, CamlF> From<ScalarChallenge<F>> for CamlScalarChallenge<CamlF>
where CamlF: From<F>,

Source§

fn from(sc: ScalarChallenge<F>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<F> Freeze for ScalarChallenge<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for ScalarChallenge<F>
where F: RefUnwindSafe,

§

impl<F> Send for ScalarChallenge<F>
where F: Send,

§

impl<F> Sync for ScalarChallenge<F>
where F: Sync,

§

impl<F> Unpin for ScalarChallenge<F>
where F: Unpin,

§

impl<F> UnwindSafe for ScalarChallenge<F>
where F: UnwindSafe,

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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

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

§

fn vzip(self) -> V