Skip to content

Commit

Permalink
Serialize DuplexChallenger and deps
Browse files Browse the repository at this point in the history
Change the Cargo.toml version so that [patch] works in sp1
  • Loading branch information
Champii committed Aug 12, 2024
1 parent 88ea2b8 commit 9321acb
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion baby-bear/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "p3-baby-bear"
version = "0.1.0"
version = "0.1.4"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand Down
3 changes: 2 additions & 1 deletion baby-bear/src/poseidon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use p3_field::PrimeField32;
use p3_poseidon2::DiffusionPermutation;
use p3_symmetric::Permutation;
use serde::{Deserialize, Serialize};

use crate::{monty_reduce, to_babybear_array, BabyBear};

Expand Down Expand Up @@ -78,7 +79,7 @@ const POSEIDON2_INTERNAL_MATRIX_DIAG_24_MONTY_SHIFTS: [u8; 23] = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23,
];

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct DiffusionMatrixBabyBear;

impl Permutation<[BabyBear; 16]> for DiffusionMatrixBabyBear {
Expand Down
4 changes: 3 additions & 1 deletion challenger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "p3-challenger"
version = "0.1.0"
version = "0.1.4"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand All @@ -10,6 +10,8 @@ p3-util = { path = "../util" }
p3-maybe-rayon = { path = "../maybe-rayon" }
p3-symmetric = { path = "../symmetric" }
tracing = "0.1.37"
serde = { version = "1.0", features = ["derive"] }
serde_with = "3.8.1"

[dev-dependencies]
p3-goldilocks = { path = "../goldilocks" }
5 changes: 4 additions & 1 deletion challenger/src/duplex_challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ use alloc::vec::Vec;

use p3_field::{ExtensionField, Field, PrimeField64};
use p3_symmetric::{CryptographicPermutation, Hash};
use serde::{Deserialize, Serialize};

use crate::{CanObserve, CanSample, CanSampleBits, FieldChallenger};

#[derive(Clone, Debug)]
#[serde_with::serde_as]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct DuplexChallenger<F, P, const WIDTH: usize, const RATE: usize>
where
F: Clone,
P: CryptographicPermutation<[F; WIDTH]>,
{
#[serde_as(as = "[_; WIDTH]")]
pub sponge_state: [F; WIDTH],
pub input_buffer: Vec<F>,
pub output_buffer: Vec<F>,
Expand Down
2 changes: 1 addition & 1 deletion field/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "p3-field"
version = "0.1.0"
version = "0.1.4"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand Down
6 changes: 4 additions & 2 deletions poseidon2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "p3-poseidon2"
version = "0.1.0"
version = "0.1.4"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand All @@ -10,6 +10,8 @@ p3-field = { path = "../field" }
p3-symmetric = { path = "../symmetric" }
p3-mds = { path = "../mds" }
rand = { version = "0.8.5", features = ["min_const_gen"] }
serde = { version = "1.0", features = ["derive"] }
serde_with = "3.8.1"

[dev-dependencies]
p3-mersenne-31 = { path = "../mersenne-31" }
Expand All @@ -21,4 +23,4 @@ criterion = "0.5.1"

[[bench]]
name = "poseidon2"
harness = false
harness = false
5 changes: 4 additions & 1 deletion poseidon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ use p3_symmetric::{CryptographicPermutation, Permutation};
use rand::distributions::{Distribution, Standard};
use rand::Rng;
pub use round_numbers::poseidon2_round_numbers_128;
use serde::{Deserialize, Serialize};

const SUPPORTED_WIDTHS: [usize; 8] = [2, 3, 4, 8, 12, 16, 20, 24];

/// The Poseidon2 permutation.
#[derive(Clone, Debug)]
#[serde_with::serde_as]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Poseidon2<F, MdsLight, Diffusion, const WIDTH: usize, const D: u64> {
/// The number of external rounds.
rounds_f: usize,

/// The external round constants.
#[serde_as(as = "Vec<[_; WIDTH]>")]
external_constants: Vec<[F; WIDTH]>,

/// The linear layer used in External Rounds. Should be either MDS or a
Expand Down
3 changes: 2 additions & 1 deletion poseidon2/src/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use p3_field::{AbstractField, PrimeField};
use p3_mds::MdsPermutation;
use p3_symmetric::Permutation;
use serde::{Deserialize, Serialize};

extern crate alloc;

Expand Down Expand Up @@ -143,7 +144,7 @@ fn mds_light_permutation<AF: AbstractField, MdsPerm4: MdsPermutation<AF, 4>, con
}
}

#[derive(Default, Clone)]
#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct Poseidon2ExternalMatrixGeneral;

impl<AF, const WIDTH: usize> Permutation<[AF; WIDTH]> for Poseidon2ExternalMatrixGeneral
Expand Down
2 changes: 1 addition & 1 deletion symmetric/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "p3-symmetric"
version = "0.1.0"
version = "0.1.4"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand Down

0 comments on commit 9321acb

Please sign in to comment.