Skip to content

Commit

Permalink
Fix Plonky3 proofs for removed machines (#2221)
Browse files Browse the repository at this point in the history
We removed them in the proof, but still ran second-stage witgen for it.
  • Loading branch information
georgwiese authored Dec 10, 2024
1 parent 670802a commit 11c3c70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
16 changes: 11 additions & 5 deletions backend/src/plonky3/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,17 @@ where
let mut witness_by_machine = self
.split
.iter()
.map(|(machine, (pil, _))| {
(
machine.clone(),
machine_witness_columns(witness, pil, machine),
)
.filter_map(|(machine, (pil, _))| {
let witness_columns = machine_witness_columns(witness, pil, machine);
if witness_columns[0].1.is_empty() {
// Empty machines can be removed entirely.
None
} else {
Some((
machine.clone(),
machine_witness_columns(witness, pil, machine),
))
}
})
.collect::<BTreeMap<_, _>>();

Expand Down
19 changes: 8 additions & 11 deletions plonky3/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ where
}
}

/// Prove a program execution.
/// Note that `witness_by_machine` might not have all the machines, empty ones are expected
/// to be removed already.
#[instrument(skip_all)]
#[allow(clippy::multiple_bound_locations)] // cfg not supported in where clauses?
pub fn prove<T: FieldElementMap>(
Expand All @@ -405,18 +408,12 @@ where
ProverData<T>: Send,
Commitment<T>: Send,
{
let (tables, stage_0): (BTreeMap<_, _>, BTreeMap<_, _>) = program
.split
let (tables, stage_0): (BTreeMap<_, _>, BTreeMap<_, _>) = witness_by_machine
.iter()
.filter_map(|(name, (_, constraint_system))| {
let columns = witness_by_machine.get(name).unwrap();
.map(|(name, columns)| {
let constraint_system = &program.split.get(name).unwrap().1;
let degree = columns[0].1.len();

if degree == 0 {
// If a machine has no rows, remove it entirely.
return None;
}

let table = Table {
air: PowdrTable::new(constraint_system),
degree,
Expand All @@ -433,7 +430,7 @@ where
);
}

Some((
(
(name.clone(), table),
(
name.clone(),
Expand All @@ -455,7 +452,7 @@ where
.collect(),
},
),
))
)
})
.unzip();

Expand Down

0 comments on commit 11c3c70

Please sign in to comment.