diff --git a/src/plonk/permutation/keygen.rs b/src/plonk/permutation/keygen.rs index d5bfadd..c7d9274 100644 --- a/src/plonk/permutation/keygen.rs +++ b/src/plonk/permutation/keygen.rs @@ -30,6 +30,9 @@ impl Assembly { columns.push((0..params.n).map(|j| (i, j as usize)).collect()); } + // Before any equality constraints are applied, every cell in the permutation is + // in a 1-cycle; therefore mapping and aux are identical, because every cell is + // its own distinguished element. Assembly { mapping: columns.clone(), aux: columns, @@ -53,9 +56,12 @@ impl Assembly { return Err(Error::BoundsFailure); } + // See book/src/design/permutation.md for a description of this algorithm. + let mut left_cycle = self.aux[left_column][left_row]; let mut right_cycle = self.aux[right_column][right_row]; + // If left and right are in the same cycle, do nothing. if left_cycle == right_cycle { return Ok(()); } @@ -64,6 +70,7 @@ impl Assembly { std::mem::swap(&mut left_cycle, &mut right_cycle); } + // Merge the right cycle into the left one. self.sizes[left_cycle.0][left_cycle.1] += self.sizes[right_cycle.0][right_cycle.1]; let mut i = right_cycle; loop {