forked from Plonky3/Plonky3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
127 lines (114 loc) · 3.15 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! This crate contains a framework for low-degree tests (LDTs).
#![no_std]
extern crate alloc;
use alloc::vec::Vec;
use core::marker::PhantomData;
use p3_challenger::Challenger;
use p3_commit::{DirectMMCS, MMCS};
use p3_commit::{UnivariatePCS, PCS};
use p3_field::{AbstractExtensionField, ExtensionField, Field, TwoAdicField};
use p3_lde::TwoAdicLDE;
use p3_matrix::dense::RowMajorMatrix;
/// A batch low-degree test (LDT).
pub trait LDT<F: Field, M: MMCS<F>> {
type Proof;
type Error;
/// Prove that each column of each matrix in `codewords` is a codeword.
fn prove<Chal>(&self, codewords: &[M::ProverData], challenger: &mut Chal) -> Self::Proof
where
Chal: Challenger<F>;
fn verify<Chal>(
&self,
codeword_commits: &[M::Commitment],
proof: &Self::Proof,
challenger: &mut Chal,
) -> Result<(), Self::Error>
where
Chal: Challenger<F>;
}
pub struct LDTBasedPCS<Val, Dom, LDE, M, L> {
lde: LDE,
added_bits: usize,
mmcs: M,
_phantom_val: PhantomData<Val>,
_phantom_dom: PhantomData<Dom>,
_phantom_l: PhantomData<L>,
}
impl<Val, Dom, LDE, M, L> LDTBasedPCS<Val, Dom, LDE, M, L> {
pub fn new(lde: LDE, added_bits: usize, mmcs: M) -> Self {
Self {
lde,
added_bits,
mmcs,
_phantom_val: PhantomData,
_phantom_dom: PhantomData,
_phantom_l: PhantomData,
}
}
}
impl<Val, Dom, LDE, M, L> PCS<Val> for LDTBasedPCS<Val, Dom, LDE, M, L>
where
Val: Field,
Dom: ExtensionField<Val> + TwoAdicField,
LDE: TwoAdicLDE<Val, Dom>,
M: DirectMMCS<Dom, Mat = RowMajorMatrix<Dom>>,
L: LDT<Dom, M>,
{
type Commitment = M::Commitment;
type ProverData = M::ProverData;
type Proof = L::Proof;
type Error = L::Error;
fn commit_batches(
&self,
polynomials: Vec<RowMajorMatrix<Val>>,
) -> (Self::Commitment, Self::ProverData) {
// TODO: Streaming?
let ldes = polynomials
.into_iter()
.map(|poly| self.lde.lde_batch(poly, self.added_bits))
.collect();
self.mmcs.commit(ldes)
}
fn get_committed_value(
&self,
_prover_data: &Self::ProverData,
_poly: usize,
_value: usize,
) -> Val {
todo!()
}
}
impl<Val, Dom, LDE, M, L> UnivariatePCS<Val> for LDTBasedPCS<Val, Dom, LDE, M, L>
where
Val: Field,
Dom: ExtensionField<Val> + TwoAdicField,
LDE: TwoAdicLDE<Val, Dom>,
M: DirectMMCS<Dom, Mat = RowMajorMatrix<Dom>>,
L: LDT<Dom, M>,
{
fn open_multi_batches<EF, Chal>(
&self,
_prover_data: &[Self::ProverData],
_points: &[EF],
_challenger: &mut Chal,
) -> (Vec<Vec<Vec<EF>>>, Self::Proof)
where
EF: AbstractExtensionField<Val>,
Chal: Challenger<Val>,
{
todo!()
}
fn verify_multi_batches<EF, Chal>(
&self,
_commits: &[Self::Commitment],
_points: &[EF],
_values: &[Vec<Vec<EF>>],
_proof: &Self::Proof,
) -> Result<(), Self::Error>
where
EF: AbstractExtensionField<Val>,
Chal: Challenger<Val>,
{
todo!()
}
}