Skip to content

Commit

Permalink
feat: support for public inputs columns (#55)
Browse files Browse the repository at this point in the history
* feat: support public columns

* fix: unrequired powdr change, annotate hack with issue
  • Loading branch information
Maddiaa0 authored May 13, 2024
1 parent 9351738 commit 0cab75e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
8 changes: 5 additions & 3 deletions asm_to_pil/src/vm_to_constrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl<T: FieldElement> ASMPILConverter<T> {
ty,
},
);
self.pil.push(witness_column(start, name, None));
self.pil.push(witness_column(start, name, None, false));
}

fn handle_instruction_def(
Expand Down Expand Up @@ -846,7 +846,7 @@ impl<T: FieldElement> ASMPILConverter<T> {
),
)
});
witness_column(0, free_value, prover_query)
witness_column(0, free_value, prover_query, false)
})
.collect::<Vec<_>>();
self.pil.extend(free_value_pil);
Expand Down Expand Up @@ -877,7 +877,7 @@ impl<T: FieldElement> ASMPILConverter<T> {
/// Creates a pair of witness and fixed column and matches them in the lookup.
fn create_witness_fixed_pair(&mut self, start: usize, name: &str) {
let fixed_name = format!("p_{name}");
self.pil.push(witness_column(start, name, None));
self.pil.push(witness_column(start, name, None, false));
self.line_lookup
.push((name.to_string(), fixed_name.clone()));
self.rom_constant_names.push(fixed_name);
Expand Down Expand Up @@ -1082,6 +1082,7 @@ fn witness_column<S: Into<String>, T>(
start: usize,
name: S,
def: Option<FunctionDefinition<T>>,
is_public: bool
) -> PilStatement<T> {
PilStatement::PolynomialCommitDeclaration(
start,
Expand All @@ -1090,6 +1091,7 @@ fn witness_column<S: Into<String>, T>(
array_size: None,
}],
def,
is_public,
)
}

Expand Down
7 changes: 4 additions & 3 deletions ast/src/parsed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,13 @@ impl<T: Display> Display for PilStatement<T> {
PilStatement::PolynomialConstantDefinition(_, name, definition) => {
write!(f, "pol constant {name}{definition};")
}
PilStatement::PolynomialCommitDeclaration(_, names, value) => {
PilStatement::PolynomialCommitDeclaration(_, names, value, public) => {
write!(
f,
"pol commit {}{};",
"pol commit {}{}{};",
if *public { "public " } else { " " },
names.iter().format(", "),
value.as_ref().map(|v| format!("{v}")).unwrap_or_default()
value.as_ref().map(|v| format!("{v}")).unwrap_or_default(),
)
}
PilStatement::PolynomialIdentity(_, _attr, expression) => {
Expand Down
2 changes: 1 addition & 1 deletion ast/src/parsed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum PilStatement<T> {
),
PolynomialConstantDeclaration(usize, Vec<PolynomialName<T>>),
PolynomialConstantDefinition(usize, String, FunctionDefinition<T>),
PolynomialCommitDeclaration(usize, Vec<PolynomialName<T>>, Option<FunctionDefinition<T>>),
PolynomialCommitDeclaration(usize, Vec<PolynomialName<T>>, Option<FunctionDefinition<T>>, /*public=*/ bool),
PolynomialIdentity(usize, Option<String>, Expression<T>),
PlookupIdentity(
usize,
Expand Down
8 changes: 4 additions & 4 deletions ast/src/parsed/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
.try_for_each(|e| e.visit_expressions_mut(f, o)),

PilStatement::PolynomialConstantDefinition(_, _, fundef)
| PilStatement::PolynomialCommitDeclaration(_, _, Some(fundef)) => {
| PilStatement::PolynomialCommitDeclaration(_, _, Some(fundef), _) => {
fundef.visit_expressions_mut(f, o)
}
PilStatement::PolynomialCommitDeclaration(_, _, None)
PilStatement::PolynomialCommitDeclaration(_, _, None, _)
| PilStatement::Include(_, _)
| PilStatement::PolynomialConstantDeclaration(_, _)
| PilStatement::LetStatement(_, _, None) => ControlFlow::Continue(()),
Expand Down Expand Up @@ -260,10 +260,10 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
.try_for_each(|e| e.visit_expressions(f, o)),

PilStatement::PolynomialConstantDefinition(_, _, fundef)
| PilStatement::PolynomialCommitDeclaration(_, _, Some(fundef)) => {
| PilStatement::PolynomialCommitDeclaration(_, _, Some(fundef), _) => {
fundef.visit_expressions(f, o)
}
PilStatement::PolynomialCommitDeclaration(_, _, None)
PilStatement::PolynomialCommitDeclaration(_, _, None, _)
| PilStatement::Include(_, _)
| PilStatement::PolynomialConstantDeclaration(_, _)
| PilStatement::LetStatement(_, _, None) => ControlFlow::Continue(()),
Expand Down
6 changes: 4 additions & 2 deletions parser/src/powdr.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ PolynomialDefinition: PilStatement<T> = {
<@L> PolCol <Identifier> "=" <Expression> => PilStatement::PolynomialDefinition(<>)
}


PublicDeclaration: PilStatement<T> = {
<@L> "public" <Identifier> "="
<NamespacedPolynomialReference>
Expand Down Expand Up @@ -121,9 +122,10 @@ ArrayLiteralTerm: ArrayExpression<T> = {
}

PolynomialCommitDeclaration: PilStatement<T> = {
<@L> PolCol CommitWitness <PolynomialNameList> => PilStatement::PolynomialCommitDeclaration(<>, None),
<@L> PolCol CommitWitness <PolynomialNameList> => PilStatement::PolynomialCommitDeclaration(<>, None, false),
<@L> PolCol "public" <PolynomialNameList> => PilStatement::PolynomialCommitDeclaration(<>, None, true),
<start:@L> PolCol CommitWitness <name:PolynomialName> "(" <param:ParameterList> ")" "query" <value:Expression>
=> PilStatement::PolynomialCommitDeclaration(start, vec![name], Some(FunctionDefinition::Query(param, value)))
=> PilStatement::PolynomialCommitDeclaration(start, vec![name], Some(FunctionDefinition::Query(param, value)), false)
}

PolynomialIdentity: PilStatement<T> = {
Expand Down
13 changes: 9 additions & 4 deletions pil_analyzer/src/statement_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where
self.handle_public_declaration(start, name, polynomial, array_index, index)
}
PilStatement::PolynomialConstantDeclaration(start, polynomials) => {
self.handle_polynomial_declarations(start, polynomials, PolynomialType::Constant)
self.handle_polynomial_declarations(start, polynomials, PolynomialType::Constant, false)
}
PilStatement::PolynomialConstantDefinition(start, name, definition) => self
.handle_symbol_definition(
Expand All @@ -120,10 +120,10 @@ where
SymbolKind::Poly(PolynomialType::Constant),
Some(definition),
),
PilStatement::PolynomialCommitDeclaration(start, polynomials, None) => {
self.handle_polynomial_declarations(start, polynomials, PolynomialType::Committed)
PilStatement::PolynomialCommitDeclaration(start, polynomials, None, is_public) => {
self.handle_polynomial_declarations(start, polynomials, PolynomialType::Committed, is_public)
}
PilStatement::PolynomialCommitDeclaration(start, mut polynomials, Some(definition)) => {
PilStatement::PolynomialCommitDeclaration(start, mut polynomials, Some(definition), _) => {
assert!(polynomials.len() == 1);
let name = polynomials.pop().unwrap();
self.handle_symbol_definition(
Expand Down Expand Up @@ -267,10 +267,15 @@ where
start: usize,
polynomials: Vec<PolynomialName<T>>,
polynomial_type: PolynomialType,
is_public: bool,
) -> Vec<PILItem<T>> {
polynomials
.into_iter()
.flat_map(|PolynomialName { name, array_size }| {

// hack(https://github.com/AztecProtocol/aztec-packages/issues/6359): add an is_public modifier to the end of a committed polynomial
let name = if is_public { format!("{name}__is_public")} else {name};

self.handle_symbol_definition(
start,
name,
Expand Down

0 comments on commit 0cab75e

Please sign in to comment.