Skip to content

Commit

Permalink
Subgroup check skip (#79)
Browse files Browse the repository at this point in the history
* added skip subgroup check option

* changed subgroup check parameter

* added no option to SubgroupCheckMode

* cargo fmt
  • Loading branch information
mstraka100 authored Jun 10, 2021
1 parent 4d76416 commit 5b5143a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions phase1/src/helpers/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ cfg_if! {
compression,
CheckForCorrectness::OnlyNonZero,
)?;

const SECURITY_PARAM: usize = 128;
const BATCH_SIZE: usize = 1 << 12;
let now = std::time::Instant::now();
let all_in_prime_order_subgroup = match (elements.len() > BATCH_SIZE, subgroup_check_mode) {
let prime_order_subgroup_check_pass = match (elements.len() > BATCH_SIZE, subgroup_check_mode) {
(_, SubgroupCheckMode::No) => true,
(true, SubgroupCheckMode::Auto) | (_, SubgroupCheckMode::Batched) => {
match batch_verify_in_subgroup(elements, SECURITY_PARAM, &mut rand::thread_rng()) {
Ok(()) => true,
Expand All @@ -122,7 +124,7 @@ cfg_if! {
}
};
debug!("Subgroup verification for {} elems: {}us", end - start, now.elapsed().as_micros());
if !all_in_prime_order_subgroup {
if !prime_order_subgroup_check_pass {
return Err(Error::IncorrectSubgroup);
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions phase1/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
.expect(
"could not check element are non zero and in prime order subgroup (beta g1)",
);

if ratio_check {
check_power_ratios::<E>(
(beta_g1, compressed_output, CheckForCorrectness::No),
Expand Down
7 changes: 5 additions & 2 deletions setup-utils/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub enum SubgroupCheckMode {
Auto,
Direct,
Batched,
No,
}

impl fmt::Display for SubgroupCheckMode {
Expand All @@ -98,6 +99,7 @@ impl fmt::Display for SubgroupCheckMode {
SubgroupCheckMode::Auto => write!(f, "Auto"),
SubgroupCheckMode::Direct => write!(f, "Direct"),
SubgroupCheckMode::Batched => write!(f, "Batched"),
SubgroupCheckMode::No => write!(f, "No"),
}
}
}
Expand Down Expand Up @@ -135,7 +137,8 @@ pub fn check_subgroup<C: AffineCurve>(
) -> core::result::Result<(), Error> {
const SECURITY_PARAM: usize = 128;
const BATCH_SIZE: usize = 1 << 12;
let all_in_prime_order_subgroup = match (elements.len() > BATCH_SIZE, subgroup_check_mode) {
let prime_order_subgroup_check_pass = match (elements.len() > BATCH_SIZE, subgroup_check_mode) {
(_, SubgroupCheckMode::No) => true,
(true, SubgroupCheckMode::Auto) | (_, SubgroupCheckMode::Batched) => {
match batch_verify_in_subgroup(elements, SECURITY_PARAM, &mut rand::thread_rng()) {
Ok(()) => true,
Expand All @@ -147,7 +150,7 @@ pub fn check_subgroup<C: AffineCurve>(
.is_zero()
}),
};
if !all_in_prime_order_subgroup {
if !prime_order_subgroup_check_pass {
return Err(Error::IncorrectSubgroup);
}

Expand Down

0 comments on commit 5b5143a

Please sign in to comment.