Skip to content

Commit

Permalink
Witness generation for block machines connected via permutations
Browse files Browse the repository at this point in the history
  • Loading branch information
georgwiese committed Feb 29, 2024
1 parent a353d3e commit f3e3a8c
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 74 deletions.
4 changes: 3 additions & 1 deletion ast/src/analyzed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ impl<T> Identity<AlgebraicExpression<T>> {
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize, JsonSchema)]
#[derive(
Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Serialize, Deserialize, JsonSchema,
)]
pub enum IdentityKind {
Polynomial,
Plookup,
Expand Down
10 changes: 10 additions & 0 deletions executor/src/witgen/block_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> BlockProcessor<'a, 'b, 'c
}
}

pub fn from_processor(
processor: Processor<'a, 'b, 'c, T, Q>,
identities: &'c [&'a Identity<Expression<T>>],
) -> Self {
Self {
processor,
identities,
}
}

pub fn with_outer_query(
self,
outer_query: OuterQuery<'a, T>,
Expand Down
12 changes: 9 additions & 3 deletions executor/src/witgen/identity_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use powdr_ast::{
};
use powdr_number::FieldElement;

use crate::witgen::machines::Machine;
use crate::witgen::{machines::Machine, EvalError};

use super::{
affine_expression::AffineExpression, machines::KnownMachine, rows::RowPair, EvalResult,
Expand Down Expand Up @@ -205,8 +205,14 @@ impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> IdentityProcessor<'a, 'b,
let selector_value = right
.selector
.as_ref()
.map(|s| current_rows.evaluate(s).unwrap().constant_value().unwrap())
.unwrap_or(T::one());
.map(|s| {
current_rows
.evaluate(s)
.ok()
.and_then(|affine_expression| affine_expression.constant_value())
.ok_or(EvalError::Generic("Selector is not 1!".to_string()))
})
.unwrap_or(Ok(T::one()))?;
assert_eq!(selector_value, T::one());

let mut updates = EvalValue::complete(vec![]);
Expand Down
Loading

0 comments on commit f3e3a8c

Please sign in to comment.