Skip to content

Commit

Permalink
transmute tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubarov committed Dec 19, 2023
1 parent e43a9fb commit 970f06b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions keccak-air/src/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use p3_util::indices_arr;
use crate::constants::R;
use crate::{NUM_ROUNDS, RATE_LIMBS, U64_LIMBS};

#[repr(C)]
pub(crate) struct KeccakCols<T> {
/// The `i`th value is set to 1 if we are in the `i`th round, otherwise 0.
pub step_flags: [T; NUM_ROUNDS],
Expand Down Expand Up @@ -121,22 +122,22 @@ const fn make_col_map() -> KeccakCols<usize> {

impl<T> Borrow<KeccakCols<T>> for [T] {
fn borrow(&self) -> &KeccakCols<T> {
// TODO: Double check if this is correct & consider making asserts debug-only.
debug_assert_eq!(self.len(), NUM_KECCAK_COLS);
let (prefix, shorts, suffix) = unsafe { self.align_to::<KeccakCols<T>>() };
assert!(prefix.is_empty(), "Data was not aligned");
assert!(suffix.is_empty(), "Data was not aligned");
assert_eq!(shorts.len(), 1);
debug_assert!(prefix.is_empty(), "Alignment should match");
debug_assert!(suffix.is_empty(), "Alignment should match");
debug_assert_eq!(shorts.len(), 1);
&shorts[0]
}
}

impl<T> BorrowMut<KeccakCols<T>> for [T] {
fn borrow_mut(&mut self) -> &mut KeccakCols<T> {
// TODO: Double check if this is correct & consider making asserts debug-only.
debug_assert_eq!(self.len(), NUM_KECCAK_COLS);
let (prefix, shorts, suffix) = unsafe { self.align_to_mut::<KeccakCols<T>>() };
assert!(prefix.is_empty(), "Data was not aligned");
assert!(suffix.is_empty(), "Data was not aligned");
assert_eq!(shorts.len(), 1);
debug_assert!(prefix.is_empty(), "Alignment should match");
debug_assert!(suffix.is_empty(), "Alignment should match");
debug_assert_eq!(shorts.len(), 1);
&mut shorts[0]
}
}
4 changes: 2 additions & 2 deletions keccak-air/src/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub fn generate_trace_rows<F: PrimeField64>(inputs: Vec<[u64; 25]>) -> RowMajorM
let mut trace =
RowMajorMatrix::new(vec![F::zero(); num_rows * NUM_KECCAK_COLS], NUM_KECCAK_COLS);
let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<KeccakCols<F>>() };
assert!(prefix.is_empty(), "Data was not aligned");
assert!(suffix.is_empty(), "Data was not aligned");
assert!(prefix.is_empty(), "Alignment should match");
assert!(suffix.is_empty(), "Alignment should match");
assert_eq!(rows.len(), num_rows);

let padded_inputs = inputs.into_iter().chain(iter::repeat([0; 25]));
Expand Down

0 comments on commit 970f06b

Please sign in to comment.