From 1701a27d471fa996aa17f454383581cb1f1beb3b Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:56:42 +0000 Subject: [PATCH] fix: merge resolve --- ast/src/analyzed/mod.rs | 4 ++-- backend/src/bberg_impl.rs | 8 ++++---- backend/src/pilstark/estark.rs | 2 +- bberg/src/circuit_builder.rs | 33 ++++++++++++++++++--------------- bberg/src/main.rs | 6 ++---- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/ast/src/analyzed/mod.rs b/ast/src/analyzed/mod.rs index 38fd57e1e..bdff69887 100644 --- a/ast/src/analyzed/mod.rs +++ b/ast/src/analyzed/mod.rs @@ -386,8 +386,8 @@ pub struct Identity { // // NTS(Md) Both left and right are only used in the case of perm / plookup // - pub left: SelectedExpressions, // left is selector expressions - for an arithmetic gate, the entire relation is in SL - pub right: SelectedExpressions, // right is the overall expressions + pub left: SelectedExpressions, // left is selector expressions - for an arithmetic gate, the entire relation is in SL + pub right: SelectedExpressions, // right is the overall expressions } impl Identity { diff --git a/backend/src/bberg_impl.rs b/backend/src/bberg_impl.rs index 98e6129f1..8792fa585 100644 --- a/backend/src/bberg_impl.rs +++ b/backend/src/bberg_impl.rs @@ -37,7 +37,7 @@ impl BackendImplWithSetup for BBergCodegen { } // TODO: implement this - fn write_setup(&self, mut output: &mut dyn io::Write) -> Result<(), io::Error> { + fn write_setup(&self, _output: &mut dyn io::Write) -> Result<(), io::Error> { Ok(()) // self.write_setup(&mut output) } @@ -51,9 +51,9 @@ impl BackendImpl for BBergMock { fn prove( &self, - pil: &Analyzed, - fixed: &[(&str, Vec)], - witness: &[(&str, Vec)], + _pil: &Analyzed, + _fixed: &[(&str, Vec)], + _witness: &[(&str, Vec)], prev_proof: Option, ) -> (Option, Option) { if prev_proof.is_some() { diff --git a/backend/src/pilstark/estark.rs b/backend/src/pilstark/estark.rs index b7b7b558d..cb27e4847 100644 --- a/backend/src/pilstark/estark.rs +++ b/backend/src/pilstark/estark.rs @@ -113,7 +113,7 @@ impl BackendImpl for EStark { &setup.program, &pil, &self.params, - "", + // "", ) .unwrap(); diff --git a/bberg/src/circuit_builder.rs b/bberg/src/circuit_builder.rs index eaa88a3bf..0266bca6d 100644 --- a/bberg/src/circuit_builder.rs +++ b/bberg/src/circuit_builder.rs @@ -2,13 +2,16 @@ use std::collections::{HashMap, HashSet}; use std::fs::File; use std::{fmt::Display, io::Write, process::id}; -use ast::parsed::UnaryOperator; +use ast::parsed::{SelectedExpressions, UnaryOperator}; // use acvm::acir::native_types::Expression; use ast::{analyzed::Identity, asm_analysis::DegreeStatement, parsed::BinaryOperator}; use itertools::Itertools; use num_bigint::BigUint; -use ast::analyzed::{Analyzed, Expression, IdentityKind, Reference, SelectedExpressions}; +use ast::analyzed::{ + AlgebraicBinaryOperator, AlgebraicExpression as Expression, AlgebraicUnaryOperator, Analyzed, + IdentityKind, Reference, +}; use num_traits::{identities, One}; use number::{BigInt, DegreeType, FieldElement}; @@ -490,14 +493,14 @@ fn get_cols_in_identity_macro(all_rows_and_shifts: &Vec) -> String { ) } -fn create_identity( - expression: &SelectedExpressions, +fn create_identity( + expression: &SelectedExpressions>, collected_shifts: &mut HashSet, ) -> Option { // We want to read the types of operators and then create the appropiate code if let Some(expr) = &expression.selector { - let x = craft_expression(&expr, collected_shifts); + let x = craft_expression(expr, collected_shifts); println!("{:?}", x); Some(x) } else { @@ -518,7 +521,7 @@ fn create_subrelation(index: usize, preamble: String, identity: &mut BBIdentity) auto tmp = {id}; tmp *= scaling_factor; - tmp *= main_FIRST; // Temp to switch off + tmp *= (-main_FIRST+ FF(1)); // Temp to switch off std::get<{index}>(evals) += tmp; }}", ) @@ -530,7 +533,7 @@ fn craft_expression( ) -> BBIdentity { match expr { Expression::Number(n) => (1, format!("FF({})", n.to_arbitrary_integer())), - Expression::Reference(Reference::Poly(polyref)) => { + Expression::Reference(polyref) => { assert_eq!(polyref.index, None); let mut poly_name = format!("{}", &polyref.name.replace(".", "_")); let mut degree = 1; @@ -553,27 +556,27 @@ fn craft_expression( // dbg!(&lhe); let degree = std::cmp::max(ld, rd); match op { - BinaryOperator::Add => (degree, format!("({} + {})", lhs, rhs)), - BinaryOperator::Sub => match lhe.as_ref() { + AlgebraicBinaryOperator::Add => (degree, format!("({} + {})", lhs, rhs)), + AlgebraicBinaryOperator::Sub => match lhe.as_ref() { // BBerg hack, we do not want a field on the lhs of an expression Expression::Number(_) => (degree, format!("(-{} + {})", rhs, lhs)), _ => (degree, format!("({} - {})", lhs, rhs)), }, - BinaryOperator::Mul => (degree + 1, format!("({} * {})", lhs, rhs)), + AlgebraicBinaryOperator::Mul => (degree + 1, format!("({} * {})", lhs, rhs)), _ => unimplemented!("{:?}", expr), } } - Expression::Constant(name) => { - panic!("Constant {name} was not inlined. optimize_constants needs to be run at least.") - } + // Expression::Constant(name) => { + // panic!("Constant {name} was not inlined. optimize_constants needs to be run at least.") + // } // pub enum UnaryOperator { // Plus, // Minus, // LogicalNot, // } Expression::UnaryOperation(operator, expression) => match operator { - UnaryOperator::Minus => { + AlgebraicUnaryOperator::Minus => { let (d, e) = craft_expression(expression, collected_shifts); (d, format!("-{}", e)) } @@ -589,7 +592,7 @@ type BBIdentity = (DegreeType, String); /// Todo, eventually these will need to be siloed based on the file name they are in fn create_identities( - identities: &Vec>, + identities: &Vec>>, ) -> (Vec, Vec, HashSet) { // We only want the expressions for now // When we have a poly type, we only need the left side of it diff --git a/bberg/src/main.rs b/bberg/src/main.rs index 277902b22..55c49655c 100644 --- a/bberg/src/main.rs +++ b/bberg/src/main.rs @@ -12,9 +12,6 @@ use std::iter; use std::collections::HashMap; - - - /// Module to convert brillig assmebly into powdr assembly // struct BrilligArchitecture {} @@ -58,7 +55,8 @@ fn main() { let bytecode = Vec::from(decoded); // Create a new circuit from the bytecode instance - let circuit: Circuit = Circuit::read(&*bytecode).expect("Failed to deserialize circuit"); + let circuit: Circuit = + Circuit::deserialize_circuit(&*bytecode).expect("Failed to deserialize circuit"); println!("circuit: {:?}", circuit);