diff --git a/src/circuit_builder.rs b/src/circuit_builder.rs index 8caecc25..4990cffe 100644 --- a/src/circuit_builder.rs +++ b/src/circuit_builder.rs @@ -359,7 +359,13 @@ impl, const D: usize> CircuitBuilder { fn sigma_vecs(&self, k_is: &[F], subgroup: &[F]) -> Vec> { let degree = self.gate_instances.len(); let degree_log = log2_strict(degree); - let mut target_partition = TargetPartition::default(); + let mut target_partition = TargetPartition::new(|t| match t { + Target::Wire(Wire { gate, input }) => gate * self.config.num_routed_wires + input, + Target::PublicInput { index } => degree * self.config.num_routed_wires + index, + Target::VirtualTarget { index } => { + degree * self.config.num_routed_wires + self.public_input_index + index + } + }); for gate in 0..degree { for input in 0..self.config.num_routed_wires { diff --git a/src/permutation_argument.rs b/src/permutation_argument.rs index 6a1838a6..f7ee9a5e 100644 --- a/src/permutation_argument.rs +++ b/src/permutation_argument.rs @@ -18,21 +18,18 @@ pub struct ForestNode { } #[derive(Debug, Clone)] -pub struct TargetPartition { +pub struct TargetPartition usize> { forest: Vec>, - indices: HashMap, + indices: F, } -impl Default for TargetPartition { - fn default() -> Self { +impl usize> TargetPartition { + pub fn new(f: F) -> Self { Self { forest: Vec::new(), - indices: Default::default(), + indices: f, } } -} - -impl TargetPartition { /// Add a new partition with a single member. pub fn add(&mut self, t: T) { let index = self.forest.len(); @@ -42,7 +39,6 @@ impl TargetPartition { size: 1, index, }); - self.indices.insert(t, index); } /// Path halving @@ -58,8 +54,8 @@ impl TargetPartition { /// Merge the two partitions containing the two given targets. Does nothing if the targets are /// already members of the same partition. pub fn merge(&mut self, tx: T, ty: T) { - let index_x = self.indices[&tx]; - let index_y = self.indices[&ty]; + let index_x = (self.indices)(tx); + let index_y = (self.indices)(ty); let mut x = self.forest[index_x]; let mut y = self.forest[index_y]; @@ -81,7 +77,7 @@ impl TargetPartition { self.forest[index_y] = y; } } -impl TargetPartition { +impl usize> TargetPartition { pub fn wire_partitions(&mut self) -> WirePartitions { let mut partition = HashMap::<_, Vec<_>>::new(); let nodes = self.forest.clone();