Skip to content

Commit

Permalink
fix(snark-wrapper): call range check with proper params (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
saitima authored Dec 10, 2024
1 parent b9eea46 commit cba8e9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion crates/franklin-crypto/src/plonk/circuit/goldilocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl<E: Engine> Hash for GoldilocksField<E> {
}

pub fn range_check_for_num_bits<E: Engine, CS: ConstraintSystem<E>>(cs: &mut CS, num: &Num<E>, num_bits: usize) -> Result<(), SynthesisError> {
range_check_for_num_bits_coarsely(cs, num, num_bits, true)
}

pub fn range_check_for_num_bits_coarsely<E: Engine, CS: ConstraintSystem<E>>(cs: &mut CS, num: &Num<E>, num_bits: usize, coarsely: bool) -> Result<(), SynthesisError> {
assert!(num_bits % 16 == 0);

if let Num::Constant(value) = num {
Expand All @@ -56,7 +60,7 @@ pub fn range_check_for_num_bits<E: Engine, CS: ConstraintSystem<E>>(cs: &mut CS,
} else {
// Name of the table should be checked
if let Ok(table) = cs.get_table(BITWISE_LOGICAL_OPS_TABLE_NAME) {
enforce_range_check_using_bitop_table(cs, &num.get_variable(), num_bits, table, true)?;
enforce_range_check_using_bitop_table(cs, &num.get_variable(), num_bits, table, coarsely)?;
} else if <CS::Params as PlonkConstraintSystemParams<E>>::CAN_ACCESS_NEXT_TRACE_STEP {
enforce_range_check_using_naive_approach(cs, &num.get_variable(), num_bits)?;
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/snark-wrapper/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ fn aggregate_public_inputs<E: Engine, CS: ConstraintSystem<E>>(cs: &mut CS, publ
);

// Firstly we check that public inputs have correct size
use rescue_poseidon::franklin_crypto::plonk::circuit::goldilocks::range_check_for_num_bits;
use rescue_poseidon::franklin_crypto::plonk::circuit::goldilocks::range_check_for_num_bits_coarsely;
for pi in public_inputs.iter() {
range_check_for_num_bits(cs, &pi.into_num(), 64)?;
range_check_for_num_bits_coarsely(cs, &pi.into_num(), 64, false)?;
}

// compute aggregated pi value
Expand Down

0 comments on commit cba8e9c

Please sign in to comment.