Skip to content

Commit

Permalink
more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenciak committed May 30, 2024
1 parent 1023495 commit 1e60632
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/poseidon/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ where
{
// Use a simple matrix multiplication as the permutation.
let mut state = sbox_result;
let matmul_constants: Array<<<AB as AirBuilder>::Expr as AbstractField>::F, C::WIDTH> =
C::matrix_diag().map(|u| <AB::Expr as AbstractField>::F::from_f(u));
let matmul_constants = C::matrix_diag().map(AB::F::from);
matmul_generic(&mut state, &matmul_constants);

for (state, &output_expected) in zip(state, &local.output) {
Expand Down
20 changes: 17 additions & 3 deletions src/poseidon/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use hybrid_array::{typenum::*, Array, ArraySize};
use itertools::Itertools;
use p3_baby_bear::BabyBear;
use p3_field::Field;
use p3_field::{AbstractField, Field};

use super::constants::MATRIX_DIAG_4_BABYBEAR;
use super::constants::{FULL_RC_4_8, MATRIX_DIAG_4_BABYBEAR, PART_RC_4_21};
// use p3_baby_bear::BabyBear;

trait ConstantsProvided {}
Expand Down Expand Up @@ -41,7 +42,20 @@ impl PoseidonConfig for BabyBearConfig4 {
}

fn round_constants() -> impl IntoIterator<Item = &'static Array<Self::F, Self::WIDTH>> {
todo!()
let first_half = FULL_RC_4_8
.iter()
.map(|u| Array::from_slice(u).as_ref())
.take(4);
let second_half = FULL_RC_4_8
.iter()
.map(|u| Array::from_slice(u).as_ref())
.skip(4);

let partial_round_constants = PART_RC_4_21
.into_iter()
.map(|v| Array::from_fn(|i| if i == 0 { v } else { BabyBear::zero() }).as_ref());

first_half.chain(partial_round_constants).chain(second_half)
}
}

Expand Down

0 comments on commit 1e60632

Please sign in to comment.