Skip to content

Commit

Permalink
fix: range_check testing
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobottazzi committed Dec 11, 2023
1 parent d6e57c5 commit 13292a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 2 additions & 3 deletions kzg_prover/src/chips/range/range_check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use halo2_proofs::arithmetic::Field;
use halo2_proofs::circuit::{AssignedCell, Layouter, Region, Value};
use halo2_proofs::circuit::{AssignedCell, Region, Value};
use halo2_proofs::halo2curves::bn256::Fr as Fp;
use halo2_proofs::plonk::{Advice, Column, ConstraintSystem, Error, Expression, Fixed};
use halo2_proofs::poly::Rotation;
Expand All @@ -24,7 +24,6 @@ use crate::chips::range::utils::decompose_fp_to_bytes;
#[derive(Debug, Copy, Clone)]
pub struct RangeCheckConfig<const N_BYTES: usize> {
zs: [Column<Advice>; N_BYTES],
range: Column<Fixed>,
}

/// Helper chip that verfiies that the element witnessed in a given cell lies within a given range defined by N_BYTES.
Expand Down Expand Up @@ -109,7 +108,7 @@ impl<const N_BYTES: usize> RangeCheckChip<N_BYTES> {
);
}

RangeCheckConfig { zs, range }
RangeCheckConfig { zs }
}

/// Assign the truncated right-shifted values of the element to be checked to the corresponding columns zs at offset 0 starting from the element to be checked.
Expand Down
24 changes: 21 additions & 3 deletions kzg_prover/src/chips/range/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::chips::range::range_check::{RangeCheckChip, RangeCheckConfig};
use halo2_proofs::{
circuit::{AssignedCell, Layouter, SimpleFloorPlanner, Value},
halo2curves::bn256::Fr as Fp,
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Selector},
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Selector},
poly::Rotation,
};

Expand Down Expand Up @@ -88,6 +88,7 @@ impl AddChip {
pub struct TestConfig<const N_BYTES: usize> {
pub addchip_config: AddConfig,
pub range_check_config: RangeCheckConfig<N_BYTES>,
pub range: Column<Fixed>,
}

// The test circuit takes two inputs a and b.
Expand Down Expand Up @@ -137,6 +138,7 @@ impl<const N_BYTES: usize> Circuit<Fp> for TestCircuit<N_BYTES> {
TestConfig {
addchip_config,
range_check_config,
range,
}
}
}
Expand All @@ -150,6 +152,22 @@ impl<const N_BYTES: usize> Circuit<Fp> for TestCircuit<N_BYTES> {
let range_chip = RangeCheckChip::construct(config.range_check_config);

// Load the lookup table
let range = 1 << 8;

layouter.assign_region(
|| format!("load range check table of {} bits", 8 * N_BYTES),
|mut region| {
for i in 0..range {
region.assign_fixed(
|| "assign cell in fixed column",
config.range,
i,
|| Value::known(Fp::from(i as u64)),
)?;
}
Ok(())
},
)?;

// Initiate the add chip
let addchip = AddChip::construct(config.addchip_config);
Expand Down Expand Up @@ -219,7 +237,7 @@ mod testing {
VerifyFailure::Permutation {
column: (Any::advice(), 4).into(),
location: FailureLocation::InRegion {
region: (1, "Perform range check on c").into(),
region: (2, "Perform range check on c").into(),
offset: 0
}
},
Expand Down Expand Up @@ -252,7 +270,7 @@ mod testing {
VerifyFailure::Permutation {
column: (Any::advice(), 6).into(),
location: FailureLocation::InRegion {
region: (1, "Perform range check on c").into(),
region: (2, "Perform range check on c").into(),
offset: 0
}
},
Expand Down

0 comments on commit 13292a7

Please sign in to comment.