Skip to content

Commit

Permalink
exp half lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Dec 23, 2024
1 parent 119bbe0 commit 8a2218a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 31 deletions.
50 changes: 25 additions & 25 deletions ceno_zkvm/benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,33 @@ fn setup() -> (Program, Platform) {

fn fibonacci_prove(c: &mut Criterion) {
let (program, platform) = setup();
for max_steps in [1usize << 20, 1usize << 21, 1usize << 22] {
for max_steps in [1usize << 22] {
// estimate proof size data first
let (proof, verifier) = run_e2e_with_checkpoint::<E, Pcs>(
program.clone(),
platform.clone(),
vec![],
max_steps,
Checkpoint::PrepSanityCheck,
)
.0
.expect("PrepSanityCheck do not provide proof and verifier");
// let (proof, verifier) = run_e2e_with_checkpoint::<E, Pcs>(
// program.clone(),
// platform.clone(),
// vec![],
// max_steps,
// Checkpoint::PrepSanityCheck,
// )
// .0
// .expect("PrepSanityCheck do not provide proof and verifier");

let serialize_size = bincode::serialize(&proof).unwrap().len();
let stat_recorder = StatisticRecorder::default();
let transcript = BasicTranscriptWithStat::new(&stat_recorder, b"riscv");
assert!(
verifier
.verify_proof_halt(proof, transcript, false)
.expect("verify proof return with error"),
);
println!();
println!(
"max_steps = {}, proof size = {}, hashes count = {}",
max_steps,
serialize_size,
stat_recorder.into_inner().field_appended_num
);
// let serialize_size = bincode::serialize(&proof).unwrap().len();
// let stat_recorder = StatisticRecorder::default();
// let transcript = BasicTranscriptWithStat::new(&stat_recorder, b"riscv");
// assert!(
// verifier
// .verify_proof_halt(proof, transcript, false)
// .expect("verify proof return with error"),
// );
// println!();
// println!(
// "max_steps = {}, proof size = {}, hashes count = {}",
// max_steps,
// serialize_size,
// stat_recorder.into_inner().field_appended_num
// );

// expand more input size once runtime is acceptable
let mut group = c.benchmark_group(format!("fibonacci_max_steps_{}", max_steps));
Expand Down
7 changes: 6 additions & 1 deletion ceno_zkvm/benches/riscv_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ fn bench_add(c: &mut Criterion) {
let num_instances = 1 << instance_num_vars;
let mut transcript = BasicTranscript::new(b"riscv");
let commit =
Pcs::batch_commit_and_write(&prover.pk.pp, &wits_in, &mut transcript)
Pcs::batch_commit_and_write(&prover.pk.pp, &wits_in[0..wits_in.len()/2], &mut transcript)
.unwrap();
let challenges = [
transcript.read_challenge().elements,
transcript.read_challenge().elements,
];
println!(
"AddInstruction::batch_commit_and_write, instance_num_vars = {}, time = {}",
instance_num_vars,
timer.elapsed().as_secs_f64()
);

let _ = prover
.create_opcode_proof(
Expand Down
30 changes: 25 additions & 5 deletions ceno_zkvm/src/scheme/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,26 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
circuit_name = circuit_name,
profiling_2 = true
);
let cs = self.pk.circuit_pks[&circuit_name].get_cs();
let is_opcode_circuit = cs.lk_table_expressions.is_empty()
&& cs.r_table_expressions.is_empty()
&& cs.w_table_expressions.is_empty();
let witness = match num_instances {
0 => vec![],
_ => {
let witness = witness.into_mles();
commitments.insert(
circuit_name.clone(),
PCS::batch_commit_and_write(&self.pk.pp, &witness, &mut transcript)
.map_err(ZKVMError::PCSError)?,
PCS::batch_commit_and_write(
&self.pk.pp,
if is_opcode_circuit && witness.len() > 1 {
&witness[0..witness.len() / 2]
} else {
&witness
},
&mut transcript,
)
.map_err(ZKVMError::PCSError)?,
);
witness
}
Expand Down Expand Up @@ -614,12 +626,20 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
name,
witnesses.len()
);
let (witnesses, wits_in_evals) = if witnesses.len() > 1 {
(
&witnesses[0..witnesses.len() / 2],
&wits_in_evals[0..wits_in_evals.len() / 2],
)
} else {
(witnesses.as_slice(), wits_in_evals.as_slice())
};
let wits_opening_proof = PCS::simple_batch_open(
pp,
&witnesses,
witnesses,
&wits_commit,
&input_open_point,
wits_in_evals.as_slice(),
wits_in_evals,
transcript,
)
.map_err(ZKVMError::PCSError)?;
Expand All @@ -646,7 +666,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
lk_records_in_evals,
wits_commit,
wits_opening_proof,
wits_in_evals,
wits_in_evals: wits_in_evals.to_vec(),
})
}

Expand Down
11 changes: 11 additions & 0 deletions ceno_zkvm/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ impl<E: ExtensionField> ZKVMConstraintSystem<E> {
let mut circuit_builder =
CircuitBuilder::<E>::new_with_params(&mut cs, self.params.clone());
let config = OC::construct_circuit(&mut circuit_builder).unwrap();
println!(
"before lk expression {} lk len {}",
OC::name(),
cs.lk_expressions.len()
);
cs.lk_expressions = cs.lk_expressions.split_off(cs.lk_expressions.len() / 2);
println!(
"after lk expression {} lk len {}",
OC::name(),
cs.lk_expressions.len()
);
assert!(self.circuit_css.insert(OC::name(), cs).is_none());

config
Expand Down
2 changes: 2 additions & 0 deletions mpcs/src/basefold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ where
evals: &[E],
transcript: &mut impl Transcript<E>,
) -> Result<Self::Proof, Error> {
let polys = &polys[0..comm.num_polys];
let evals = &evals[0..comm.num_polys];
let timer = start_timer!(|| "Basefold::batch_open");
let num_vars = polys[0].num_vars();

Expand Down

0 comments on commit 8a2218a

Please sign in to comment.