Skip to content

Commit

Permalink
chore: refactor exact instances of ok_or_else (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker authored Mar 14, 2022
1 parent c1ba266 commit 9590fac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
21 changes: 9 additions & 12 deletions plonk/src/circuit/customized/ultraplonk/plonk_verifier/gadgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ where
add_pcs_eval_circuit(
circuit,
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
wire_eval,
&non_native_field_info.modulus_fp_elem,
)?;
Expand All @@ -160,10 +159,9 @@ where
add_pcs_eval_circuit(
circuit,
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
sigma_eval,
&non_native_field_info.modulus_fp_elem,
)?;
Expand All @@ -172,10 +170,9 @@ where
add_pcs_eval_circuit(
circuit,
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
&poly_evals.perm_next_eval,
&non_native_field_info.modulus_fp_elem,
)?;
Expand Down
14 changes: 6 additions & 8 deletions plonk/src/circuit/customized/ultraplonk/plonk_verifier/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,9 @@ where

// preparing data for second statement
let r_0_component = circuit.mod_mul(
match alpha_bases_elem_var.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
alpha_bases_elem_var
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
&r_plonk_j_fp_elem_var,
&non_native_field_info.modulus_fp_elem,
)?;
Expand Down Expand Up @@ -532,10 +531,9 @@ where
// where a_bar, b_bar and c_bar are in w_evals
// ============================================

let current_alpha_bases = match alpha_bases_elem_var.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
};
let current_alpha_bases = alpha_bases_elem_var
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?;

let mut coeff_fp_elem_var = alpha_2_mul_l1;
let w_evals = &batch_proof.poly_evals_vec[i].wires_evals;
Expand Down
35 changes: 15 additions & 20 deletions plonk/src/proof_system/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,30 +720,27 @@ where
for &wire_eval in poly_evals.wires_evals.iter() {
Self::add_pcs_eval(
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
wire_eval,
);
}
for &sigma_eval in poly_evals.wire_sigma_evals.iter() {
Self::add_pcs_eval(
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
sigma_eval,
);
}
// evaluations at point `zeta * g`
Self::add_pcs_eval(
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
poly_evals.perm_next_eval,
);

Expand All @@ -754,21 +751,19 @@ where
for &eval in evals.evals_vec().iter() {
Self::add_pcs_eval(
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
eval,
);
}
// evaluations at point `zeta * g`
for &next_eval in evals.next_evals_vec().iter() {
Self::add_pcs_eval(
&mut result,
match v_and_uv_basis.next() {
Some(p) => p,
None => return Err(PlonkError::IteratorOutOfRange),
},
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
next_eval,
);
}
Expand Down

0 comments on commit 9590fac

Please sign in to comment.