mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-05-28 12:49:54 +00:00
fix for non-2x2 permutation case
This commit is contained in:
parent
f01d373d1e
commit
4f7a587bfa
@ -55,7 +55,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
|
|
||||||
let chunk_size = a1.len();
|
let chunk_size = a1.len();
|
||||||
|
|
||||||
let (switch, gate_out1, gate_out2) = self.create_switch(a1, a2);
|
let (_switch, gate_out1, gate_out2) = self.create_switch(a1, a2);
|
||||||
for e in 0..chunk_size {
|
for e in 0..chunk_size {
|
||||||
self.connect(b1[e], gate_out1[e]);
|
self.connect(b1[e], gate_out1[e]);
|
||||||
self.connect(b2[e], gate_out2[e]);
|
self.connect(b2[e], gate_out2[e]);
|
||||||
@ -177,7 +177,6 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
self.assert_permutation(child_2_a, child_2_b);
|
self.assert_permutation(child_2_a, child_2_b);
|
||||||
|
|
||||||
self.add_simple_generator(PermutationGenerator::<F> {
|
self.add_simple_generator(PermutationGenerator::<F> {
|
||||||
chunk_size,
|
|
||||||
a,
|
a,
|
||||||
b,
|
b,
|
||||||
a_switches,
|
a_switches,
|
||||||
@ -271,12 +270,13 @@ fn route<F: Field>(
|
|||||||
enqueue_other_side(&mut partial_routes, witness, &mut newly_set, 1, n - 1, true);
|
enqueue_other_side(&mut partial_routes, witness, &mut newly_set, 1, n - 1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut route_switch = |partial_routes: &mut [BTreeMap<usize, bool>],
|
let route_switch = |partial_routes: &mut [BTreeMap<usize, bool>],
|
||||||
witness: &PartitionWitness<F>,
|
witness: &PartitionWitness<F>,
|
||||||
out_buffer: &mut GeneratedValues<F>,
|
out_buffer: &mut GeneratedValues<F>,
|
||||||
side: usize,
|
newly_set: &mut [Vec<bool>],
|
||||||
switch_index: usize,
|
side: usize,
|
||||||
swap: bool| {
|
switch_index: usize,
|
||||||
|
swap: bool| {
|
||||||
// First, we actually set the switch configuration.
|
// First, we actually set the switch configuration.
|
||||||
out_buffer.set_target(switches[side][switch_index], F::from_bool(swap));
|
out_buffer.set_target(switches[side][switch_index], F::from_bool(swap));
|
||||||
newly_set[side][switch_index] = true;
|
newly_set[side][switch_index] = true;
|
||||||
@ -285,22 +285,8 @@ fn route<F: Field>(
|
|||||||
// that they get routed in the next step.
|
// that they get routed in the next step.
|
||||||
let this_i_1 = switch_index * 2;
|
let this_i_1 = switch_index * 2;
|
||||||
let this_i_2 = this_i_1 + 1;
|
let this_i_2 = this_i_1 + 1;
|
||||||
enqueue_other_side(
|
enqueue_other_side(partial_routes, witness, newly_set, side, this_i_1, swap);
|
||||||
partial_routes,
|
enqueue_other_side(partial_routes, witness, newly_set, side, this_i_2, !swap);
|
||||||
witness,
|
|
||||||
&mut newly_set,
|
|
||||||
side,
|
|
||||||
this_i_1,
|
|
||||||
swap,
|
|
||||||
);
|
|
||||||
enqueue_other_side(
|
|
||||||
partial_routes,
|
|
||||||
witness,
|
|
||||||
&mut newly_set,
|
|
||||||
side,
|
|
||||||
this_i_2,
|
|
||||||
!swap,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If {a,b}_only_routes is empty, then we can route any switch next. For efficiency, we will
|
// If {a,b}_only_routes is empty, then we can route any switch next. For efficiency, we will
|
||||||
@ -322,6 +308,7 @@ fn route<F: Field>(
|
|||||||
&mut partial_routes,
|
&mut partial_routes,
|
||||||
witness,
|
witness,
|
||||||
out_buffer,
|
out_buffer,
|
||||||
|
&mut newly_set,
|
||||||
side,
|
side,
|
||||||
this_switch_i,
|
this_switch_i,
|
||||||
swap,
|
swap,
|
||||||
@ -331,7 +318,8 @@ fn route<F: Field>(
|
|||||||
} else {
|
} else {
|
||||||
// We can route any switch next. Continue our scan for pending switches.
|
// We can route any switch next. Continue our scan for pending switches.
|
||||||
while scan_index[side] < switches[side].len()
|
while scan_index[side] < switches[side].len()
|
||||||
&& witness.contains(switches[side][scan_index[side]])
|
&& (witness.contains(switches[side][scan_index[side]])
|
||||||
|
|| newly_set[side][scan_index[side]])
|
||||||
{
|
{
|
||||||
scan_index[side] += 1;
|
scan_index[side] += 1;
|
||||||
}
|
}
|
||||||
@ -341,6 +329,7 @@ fn route<F: Field>(
|
|||||||
&mut partial_routes,
|
&mut partial_routes,
|
||||||
witness,
|
witness,
|
||||||
out_buffer,
|
out_buffer,
|
||||||
|
&mut newly_set,
|
||||||
side,
|
side,
|
||||||
scan_index[side],
|
scan_index[side],
|
||||||
false,
|
false,
|
||||||
@ -354,7 +343,6 @@ fn route<F: Field>(
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct PermutationGenerator<F: Field> {
|
struct PermutationGenerator<F: Field> {
|
||||||
chunk_size: usize,
|
|
||||||
a: Vec<Vec<Target>>,
|
a: Vec<Vec<Target>>,
|
||||||
b: Vec<Vec<Target>>,
|
b: Vec<Vec<Target>>,
|
||||||
a_switches: Vec<Target>,
|
a_switches: Vec<Target>,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user