pub struct BinaryChallenger<F, Inner> { /* private fields */ }Expand description
A challenger for a binary tower field, driven by a challenger over bytes.
A tower level is a whole number of bytes wide, and every bit pattern is an element.
A transcript over the field is therefore a transcript over its bytes. Nothing is encoded, decoded or rejection-sampled in either direction.
Observing: absorbs the little-endian bytes of the element into the inner challenger.
Sampling: reads the little-endian bytes of the element from the inner challenger.
Since the field has exactly 2^(8·NUM_BYTES) elements, uniform bytes give a uniform
field element.
Proof of work: unlike the field and bit sampling above, which work at every level,
grinding is only viable in the wider ones. GrindingChallenger::grind enumerates
candidates with a 64-bit counter and demands GRIND_MARGIN_BITS of headroom below that
space, which puts a ceiling of min(F::bits(), 64) − GRIND_MARGIN_BITS on the width of a
single request:
| witness field | largest supported bits |
|---|---|
BinaryField2, BinaryField4, BinaryField8 | none: every nonzero request panics |
BinaryField16 | 8 |
BinaryField32 | 24 |
BinaryField64 | 56 |
BinaryField128 | 56, bounded by the counter rather than the field |
So the levels below GF(2^32) implement GrindingChallenger without being usable
proof-of-work witness types, and a 128-bit witness buys no more width than a 64-bit one.
Implementations§
Source§impl<F, Inner> BinaryChallenger<F, Inner>
impl<F, Inner> BinaryChallenger<F, Inner>
Source§impl<F, H> BinaryChallenger<F, HashChallenger<u8, H, 32>>
impl<F, H> BinaryChallenger<F, HashChallenger<u8, H, 32>>
Sourcepub const fn from_hasher(initial_state: Vec<u8>, hasher: H) -> Self
pub const fn from_hasher(initial_state: Vec<u8>, hasher: H) -> Self
Wrap a fresh HashChallenger over the given hasher and initial transcript.
Trait Implementations§
Source§impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<&MerkleCap<G, [u8; N]>> for BinaryChallenger<F, Inner>
impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<&MerkleCap<G, [u8; N]>> for BinaryChallenger<F, Inner>
Source§impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<&MerkleCap<G, [u64; N]>> for BinaryChallenger<F, Inner>
impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<&MerkleCap<G, [u64; N]>> for BinaryChallenger<F, Inner>
Source§impl<F: TowerLevel, Inner: CanObserve<u8>> CanObserve<F> for BinaryChallenger<F, Inner>
impl<F: TowerLevel, Inner: CanObserve<u8>> CanObserve<F> for BinaryChallenger<F, Inner>
Source§impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<Hash<G, u8, N>> for BinaryChallenger<F, Inner>
impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<Hash<G, u8, N>> for BinaryChallenger<F, Inner>
Source§impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<Hash<G, u64, N>> for BinaryChallenger<F, Inner>
Word digests are absorbed as the little-endian bytes of each word, in order.
impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<Hash<G, u64, N>> for BinaryChallenger<F, Inner>
Word digests are absorbed as the little-endian bytes of each word, in order.
The digest’s own field is free of this challenger’s, as it is for a byte digest. A commitment over one level can then be bound into a transcript over another.
Source§impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<MerkleCap<G, [u8; N]>> for BinaryChallenger<F, Inner>
impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<MerkleCap<G, [u8; N]>> for BinaryChallenger<F, Inner>
Source§impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<MerkleCap<G, [u64; N]>> for BinaryChallenger<F, Inner>
impl<F, G, const N: usize, Inner: CanObserve<u8>> CanObserve<MerkleCap<G, [u64; N]>> for BinaryChallenger<F, Inner>
Source§impl<F, EF, Inner> CanSample<EF> for BinaryChallenger<F, Inner>
impl<F, EF, Inner> CanSample<EF> for BinaryChallenger<F, Inner>
Source§fn sample_into_slice(&mut self, values: &mut [T])
fn sample_into_slice(&mut self, values: &mut [T])
Source§fn sample_array<const N: usize>(&mut self) -> [T; N]
fn sample_array<const N: usize>(&mut self) -> [T; N]
N challenge values from the transcript.Source§fn sample_vec(&mut self, n: usize) -> Vec<T>
fn sample_vec(&mut self, n: usize) -> Vec<T>
Vec of n challenge values from the transcript.Source§impl<F, Inner> CanSampleBits<usize> for BinaryChallenger<F, Inner>
impl<F, Inner> CanSampleBits<usize> for BinaryChallenger<F, Inner>
Source§fn sample_bits(&mut self, bits: usize) -> usize
fn sample_bits(&mut self, bits: usize) -> usize
Sample a bitstring by masking bytes taken from the inner stream.
A challenger that bit-decomposes a sampled field element can only extract as many
bits as that element carries, and so has to bound the request by the field order.
This one instead reads its entropy straight off the inner byte stream, so how many
bits are available per call does not depend on F’s width at all: a challenger over
a narrow level can still draw a query index far wider than one of its own elements.
The one real bound is that the result must fit in a usize, which also keeps it
within the u64 the bytes are read into.
Source§impl<F, Inner> CanSampleUniformBits<F> for BinaryChallenger<F, Inner>
impl<F, Inner> CanSampleUniformBits<F> for BinaryChallenger<F, Inner>
Source§fn sample_uniform_bits<const RESAMPLE: bool>(
&mut self,
bits: usize,
) -> Result<usize, ResamplingError>
fn sample_uniform_bits<const RESAMPLE: bool>( &mut self, bits: usize, ) -> Result<usize, ResamplingError>
Sample uniform bits by masking bytes from the inner stream.
§Overview
The inner stream emits cryptographic-hash bytes uniform on [0, 2^8).
Reading 8 bytes as a 64-bit integer and masking the low bits is exactly uniform
on [0, 2^bits).
No field-element decomposition occurs, so no rejection band exists. The const generic is therefore inert: this function never errors and never resamples.
Source§impl<F, Inner> FieldChallenger<F> for BinaryChallenger<F, Inner>
impl<F, Inner> FieldChallenger<F> for BinaryChallenger<F, Inner>
Source§fn observe_algebra_element<A>(&mut self, alg_elem: A)where
A: BasedVectorSpace<F>,
fn observe_algebra_element<A>(&mut self, alg_elem: A)where
A: BasedVectorSpace<F>,
Source§fn observe_algebra_slice<A>(&mut self, alg_elems: &[A])where
A: BasedVectorSpace<F> + Clone,
fn observe_algebra_slice<A>(&mut self, alg_elems: &[A])where
A: BasedVectorSpace<F> + Clone,
Source§fn sample_algebra_element<A>(&mut self) -> Awhere
A: BasedVectorSpace<F>,
fn sample_algebra_element<A>(&mut self) -> Awhere
A: BasedVectorSpace<F>,
Source§fn observe_base_as_algebra_element<EF>(&mut self, val: F)where
EF: Algebra<F> + BasedVectorSpace<F>,
fn observe_base_as_algebra_element<EF>(&mut self, val: F)where
EF: Algebra<F> + BasedVectorSpace<F>,
Source§impl<F, Inner> GrindingChallenger for BinaryChallenger<F, Inner>
impl<F, Inner> GrindingChallenger for BinaryChallenger<F, Inner>
Auto Trait Implementations§
impl<F, Inner> Freeze for BinaryChallenger<F, Inner>
impl<F, Inner> RefUnwindSafe for BinaryChallenger<F, Inner>
impl<F, Inner> Send for BinaryChallenger<F, Inner>
impl<F, Inner> Sync for BinaryChallenger<F, Inner>
impl<F, Inner> Unpin for BinaryChallenger<F, Inner>
impl<F, Inner> UnsafeUnpin for BinaryChallenger<F, Inner>
impl<F, Inner> UnwindSafe for BinaryChallenger<F, Inner>
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