Skip to content

Commit 2a90036

Browse files
authored
Merge pull request #13 from lita-xyz/carlo/SyncSend
Sync and Send trait implementation
2 parents 764f45a + cc36bf3 commit 2a90036

File tree

22 files changed

+284
-79
lines changed

22 files changed

+284
-79
lines changed

challenger/src/duplex_challenger.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ where
1818
permutation: P,
1919
}
2020

21+
impl<F, P, const WIDTH: usize> Default for DuplexChallenger<F, P, WIDTH>
22+
where
23+
F: Field,
24+
P: CryptographicPermutation<[F; WIDTH]> + Default,
25+
{
26+
fn default() -> Self {
27+
Self {
28+
sponge_state: [F::zero(); WIDTH],
29+
input_buffer: Vec::new(),
30+
output_buffer: Vec::new(),
31+
permutation: P::default(),
32+
}
33+
}
34+
}
35+
2136
impl<F, P, const WIDTH: usize> DuplexChallenger<F, P, WIDTH>
2237
where
2338
F: Copy,

commit/src/adapters/extension_mmcs.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ pub struct ExtensionMmcs<F, EF, InnerMmcs> {
1313
_phantom: PhantomData<(F, EF)>,
1414
}
1515

16+
impl<F, EF, InnerMmcs> Default for ExtensionMmcs<F, EF, InnerMmcs>
17+
where
18+
F: Field,
19+
EF: ExtensionField<F>,
20+
InnerMmcs: Mmcs<F> + Default,
21+
{
22+
fn default() -> Self {
23+
Self {
24+
inner: InnerMmcs::default(),
25+
_phantom: PhantomData::<(F, EF)>,
26+
}
27+
}
28+
}
29+
1630
impl<F, EF, InnerMmcs> ExtensionMmcs<F, EF, InnerMmcs> {
1731
pub fn new(inner: InnerMmcs) -> Self {
1832
Self {

commit/src/mmcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use serde::Serialize;
2020
/// matrices. Other MMCSs may be virtual combinations of child MMCSs, or may be constructed in a
2121
/// streaming manner.
2222
pub trait Mmcs<T>: Clone {
23-
type ProverData;
23+
type ProverData: Clone;
2424
type Commitment: Clone + Serialize + DeserializeOwned;
25-
type Proof: Serialize + DeserializeOwned;
25+
type Proof: Serialize + DeserializeOwned + Clone;
2626
type Error: Debug;
2727
type Mat<'a>: MatrixRows<T> + Sync
2828
where

commit/src/pcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub trait Pcs<Val: Field, In: MatrixRows<Val>> {
2222
type Commitment: Clone + Serialize + DeserializeOwned;
2323

2424
/// Data that the prover stores for committed polynomials, to help the prover with opening.
25-
type ProverData;
25+
type ProverData: Clone;
2626

2727
/// The opening argument.
28-
type Proof: Serialize + DeserializeOwned;
28+
type Proof: Serialize + DeserializeOwned + Clone;
2929

3030
type Error: Debug;
3131

field-testing/src/bench_func.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ where
1313
{
1414
let mut rng = rand::thread_rng();
1515
let x = rng.gen::<F>();
16-
c.bench_function(&format!("{} square", name), |b| {
16+
c.bench_function(&format!("{name} square"), |b| {
1717
b.iter(|| black_box(black_box(x).square()))
1818
});
1919
}
@@ -24,7 +24,7 @@ where
2424
{
2525
let mut rng = rand::thread_rng();
2626
let x = rng.gen::<F>();
27-
c.bench_function(&format!("{} inv", name), |b| {
27+
c.bench_function(&format!("{name} inv"), |b| {
2828
b.iter(|| black_box(black_box(x)).inverse())
2929
});
3030
}
@@ -36,7 +36,7 @@ where
3636
let mut rng = rand::thread_rng();
3737
let x = rng.gen::<F>();
3838
let y = rng.gen::<F>();
39-
c.bench_function(&format!("{} mul", name), |b| {
39+
c.bench_function(&format!("{name} mul"), |b| {
4040
b.iter(|| black_box(black_box(x) * black_box(y)))
4141
});
4242
}
@@ -55,7 +55,7 @@ pub fn benchmark_iter_sum<F: Field, const N: usize, const REPS: usize>(
5555
input.push(rng.gen::<[F; N]>())
5656
}
5757
let mut output = [F::zero(); REPS];
58-
c.bench_function(&format!("{} sum/{}, {}", name, REPS, N), |b| {
58+
c.bench_function(&format!("{name} sum/{REPS}, {N}"), |b| {
5959
b.iter(|| {
6060
for i in 0..REPS {
6161
output[i] = input[i].iter().cloned().sum()
@@ -69,7 +69,7 @@ pub fn benchmark_add_latency<F: Field, const N: usize>(c: &mut Criterion, name:
6969
where
7070
Standard: Distribution<F>,
7171
{
72-
c.bench_function(&format!("{} add-latency/{}", name, N), |b| {
72+
c.bench_function(&format!("{name} add-latency/{N}"), |b| {
7373
b.iter_batched(
7474
|| {
7575
let mut rng = rand::thread_rng();
@@ -89,7 +89,7 @@ pub fn benchmark_add_throughput<F: Field, const N: usize>(c: &mut Criterion, nam
8989
where
9090
Standard: Distribution<F>,
9191
{
92-
c.bench_function(&format!("{} add-throughput/{}", name, N), |b| {
92+
c.bench_function(&format!("{name} add-throughput/{N}"), |b| {
9393
b.iter_batched(
9494
|| {
9595
let mut rng = rand::thread_rng();
@@ -132,7 +132,7 @@ pub fn benchmark_sub_latency<F: Field, const N: usize>(c: &mut Criterion, name:
132132
where
133133
Standard: Distribution<F>,
134134
{
135-
c.bench_function(&format!("{} sub-latency/{}", name, N), |b| {
135+
c.bench_function(&format!("{name} sub-latency/{N}"), |b| {
136136
b.iter_batched(
137137
|| {
138138
let mut rng = rand::thread_rng();
@@ -152,7 +152,7 @@ pub fn benchmark_sub_throughput<F: Field, const N: usize>(c: &mut Criterion, nam
152152
where
153153
Standard: Distribution<F>,
154154
{
155-
c.bench_function(&format!("{} sub-throughput/{}", name, N), |b| {
155+
c.bench_function(&format!("{name} sub-throughput/{N}"), |b| {
156156
b.iter_batched(
157157
|| {
158158
let mut rng = rand::thread_rng();

field/src/extension/binomial_extension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ where
237237
(_, false) => format!("{x} X^{i}"),
238238
})
239239
.join(" + ");
240-
write!(f, "{}", str)
240+
write!(f, "{str}")
241241
}
242242
}
243243
}

fri/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[derive(Clone, Default)]
12
pub struct FriConfig<M> {
23
pub log_blowup: usize,
34
pub num_queries: usize,

fri/src/proof.rs

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ use p3_commit::Mmcs;
44
use p3_field::Field;
55
use serde::{Deserialize, Serialize};
66

7-
#[derive(Serialize, Deserialize)]
7+
#[derive(Serialize, Deserialize, Clone)]
88
#[serde(bound(
99
serialize = "Witness: Serialize",
1010
deserialize = "Witness: Deserialize<'de>"
1111
))]
12-
pub struct FriProof<F: Field, M: Mmcs<F>, Witness> {
12+
pub struct FriProof<F: Field, M: Mmcs<F>, Witness>
13+
where
14+
F: Send + Sync,
15+
M::Commitment: Send + Sync,
16+
M::Proof: Send + Sync,
17+
Witness: Send + Sync,
18+
{
1319
pub(crate) commit_phase_commits: Vec<M::Commitment>,
1420
pub(crate) query_proofs: Vec<QueryProof<F, M>>,
1521
// This could become Vec<FC::Challenge> if this library was generalized to support non-constant
@@ -18,22 +24,62 @@ pub struct FriProof<F: Field, M: Mmcs<F>, Witness> {
1824
pub(crate) pow_witness: Witness,
1925
}
2026

21-
#[derive(Serialize, Deserialize)]
27+
unsafe impl<F: Field + Send + Sync, M: Mmcs<F>, Witness: Send + Sync> Send
28+
for FriProof<F, M, Witness>
29+
where
30+
M::Commitment: Send + Sync,
31+
M::Proof: Send + Sync,
32+
{
33+
}
34+
35+
unsafe impl<F: Field + Send + Sync, M: Mmcs<F>, Witness: Send + Sync> Sync
36+
for FriProof<F, M, Witness>
37+
where
38+
M::Commitment: Send + Sync,
39+
M::Proof: Send + Sync,
40+
{
41+
}
42+
43+
/// For each commit phase commitment, this contains openings of a commit phase codeword at the
44+
/// queried location, along with an opening proof.
45+
#[derive(Serialize, Deserialize, Clone)]
2246
#[serde(bound = "")]
23-
pub struct QueryProof<F: Field, M: Mmcs<F>> {
24-
/// For each commit phase commitment, this contains openings of a commit phase codeword at the
25-
/// queried location, along with an opening proof.
47+
pub struct QueryProof<F: Field, M: Mmcs<F>>
48+
where
49+
F: Send + Sync,
50+
M::Proof: Send + Sync,
51+
{
2652
pub(crate) commit_phase_openings: Vec<CommitPhaseProofStep<F, M>>,
2753
}
2854

29-
#[derive(Serialize, Deserialize)]
55+
unsafe impl<F: Field + Send + Sync, M: Mmcs<F>> Send for QueryProof<F, M> where M::Proof: Send + Sync
56+
{}
57+
58+
unsafe impl<F: Field + Send + Sync, M: Mmcs<F>> Sync for QueryProof<F, M> where M::Proof: Send + Sync
59+
{}
60+
61+
// The opening of the commit phase codeword at the sibling location.
62+
// This may change to Vec<FC::Challenge> if the library is generalized to support other FRI
63+
// folding arities besides 2, meaning that there can be multiple siblings.
64+
#[derive(Serialize, Deserialize, Clone)]
3065
// #[serde(bound(serialize = "F: Serialize"))]
3166
#[serde(bound = "")]
32-
pub struct CommitPhaseProofStep<F: Field, M: Mmcs<F>> {
33-
/// The opening of the commit phase codeword at the sibling location.
34-
// This may change to Vec<FC::Challenge> if the library is generalized to support other FRI
35-
// folding arities besides 2, meaning that there can be multiple siblings.
67+
pub struct CommitPhaseProofStep<F: Field, M: Mmcs<F>>
68+
where
69+
F: Send + Sync,
70+
M::Proof: Send + Sync,
71+
{
3672
pub(crate) sibling_value: F,
3773

3874
pub(crate) opening_proof: M::Proof,
3975
}
76+
77+
unsafe impl<F: Field + Send + Sync, M: Mmcs<F>> Send for CommitPhaseProofStep<F, M> where
78+
M::Proof: Send + Sync
79+
{
80+
}
81+
82+
unsafe impl<F: Field + Send + Sync, M: Mmcs<F>> Sync for CommitPhaseProofStep<F, M> where
83+
M::Proof: Send + Sync
84+
{
85+
}

fri/src/prover.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ pub fn prove<F, M, Challenger>(
1919
challenger: &mut Challenger,
2020
) -> (FriProof<F, M, Challenger::Witness>, Vec<usize>)
2121
where
22-
F: TwoAdicField,
22+
F: TwoAdicField + Send + Sync,
2323
M: DirectMmcs<F> + Send + Sync,
24-
Challenger: GrindingChallenger + CanObserve<M::Commitment> + CanSample<F>,
25-
<M as Mmcs<F>>::Proof: Send,
26-
<M as Mmcs<F>>::ProverData: Send + Sync,
24+
M::Commitment: Send + Sync,
25+
M::Proof: Send + Sync,
26+
M::ProverData: Send + Sync,
27+
Challenger: GrindingChallenger + CanObserve<M::Commitment> + CanSample<F> + Send + Sync,
28+
Challenger::Witness: Send + Sync,
2729
{
2830
let log_max_height = input.iter().rposition(Option::is_some).unwrap();
2931

@@ -61,6 +63,7 @@ fn answer_query<F, M>(
6163
where
6264
F: Field,
6365
M: Mmcs<F>,
66+
M::Proof: Send + Sync,
6467
{
6568
let commit_phase_openings = commit_phase_commits
6669
.iter()
@@ -98,6 +101,7 @@ fn commit_phase<F, M, Challenger>(
98101
where
99102
F: TwoAdicField,
100103
M: DirectMmcs<F>,
104+
M::Commitment: Send + Sync,
101105
Challenger: CanObserve<M::Commitment> + CanSample<F>,
102106
{
103107
let mut current = input[log_max_height].as_ref().unwrap().clone();

0 commit comments

Comments
 (0)