Skip to content

Commit

Permalink
feat(recursion): Add interactions to poseidon2 skinny (#658)
Browse files Browse the repository at this point in the history
Co-authored-by: John Guibas <[email protected]>
  • Loading branch information
kevjue and jtguibas authored May 6, 2024
1 parent 2972d71 commit 4f393a9
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 186 deletions.
2 changes: 1 addition & 1 deletion recursion/core/src/memory/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
let local = main.row_slice(0);
let local: &MemoryInitCols<AB::Var> = (*local).borrow();

// Verify that is_initilize and is_finalize are bool and that at most one is true.
// Verify that is_initialize and is_finalize are bool and that at most one is true.
builder.assert_bool(local.is_initialize);
builder.assert_bool(local.is_finalize);
builder.assert_bool(local.is_initialize + local.is_finalize);
Expand Down
3 changes: 1 addition & 2 deletions recursion/core/src/multi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use sp1_derive::AlignedBorrow;

use crate::air::SP1RecursionAirBuilder;
use crate::fri_fold::{FriFoldChip, FriFoldCols};
use crate::poseidon2::external::Poseidon2Cols;
use crate::poseidon2::Poseidon2Chip;
use crate::poseidon2::{Poseidon2Chip, Poseidon2Cols};
use crate::runtime::{ExecutionRecord, RecursionProgram};

pub const NUM_MULTI_COLS: usize = core::mem::size_of::<MultiCols<u8>>();
Expand Down
61 changes: 61 additions & 0 deletions recursion/core/src/poseidon2/columns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use sp1_derive::AlignedBorrow;

use crate::{memory::MemoryReadWriteSingleCols, poseidon2_wide::external::WIDTH};

/// The column layout for the chip.
#[derive(AlignedBorrow, Clone, Copy)]
#[repr(C)]
pub struct Poseidon2Cols<T: Copy> {
pub timestamp: T,
pub dst_input: T,
pub left_input: T,
pub right_input: T,
pub rounds: [T; 24], // 1 round for memory input; 1 round for initialize; 8 rounds for external; 13 rounds for internal; 1 round for memory output
pub is_computation: T,
pub is_memory_access: T,
pub round_specific_cols: RoundSpecificCols<T>,
}

#[derive(AlignedBorrow, Clone, Copy)]
#[repr(C)]
pub union RoundSpecificCols<T: Copy> {
computation: ComputationCols<T>,
memory_access: MemAccessCols<T>,
}

// SAFETY: Each view is a valid interpretation of the underlying array.
impl<T: Copy> RoundSpecificCols<T> {
pub fn computation(&self) -> &ComputationCols<T> {
unsafe { &self.computation }
}

pub fn computation_mut(&mut self) -> &mut ComputationCols<T> {
unsafe { &mut self.computation }
}

pub fn memory_access(&self) -> &MemAccessCols<T> {
unsafe { &self.memory_access }
}

pub fn memory_access_mut(&mut self) -> &mut MemAccessCols<T> {
unsafe { &mut self.memory_access }
}
}

#[derive(AlignedBorrow, Clone, Copy)]
#[repr(C)]
pub struct ComputationCols<T> {
pub input: [T; WIDTH],
pub add_rc: [T; WIDTH],
pub sbox_deg_3: [T; WIDTH],
pub sbox_deg_7: [T; WIDTH],
pub output: [T; WIDTH],
}

#[derive(AlignedBorrow, Clone, Copy)]
#[repr(C)]
pub struct MemAccessCols<T> {
pub addr_first_half: T,
pub addr_second_half: T,
pub mem_access: [MemoryReadWriteSingleCols<T>; WIDTH],
}
Loading

0 comments on commit 4f393a9

Please sign in to comment.