From 5c3050f1bbab2b8eff5cb778ded989b67a1eec8d Mon Sep 17 00:00:00 2001 From: Vivek Pandya Date: Mon, 9 Oct 2023 14:06:56 +0530 Subject: [PATCH] Fix column assignment and generations --- poseidon2-starky/src/plonky2/columns.rs | 10 +++++----- poseidon2-starky/src/plonky2/generation.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/poseidon2-starky/src/plonky2/columns.rs b/poseidon2-starky/src/plonky2/columns.rs index 0c5e80f..deccaf5 100644 --- a/poseidon2-starky/src/plonky2/columns.rs +++ b/poseidon2-starky/src/plonky2/columns.rs @@ -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 diff --git a/poseidon2-starky/src/plonky2/generation.rs b/poseidon2-starky/src/plonky2/generation.rs index 3b26c30..c1be9fe 100644 --- a/poseidon2-starky/src/plonky2/generation.rs +++ b/poseidon2-starky/src/plonky2/generation.rs @@ -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 @@ -37,7 +37,7 @@ fn generate_1st_full_round_state( // Linear layer at start Field::matmul_external(&mut current_state); - for r in 0..ROUND_F_BEGIN { + for r in 0..(ROUNDS_F / 2) { ::constant_layer(&mut current_state, r); ::sbox_layer(&mut current_state); Field::matmul_external(&mut current_state); @@ -71,7 +71,7 @@ fn generate_2st_full_round_state( 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 { ::constant_layer(&mut current_state, r); ::sbox_layer(&mut current_state); Field::matmul_external(&mut current_state);