Skip to content

Commit

Permalink
Fix column assignment and generations
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekvpandya committed Oct 9, 2023
1 parent c0dc585 commit 5c3050f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions poseidon2-starky/src/plonky2/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ pub(crate) const COL_1ST_FULLROUND_STATE_START: usize = COL_INPUT_START + STATE_

/// The value of state[0] after each partial round
pub(crate) const COL_PARTIAL_ROUND_STATE_START: usize =
COL_1ST_FULLROUND_STATE_START + STATE_SIZE * ROUNDS_F; // 12 + 96
COL_1ST_FULLROUND_STATE_START + STATE_SIZE * (ROUNDS_F / 2); // 12 + 48

/// The starting point of the state after the partial round
pub(crate) const COL_PARTIAL_ROUND_END_STATE_START: usize =
COL_PARTIAL_ROUND_STATE_START + ROUNDS_P - 1; // 12 + 96 + 22
COL_PARTIAL_ROUND_STATE_START + ROUNDS_P - 1; // 12 + 48 + 22

/// The starting point of the state after each 2nd full round
pub(crate) const COL_2ND_FULLROUND_STATE_START: usize =
COL_PARTIAL_ROUND_END_STATE_START + STATE_SIZE; // 12 + 96 + 22 + 12
COL_PARTIAL_ROUND_END_STATE_START + STATE_SIZE; // 12 + 48 + 22 + 12

/// The starting point of the column output
/// This is the same as the last state after the 2nd full round
pub(crate) const COL_OUTPUT_START: usize =
COL_2ND_FULLROUND_STATE_START + STATE_SIZE * (ROUNDS_F - 1);
COL_2ND_FULLROUND_STATE_START + STATE_SIZE * ((ROUNDS_F / 2) - 1); // 12 + 48 + 22 + 12 + 36

/// The total number of columns
pub(crate) const NUM_COLS: usize = COL_2ND_FULLROUND_STATE_START + STATE_SIZE * ROUNDS_F; // 12 + 96 + 22 + 12 + 96
pub(crate) const NUM_COLS: usize = COL_2ND_FULLROUND_STATE_START + STATE_SIZE * (ROUNDS_F / 2); // 12 + 96 + 22 + 12 + 36 + 12
6 changes: 3 additions & 3 deletions poseidon2-starky/src/plonky2/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::plonky2::columns::{
};
use plonky2::hash::{
hash_types::RichField,
poseidon2::{Poseidon2, ROUND_F_BEGIN, ROUND_F_END, WIDTH},
poseidon2::{Poseidon2, WIDTH},
};

// Represent a row of the preimage
Expand Down Expand Up @@ -37,7 +37,7 @@ fn generate_1st_full_round_state<Field: RichField>(
// Linear layer at start
Field::matmul_external(&mut current_state);

for r in 0..ROUND_F_BEGIN {
for r in 0..(ROUNDS_F / 2) {
<Field as Poseidon2>::constant_layer(&mut current_state, r);
<Field as Poseidon2>::sbox_layer(&mut current_state);
Field::matmul_external(&mut current_state);
Expand Down Expand Up @@ -71,7 +71,7 @@ fn generate_2st_full_round_state<Field: RichField>(
assert_eq!(STATE_SIZE, WIDTH);
let mut current_state = *last_rount_output;

for r in ROUND_F_BEGIN..ROUND_F_END {
for r in (ROUNDS_F / 2)..ROUNDS_F {
<Field as Poseidon2>::constant_layer(&mut current_state, r);
<Field as Poseidon2>::sbox_layer(&mut current_state);
Field::matmul_external(&mut current_state);
Expand Down

0 comments on commit 5c3050f

Please sign in to comment.