Skip to content

Commit 1f43c1f

Browse files
committed
Graft ceno prover
1 parent abe0522 commit 1f43c1f

File tree

8 files changed

+1223
-25
lines changed

8 files changed

+1223
-25
lines changed

circ_blocks/Cargo.lock

Lines changed: 1117 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spartan_parallel/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ colored = { version = "2", default-features = false, optional = true }
3030
flate2 = { version = "1" }
3131
goldilocks = { git = "https://github.com/scroll-tech/ceno-Goldilocks" }
3232
ff = "0.13.0"
33+
multilinear_extensions = { path = "../../ceno/multilinear_extensions" }
34+
sumcheck = { path = "../../ceno/sumcheck" }
35+
ff_ext = { path = "../../ceno/ff_ext" }
36+
transcript = { path = "../../ceno/transcript" }
37+
ceno_zkvm = { path = "../../ceno/ceno_zkvm" }
38+
halo2curves = "0.1.0"
3339

3440
[dev-dependencies]
3541
criterion = "0.5"

spartan_parallel/src/dense_mlpoly.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rayon::prelude::*;
1717
pub struct DensePolynomial<S: SpartanExtensionField> {
1818
num_vars: usize, // the number of variables in the multilinear polynomial
1919
len: usize,
20-
Z: Vec<S>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs
20+
pub Z: Vec<S>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs
2121
}
2222

2323
pub struct EqPolynomial<S: SpartanExtensionField> {
@@ -449,6 +449,7 @@ impl<S: SpartanExtensionField> PolyEvalProof<S> {
449449
}
450450
}
451451

452+
/*
452453
#[cfg(test)]
453454
mod tests {
454455
use super::*;
@@ -610,3 +611,4 @@ mod tests {
610611
assert_eq!(R, R2);
611612
}
612613
}
614+
*/

spartan_parallel/src/r1csproof.rs

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ use super::timer::Timer;
1010
use super::transcript::ProofTranscript;
1111
use crate::scalar::SpartanExtensionField;
1212
use crate::{ProverWitnessSecInfo, VerifierWitnessSecInfo};
13+
use ff_ext::ExtensionField;
14+
use goldilocks::GoldilocksExt2;
1315
use merlin::Transcript;
16+
use multilinear_extensions::mle::DenseMultilinearExtension;
1417
use serde::{Deserialize, Serialize};
1518
use std::cmp::min;
1619
use std::iter::zip;
20+
use std::sync::Arc;
21+
use multilinear_extensions::{
22+
mle::IntoMLE,
23+
virtual_poly::VPAuxInfo,
24+
virtual_poly_v2::{ArcMultilinearExtension, VirtualPolynomialV2},
25+
};
26+
use std::iter;
27+
use ceno_zkvm::virtual_polys::VirtualPolynomials;
28+
use sumcheck::structs::{IOPProverStateV2, IOPVerifierState};
29+
use ff::Field;
30+
use halo2curves::serde::SerdeObject;
31+
use transcript::BasicTranscript;
1732

1833
#[derive(Serialize, Deserialize, Debug)]
1934
pub struct R1CSProof<S: SpartanExtensionField> {
@@ -206,9 +221,9 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
206221
num_witness_secs.log_2(),
207222
max_num_inputs.log_2(),
208223
);
209-
let tau_p = transcript.challenge_vector(b"challenge_tau_p", num_rounds_p);
210-
let tau_q = transcript.challenge_vector(b"challenge_tau_q", num_rounds_q);
211-
let tau_x = transcript.challenge_vector(b"challenge_tau_x", num_rounds_x);
224+
let tau_p: Vec<S> = transcript.challenge_vector(b"challenge_tau_p", num_rounds_p);
225+
let tau_q: Vec<S> = transcript.challenge_vector(b"challenge_tau_q", num_rounds_q);
226+
let tau_x: Vec<S> = transcript.challenge_vector(b"challenge_tau_x", num_rounds_x);
212227

213228
// compute the initial evaluation table for R(\tau, x)
214229
let mut poly_tau_p = DensePolynomial::new(EqPolynomial::new(tau_p).evals());
@@ -226,6 +241,70 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
226241
);
227242
timer_tmp.stop();
228243

244+
// == test: ceno_verifier_bench ==
245+
let B = poly_Az.to_dense_poly();
246+
let C = poly_Bz.to_dense_poly();
247+
let D = poly_Cz.to_dense_poly();
248+
249+
let z_len = B.Z.len();
250+
let tau_pqx_len = poly_tau_p.Z.len() + poly_tau_q.Z.len() + poly_tau_x.Z.len();
251+
let A = DensePolynomial::new(
252+
poly_tau_p.clone().Z
253+
.into_iter()
254+
.chain(poly_tau_q.clone().Z)
255+
.chain(poly_tau_x.clone().Z)
256+
.chain(iter::repeat(S::field_zero()).take(z_len - tau_pqx_len))
257+
.collect()
258+
);
259+
260+
let arc_A: ArcMultilinearExtension<'_, GoldilocksExt2> = Arc::new(
261+
A.Z.iter().cloned().map(|s|
262+
GoldilocksExt2::from_raw_bytes_unchecked(&s.inner().to_raw_bytes())
263+
)
264+
.collect::<Vec<GoldilocksExt2>>()
265+
.into_mle()
266+
);
267+
let arc_B: ArcMultilinearExtension<'_, GoldilocksExt2> = Arc::new(
268+
B.Z.iter().cloned().map(|s|
269+
GoldilocksExt2::from_raw_bytes_unchecked(&s.inner().to_raw_bytes())
270+
)
271+
.collect::<Vec<GoldilocksExt2>>()
272+
.into_mle()
273+
);
274+
let arc_C: ArcMultilinearExtension<'_, GoldilocksExt2> = Arc::new(
275+
C.Z.iter().cloned().map(|s|
276+
GoldilocksExt2::from_raw_bytes_unchecked(&s.inner().to_raw_bytes())
277+
)
278+
.collect::<Vec<GoldilocksExt2>>()
279+
.into_mle()
280+
);
281+
let arc_D: ArcMultilinearExtension<'_, GoldilocksExt2> = Arc::new(
282+
D.Z.iter().cloned().map(|s|
283+
GoldilocksExt2::from_raw_bytes_unchecked(&s.inner().to_raw_bytes())
284+
)
285+
.collect::<Vec<GoldilocksExt2>>()
286+
.into_mle()
287+
);
288+
289+
let max_num_vars = 22;
290+
let num_threads = 8;
291+
let virtual_polys: VirtualPolynomialV2<'_, GoldilocksExt2> = VirtualPolynomialV2::new(max_num_vars);
292+
293+
let mut virtual_polys = VirtualPolynomials::<GoldilocksExt2>::new(num_threads, max_num_vars);
294+
virtual_polys.add_mle_list(vec![&arc_A, &arc_B, &arc_C], GoldilocksExt2::ONE);
295+
virtual_polys.add_mle_list(vec![&arc_A, &arc_D], GoldilocksExt2::ZERO - GoldilocksExt2::ONE);
296+
297+
let mut ceno_transcript = BasicTranscript::new(b"test");
298+
299+
let timer_tmp = Timer::new("=> prove_sum_check with ceno: IOPProverStateV2::prove_batch_polys");
300+
let (sumcheck_proofs, _) = IOPProverStateV2::prove_batch_polys(
301+
num_threads,
302+
virtual_polys.get_batched_polys(),
303+
&mut ceno_transcript,
304+
);
305+
timer_tmp.stop();
306+
// == test: ceno_verifier_bench ==
307+
229308
// Sumcheck 1: (Az * Bz - Cz) * eq(x, q, p) = 0
230309
let timer_tmp = Timer::new("prove_sum_check");
231310
let (sc_proof_phase1, rx, _claims_phase1) = R1CSProof::prove_phase_one(

spartan_parallel/src/scalar/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
mod fp;
1+
// mod fp;
22
mod fp2;
33

44
use ff::Field;
5-
pub use fp::Scalar;
5+
// pub use fp::Scalar;
66
pub use fp2::ScalarExt2;
77
use goldilocks::ExtensionField;
88
use merlin::Transcript;
@@ -17,6 +17,8 @@ use std::{
1717
};
1818
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
1919
use zeroize::Zeroize;
20+
use ff_ext::ExtensionField as CenoExtensionField;
21+
use halo2curves::serde::SerdeObject;
2022

2123
/// Trait describing the field element
2224
/// Wraps around Goldilocks field towers from ceno-goldilocks
@@ -51,7 +53,7 @@ pub trait SpartanExtensionField:
5153
+ Sync
5254
{
5355
/// Inner Goldilocks extension field
54-
type InnerType: ExtensionField + Field + Send + Sync;
56+
type InnerType: ExtensionField + Field + Send + Sync + CenoExtensionField + SerdeObject;
5557

5658
/// Basefield for conserving computational resources
5759
type BaseField: Field + Send + Sync;
@@ -180,11 +182,11 @@ pub trait SpartanExtensionField:
180182
}
181183
}
182184

183-
impl<'a> From<&'a Scalar> for [u8; 32] {
184-
fn from(value: &'a Scalar) -> [u8; 32] {
185-
value.to_bytes()
186-
}
187-
}
185+
// impl<'a> From<&'a Scalar> for [u8; 32] {
186+
// fn from(value: &'a Scalar) -> [u8; 32] {
187+
// value.to_bytes()
188+
// }
189+
// }
188190

189191
/// macro_rules! impl_add_binop_specify_output
190192
#[macro_export]

spartan_parallel/src/sparse_mlpoly.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ impl<S: SpartanExtensionField> SparseMatPolyEvalProof<S> {
14751475
}
14761476
}
14771477

1478+
/*
14781479
#[cfg(test)]
14791480
mod tests {
14801481
use super::*;
@@ -1541,3 +1542,4 @@ mod tests {
15411542
.is_ok());
15421543
}
15431544
}
1545+
*/

spartan_parallel/src/unipoly.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl<S: SpartanExtensionField> AppendToTranscript for UniPoly<S> {
113113
}
114114
}
115115

116+
/*
116117
#[cfg(test)]
117118
mod tests {
118119
use super::*;
@@ -174,3 +175,4 @@ mod tests {
174175
assert_eq!(poly.evaluate(&Scalar::from(4_usize)), e4);
175176
}
176177
}
178+
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const u32 REPETITION = 10000
1+
const u32 REPETITION = 1000

0 commit comments

Comments
 (0)