Skip to content

Commit

Permalink
Simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Mar 27, 2023
1 parent 6d5617e commit ad5d8b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
29 changes: 15 additions & 14 deletions utils/src/try_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,21 @@ where
P: PairValidator<OK>,
E: From<InvalidPair<P::MappedItem>>,
{
iter.into_iter().scan(None, move |last, cur| match cur {
err @ Err(_) => Some(err),
Ok(cur) => {
let item = if let Some((prev, cur)) = last
.replace(validator.map(&cur))
.map(|prev| (prev, validator.map(&cur)))
.filter(|(prev, cur)| !validator.validate(prev, cur))
{
Err(InvalidPair(prev, cur).into())
} else {
Ok(cur)
};

Some(item)
let mut last = None;

iter.into_iter().map(move |cur| {
let cur = cur?;

let invalid = last
.replace(validator.map(&cur))
.zip(last.as_ref())
.map(|(prev, cur)| (prev, cur))
.filter(|(prev, cur)| !validator.validate(prev, cur));

if let Some((prev, _)) = invalid {
Err(InvalidPair(prev, validator.map(&cur)).into())
} else {
Ok(cur)
}
})
}
2 changes: 1 addition & 1 deletion vb_accumulator/src/batch_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ mod tests {
);
assert_eq!(Poly_v_D::generate(&[], &alpha).eval(&x), Fr::zero());

for i in &[100, 70, 50, 40, 35, 20, 10, 7, 1, 0] {
for &i in &[100, 70, 50, 40, 35, 20, 10, 7, 1, 0] {
let updates_1 = (0..i).map(|_| Fr::rand(&mut rng)).collect::<Vec<Fr>>();
let poly_v_AD = Poly_v_AD::generate(&updates, &updates_1, &alpha);
assert_eq!(
Expand Down
6 changes: 3 additions & 3 deletions vb_accumulator/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ mod tests {
// Same seed generates same keypair
let params = SetupParams::<Bls12_381>::new::<Blake2b512>("test".as_bytes());
assert!(params.is_valid());
let mut invalid_params = params;
let mut invalid_params = params.clone();
invalid_params.P = <Bls12_381 as Pairing>::G1Affine::zero();
assert!(!invalid_params.is_valid());
let mut invalid_params = params;
let mut invalid_params = params.clone();
invalid_params.P_tilde = <Bls12_381 as Pairing>::G2Affine::zero();
assert!(!invalid_params.is_valid());
let mut invalid_params = params;
let mut invalid_params = params.clone();
invalid_params.P = <Bls12_381 as Pairing>::G1Affine::zero();
invalid_params.P_tilde = <Bls12_381 as Pairing>::G2Affine::zero();
assert!(!invalid_params.is_valid());
Expand Down
8 changes: 4 additions & 4 deletions vb_accumulator/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ mod tests {
.unwrap();

// This witness is updated with only 1 batch in each iteration of the loop below
let mut wit_temp = wit;
let mut wit_temp = wit.clone();

for i in 0..additions.len() {
let omega = Omega::new(
Expand Down Expand Up @@ -1670,7 +1670,7 @@ mod tests {
.get_membership_witness(&e0, &keypair.secret_key, &mut state)
.unwrap();

let mut wit_temp = wit;
let mut wit_temp = wit.clone();

let mut omegas = vec![];
let mut additions = vec![];
Expand Down Expand Up @@ -1927,8 +1927,8 @@ mod tests {
.get_non_membership_witness(&non_member, &keypair.secret_key, &state, &params)
.unwrap();

let mut m_wit = m_wit_initial;
let mut nm_wit = nm_wit_initial;
let mut m_wit = m_wit_initial.clone();
let mut nm_wit = nm_wit_initial.clone();

let mut batched_public_info = vec![];

Expand Down

0 comments on commit ad5d8b9

Please sign in to comment.