Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid redundant computation in Protogalaxy #1349

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
7b598ac
temp: brillig impl 1
Maddiaa0 Oct 4, 2023
5be0673
temp
Maddiaa0 Oct 10, 2023
e7c4a7d
rm starky param
Maddiaa0 Oct 10, 2023
8eca3e7
temp
Maddiaa0 Oct 12, 2023
188596e
codegen
Maddiaa0 Oct 13, 2023
fc3fc57
checkpoint
Maddiaa0 Oct 13, 2023
cf670c0
feat: prover and verifier generation (#2)
Maddiaa0 Oct 16, 2023
3c79e43
zero poly fixes
Maddiaa0 Oct 23, 2023
287b456
stable
Maddiaa0 Oct 23, 2023
6a396e4
shift fixes, with cycle hacks
Maddiaa0 Oct 24, 2023
804647f
small fixes for bberg trace builder so it works with bberg when targe…
dbanks12 Oct 25, 2023
a7a7c7f
little fix to get cargo building again (#4)
dbanks12 Oct 25, 2023
a937dc6
Merge branch 'main' into md/brillig
Maddiaa0 Nov 6, 2023
1701a27
fix: merge resolve
Maddiaa0 Nov 6, 2023
1dd45d1
fix: clippy (#5)
Maddiaa0 Nov 8, 2023
51f378a
fix: remove pil opt (#6)
Maddiaa0 Nov 8, 2023
ffbc314
fix: commit lockfile
Maddiaa0 Nov 9, 2023
9f50e77
fix: only use powdr, do not generate trace builder cpp (#7)
Maddiaa0 Nov 13, 2023
034ea93
feat: allow specifying name of output files in pil cli (#8)
Maddiaa0 Nov 13, 2023
5cd0c60
fix: remove artifacts (#10)
Maddiaa0 Nov 14, 2023
c7d2adf
feat: bberg pil only binary (#11)
Maddiaa0 Nov 14, 2023
98bc6f8
fix: remove brillig to powdr (#12)
Maddiaa0 Nov 14, 2023
4c33b2c
chore: refactor bb circuit builder / file writer (#13)
Maddiaa0 Nov 14, 2023
95e4676
chore: use traits to remove add files function (#14)
Maddiaa0 Nov 15, 2023
860b78d
chore: merge upstream (#15)
Maddiaa0 Nov 15, 2023
b0ebac8
fix
Maddiaa0 Nov 15, 2023
4635736
fix: remove FIRST and LAST requirement (#16)
Maddiaa0 Nov 15, 2023
9015bef
chore: sync bb master (#17)
Maddiaa0 Nov 21, 2023
3a9f7d5
fix: dynamic naming (#18)
Maddiaa0 Nov 21, 2023
19c18b9
Merge branch 'main' into avm
Maddiaa0 Nov 21, 2023
8b402ac
Merge branch 'avm' of github.com:Maddiaa0/powdr into avm
Maddiaa0 Nov 21, 2023
a7874e7
Merge pull request #19 from AztecProtocol/md/resync
Maddiaa0 Nov 21, 2023
e2b60c1
fix
Maddiaa0 Nov 21, 2023
553590b
Merge pull request #20 from AztecProtocol/md/merge-fix
Maddiaa0 Nov 21, 2023
a22c379
Rename circuit_builder.rs to vm_builder.rs
jeanmon Nov 23, 2023
30789f8
Rename trace_builder to circuit_builder
jeanmon Nov 23, 2023
7889b9b
Fix compilation errors and warnings
jeanmon Nov 23, 2023
b07215e
Replace build_circuit method by set_trace()
jeanmon Nov 23, 2023
e8ba49b
Merge pull request #21 from AztecProtocol/jm/new-interface
jeanmon Nov 23, 2023
1a10dba
feat: makes the code output more granular, rather than creating one m…
Maddiaa0 Nov 30, 2023
5dad742
refactor: cleanup codegen (#25)
Maddiaa0 Dec 5, 2023
694d05a
chore: back on master (#27)
Maddiaa0 Dec 5, 2023
b61f85d
Merge branch 'main' into avm
Maddiaa0 Dec 6, 2023
8acce8a
merge fix
Maddiaa0 Dec 6, 2023
0ec361e
Merge branch 'avm' into md/keepy-uppies
Maddiaa0 Dec 6, 2023
2c3a6dd
Merge pull request #28 from AztecProtocol/md/keepy-uppies
Maddiaa0 Dec 6, 2023
dbf2d4c
temp
Maddiaa0 Dec 7, 2023
0cf596d
fix: degree calculation for multiplication case (#29)
jeanmon Dec 7, 2023
3090265
fix: remove unused deps, cargo update (#31)
Maddiaa0 Dec 7, 2023
a7ec94c
feat: include attribute in permutation identities
Maddiaa0 Dec 7, 2023
6b5e4d9
temp: perms
Maddiaa0 Dec 7, 2023
9756ad4
working
Maddiaa0 Dec 8, 2023
543404a
chore: permutation builder refactor
Maddiaa0 Dec 11, 2023
c0bbea7
fix: account for instances with no permutations
Maddiaa0 Dec 11, 2023
92f59f2
fix: differentiate between perm and perm relation
Maddiaa0 Dec 11, 2023
9ea2a1c
fix: move relation builder
Maddiaa0 Dec 12, 2023
5e3bffa
chore: clippy / fmt
Maddiaa0 Dec 12, 2023
e3e8dfd
feat(debug): tag relations with debug information (#33)
Maddiaa0 Dec 13, 2023
7456c44
Merge pull request #32 from AztecProtocol/md/integrate-logup
jeanmon Dec 14, 2023
b8b1f57
chore(bb): sync (#34)
Maddiaa0 Dec 19, 2023
a8473d3
Support for large unsigned integer constants up to 256 bits
jeanmon Dec 20, 2023
a1733e2
Merge pull request #35 from AztecProtocol/jm/large_integer_support
jeanmon Dec 20, 2023
efef4a1
Enforce that a field value is on the rhs of a multiplication/addition…
jeanmon Jan 3, 2024
5ed8dc7
feat: support bberg lookups (#37)
Maddiaa0 Jan 9, 2024
ea8c518
chore: remove sumcheck declare macro (#38)
Maddiaa0 Jan 9, 2024
04fd1af
feat: update pg changes (#39)
Maddiaa0 Jan 12, 2024
636183e
chore: sync with bb namespace changes (#40)
Maddiaa0 Jan 19, 2024
b102f90
chore: update #4318 of namespace changes (#41)
Maddiaa0 Feb 7, 2024
2857cd2
chore: transcript change
Maddiaa0 Feb 9, 2024
0a3be00
Merge pull request #42 from AztecProtocol/md/update-transcript
jeanmon Feb 9, 2024
12d3a83
fix: Align lookup namespaces with simplification performed in Barrete…
jeanmon Feb 12, 2024
5eff680
Any generated file names use a snake case version of the prefix
jeanmon Feb 13, 2024
c9c61dc
Merge pull request #44 from AztecProtocol/jm/snake-case-file-names
jeanmon Feb 13, 2024
92656a8
Use snake case for the folder containing permutation and lookup
jeanmon Feb 13, 2024
89583f9
Merge pull request #45 from AztecProtocol/jm/lookup-equiv-snake-case-…
jeanmon Feb 13, 2024
ee8dca8
fix: lhs and rhs distinction in perms (#46)
Maddiaa0 Feb 14, 2024
9063b8a
fix: Port latest changes related to composer and flavor code (#47)
jeanmon Mar 5, 2024
a0d7f2d
Generated permutation and lookup filenames are lower-cased
jeanmon Mar 7, 2024
bbe149c
Throw an exception when lookup relation fails
jeanmon Mar 8, 2024
b92e670
Merge pull request #48 from AztecProtocol/jm/snake_case_perm_lookup_f…
jeanmon Mar 11, 2024
e5c2b6a
Zeromorph related changes backported into code-gen
jeanmon Mar 20, 2024
30c26b2
Merge pull request #49 from AztecProtocol/jm/port-zeromorph-changes
jeanmon Mar 20, 2024
7e580ba
Comment
jeanmon Mar 22, 2024
d88e16c
Merge pull request #50 from AztecProtocol/jm/chore-comment
jeanmon Mar 22, 2024
f448ae9
Backport of Aztec PR #5406
jeanmon Mar 25, 2024
5d7c145
Merge pull request #51 from AztecProtocol/jm/meld-flavor-builder
jeanmon Mar 25, 2024
2901274
feat: sort lists
Maddiaa0 Mar 26, 2024
e941cad
fmt
Maddiaa0 Mar 26, 2024
360c13d
Merge pull request #52 from AztecProtocol/md/remove-non-determinism
jeanmon Mar 27, 2024
22afee0
feat: support large literals in FF-limb decomp
IlyasRidhuan Apr 3, 2024
de7fb1f
Update relation_builder.rs
jeanmon Apr 4, 2024
10267b9
Merge pull request #53 from IlyasRidhuan/ir/ff_limbs_ul
jeanmon Apr 4, 2024
133cb68
feat: bb logup proving support (#54)
Maddiaa0 Apr 9, 2024
81f89e1
Port changes of ProvingKey_ for AVM
jeanmon Apr 25, 2024
fe16461
Merge pull request #57 from AztecProtocol/jm/proving-key-changes
IlyasRidhuan Apr 29, 2024
4b0d962
Port of PR #5844 from aztec-package
jeanmon May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,469 changes: 5,469 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ members = [
"asm_to_pil",
"halo2",
"backend",
"bberg",
"bberg_pil_cli",
"ast",
"analysis",
"linker",
Expand Down
18 changes: 13 additions & 5 deletions asm_to_pil/src/vm_to_constrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl<T: FieldElement> ASMPILConverter<T> {
),
PilStatement::PolynomialIdentity(
0,
None,
lhs - (Expression::from(T::one())
- next_reference("first_step"))
* direct_reference(pc_update_name),
Expand All @@ -154,10 +155,14 @@ impl<T: FieldElement> ASMPILConverter<T> {
ReadOnly => {
let not_reset: Expression<T> =
Expression::from(T::one()) - direct_reference("instr__reset");
vec![PilStatement::PolynomialIdentity(0, not_reset * (lhs - rhs))]
vec![PilStatement::PolynomialIdentity(
0,
None,
not_reset * (lhs - rhs),
)]
}
_ => {
vec![PilStatement::PolynomialIdentity(0, lhs - rhs)]
vec![PilStatement::PolynomialIdentity(0, None, lhs - rhs)]
}
}
})
Expand All @@ -175,6 +180,7 @@ impl<T: FieldElement> ASMPILConverter<T> {

self.pil.push(PilStatement::PlookupIdentity(
0,
None,
SelectedExpressions {
selector: None,
expressions: self
Expand Down Expand Up @@ -389,7 +395,7 @@ impl<T: FieldElement> ASMPILConverter<T> {
});

for mut statement in body {
if let PilStatement::PolynomialIdentity(_start, expr) = statement {
if let PilStatement::PolynomialIdentity(_start, _attr, expr) = statement {
match extract_update(expr) {
(Some(var), expr) => {
let reference = direct_reference(&instruction_flag);
Expand All @@ -406,13 +412,14 @@ impl<T: FieldElement> ASMPILConverter<T> {
}
(None, expr) => self.pil.push(PilStatement::PolynomialIdentity(
0,
None,
direct_reference(&instruction_flag) * expr.clone(),
)),
}
} else {
match &mut statement {
PilStatement::PermutationIdentity(_, left, _)
| PilStatement::PlookupIdentity(_, left, _) => {
PilStatement::PermutationIdentity(_, _attr, left, _)
| PilStatement::PlookupIdentity(_, _attr, left, _) => {
assert!(
left.selector.is_none(),
"LHS selector not supported, could and-combine with instruction flag later."
Expand Down Expand Up @@ -715,6 +722,7 @@ impl<T: FieldElement> ASMPILConverter<T> {
.sum();
self.pil.push(PilStatement::PolynomialIdentity(
0,
None,
direct_reference(register) - assign_constraint,
));
}
Expand Down
8 changes: 7 additions & 1 deletion ast/src/analyzed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ impl<T: Display> Display for Identity<Expression<T>> {
}
}
IdentityKind::Plookup => write!(f, "{} in {};", self.left, self.right),
IdentityKind::Permutation => write!(f, "{} is {};", self.left, self.right),
IdentityKind::Permutation => write!(
f,
"#[{}] {} is {};",
self.attribute.clone().unwrap_or_default(),
self.left,
self.right
),
IdentityKind::Connect => write!(f, "{} connect {};", self.left, self.right),
}
}
Expand Down
12 changes: 9 additions & 3 deletions ast/src/analyzed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ impl<T> Analyzed<T> {
self.identities.push(Identity {
id,
kind: IdentityKind::Polynomial,
attribute: None, // TODO(md): None for the meantime as we do not have tagged identities, will be updated in following pr
source,
left: SelectedExpressions {
selector: Some(identity),
Expand Down Expand Up @@ -504,11 +505,16 @@ pub struct Identity<Expr> {
/// The ID is specific to the identity kind.
pub id: u64,
pub kind: IdentityKind,
pub attribute: Option<String>,
pub source: SourceRef,
/// For a simple polynomial identity, the selector contains
/// the actual expression (see expression_for_poly_id).
pub left: SelectedExpressions<Expr>,
pub right: SelectedExpressions<Expr>,
//
//
// NTS(Md) Both left and right are only used in the case of perm / plookup
//
pub left: SelectedExpressions<Expr>, // left is selector expressions - for an arithmetic gate, the entire relation is in SL
pub right: SelectedExpressions<Expr>, // right is the overall expressions
}

impl<Expr> Identity<Expr> {
Expand All @@ -530,7 +536,7 @@ pub enum IdentityKind {
Polynomial,
Plookup,
Permutation,
Connect,
Connect, // not used
}

impl<T> SelectedExpressions<AlgebraicExpression<T>> {
Expand Down
11 changes: 8 additions & 3 deletions ast/src/parsed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,20 @@ impl<T: Display> Display for PilStatement<T> {
value.as_ref().map(|v| format!("{v}")).unwrap_or_default()
)
}
PilStatement::PolynomialIdentity(_, expression) => {
PilStatement::PolynomialIdentity(_, _attr, expression) => {
if let Expression::BinaryOperation(left, BinaryOperator::Sub, right) = expression {
write!(f, "{left} = {right};")
} else {
write!(f, "{expression} = 0;")
}
}
PilStatement::PlookupIdentity(_, left, right) => write!(f, "{left} in {right};"),
PilStatement::PermutationIdentity(_, left, right) => write!(f, "{left} is {right};"),
PilStatement::PlookupIdentity(_, _, left, right) => write!(f, "{left} in {right};"),
PilStatement::PermutationIdentity(
_, //
_, //
left,
right,
) => write!(f, "{left} is {right};"), //
PilStatement::ConnectIdentity(_, left, right) => write!(
f,
"{{ {} }} connect {{ {} }};",
Expand Down
9 changes: 8 additions & 1 deletion ast/src/parsed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ pub enum PilStatement<T> {
PolynomialConstantDeclaration(usize, Vec<PolynomialName<T>>),
PolynomialConstantDefinition(usize, String, FunctionDefinition<T>),
PolynomialCommitDeclaration(usize, Vec<PolynomialName<T>>, Option<FunctionDefinition<T>>),
PolynomialIdentity(usize, Expression<T>),
PolynomialIdentity(usize, Option<String>, Expression<T>),
PlookupIdentity(
usize,
Option<String>,
SelectedExpressions<Expression<T>>,
SelectedExpressions<Expression<T>>,
),
PermutationIdentity(
usize,
Option<String>,
SelectedExpressions<Expression<T>>,
SelectedExpressions<Expression<T>>,
),
Expand All @@ -50,6 +52,11 @@ pub enum PilStatement<T> {
Expression(usize, Expression<T>),
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub struct Attribute {
pub name: Option<String>,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub struct SelectedExpressions<Expr> {
pub selector: Option<Expr>,
Expand Down
22 changes: 16 additions & 6 deletions ast/src/parsed/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
{
match self {
PilStatement::Expression(_, e) => e.visit_expressions_mut(f, o),
PilStatement::PlookupIdentity(_, left, right)
| PilStatement::PermutationIdentity(_, left, right) => [left, right]
PilStatement::PlookupIdentity(_, _, left, right)
| PilStatement::PermutationIdentity(
_, //
_, //
left,
right,
) => [left, right] //
.into_iter()
.try_for_each(|e| e.visit_expressions_mut(f, o)),
PilStatement::ConnectIdentity(_start, left, right) => left
Expand All @@ -203,7 +208,7 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi

PilStatement::Namespace(_, _, e)
| PilStatement::PolynomialDefinition(_, _, e)
| PilStatement::PolynomialIdentity(_, e)
| PilStatement::PolynomialIdentity(_, _, e)
| PilStatement::PublicDeclaration(_, _, _, None, e)
| PilStatement::ConstantDefinition(_, _, e)
| PilStatement::LetStatement(_, _, Some(e)) => e.visit_expressions_mut(f, o),
Expand All @@ -229,8 +234,13 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
{
match self {
PilStatement::Expression(_, e) => e.visit_expressions(f, o),
PilStatement::PlookupIdentity(_, left, right)
| PilStatement::PermutationIdentity(_, left, right) => [left, right]
PilStatement::PlookupIdentity(_, _, left, right)
| PilStatement::PermutationIdentity(
_, //
_, //
left,
right,
) => [left, right] //
.into_iter()
.try_for_each(|e| e.visit_expressions(f, o)),
PilStatement::ConnectIdentity(_start, left, right) => left
Expand All @@ -240,7 +250,7 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi

PilStatement::Namespace(_, _, e)
| PilStatement::PolynomialDefinition(_, _, e)
| PilStatement::PolynomialIdentity(_, e)
| PilStatement::PolynomialIdentity(_, _, e)
| PilStatement::PublicDeclaration(_, _, _, None, e)
| PilStatement::ConstantDefinition(_, _, e)
| PilStatement::LetStatement(_, _, Some(e)) => e.visit_expressions(f, o),
Expand Down
4 changes: 4 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ edition = "2021"

[features]
halo2 = ["dep:halo2"]
# TODO: enable feature flag for bberg backend
# bberg = ["dep:bberg"]

[dependencies]
halo2 = { path = "../halo2", optional = true }
bberg = { path = "../bberg"}

pil_analyzer = { path = "../pil_analyzer" }
number = { path = "../number" }
ast = { path = "../ast" }
Expand Down
Empty file.
68 changes: 68 additions & 0 deletions backend/src/bberg_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::io::{self};

use crate::{BackendImpl, BackendImplWithSetup, Proof};
use ast::analyzed::Analyzed;

// We do not directly have a bberg prover at the moment
// however we can just perform codegen
use bberg::bberg_codegen::BBergCodegen;
use number::{DegreeType, FieldElement};

impl<T: FieldElement> BackendImpl<T> for BBergCodegen {
fn new(degree: DegreeType) -> Self {
BBergCodegen::assert_field_is_compatible::<T>();
BBergCodegen::new(degree)
}

fn prove(
&self,
pil: &Analyzed<T>,
fixed: &[(String, Vec<T>)],
witness: &[(String, Vec<T>)],
_prev_proof: Option<Proof>,
bname: Option<String>,
) -> (Option<Proof>, Option<String>) {
self.build_ast(pil, fixed, witness, bname);

// Note(md): In the current bberg impl we do not produce proofs here
// as we do cpp code generation, and then create proofs with bberg
// This may change in the future when the library matures to be more pluggable
(None, None)
}
}

impl<T: FieldElement> BackendImplWithSetup<T> for BBergCodegen {
fn new_from_setup(mut input: &mut dyn io::Read) -> Result<Self, io::Error> {
BBergCodegen::assert_field_is_compatible::<T>();
BBergCodegen::new_from_setup(&mut input)
}

// TODO: implement this
fn write_setup(&self, _output: &mut dyn io::Write) -> Result<(), io::Error> {
Ok(())
// self.write_setup(&mut output)
}
}

pub struct BBergMock;
impl<T: FieldElement> BackendImpl<T> for BBergMock {
fn new(_degree: DegreeType) -> Self {
Self
}

fn prove(
&self,
_pil: &Analyzed<T>,
_fixed: &[(String, Vec<T>)],
_witness: &[(String, Vec<T>)],
prev_proof: Option<Proof>,
_bname: Option<String>,
) -> (Option<Proof>, Option<String>) {
if prev_proof.is_some() {
unimplemented!("BBergMock backend does not support aggregation");
}

// TODO: mock prover
unimplemented!("BBergMock backend is not implemented");
}
}
4 changes: 3 additions & 1 deletion backend/src/halo2_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl<T: FieldElement> BackendImpl<T> for Halo2Prover {
fixed: &[(String, Vec<T>)],
witness: &[(String, Vec<T>)],
prev_proof: Option<Proof>,
_name: Option<String>,
) -> (Option<Proof>, Option<String>) {
let proof = match prev_proof {
Some(proof) => self.prove_aggr(pil, fixed, witness, proof),
Expand All @@ -27,7 +28,7 @@ impl<T: FieldElement> BackendImpl<T> for Halo2Prover {
}
}

impl<T: FieldElement> BackendImplWithSetup<T> for halo2::Halo2Prover {
impl<T: FieldElement> BackendImplWithSetup<T> for Halo2Prover {
fn new_from_setup(mut input: &mut dyn io::Read) -> Result<Self, io::Error> {
Halo2Prover::assert_field_is_compatible::<T>();
Halo2Prover::new_from_setup(&mut input)
Expand All @@ -50,6 +51,7 @@ impl<T: FieldElement> BackendImpl<T> for Halo2Mock {
fixed: &[(String, Vec<T>)],
witness: &[(String, Vec<T>)],
prev_proof: Option<Proof>,
_name: Option<String>,
) -> (Option<Proof>, Option<String>) {
if prev_proof.is_some() {
unimplemented!("Halo2Mock backend does not support aggregation");
Expand Down
Loading