Skip to content

Commit

Permalink
cleanup hardcode
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jan 7, 2025
1 parent 942266b commit 1c3a5b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 11 additions & 7 deletions transcript/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ use p3_mds::MdsPermutation;
use p3_poseidon::Poseidon;
use p3_symmetric::Permutation;

// follow https://github.com/Plonky3/Plonky3/blob/main/poseidon/benches/poseidon.rs#L22
pub(crate) const WIDTH: usize = 8;
pub(crate) const ALPHA: u64 = 7;

#[derive(Clone)]
pub struct BasicTranscript<E: ExtensionField, Mds> {
// TODO generalized to accept general permutation
poseidon: Poseidon<E::BaseField, Mds, 8, 7>,
state: [E::BaseField; 8],
poseidon: Poseidon<E::BaseField, Mds, WIDTH, ALPHA>,
state: [E::BaseField; WIDTH],
}

impl<E: ExtensionField, Mds> BasicTranscript<E, Mds>
where
Mds: MdsPermutation<E::BaseField, 8> + Default,
Mds: MdsPermutation<E::BaseField, WIDTH> + Default,
{
/// Create a new IOP transcript.
pub fn new(label: &'static [u8]) -> Self {
Expand All @@ -27,7 +31,7 @@ where
let num_partial_rounds = 22;

let num_rounds = 2 * half_num_full_rounds + num_partial_rounds;
let num_constants = 8 * num_rounds;
let num_constants = WIDTH * num_rounds;
let constants = vec![E::BaseField::ZERO; num_constants];

let poseidon = Poseidon::<E::BaseField, _, _, _>::new(
Expand All @@ -36,7 +40,7 @@ where
constants,
mds,
);
let input: [E::BaseField; 8] = array::from_fn(|_| E::BaseField::ZERO);
let input = array::from_fn(|_| E::BaseField::ZERO);
let label_f = E::BaseField::bytes_to_field_elements(label);
let mut new = BasicTranscript::<E, _> {
poseidon,
Expand All @@ -59,7 +63,7 @@ where

impl<E: ExtensionField, Mds> Transcript<E> for BasicTranscript<E, Mds>
where
Mds: MdsPermutation<E::BaseField, 8> + Default,
Mds: MdsPermutation<E::BaseField, WIDTH> + Default,
{
fn append_field_element_ext(&mut self, element: &E) {
self.append_field_elements(element.as_bases());
Expand Down Expand Up @@ -102,6 +106,6 @@ where
impl<E: ExtensionField, Mds> ForkableTranscript<E> for BasicTranscript<E, Mds>
where
E::BaseField: FieldAlgebra + PrimeField,
Mds: MdsPermutation<E::BaseField, 8> + Default,
Mds: MdsPermutation<E::BaseField, WIDTH> + Default,
{
}
8 changes: 4 additions & 4 deletions transcript/src/statistics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{BasicTranscript, Challenge, ForkableTranscript, Transcript};
use crate::{BasicTranscript, Challenge, ForkableTranscript, Transcript, basic::WIDTH};
use ff_ext::ExtensionField;
use p3_mds::MdsPermutation;
use std::cell::RefCell;
Expand All @@ -18,7 +18,7 @@ pub struct BasicTranscriptWithStat<'a, E: ExtensionField, Mds> {

impl<'a, E: ExtensionField, Mds> BasicTranscriptWithStat<'a, E, Mds>
where
Mds: MdsPermutation<E::BaseField, 8> + Default,
Mds: MdsPermutation<E::BaseField, WIDTH> + Default,
{
pub fn new(stat: &'a StatisticRecorder, label: &'static [u8]) -> Self {
Self {
Expand All @@ -30,7 +30,7 @@ where

impl<E: ExtensionField, Mds> Transcript<E> for BasicTranscriptWithStat<'_, E, Mds>
where
Mds: MdsPermutation<E::BaseField, 8> + Default,
Mds: MdsPermutation<E::BaseField, WIDTH> + Default,
{
fn append_field_elements(&mut self, elements: &[E::BaseField]) {
self.stat.borrow_mut().field_appended_num += 1;
Expand Down Expand Up @@ -64,6 +64,6 @@ where
}

impl<E: ExtensionField, Mds> ForkableTranscript<E> for BasicTranscriptWithStat<'_, E, Mds> where
Mds: MdsPermutation<E::BaseField, 8> + Default
Mds: MdsPermutation<E::BaseField, WIDTH> + Default
{
}

0 comments on commit 1c3a5b6

Please sign in to comment.