Skip to content

Commit

Permalink
fix: Handle value obtentions for AssignedCells (privacy-scaling-explo…
Browse files Browse the repository at this point in the history
…rations#486)

* fix: Handle value obtentions for AssignedCells

Previously we were unwrapping directly after asking to the AssignedCells
for their value.

Now since during setup phase these values are also queried, we simply
retunr a default value for them.

* fix: Handle value obtentions for AssignedCells

Previously we were unwrapping directly after asking to the AssignedCells
for their value.

Now since during setup phase these values are also queried, we simply
retunr a default value for them.

* fix: Swap cloned for copied with Result for value
  • Loading branch information
CPerezz authored May 4, 2022
1 parent 2fc5423 commit 2792434
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions keccak256/src/arith_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ pub fn state_bigint_to_field<F: Field, const N: usize>(state: StateBigInt) -> [F
/// Returns only the value of a an assigned state cell.
pub fn split_state_cells<F: Field, const N: usize>(state: [AssignedCell<F, F>; N]) -> [F; N] {
let mut res = [F::zero(); N];
state
.iter()
.enumerate()
.for_each(|(idx, assigned_cell)| res[idx] = *assigned_cell.value().unwrap());
state.iter().enumerate().for_each(|(idx, assigned_cell)| {
res[idx] = assigned_cell.value().copied().unwrap_or_default()
});
res
}

Expand Down
4 changes: 2 additions & 2 deletions keccak256/src/circuit/word_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<F: Field> WordBuilderConfig<F> {
.iter()
.enumerate()
.map(|(idx, byte_cell)| {
F::from(1u64 << (idx * 8)) * byte_cell.value().unwrap_or(&F::zero())
F::from(1u64 << (idx * 8)) * byte_cell.value().copied().unwrap_or_default()
})
.reduce(|acc, byte_shifted| acc + byte_shifted)
// Unwrapping is safe here as we recieve an array that contails all elements.
Expand Down Expand Up @@ -135,7 +135,7 @@ mod tests {
plonk::{Advice, Any, Circuit},
};
use pairing::bn256::Fr;
//use pretty_assertions::assert_eq;
use pretty_assertions::assert_eq;

#[test]
fn test_word_construction_gate() {
Expand Down
2 changes: 1 addition & 1 deletion keccak256/src/permutation/base_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<F: Field> BaseConversionConfig<F> {
) -> Result<AssignedCell<F, F>, Error> {
let (input_coefs, output_coefs, _) = self
.base_info
.compute_coefs(*input.value().unwrap_or(&F::zero()))?;
.compute_coefs(input.value().copied().unwrap_or_default())?;

layouter.assign_region(
|| "Base conversion",
Expand Down
4 changes: 2 additions & 2 deletions keccak256/src/permutation/rho_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl<F: Field> LaneRotateConversionConfig<F> {
Error,
> {
let (conversions, special) = RhoLane::new(
f_to_biguint(*lane_base_13.value().unwrap_or(&F::zero())),
f_to_biguint(lane_base_13.value().copied().unwrap_or_default()),
self.rotation,
)
.get_full_witness();
Expand Down Expand Up @@ -432,7 +432,7 @@ impl<F: Field> SumConfig<F> {
self.q_enable.enable(&mut region, offset)?;
xs_item.copy_advice(|| "x", &mut region, self.x, offset)?;
region.assign_advice(|| "sum", self.sum, offset, || Ok(sum))?;
sum += xs_item.value().unwrap_or(&F::zero());
sum += xs_item.value().copied().unwrap_or_default();
offset += 1;
}
let sum = region.assign_advice(|| "last sum", self.sum, offset, || Ok(sum))?;
Expand Down
2 changes: 1 addition & 1 deletion keccak256/src/permutation/state_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod tests {
let output_state = self.conversion.assign_region(layouter, &state, flag)?;
let output_state: [F; 25] = output_state
.iter()
.map(|cell| *cell.value().unwrap())
.map(|cell| cell.value().copied().unwrap_or_default())
.collect::<Vec<F>>()
.try_into()
.unwrap();
Expand Down

0 comments on commit 2792434

Please sign in to comment.