Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lookup records for mockprover #197

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ceno_zkvm/src/instructions/riscv/blt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ impl<E: ExtensionField> Instruction<E> for BltInstruction {
mod test {
use super::*;
use ceno_emul::StepRecord;
use ff::Field;
use goldilocks::GoldilocksExt2;
use itertools::Itertools;
use multilinear_extensions::mle::IntoMLEs;
use rand::rngs::OsRng;
use std::array;

use crate::{circuit_builder::ConstraintSystem, scheme::mock_prover::MockProver};

Expand All @@ -257,17 +260,18 @@ mod test {
)
.unwrap();

MockProver::run(
let rng = OsRng;
let challenges: [GoldilocksExt2; 2] = array::from_fn(|_| GoldilocksExt2::random(rng));
MockProver::assert_satisfied(
&mut circuit_builder,
&raw_witin
.de_interleaving()
.into_mles()
.into_iter()
.map(|v| v.into())
.collect_vec(),
None,
)
.expect_err("lookup will fail");
Some(challenges),
);
Ok(())
}

Expand Down
40 changes: 40 additions & 0 deletions ceno_zkvm/src/scheme/mock_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ impl<'a, E: ExtensionField> MockProver<E> {
let mut table_vec = vec![];
load_u5_table(&mut table_vec, cb, challenge);
load_u16_table(&mut table_vec, cb, challenge);
load_and_table(&mut table_vec, cb, challenge);
load_ltu_table(&mut table_vec, cb, challenge);

// Lookup expressions
for (expr, name) in cb
Expand Down Expand Up @@ -350,6 +352,44 @@ pub fn load_u16_table<E: ExtensionField>(
}
}

pub fn load_and_table<E: ExtensionField>(
t_vec: &mut Vec<E>,
cb: &CircuitBuilder<E>,
challenge: [E; 2],
) {
for i in 0..(1 << 16) {
let a = i >> 8;
let b = i & 0xFF;
let c = a & b;
let rlc_record = cb.rlc_chip_record(vec![
Expression::Constant(E::BaseField::from(ROMType::And as u64)),
i.into(),
c.into(),
]);
let rlc_record = eval_by_expr(&[], &challenge, &rlc_record);
t_vec.push(rlc_record);
}
}

pub fn load_ltu_table<E: ExtensionField>(
t_vec: &mut Vec<E>,
cb: &CircuitBuilder<E>,
challenge: [E; 2],
) {
for i in 0..(1 << 16) {
let a = i >> 8;
let b = i & 0xFF;
let c = (a < b) as usize;
let rlc_record = cb.rlc_chip_record(vec![
Expression::Constant(E::BaseField::from(ROMType::Ltu as u64)),
i.into(),
c.into(),
]);
let rlc_record = eval_by_expr(&[], &challenge, &rlc_record);
t_vec.push(rlc_record);
}
}

#[allow(unused_imports)]
#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion ceno_zkvm/src/uint/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<const M: usize, E: ExtensionField> UInt<M, 8, E> {
circuit_builder.lookup_and_byte(
high_limb_no_msb.expr(),
high_limb.clone(),
Expression::from(1 << 7),
Expression::from(0b0111_1111),
)?;

let inv_128 = F::from(128).invert().unwrap();
Expand Down
Loading