Skip to content

Commit 9ce2413

Browse files
committed
migrate table circuit to gkr-iop
1 parent 08b86ef commit 9ce2413

File tree

25 files changed

+248
-299
lines changed

25 files changed

+248
-299
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ lto = "thin"
9999
#[patch."ssh://[email protected]/scroll-tech/ceno-gpu.git"]
100100
#ceno_gpu = { path = "../ceno-gpu/cuda_hal", package = "cuda_hal" }
101101

102-
#[patch."https://github.com/scroll-tech/gkr-backend"]
103-
#ff_ext = { path = "../gkr-backend/crates/ff_ext", package = "ff_ext" }
104-
#mpcs = { path = "../gkr-backend/crates/mpcs", package = "mpcs" }
105-
#multilinear_extensions = { path = "../gkr-backend/crates/multilinear_extensions", package = "multilinear_extensions" }
106-
#p3 = { path = "../gkr-backend/crates/p3", package = "p3" }
107-
#poseidon = { path = "../gkr-backend/crates/poseidon", package = "poseidon" }
108-
#sumcheck = { path = "../gkr-backend/crates/sumcheck", package = "sumcheck" }
109-
#transcript = { path = "../gkr-backend/crates/transcript", package = "transcript" }
110-
#whir = { path = "../gkr-backend/crates/whir", package = "whir" }
111-
#witness = { path = "../gkr-backend/crates/witness", package = "witness" }
102+
[patch."https://github.com/scroll-tech/gkr-backend"]
103+
ff_ext = { path = "../gkr-backend/crates/ff_ext", package = "ff_ext" }
104+
mpcs = { path = "../gkr-backend/crates/mpcs", package = "mpcs" }
105+
multilinear_extensions = { path = "../gkr-backend/crates/multilinear_extensions", package = "multilinear_extensions" }
106+
p3 = { path = "../gkr-backend/crates/p3", package = "p3" }
107+
poseidon = { path = "../gkr-backend/crates/poseidon", package = "poseidon" }
108+
sumcheck = { path = "../gkr-backend/crates/sumcheck", package = "sumcheck" }
109+
transcript = { path = "../gkr-backend/crates/transcript", package = "transcript" }
110+
whir = { path = "../gkr-backend/crates/whir", package = "whir" }
111+
witness = { path = "../gkr-backend/crates/witness", package = "witness" }

ceno_zkvm/src/chip_handler/general.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl<'a, E: ExtensionField> PublicIOQuery for CircuitBuilder<'a, E> {
4141
fn query_exit_code(&mut self) -> Result<[Instance; UINT_LIMBS], CircuitBuilderError> {
4242
Ok([
4343
self.cs.query_instance(EXIT_CODE_IDX)?,
44-
self.cs
45-
.query_instance(EXIT_CODE_IDX + 1)?,
44+
self.cs.query_instance(EXIT_CODE_IDX + 1)?,
4645
])
4746
}
4847

@@ -68,10 +67,8 @@ impl<'a, E: ExtensionField> PublicIOQuery for CircuitBuilder<'a, E> {
6867

6968
fn query_public_io(&mut self) -> Result<[Instance; UINT_LIMBS], CircuitBuilderError> {
7069
Ok([
71-
self.cs
72-
.query_instance_for_openings(|| "public_io_low", PUBLIC_IO_IDX)?,
73-
self.cs
74-
.query_instance_for_openings(|| "public_io_high", PUBLIC_IO_IDX + 1)?,
70+
self.cs.query_instance_for_openings(PUBLIC_IO_IDX)?,
71+
self.cs.query_instance_for_openings(PUBLIC_IO_IDX + 1)?,
7572
])
7673
}
7774
}

ceno_zkvm/src/precompiles/bitwise_keccakf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ pub fn run_keccakf<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + 'stat
918918
&[],
919919
&[],
920920
&[],
921+
&[],
921922
);
922923
exit_span!(span);
923924

ceno_zkvm/src/precompiles/lookup_keccakf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ pub fn run_faster_keccakf<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>
11551155
&structural_witness,
11561156
&fixed,
11571157
&[],
1158+
&[],
11581159
&challenges,
11591160
);
11601161
exit_span!(span);

ceno_zkvm/src/precompiles/weierstrass/weierstrass_add.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ pub fn run_weierstrass_add<
712712
&structural_witness,
713713
&fixed,
714714
&[],
715+
&[],
715716
&challenges,
716717
);
717718
exit_span!(span);

ceno_zkvm/src/precompiles/weierstrass/weierstrass_decompress.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ pub fn run_weierstrass_decompress<
692692
&structural_witness,
693693
&fixed,
694694
&[],
695+
&[],
695696
&challenges,
696697
);
697698
exit_span!(span);

ceno_zkvm/src/precompiles/weierstrass/weierstrass_double.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ pub fn run_weierstrass_double<
714714
&structural_witness,
715715
&fixed,
716716
&[],
717+
&[],
717718
&challenges,
718719
);
719720
exit_span!(span);

ceno_zkvm/src/scheme/cpu/mod.rs

Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -542,48 +542,6 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> TowerProver<CpuBacke
542542
impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> MainSumcheckProver<CpuBackend<E, PCS>>
543543
for CpuProver<CpuBackend<E, PCS>>
544544
{
545-
#[allow(clippy::type_complexity)]
546-
#[tracing::instrument(skip_all, name = "table_witness", fields(profiling_3), level = "trace")]
547-
fn table_witness<'a>(
548-
&self,
549-
input: &ProofInput<'a, CpuBackend<<CpuBackend<E, PCS> as ProverBackend>::E, PCS>>,
550-
cs: &ConstraintSystem<<CpuBackend<E, PCS> as ProverBackend>::E>,
551-
challenges: &[<CpuBackend<E, PCS> as ProverBackend>::E],
552-
) -> Vec<Arc<<CpuBackend<E, PCS> as ProverBackend>::MultilinearPoly<'a>>> {
553-
// main constraint: lookup denominator and numerator record witness inference
554-
let record_span = entered_span!("record");
555-
let records: Vec<ArcMultilinearExtension<'_, E>> = cs
556-
.r_table_expressions
557-
.par_iter()
558-
.map(|r| &r.expr)
559-
.chain(cs.r_expressions.par_iter())
560-
.chain(cs.w_table_expressions.par_iter().map(|w| &w.expr))
561-
.chain(cs.w_expressions.par_iter())
562-
.chain(
563-
cs.lk_table_expressions
564-
.par_iter()
565-
.map(|lk| &lk.multiplicity),
566-
)
567-
.chain(cs.lk_table_expressions.par_iter().map(|lk| &lk.values))
568-
.chain(cs.lk_expressions.par_iter())
569-
.map(|expr| {
570-
wit_infer_by_expr(
571-
expr,
572-
cs.num_witin,
573-
cs.num_structural_witin,
574-
cs.num_fixed as WitnessId,
575-
&input.fixed,
576-
&input.witness,
577-
&input.structural_witness,
578-
&input.public_input,
579-
challenges,
580-
)
581-
})
582-
.collect();
583-
exit_span!(record_span);
584-
records
585-
}
586-
587545
#[allow(clippy::type_complexity)]
588546
#[tracing::instrument(
589547
skip_all,
@@ -619,42 +577,15 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> MainSumcheckProver<C
619577
let num_var_with_rotation = log2_num_instances + composed_cs.rotation_vars().unwrap_or(0);
620578

621579
if let Some(gkr_circuit) = gkr_circuit {
622-
// let pub_io_evals = // get public io evaluations
623-
// cs.instance_openings
624-
// .keys()
625-
// .sorted()
626-
// .map(|Instance(inst_id)| {
627-
// let mle = &input.public_input[*inst_id];
628-
// assert_eq!(
629-
// mle.evaluations.len(),
630-
// 1,
631-
// "doesnt support instance with evaluation length > 1"
632-
// );
633-
// match mle.evaluations() {
634-
// FieldType::Base(smart_slice) => E::from(smart_slice[0]),
635-
// FieldType::Ext(smart_slice) => smart_slice[0],
636-
// _ => unreachable!(),
637-
// }
638-
// })
639-
// .collect_vec();
640-
let pub_io_evals = // get public io evaluations
641-
input.public_input
642-
.iter().map(|mle| {
643-
match mle.evaluations() {
644-
FieldType::Base(smart_slice) => E::from(smart_slice[0]),
645-
FieldType::Ext(smart_slice) => smart_slice[0],
646-
_ => unreachable!(),
647-
}
648-
})
649-
.collect_vec();
650-
let filtered_pub_io_mle = cs
580+
let pub_io_mles = cs
651581
.instance_openings
652582
.iter()
653-
.map(|(id, _)| input.public_input[id.0].clone())
583+
.map(|instance| input.public_input[instance.0].clone())
654584
.collect_vec();
655585
let GKRProverOutput {
656586
gkr_proof,
657587
opening_evaluations,
588+
mut rt,
658589
} = gkr_circuit.prove::<CpuBackend<E, PCS>, CpuProver<_>>(
659590
num_threads,
660591
num_var_with_rotation,
@@ -664,21 +595,26 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> MainSumcheckProver<C
664595
&input.witness,
665596
&input.structural_witness,
666597
&input.fixed,
667-
&filtered_pub_io_mle,
598+
&pub_io_mles,
668599
)
669600
.cloned()
670601
.collect_vec(),
671602
)],
672603
},
673604
// eval value doesnt matter as it wont be used by prover
674605
&vec![PointAndEval::new(rt_tower, E::ZERO); gkr_circuit.final_out_evals.len()],
675-
&pub_io_evals,
606+
&input
607+
.pub_io_evals
608+
.iter()
609+
.map(|v| v.map_either(E::from, |v| v).into_inner())
610+
.collect_vec(),
676611
challenges,
677612
transcript,
678613
num_instances,
679614
)?;
615+
assert_eq!(rt.len(), 1, "TODO support multi-layer gkr iop");
680616
Ok((
681-
opening_evaluations[0].point.clone(),
617+
rt.remove(0),
682618
MainSumcheckEvals {
683619
wits_in_evals: opening_evaluations
684620
.iter()
@@ -688,7 +624,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> MainSumcheckProver<C
688624
.collect_vec(),
689625
fixed_in_evals: opening_evaluations
690626
.iter()
691-
.skip((cs.num_witin + cs.num_structural_witin) as usize)
627+
.skip(cs.num_witin as usize)
692628
.take(cs.num_fixed)
693629
.map(|Evaluation { value, .. }| value)
694630
.copied()

ceno_zkvm/src/scheme/hal.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use std::{collections::BTreeMap, sync::Arc};
2-
31
use crate::{
42
circuit_builder::ConstraintSystem,
53
error::ZKVMError,
64
scheme::cpu::TowerRelationOutput,
75
structs::{ComposedConstrainSystem, ZKVMProvingKey},
86
};
7+
use either::Either;
98
use ff_ext::ExtensionField;
109
use gkr_iop::{
1110
gkr::GKRProof,
1211
hal::{ProtocolWitnessGeneratorProver, ProverBackend},
1312
};
1413
use mpcs::{Point, PolynomialCommitmentScheme};
1514
use multilinear_extensions::{mle::MultilinearExtension, util::ceil_log2};
15+
use std::{collections::BTreeMap, sync::Arc};
1616
use sumcheck::structs::IOPProverMessage;
1717
use transcript::Transcript;
1818
use witness::next_pow2_instance_padding;
@@ -37,6 +37,7 @@ pub struct ProofInput<'a, PB: ProverBackend> {
3737
pub structural_witness: Vec<Arc<PB::MultilinearPoly<'a>>>,
3838
pub fixed: Vec<Arc<PB::MultilinearPoly<'a>>>,
3939
pub public_input: Vec<Arc<PB::MultilinearPoly<'a>>>,
40+
pub pub_io_evals: Vec<Either<<PB::E as ExtensionField>::BaseField, PB::E>>,
4041
pub num_instances: usize,
4142
}
4243

@@ -109,13 +110,6 @@ pub struct MainSumcheckEvals<E: ExtensionField> {
109110
}
110111

111112
pub trait MainSumcheckProver<PB: ProverBackend> {
112-
fn table_witness<'a>(
113-
&self,
114-
input: &ProofInput<'a, PB>,
115-
cs: &ConstraintSystem<PB::E>,
116-
challenges: &[PB::E],
117-
) -> Vec<Arc<PB::MultilinearPoly<'a>>>;
118-
119113
// this prover aims to achieve two goals:
120114
// 1. the validity of last layer in the tower tree is reduced to
121115
// the validity of read/write/logup records through sumchecks;

0 commit comments

Comments
 (0)