Skip to content

Commit dcf7c62

Browse files
committed
debug
1 parent ee54156 commit dcf7c62

File tree

10 files changed

+113
-55
lines changed

10 files changed

+113
-55
lines changed

ceno_zkvm/src/instructions.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ where
9797
num_witin: usize,
9898
steps: Vec<StepRecord>,
9999
gkr_layout: &mut Self::Layout,
100-
) -> Result<(RowMajorMatrix<E::BaseField>, LkMultiplicity), ZKVMError> {
100+
) -> Result<
101+
(
102+
RowMajorMatrix<E::BaseField>,
103+
GKRCircuitWitness<E>,
104+
LkMultiplicity,
105+
),
106+
ZKVMError,
107+
> {
101108
let nthreads = max_usable_threads();
102109
let num_instance_per_batch = if steps.len() > 256 {
103110
steps.len().div_ceil(nthreads)
@@ -163,6 +170,6 @@ where
163170
.collect::<Result<(), ZKVMError>>()?;
164171

165172
raw_witin.padding_by_strategy();
166-
Ok((raw_witin, lk_multiplicity))
173+
Ok((raw_witin, gkr_witness, lk_multiplicity))
167174
}
168175
}

ceno_zkvm/src/instructions/riscv/dummy/dummy_ecall.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<E: ExtensionField, S: SyscallSpec> Instruction<E> for LargeEcallDummy<E, S>
7979
.collect::<Result<Vec<_>, _>>()?;
8080

8181
// Temporarily set this to < 24 to avoid cb.num_witin overflow
82-
let active_rounds = 0;
82+
let active_rounds = 12;
8383

8484
let mut lookups = Vec::with_capacity(
8585
active_rounds
@@ -187,7 +187,7 @@ impl<E: ExtensionField> GKRIOPInstruction<E> for LargeEcallDummy<E, KeccakSpec>
187187
) -> Result<(), ZKVMError> {
188188
Self::assign_instance(config, instance, lk_multiplicity, step)?;
189189

190-
let active_rounds = 0;
190+
let active_rounds = 12;
191191
let mut wit_iter = lookups.iter().map(|f| f.to_canonical_u64());
192192
let mut var_iter = config.lookups.iter();
193193

@@ -197,28 +197,29 @@ impl<E: ExtensionField> GKRIOPInstruction<E> for LargeEcallDummy<E, KeccakSpec>
197197
let mut pop_arg = || -> u64 {
198198
let wit = wit_iter.next().unwrap();
199199
let var = var_iter.next().unwrap();
200-
// set_val!(instance, var, wit);
201-
set_val!(instance, var, 0);
200+
set_val!(instance, var, wit);
201+
// set_val!(instance, var, 0);
202202
wit
203203
};
204204

205205
for _round in 0..active_rounds {
206206
for _i in 0..AND_LOOKUPS_PER_ROUND {
207-
// lk_multiplicity.lookup_and_byte(pop_arg(), pop_arg());
208-
lk_multiplicity.lookup_and_byte(0, 0);
209-
pop_arg();
210-
pop_arg();
207+
lk_multiplicity.lookup_and_byte(pop_arg(), pop_arg());
208+
// lk_multiplicity.lookup_and_byte(0, 0);
209+
// pop_arg();
210+
// pop_arg();
211211
pop_arg();
212212
}
213213
for _i in 0..XOR_LOOKUPS_PER_ROUND {
214-
lk_multiplicity.lookup_xor_byte(0, 0);
215-
pop_arg();
216-
pop_arg();
214+
lk_multiplicity.lookup_xor_byte(pop_arg(), pop_arg());
215+
// lk_multiplicity.lookup_xor_byte(0, 0);
216+
// pop_arg();
217+
// pop_arg();
217218
pop_arg();
218219
}
219220
for _i in 0..RANGE_LOOKUPS_PER_ROUND {
220-
lk_multiplicity.assert_ux::<16>(0);
221-
pop_arg();
221+
lk_multiplicity.assert_ux::<16>(pop_arg());
222+
// pop_arg();
222223
}
223224
}
224225

ceno_zkvm/src/instructions/riscv/rv32im.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ pub struct DummyExtraConfig<E: ExtensionField> {
466466
impl<E: ExtensionField> DummyExtraConfig<E> {
467467
pub fn construct_circuits(cs: &mut ZKVMConstraintSystem<E>) -> Self {
468468
let ecall_config = cs.register_opcode_circuit::<EcallDummy<E>>();
469+
// let keccak_config = cs.register_opcode_circuit::<LargeEcallDummy<E, KeccakSpec>>();
469470
let keccak_config = cs.register_keccakf_circuit();
470471
let secp256k1_add_config =
471472
cs.register_opcode_circuit::<LargeEcallDummy<E, Secp256k1AddSpec>>();
@@ -510,9 +511,10 @@ impl<E: ExtensionField> DummyExtraConfig<E> {
510511
) {
511512
fixed.register_opcode_circuit::<EcallDummy<E>>(cs);
512513
fixed.register_keccakf_circuit(cs);
514+
// fixed.register_opcode_circuit::<LargeEcallDummy<E, KeccakSpec>>(cs);
513515
fixed.register_opcode_circuit::<LargeEcallDummy<E, Secp256k1AddSpec>>(cs);
514-
fixed.register_opcode_circuit::<LargeEcallDummy<E, Secp256k1DoubleSpec>>(cs);
515516
fixed.register_opcode_circuit::<LargeEcallDummy<E, Secp256k1DecompressSpec>>(cs);
517+
fixed.register_opcode_circuit::<LargeEcallDummy<E, Secp256k1DoubleSpec>>(cs);
516518
fixed.register_opcode_circuit::<LargeEcallDummy<E, Sha256ExtendSpec>>(cs);
517519
fixed.register_opcode_circuit::<LargeEcallDummy<E, Bn254AddSpec>>(cs);
518520
fixed.register_opcode_circuit::<LargeEcallDummy<E, Bn254DoubleSpec>>(cs);
@@ -564,6 +566,12 @@ impl<E: ExtensionField> DummyExtraConfig<E> {
564566

565567
witness.assign_keccakf_circuit(cs, &self.keccak_config, keccak_steps)?;
566568

569+
// witness.assign_opcode_circuit::<LargeEcallDummy<E, KeccakSpec>>(
570+
// cs,
571+
// &self.keccak_config,
572+
// keccak_steps,
573+
//)?;
574+
567575
witness.assign_opcode_circuit::<LargeEcallDummy<E, Secp256k1AddSpec>>(
568576
cs,
569577
&self.secp256k1_add_config,

ceno_zkvm/src/scheme/prover.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use ceno_emul::KeccakSpec;
22
use ff_ext::ExtensionField;
3+
use gkr_iop::gkr::GKRCircuitWitness;
34
use std::{
45
collections::{BTreeMap, BTreeSet, HashMap},
56
sync::Arc,
@@ -99,6 +100,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
99100
let mut commitments = BTreeMap::new();
100101
let mut wits = BTreeMap::new();
101102
let mut structural_wits = BTreeMap::new();
103+
let mut keccak_gkr_wit = Some(witnesses.keccak_gkr_wit.clone());
102104

103105
let commit_to_traces_span = entered_span!("commit_to_traces", profiling_1 = true);
104106
// commit to opcode circuits first and then commit to table circuits, sorted by name
@@ -180,10 +182,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
180182
&& cs.r_table_expressions.is_empty()
181183
&& cs.w_table_expressions.is_empty();
182184

183-
if *circuit_name == <LargeEcallDummy<E, KeccakSpec> as Instruction<E>>::name() {
184-
// unimplemented!("keccak impl wip");
185-
()
186-
} else if is_opcode_circuit {
185+
if is_opcode_circuit {
187186
tracing::debug!(
188187
"opcode circuit {} has {} witnesses, {} reads, {} writes, {} lookups",
189188
circuit_name,
@@ -197,7 +196,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
197196
let gkr_iop_pk = if *circuit_name
198197
== <LargeEcallDummy<E, KeccakSpec> as Instruction<E>>::name()
199198
{
200-
Some(self.pk.keccak_pk.clone())
199+
Some((&self.pk.keccak_pk, keccak_gkr_wit.take().unwrap()))
201200
} else {
202201
None
203202
};
@@ -206,7 +205,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
206205
circuit_name,
207206
&self.pk.pp,
208207
pk,
209-
&gkr_iop_pk,
208+
gkr_iop_pk,
210209
witness,
211210
wits_commit,
212211
&pi,
@@ -266,7 +265,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
266265
name: &str,
267266
pp: &PCS::ProverParam,
268267
circuit_pk: &ProvingKey<E, PCS>,
269-
gkr_iop_pk: &Option<GKRIOPProvingKey<E, PCS, KeccakGKRIOP<E>>>,
268+
gkr_iop_pk: Option<(
269+
&GKRIOPProvingKey<E, PCS, KeccakGKRIOP<E>>,
270+
GKRCircuitWitness<E>,
271+
)>,
270272
witnesses: Vec<ArcMultilinearExtension<'_, E>>,
271273
wits_commit: PCS::CommitmentWithWitness,
272274
pi: &[ArcMultilinearExtension<'_, E>],
@@ -279,11 +281,6 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
279281
let log2_num_instances = ceil_log2(next_pow2_instances);
280282
let (chip_record_alpha, _) = (challenges[0], challenges[1]);
281283

282-
// if let Some(gkr_iop_pk) = gkr_iop_pk {
283-
// let mut gkr_iop_pk = gkr_iop_pk.clone();
284-
// unimplemented!("cannot fully handle GKRIOP component yet")
285-
// }
286-
287284
// sanity check
288285
assert_eq!(witnesses.len(), cs.num_witin as usize);
289286
assert!(
@@ -331,6 +328,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
331328

332329
// infer all tower witness after last layer
333330
let span = entered_span!("tower_witness_r_layers");
331+
334332
let r_wit_layers = infer_tower_product_witness(
335333
log2_num_instances + log2_r_count,
336334
r_records_last_layer,
@@ -455,6 +453,8 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
455453
rt_tower[..log2_num_instances].to_vec(),
456454
);
457455

456+
dbg!(rt_r.len(), rt_w.len(), rt_lk.len());
457+
458458
let num_threads = optimal_sumcheck_threads(log2_num_instances);
459459
let alpha_pow = get_challenge_pows(
460460
MAINCONSTRAIN_SUMCHECK_BATCH_SIZE + cs.assert_zero_sumcheck_expressions.len(),
@@ -481,6 +481,8 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
481481
);
482482
}
483483

484+
dbg!(sel_r.len());
485+
484486
let mut sel_w = build_eq_x_r_vec(&rt_w[log2_w_count..]);
485487
if num_instances < sel_w.len() {
486488
sel_w.splice(
@@ -630,6 +632,11 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
630632
distrinct_zerocheck_terms_set.len() + 1 // +1 from sel_non_lc_zero_sumcheck
631633
}
632634
);
635+
636+
dbg!(r_counts_per_instance);
637+
dbg!(w_counts_per_instance);
638+
dbg!(lk_counts_per_instance);
639+
633640
let mut main_sel_evals_iter = main_sel_evals.into_iter();
634641
main_sel_evals_iter.next(); // skip sel_r
635642
let r_records_in_evals = (0..r_counts_per_instance)
@@ -653,6 +660,12 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
653660
distrinct_zerocheck_terms_set.len() + 1
654661
}
655662
);
663+
664+
// if let Some(gkr_iop_pk) = gkr_iop_pk {
665+
// let mut gkr_iop_pk = gkr_iop_pk.clone();
666+
// unimplemented!("cannot fully handle GKRIOP component yet")
667+
// }
668+
656669
let input_open_point = main_sel_sumcheck_proofs.point.clone();
657670
assert!(input_open_point.len() == log2_num_instances);
658671
exit_span!(main_sel_span);
@@ -689,6 +702,19 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
689702
exit_span!(pcs_open_span);
690703
let wits_commit = PCS::get_pure_commitment(&wits_commit);
691704

705+
if let Some((gkr_iop_pk, gkr_wit)) = gkr_iop_pk {
706+
let mut gkr_iop_pk = gkr_iop_pk.clone();
707+
let gkr_circuit = gkr_iop_pk.vk.get_state().chip.gkr_circuit();
708+
709+
// let mut prover_transcript = transcript::BasicTranscript::<E>::new(b"protocol");
710+
let out_evals = vec![];
711+
712+
let gkr_iop::gkr::GKRProverOutput { gkr_proof, .. } = gkr_circuit
713+
.prove(gkr_wit, &out_evals, &vec![], transcript)
714+
.expect("Failed to prove phase");
715+
// unimplemented!("cannot fully handle GKRIOP component yet")
716+
}
717+
692718
Ok(ZKVMOpcodeProof {
693719
num_instances,
694720
record_r_out_evals,

ceno_zkvm/src/structs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use ceno_emul::{CENO_PLATFORM, KeccakSpec, Platform, StepRecord};
1111
use ff_ext::ExtensionField;
1212
use gkr_iop::{
1313
ProtocolWitnessGenerator,
14+
gkr::GKRCircuitWitness,
1415
precompiles::{KeccakLayout, KeccakTrace},
1516
};
1617
use itertools::{Itertools, chain};
@@ -343,7 +344,7 @@ impl<E: ExtensionField> ZKVMFixedTraces<E> {
343344

344345
#[derive(Default, Clone)]
345346
pub struct ZKVMWitnesses<E: ExtensionField> {
346-
keccak_phase1wit: Vec<Vec<E::BaseField>>,
347+
pub keccak_gkr_wit: GKRCircuitWitness<E>,
347348
witnesses_opcodes: BTreeMap<String, RowMajorMatrix<E::BaseField>>,
348349
witnesses_tables: BTreeMap<String, RMMCollections<E::BaseField>>,
349350
lk_mlts: BTreeMap<String, LkMultiplicity>,
@@ -374,13 +375,14 @@ impl<E: ExtensionField> ZKVMWitnesses<E> {
374375
let cs = css
375376
.get_cs(&LargeEcallDummy::<E, KeccakSpec>::name())
376377
.unwrap();
377-
let (witness, logup_multiplicity) =
378+
let (witness, gkr_witness, logup_multiplicity) =
378379
LargeEcallDummy::<E, KeccakSpec>::assign_instances_with_gkr_iop(
379380
config,
380381
cs.num_witin as usize,
381382
records,
382383
&mut css.keccak_gkr_iop.layout,
383384
)?;
385+
self.keccak_gkr_wit = gkr_witness;
384386

385387
// // Intercept row-major matrix, convert into KeccakTrace and obtain phase1_wit
386388
// self.keccak_phase1wit = css

gkr_iop/src/gkr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct GKRCircuit {
2222
pub ext_openings: Vec<(usize, EvalExpression)>,
2323
}
2424

25-
#[derive(Clone, Debug)]
25+
#[derive(Clone, Debug, Default)]
2626
pub struct GKRCircuitWitness<E: ExtensionField> {
2727
pub layers: Vec<LayerWitness<E>>,
2828
}
@@ -85,7 +85,7 @@ impl GKRCircuit {
8585
let mut challenges = challenges.to_vec();
8686
let mut evaluations = out_evals.to_vec();
8787
evaluations.resize(self.n_evaluations, PointAndEval::default());
88-
for (layer, layer_proof) in izip!(self.layers.clone(), sumcheck_proofs) {
88+
for (layer, layer_proof) in izip!(&self.layers, sumcheck_proofs) {
8989
layer.verify(layer_proof, &mut evaluations, &mut challenges, transcript)?;
9090
}
9191

gkr_iop/src/gkr/layer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct Layer {
5353
pub expr_names: Vec<String>,
5454
}
5555

56-
#[derive(Clone, Debug)]
56+
#[derive(Clone, Debug, Default)]
5757
pub struct LayerWitness<E: ExtensionField> {
5858
pub bases: Vec<Vec<E::BaseField>>,
5959
pub exts: Vec<Vec<E>>,

0 commit comments

Comments
 (0)