Skip to content

Commit

Permalink
Fix pre_eq_reduce (#17)
Browse files Browse the repository at this point in the history
* Fix pre_eq_reduce

The pre_eq_reduce should directly reduce the value to the normal form rather than checking it.

* fmt
  • Loading branch information
weikengchen authored Nov 12, 2020
1 parent 1a04adb commit 60c7dd7
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,11 @@ impl<TargetField: PrimeField, BaseField: PrimeField> Reducer<TargetField, BaseFi
pub fn pre_eq_reduce(
elem: &mut AllocatedNonNativeFieldVar<TargetField, BaseField>,
) -> R1CSResult<()> {
let cs = elem.cs.clone();
let params = get_params::<TargetField, BaseField>(&cs);

if elem.is_in_the_normal_form {
return Ok(());
}

let log = overhead!(elem.num_of_additions_over_normal_form + BaseField::one()) + 1;

if BaseField::size_in_bits() > params.bits_per_limb + log + 1 {
Ok(())
} else {
Self::reduce(elem)
}
Self::reduce(elem)
}

/// Group and check equality
Expand Down

0 comments on commit 60c7dd7

Please sign in to comment.