pub struct Sha2BlockHasherFillerHelper<C: Sha2BlockHasherSubairConfig> {
pub row_idx_encoder: Encoder,
/* private fields */
}Expand description
A helper struct for the SHA-2 trace generation. Also, separates the inner AIR from the trace generation.
Fields§
§row_idx_encoder: EncoderImplementations§
Source§impl<C: Sha2BlockHasherSubairConfig> Sha2BlockHasherFillerHelper<C>
The trace generation of SHA-2 should be done in two passes.
The first pass should do get_block_trace for every block and generate the invalid rows through
get_default_row The second pass should go through all the blocks and call
generate_missing_cells
impl<C: Sha2BlockHasherSubairConfig> Sha2BlockHasherFillerHelper<C>
The trace generation of SHA-2 should be done in two passes.
The first pass should do get_block_trace for every block and generate the invalid rows through
get_default_row The second pass should go through all the blocks and call
generate_missing_cells
pub fn new() -> Self
Sourcepub fn get_block_hash(prev_hash: &[C::Word], input: Vec<u8>) -> Vec<C::Word>
pub fn get_block_hash(prev_hash: &[C::Word], input: Vec<u8>) -> Vec<C::Word>
This function takes the input_message (padding not handled), the previous hash, and returns the new hash after processing the block input
Sourcepub fn generate_block_trace<F: PrimeField32>(
&self,
trace: &mut [F],
trace_width: usize,
trace_start_col: usize,
input: &[C::Word],
bitwise_lookup_chip: SharedBitwiseOperationLookupChip<8>,
prev_hash: &[C::Word],
next_block_prev_hash: &[C::Word],
global_block_idx: u32,
)
pub fn generate_block_trace<F: PrimeField32>( &self, trace: &mut [F], trace_width: usize, trace_start_col: usize, input: &[C::Word], bitwise_lookup_chip: SharedBitwiseOperationLookupChip<8>, prev_hash: &[C::Word], next_block_prev_hash: &[C::Word], global_block_idx: u32, )
This function takes a C::BLOCK_BITS-bit chunk of the input message (padding not handled),
the previous hash, a flag indicating if it’s the last block, the global block index, the
local block index, and the buffer values that will be put in rows 0..4.
Will populate the given trace with the trace of the block, where the width of the trace is
trace_width and the starting column for the Sha2Air is trace_start_col.
Note: this function only generates some of the required trace. Another pass is required,
refer to Self::generate_missing_cells for details.
Sourcepub fn generate_missing_cells<F: PrimeField32>(
&self,
trace: &mut [F],
trace_width: usize,
trace_start_col: usize,
)
pub fn generate_missing_cells<F: PrimeField32>( &self, trace: &mut [F], trace_width: usize, trace_start_col: usize, )
This function will fill in the cells that we couldn’t do during the first pass.
This function should be called only after generate_block_trace was called for all blocks
And Self::generate_default_row is called for all invalid rows
Will populate the missing values of trace, where the width of the trace is trace_width
Note: trace needs to be the rows 1..C::ROWS_PER_BLOCK of a block and the first row of the
next block
Sourcepub fn generate_default_row<F: PrimeField32>(
&self,
cols: &mut Sha2RoundColsRefMut<'_, F>,
first_block_prev_hash: &[C::Word],
carry_a: Option<&[F]>,
carry_e: Option<&[F]>,
global_block_idx: u32,
)
pub fn generate_default_row<F: PrimeField32>( &self, cols: &mut Sha2RoundColsRefMut<'_, F>, first_block_prev_hash: &[C::Word], carry_a: Option<&[F]>, carry_e: Option<&[F]>, global_block_idx: u32, )
Fills the cols as a padding row
Note: we still need to correctly fill in the hash values, carries and intermeds
Sourcepub fn generate_carry_ae<F: PrimeField32>(
local_cols: Sha2RoundColsRef<'_, F>,
next_cols: &mut Sha2RoundColsRefMut<'_, F>,
)
pub fn generate_carry_ae<F: PrimeField32>( local_cols: Sha2RoundColsRef<'_, F>, next_cols: &mut Sha2RoundColsRefMut<'_, F>, )
The following functions do the calculations in native field since they will be called on
padding rows which can overflow and we need to make sure it matches the AIR constraints
Puts the correct carries in the next_row, the resulting carries can be out of bounds.
Assumes next.w and next.k are zero, which is the case when constraint_word_addition is
constrained on digest rows or padding rows.
It only looks at local.a, next.a, local.e, next.e.
Sourcepub fn generate_intermed_4<F: PrimeField32>(
local_cols: Sha2RoundColsRef<'_, F>,
next_cols: &mut Sha2RoundColsRefMut<'_, F>,
)
pub fn generate_intermed_4<F: PrimeField32>( local_cols: Sha2RoundColsRef<'_, F>, next_cols: &mut Sha2RoundColsRefMut<'_, F>, )
Puts the correct intermed_4 in the next_row
Sourcepub fn generate_intermed_12<F: PrimeField32>(
local_cols: &mut Sha2RoundColsRefMut<'_, F>,
next_cols: Sha2RoundColsRef<'_, F>,
)
pub fn generate_intermed_12<F: PrimeField32>( local_cols: &mut Sha2RoundColsRefMut<'_, F>, next_cols: Sha2RoundColsRef<'_, F>, )
Puts the needed intermed_12 in the local_row
Trait Implementations§
Source§impl<C: Sha2BlockHasherSubairConfig> Default for Sha2BlockHasherFillerHelper<C>
impl<C: Sha2BlockHasherSubairConfig> Default for Sha2BlockHasherFillerHelper<C>
Auto Trait Implementations§
impl<C> Freeze for Sha2BlockHasherFillerHelper<C>
impl<C> RefUnwindSafe for Sha2BlockHasherFillerHelper<C>where
C: RefUnwindSafe,
impl<C> Send for Sha2BlockHasherFillerHelper<C>
impl<C> Sync for Sha2BlockHasherFillerHelper<C>
impl<C> Unpin for Sha2BlockHasherFillerHelper<C>where
C: Unpin,
impl<C> UnwindSafe for Sha2BlockHasherFillerHelper<C>where
C: UnwindSafe,
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.