From 0ffcb313928274b22be96daba03d9ade65864b84 Mon Sep 17 00:00:00 2001 From: schaeff Date: Fri, 12 Mar 2021 12:23:03 +0100 Subject: [PATCH 01/95] wip --- test.zok | 3 + zokrates_core/src/flatten/mod.rs | 382 +++++++++++++++++++++---------- zokrates_field/src/lib.rs | 23 +- 3 files changed, 278 insertions(+), 130 deletions(-) create mode 100644 test.zok diff --git a/test.zok b/test.zok new file mode 100644 index 000000000..f89c6ddbf --- /dev/null +++ b/test.zok @@ -0,0 +1,3 @@ +def main(field x): + assert(x < 3) + return \ No newline at end of file diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index f3a746ffd..098bf9aa6 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -191,7 +191,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { // `sizeUnknown` accordingly: // `sizeUnknown = sizeUnknown && a[0]` // * b[1] = 1 - // `sizrUnknown = sizeUnknown && a[1]` + // `sizeUnknown = sizeUnknown && a[1]` // * b[2] = 1 // `sizeUnknown = sizeUnknown && a[2]` // * b[3] = 0 @@ -203,12 +203,16 @@ impl<'ast, T: Field> Flattener<'ast, T> { // sizeUnkown * // **false => a -> {0,1} // ``` + // + // # Returns + // + // * a vector of FlatExpression which all evaluate to 1 if a <= b and 0 otherwise fn strict_le_check( &mut self, statements_flattened: &mut FlatStatements, + a: &[FlatVariable], b: &[bool], - a: Vec, - ) { + ) -> Vec> { let len = b.len(); assert_eq!(a.len(), T::get_required_bits()); assert_eq!(a.len(), b.len()); @@ -227,6 +231,8 @@ impl<'ast, T: Field> Flattener<'ast, T> { FlatExpression::Number(T::from(1)), )); + let mut res = vec![]; + for (i, b) in b.iter().enumerate() { if *b { statements_flattened.push(FlatStatement::Definition( @@ -275,12 +281,25 @@ impl<'ast, T: Field> Flattener<'ast, T> { box and_name.into(), ); - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Number(T::from(1)), - or, - )); + res.push(or); } } + + res + } + + fn enforce_strict_le_check( + &mut self, + statements_flattened: &mut FlatStatements, + a: &[FlatVariable], + b: &[bool], + ) { + let statements: Vec<_> = self + .strict_le_check(statements_flattened, a, b) + .into_iter() + .map(|c| FlatStatement::Condition(FlatExpression::Number(T::from(1)), c)) + .collect(); + statements_flattened.extend(statements); } /// Flatten an if/else expression @@ -392,157 +411,268 @@ impl<'ast, T: Field> Flattener<'ast, T> { let rhs_flattened = self.flatten_field_expression(symbols, statements_flattened, rhs); - // lhs - let lhs_id = self.define(lhs_flattened, statements_flattened); + match (lhs_flattened, rhs_flattened) { + (lhs_flattened, FlatExpression::Number(constant)) => { + // decompose lhs to bits + let lhs_id = self.define(lhs_flattened, statements_flattened); - // check that lhs and rhs are within the right range, i.e., their higher two bits are zero. We use big-endian so they are at positions 0 and 1 + // define variables for the bits + let lhs_bits_be: Vec = + (0..bit_width).map(|_| self.use_sym()).collect(); - // lhs - { - // define variables for the bits - let lhs_bits_be: Vec = - (0..safe_width).map(|_| self.use_sym()).collect(); + // add a directive to get the bits + statements_flattened.push(FlatStatement::Directive(FlatDirective::new( + lhs_bits_be.clone(), + Solver::bits(bit_width), + vec![lhs_id], + ))); - // add a directive to get the bits - statements_flattened.push(FlatStatement::Directive(FlatDirective::new( - lhs_bits_be.clone(), - Solver::bits(safe_width), - vec![lhs_id], - ))); + // bitness checks + for i in 0..bit_width { + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(lhs_bits_be[i]), + FlatExpression::Mult( + box FlatExpression::Identifier(lhs_bits_be[i]), + box FlatExpression::Identifier(lhs_bits_be[i]), + ), + )); + } + + // bit decomposition check + let mut lhs_sum = FlatExpression::Number(T::from(0)); + + for i in 0..bit_width { + lhs_sum = FlatExpression::Add( + box lhs_sum, + box FlatExpression::Mult( + box FlatExpression::Identifier(lhs_bits_be[i]), + box FlatExpression::Number(T::from(2).pow(bit_width - i - 1)), + ), + ); + } - // bitness checks - for i in 0..safe_width { statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(lhs_bits_be[i]), - FlatExpression::Mult( - box FlatExpression::Identifier(lhs_bits_be[i]), - box FlatExpression::Identifier(lhs_bits_be[i]), - ), + FlatExpression::Identifier(lhs_id), + lhs_sum, )); - } - - // bit decomposition check - let mut lhs_sum = FlatExpression::Number(T::from(0)); - for i in 0..safe_width { - lhs_sum = FlatExpression::Add( - box lhs_sum, - box FlatExpression::Mult( - box FlatExpression::Identifier(lhs_bits_be[i]), - box FlatExpression::Number(T::from(2).pow(safe_width - i - 1)), - ), + // check that this decomposition does not overflow the field + self.enforce_strict_le_check( + statements_flattened, + &lhs_bits_be, + &T::max_value().bit_vector_be(), ); - } - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(lhs_id), - lhs_sum, - )); - } + let conditions = self.strict_le_check( + statements_flattened, + &lhs_bits_be, + &constant.bit_vector_be(), + ); - // rhs - let rhs_id = self.define(rhs_flattened, statements_flattened); + // define the condition as `conditions.len() - sum(conditions)` + let condition = FlatExpression::Sub( + box FlatExpression::Number(T::from(conditions.len())), + box conditions + .into_iter() + .fold(FlatExpression::Number(T::zero()), |acc, e| { + FlatExpression::Add(box acc, box e) + }), + ); - // rhs - { - // define variables for the bits - let rhs_bits_be: Vec = - (0..safe_width).map(|_| self.use_sym()).collect(); + // return `condition == 0` - // add a directive to get the bits - statements_flattened.push(FlatStatement::Directive(FlatDirective::new( - rhs_bits_be.clone(), - Solver::bits(safe_width), - vec![rhs_id], - ))); + // copy pasted the fieldeq flattening code + let name_y = self.use_sym(); + let name_m = self.use_sym(); - // bitness checks - for i in 0..safe_width { + statements_flattened.push(FlatStatement::Directive(FlatDirective::new( + vec![name_y, name_m], + Solver::ConditionEq, + vec![condition.clone()], + ))); statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(rhs_bits_be[i]), + FlatExpression::Identifier(name_y), FlatExpression::Mult( - box FlatExpression::Identifier(rhs_bits_be[i]), - box FlatExpression::Identifier(rhs_bits_be[i]), + box condition.clone(), + box FlatExpression::Identifier(name_m), ), )); + + let res = FlatExpression::Sub( + box FlatExpression::Number(T::one()), + box FlatExpression::Identifier(name_y), + ); + + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Number(T::zero()), + FlatExpression::Mult(box res.clone(), box condition), + )); + + res } + (lhs_flattened, rhs_flattened) => { + // lhs + let lhs_id = self.define(lhs_flattened, statements_flattened); + + // check that lhs and rhs are within the right range, i.e., their higher two bits are zero. We use big-endian so they are at positions 0 and 1 + + // lhs + { + // define variables for the bits + let lhs_bits_be: Vec = + (0..safe_width).map(|_| self.use_sym()).collect(); + + // add a directive to get the bits + statements_flattened.push(FlatStatement::Directive( + FlatDirective::new( + lhs_bits_be.clone(), + Solver::bits(safe_width), + vec![lhs_id], + ), + )); - // bit decomposition check - let mut rhs_sum = FlatExpression::Number(T::from(0)); + // bitness checks + for i in 0..safe_width { + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(lhs_bits_be[i]), + FlatExpression::Mult( + box FlatExpression::Identifier(lhs_bits_be[i]), + box FlatExpression::Identifier(lhs_bits_be[i]), + ), + )); + } - for i in 0..safe_width { - rhs_sum = FlatExpression::Add( - box rhs_sum, + // bit decomposition check + let mut lhs_sum = FlatExpression::Number(T::from(0)); + + for i in 0..safe_width { + lhs_sum = FlatExpression::Add( + box lhs_sum, + box FlatExpression::Mult( + box FlatExpression::Identifier(lhs_bits_be[i]), + box FlatExpression::Number( + T::from(2).pow(safe_width - i - 1), + ), + ), + ); + } + + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(lhs_id), + lhs_sum, + )); + } + + // rhs + let rhs_id = self.define(rhs_flattened, statements_flattened); + + // rhs + { + // define variables for the bits + let rhs_bits_be: Vec = + (0..safe_width).map(|_| self.use_sym()).collect(); + + // add a directive to get the bits + statements_flattened.push(FlatStatement::Directive( + FlatDirective::new( + rhs_bits_be.clone(), + Solver::bits(safe_width), + vec![rhs_id], + ), + )); + + // bitness checks + for i in 0..safe_width { + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(rhs_bits_be[i]), + FlatExpression::Mult( + box FlatExpression::Identifier(rhs_bits_be[i]), + box FlatExpression::Identifier(rhs_bits_be[i]), + ), + )); + } + + // bit decomposition check + let mut rhs_sum = FlatExpression::Number(T::from(0)); + + for i in 0..safe_width { + rhs_sum = FlatExpression::Add( + box rhs_sum, + box FlatExpression::Mult( + box FlatExpression::Identifier(rhs_bits_be[i]), + box FlatExpression::Number( + T::from(2).pow(safe_width - i - 1), + ), + ), + ); + } + + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(rhs_id), + rhs_sum, + )); + } + + // sym := (lhs * 2) - (rhs * 2) + let subtraction_result = FlatExpression::Sub( box FlatExpression::Mult( - box FlatExpression::Identifier(rhs_bits_be[i]), - box FlatExpression::Number(T::from(2).pow(safe_width - i - 1)), + box FlatExpression::Number(T::from(2)), + box FlatExpression::Identifier(lhs_id), + ), + box FlatExpression::Mult( + box FlatExpression::Number(T::from(2)), + box FlatExpression::Identifier(rhs_id), ), ); - } - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(rhs_id), - rhs_sum, - )); - } + // define variables for the bits + let sub_bits_be: Vec = + (0..bit_width).map(|_| self.use_sym()).collect(); - // sym := (lhs * 2) - (rhs * 2) - let subtraction_result = FlatExpression::Sub( - box FlatExpression::Mult( - box FlatExpression::Number(T::from(2)), - box FlatExpression::Identifier(lhs_id), - ), - box FlatExpression::Mult( - box FlatExpression::Number(T::from(2)), - box FlatExpression::Identifier(rhs_id), - ), - ); + // add a directive to get the bits + statements_flattened.push(FlatStatement::Directive(FlatDirective::new( + sub_bits_be.clone(), + Solver::bits(bit_width), + vec![subtraction_result.clone()], + ))); - // define variables for the bits - let sub_bits_be: Vec = - (0..bit_width).map(|_| self.use_sym()).collect(); + // bitness checks + for i in 0..bit_width { + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(sub_bits_be[i]), + FlatExpression::Mult( + box FlatExpression::Identifier(sub_bits_be[i]), + box FlatExpression::Identifier(sub_bits_be[i]), + ), + )); + } - // add a directive to get the bits - statements_flattened.push(FlatStatement::Directive(FlatDirective::new( - sub_bits_be.clone(), - Solver::bits(bit_width), - vec![subtraction_result.clone()], - ))); + // check that the decomposition is in the field with a strict `< p` checks + self.enforce_strict_le_check( + statements_flattened, + &sub_bits_be, + &T::max_value().bit_vector_be(), + ); - // bitness checks - for i in 0..bit_width { - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(sub_bits_be[i]), - FlatExpression::Mult( - box FlatExpression::Identifier(sub_bits_be[i]), - box FlatExpression::Identifier(sub_bits_be[i]), - ), - )); - } + // sum(sym_b{i} * 2**i) + let mut expr = FlatExpression::Number(T::from(0)); - // check that the decomposition is in the field with a strict `< p` checks - self.strict_le_check( - statements_flattened, - &T::max_value_bit_vector_be(), - sub_bits_be.clone(), - ); + for i in 0..bit_width { + expr = FlatExpression::Add( + box expr, + box FlatExpression::Mult( + box FlatExpression::Identifier(sub_bits_be[i]), + box FlatExpression::Number(T::from(2).pow(bit_width - i - 1)), + ), + ); + } - // sum(sym_b{i} * 2**i) - let mut expr = FlatExpression::Number(T::from(0)); + statements_flattened + .push(FlatStatement::Condition(subtraction_result, expr)); - for i in 0..bit_width { - expr = FlatExpression::Add( - box expr, - box FlatExpression::Mult( - box FlatExpression::Identifier(sub_bits_be[i]), - box FlatExpression::Number(T::from(2).pow(bit_width - i - 1)), - ), - ); + FlatExpression::Identifier(sub_bits_be[bit_width - 1]) + } } - - statements_flattened.push(FlatStatement::Condition(subtraction_result, expr)); - - FlatExpression::Identifier(sub_bits_be[bit_width - 1]) } BooleanExpression::BoolEq(box lhs, box rhs) => { // lhs and rhs are booleans, they flatten to 0 or 1 diff --git a/zokrates_field/src/lib.rs b/zokrates_field/src/lib.rs index ae0bdaf6f..d8024a486 100644 --- a/zokrates_field/src/lib.rs +++ b/zokrates_field/src/lib.rs @@ -106,7 +106,8 @@ pub trait Field: /// Gets the number of bits fn bits(&self) -> u32; /// Returns this `Field`'s largest value as a big-endian bit vector - fn max_value_bit_vector_be() -> Vec { + /// Always returns `Self::get_required_bits()` elements + fn bit_vector_be(&self) -> Vec { fn bytes_to_bits(bytes: &[u8]) -> Vec { bytes .iter() @@ -114,13 +115,27 @@ pub trait Field: .collect() } - let field_bytes_le = Self::into_byte_vector(&Self::max_value()); + let field_bytes_le = Self::into_byte_vector(&self); // reverse for big-endianess let field_bytes_be = field_bytes_le.into_iter().rev().collect::>(); let field_bits_be = bytes_to_bits(&field_bytes_be); - let field_bits_be = &field_bits_be[field_bits_be.len() - Self::get_required_bits()..]; - field_bits_be.to_vec() + let field_bits_be: Vec<_> = (0..Self::get_required_bits() + .checked_sub(field_bits_be.len()) + .unwrap_or(0)) + .map(|_| &false) + .chain( + &field_bits_be[field_bits_be + .len() + .checked_sub(Self::get_required_bits()) + .unwrap_or(0)..], + ) + .cloned() + .collect(); + + assert_eq!(field_bits_be.len(), Self::get_required_bits()); + + field_bits_be } /// Returns the value as a BigUint fn to_biguint(&self) -> BigUint; From 0a963dd15283f9f18f52461b3de8bc2e4bc2bad7 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 16 Mar 2021 12:24:32 +0100 Subject: [PATCH 02/95] extract eq check code, implement c < x checks, update tests to use dynamic comparison --- test.zok | 3 - .../runtime_errors/lt_overflow_max_plus_1.zok | 2 +- .../lt_overflow_p_minus_one.zok | 2 +- zokrates_core/src/flat_absy/mod.rs | 6 + zokrates_core/src/flatten/mod.rs | 304 +++++++++--------- zokrates_core_test/tests/tests/range.json | 76 +++++ zokrates_core_test/tests/tests/range.zok | 2 + zokrates_field/src/bn128.rs | 2 +- 8 files changed, 232 insertions(+), 165 deletions(-) delete mode 100644 test.zok create mode 100644 zokrates_core_test/tests/tests/range.json create mode 100644 zokrates_core_test/tests/tests/range.zok diff --git a/test.zok b/test.zok deleted file mode 100644 index f89c6ddbf..000000000 --- a/test.zok +++ /dev/null @@ -1,3 +0,0 @@ -def main(field x): - assert(x < 3) - return \ No newline at end of file diff --git a/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok b/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok index 83b8f3376..d4affb1c1 100644 --- a/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok +++ b/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok @@ -9,4 +9,4 @@ def main(field a) -> bool: // maxvalue = 2**252 - 1 field maxvalue = a + 7237005577332262213973186563042994240829374041602535252466099000494570602496 - 1 // we added a = 0 to prevent the condition to be evaluated at compile time - return 0 < (maxvalue + 1) \ No newline at end of file + return a < (maxvalue + 1) \ No newline at end of file diff --git a/zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.zok b/zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.zok index fd7aca409..e0b5d7751 100644 --- a/zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.zok +++ b/zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.zok @@ -4,4 +4,4 @@ def main(field a) -> bool: field p = 21888242871839275222246405745257275088548364400416034343698204186575808495616 + a // we added a = 0 to prevent the condition to be evaluated at compile time - return 0 < p \ No newline at end of file + return a < p \ No newline at end of file diff --git a/zokrates_core/src/flat_absy/mod.rs b/zokrates_core/src/flat_absy/mod.rs index b96c0c228..2bf5d8951 100644 --- a/zokrates_core/src/flat_absy/mod.rs +++ b/zokrates_core/src/flat_absy/mod.rs @@ -218,6 +218,12 @@ pub enum FlatExpression { Mult(Box>, Box>), } +impl From for FlatExpression { + fn from(other: T) -> Self { + Self::Number(other) + } +} + impl FlatExpression { pub fn apply_substitution( self, diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 098bf9aa6..7b7426aaf 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -288,6 +288,47 @@ impl<'ast, T: Field> Flattener<'ast, T> { res } + fn eq_check( + &mut self, + statements_flattened: &mut Vec>, + left: FlatExpression, + right: FlatExpression, + ) -> FlatExpression { + // Wanted: (Y = (X != 0) ? 1 : 0) + // X = a - b + // # Y = if X == 0 then 0 else 1 fi + // # M = if X == 0 then 1 else 1/X fi + // Y == X * M + // 0 == (1-Y) * X + + let x = FlatExpression::Sub(box left, box right); + + let name_y = self.use_sym(); + let name_m = self.use_sym(); + + statements_flattened.push(FlatStatement::Directive(FlatDirective::new( + vec![name_y, name_m], + Solver::ConditionEq, + vec![x.clone()], + ))); + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(name_y), + FlatExpression::Mult(box x.clone(), box FlatExpression::Identifier(name_m)), + )); + + let res = FlatExpression::Sub( + box FlatExpression::Number(T::one()), + box FlatExpression::Identifier(name_y), + ); + + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Number(T::zero()), + FlatExpression::Mult(box res.clone(), box x), + )); + + res + } + fn enforce_strict_le_check( &mut self, statements_flattened: &mut FlatStatements, @@ -375,6 +416,96 @@ impl<'ast, T: Field> Flattener<'ast, T> { } } + /// Compute a range check against a constant + /// + /// # Arguments + /// + /// * `statements_flattened` - Vector where new flattened statements can be added. + /// * `e` - the `FlatExpression` that's being checked against the range. + /// * `c` - the constant upper bound of the range + /// + /// # Returns + /// * a `FlatExpression` which evaluates to `1` if `0 <= e < c`, and to `0` otherwise + fn constant_range_check( + &mut self, + statements_flattened: &mut FlatStatements, + e: FlatExpression, + c: T, + ) -> FlatExpression { + // we make use of constant `<=` checks in this function, therefore we rely on the fact that: + // `a < c <=> (a <= c - 1 if c !=0, false if c == 0)` + + if c == T::zero() { + // this is the case c == 0, we return 0, aka false + return T::zero().into(); + } + + let c = c - T::one(); + + let bit_width = T::get_required_bits(); + // decompose e to bits + let e_id = self.define(e, statements_flattened); + + // define variables for the bits + let e_bits_be: Vec = (0..bit_width).map(|_| self.use_sym()).collect(); + + // add a directive to get the bits + statements_flattened.push(FlatStatement::Directive(FlatDirective::new( + e_bits_be.clone(), + Solver::bits(bit_width), + vec![e_id], + ))); + + // bitness checks + for i in 0..bit_width { + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(e_bits_be[i]), + FlatExpression::Mult( + box FlatExpression::Identifier(e_bits_be[i]), + box FlatExpression::Identifier(e_bits_be[i]), + ), + )); + } + + // bit decomposition check + let mut e_sum = FlatExpression::Number(T::from(0)); + + for i in 0..bit_width { + e_sum = FlatExpression::Add( + box e_sum, + box FlatExpression::Mult( + box FlatExpression::Identifier(e_bits_be[i]), + box FlatExpression::Number(T::from(2).pow(bit_width - i - 1)), + ), + ); + } + + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Identifier(e_id), + e_sum, + )); + + // check that this decomposition does not overflow the field + self.enforce_strict_le_check( + statements_flattened, + &e_bits_be, + &T::max_value().bit_vector_be(), + ); + + let conditions = self.strict_le_check(statements_flattened, &e_bits_be, &c.bit_vector_be()); + + // return `len(conditions) == sum(conditions)` + self.eq_check( + statements_flattened, + T::from(conditions.len()).into(), + conditions + .into_iter() + .fold(FlatExpression::Number(T::zero()), |acc, e| { + FlatExpression::Add(box acc, box e) + }), + ) + } + /// Flattens a boolean expression /// /// # Arguments @@ -401,7 +532,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { BooleanExpression::Lt(box lhs, box rhs) => { // Get the bit width to know the size of the binary decompositions for this Field let bit_width = T::get_required_bits(); - let safe_width = bit_width - 2; // making sure we don't overflow, assert here? // We know from semantic checking that lhs and rhs have the same type // What the expression will flatten to depends on that type @@ -412,105 +542,18 @@ impl<'ast, T: Field> Flattener<'ast, T> { self.flatten_field_expression(symbols, statements_flattened, rhs); match (lhs_flattened, rhs_flattened) { - (lhs_flattened, FlatExpression::Number(constant)) => { - // decompose lhs to bits - let lhs_id = self.define(lhs_flattened, statements_flattened); - - // define variables for the bits - let lhs_bits_be: Vec = - (0..bit_width).map(|_| self.use_sym()).collect(); - - // add a directive to get the bits - statements_flattened.push(FlatStatement::Directive(FlatDirective::new( - lhs_bits_be.clone(), - Solver::bits(bit_width), - vec![lhs_id], - ))); - - // bitness checks - for i in 0..bit_width { - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(lhs_bits_be[i]), - FlatExpression::Mult( - box FlatExpression::Identifier(lhs_bits_be[i]), - box FlatExpression::Identifier(lhs_bits_be[i]), - ), - )); - } - - // bit decomposition check - let mut lhs_sum = FlatExpression::Number(T::from(0)); - - for i in 0..bit_width { - lhs_sum = FlatExpression::Add( - box lhs_sum, - box FlatExpression::Mult( - box FlatExpression::Identifier(lhs_bits_be[i]), - box FlatExpression::Number(T::from(2).pow(bit_width - i - 1)), - ), - ); - } - - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(lhs_id), - lhs_sum, - )); - - // check that this decomposition does not overflow the field - self.enforce_strict_le_check( - statements_flattened, - &lhs_bits_be, - &T::max_value().bit_vector_be(), - ); - - let conditions = self.strict_le_check( - statements_flattened, - &lhs_bits_be, - &constant.bit_vector_be(), - ); - - // define the condition as `conditions.len() - sum(conditions)` - let condition = FlatExpression::Sub( - box FlatExpression::Number(T::from(conditions.len())), - box conditions - .into_iter() - .fold(FlatExpression::Number(T::zero()), |acc, e| { - FlatExpression::Add(box acc, box e) - }), - ); - - // return `condition == 0` - - // copy pasted the fieldeq flattening code - let name_y = self.use_sym(); - let name_m = self.use_sym(); - - statements_flattened.push(FlatStatement::Directive(FlatDirective::new( - vec![name_y, name_m], - Solver::ConditionEq, - vec![condition.clone()], - ))); - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(name_y), - FlatExpression::Mult( - box condition.clone(), - box FlatExpression::Identifier(name_m), - ), - )); - - let res = FlatExpression::Sub( - box FlatExpression::Number(T::one()), - box FlatExpression::Identifier(name_y), - ); - - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Number(T::zero()), - FlatExpression::Mult(box res.clone(), box condition), - )); - - res + (x, FlatExpression::Number(constant)) => { + self.constant_range_check(statements_flattened, x, constant) } + // (c < x <= p - 1) <=> (0 <= p - 1 - x < p - 1 - c) + (FlatExpression::Number(constant), x) => self.constant_range_check( + statements_flattened, + FlatExpression::Sub(box T::max_value().into(), box x), + T::max_value() - constant, + ), (lhs_flattened, rhs_flattened) => { + let safe_width = bit_width - 2; // dynamic comparison is not complete, it only applies to words of width `bit_width - 2` + // lhs let lhs_id = self.define(lhs_flattened, statements_flattened); @@ -707,43 +750,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { ) } BooleanExpression::FieldEq(box lhs, box rhs) => { - // Wanted: (Y = (X != 0) ? 1 : 0) - // X = a - b - // # Y = if X == 0 then 0 else 1 fi - // # M = if X == 0 then 1 else 1/X fi - // Y == X * M - // 0 == (1-Y) * X - - let name_y = self.use_sym(); - let name_m = self.use_sym(); - - let x = self.flatten_field_expression( - symbols, - statements_flattened, - FieldElementExpression::Sub(box lhs, box rhs), - ); + let lhs = self.flatten_field_expression(symbols, statements_flattened, lhs); - statements_flattened.push(FlatStatement::Directive(FlatDirective::new( - vec![name_y, name_m], - Solver::ConditionEq, - vec![x.clone()], - ))); - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(name_y), - FlatExpression::Mult(box x.clone(), box FlatExpression::Identifier(name_m)), - )); + let rhs = self.flatten_field_expression(symbols, statements_flattened, rhs); - let res = FlatExpression::Sub( - box FlatExpression::Number(T::one()), - box FlatExpression::Identifier(name_y), - ); - - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Number(T::zero()), - FlatExpression::Mult(box res.clone(), box x), - )); - - res + self.eq_check(statements_flattened, lhs, rhs) } BooleanExpression::UintEq(box lhs, box rhs) => { // We reduce each side into range and apply the same approach as for field elements @@ -755,9 +766,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { // Y == X * M // 0 == (1-Y) * X - let name_y = self.use_sym(); - let name_m = self.use_sym(); - assert!(lhs.metadata.clone().unwrap().should_reduce.to_bool()); assert!(rhs.metadata.clone().unwrap().should_reduce.to_bool()); @@ -768,29 +776,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { .flatten_uint_expression(symbols, statements_flattened, rhs) .get_field_unchecked(); - let x = FlatExpression::Sub(box lhs, box rhs); - - statements_flattened.push(FlatStatement::Directive(FlatDirective::new( - vec![name_y, name_m], - Solver::ConditionEq, - vec![x.clone()], - ))); - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(name_y), - FlatExpression::Mult(box x.clone(), box FlatExpression::Identifier(name_m)), - )); - - let res = FlatExpression::Sub( - box FlatExpression::Number(T::one()), - box FlatExpression::Identifier(name_y), - ); - - statements_flattened.push(FlatStatement::Condition( - FlatExpression::Number(T::zero()), - FlatExpression::Mult(box res.clone(), box x), - )); - - res + self.eq_check(statements_flattened, lhs, rhs) } BooleanExpression::Le(box lhs, box rhs) => { let lt = self.flatten_boolean_expression( diff --git a/zokrates_core_test/tests/tests/range.json b/zokrates_core_test/tests/tests/range.json new file mode 100644 index 000000000..85a717307 --- /dev/null +++ b/zokrates_core_test/tests/tests/range.json @@ -0,0 +1,76 @@ +{ + "entry_point": "./tests/tests/range.zok", + "curves": ["Bn128"], + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Ok": { + "values": ["0", "1", "1", "1", "0"] + } + } + }, + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["0", "0", "1", "1", "1"] + } + } + }, + { + "input": { + "values": ["2"] + }, + "output": { + "Ok": { + "values": ["0", "0", "1", "1", "0"] + } + } + }, + { + "input": { + "values": ["254"] + }, + "output": { + "Ok": { + "values": ["0", "0", "1", "1", "0"] + } + } + }, + { + "input": { + "values": ["255"] + }, + "output": { + "Ok": { + "values": ["0", "0", "0", "1", "0"] + } + } + }, + { + "input": { + "values": ["21888242871839275222246405745257275088548364400416034343698204186575808495615"] + }, + "output": { + "Ok": { + "values": ["0", "0", "0", "1", "0"] + } + } + }, + { + "input": { + "values": ["21888242871839275222246405745257275088548364400416034343698204186575808495616"] + }, + "output": { + "Ok": { + "values": ["0", "0", "0", "0", "0"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/range.zok b/zokrates_core_test/tests/tests/range.zok new file mode 100644 index 000000000..667dc5c41 --- /dev/null +++ b/zokrates_core_test/tests/tests/range.zok @@ -0,0 +1,2 @@ +def main(field x) -> bool[5]: + return [x < 0, x < 1, x < 255, x < 0 - 1, x - 2 > 0 - 2] \ No newline at end of file diff --git a/zokrates_field/src/bn128.rs b/zokrates_field/src/bn128.rs index cecca7365..8a566b3ba 100644 --- a/zokrates_field/src/bn128.rs +++ b/zokrates_field/src/bn128.rs @@ -30,7 +30,7 @@ mod tests { #[test] fn max_value_bits() { - let bits = FieldPrime::max_value_bit_vector_be(); + let bits = FieldPrime::max_value().bit_vector_be(); assert_eq!( bits[0..10].to_vec(), vec![true, true, false, false, false, false, false, true, true, false] From 9f2d7afa80e6cb64f0f6a0a42d6e3ca60d6c8453 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 30 Mar 2021 19:06:57 +0200 Subject: [PATCH 03/95] update doc and changelog --- changelogs/unreleased/761-schaeff | 1 + zokrates_book/src/language/operators.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/761-schaeff diff --git a/changelogs/unreleased/761-schaeff b/changelogs/unreleased/761-schaeff new file mode 100644 index 000000000..f51dfda32 --- /dev/null +++ b/changelogs/unreleased/761-schaeff @@ -0,0 +1 @@ +Introduce constant range checks for checks of the form `x < c` where `p` is a compile-time constant, also for other comparison operators. This works for any `x` and `p`, unlike dynamic `x < y` comparison \ No newline at end of file diff --git a/zokrates_book/src/language/operators.md b/zokrates_book/src/language/operators.md index baf325887..0c84edd54 100644 --- a/zokrates_book/src/language/operators.md +++ b/zokrates_book/src/language/operators.md @@ -22,4 +22,4 @@ The following table lists the precedence and associativity of all available oper [^2]: The right operand must be a compile time constant -[^3]: Both operands are asserted to be strictly lower than the biggest power of 2 lower than `p/2` \ No newline at end of file +[^3]: Both operands are asserted to be strictly lower than the biggest power of 2 lower than `p/2`, unless one of them can be determined to be a compile-time constant \ No newline at end of file From f8dc4d7649650ce55be366b6315d0a986a59db3b Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 30 Mar 2021 17:15:48 +0200 Subject: [PATCH 04/95] introduce constant definitions --- .../examples/functions/no_args_multiple.zok | 14 +- zokrates_core/src/absy/from_ast.rs | 52 ++- zokrates_core/src/absy/mod.rs | 57 +++- zokrates_core/src/absy/node.rs | 1 + zokrates_core/src/semantics.rs | 310 +++++++++++------- zokrates_core/src/static_analysis/inline.rs | 52 +++ .../src/static_analysis/propagate_unroll.rs | 2 + zokrates_core/src/typed_absy/abi.rs | 8 +- zokrates_core/src/typed_absy/mod.rs | 28 +- zokrates_parser/src/zokrates.pest | 5 +- zokrates_pest_ast/src/lib.rs | 29 +- 11 files changed, 406 insertions(+), 152 deletions(-) diff --git a/zokrates_cli/examples/functions/no_args_multiple.zok b/zokrates_cli/examples/functions/no_args_multiple.zok index cef72d30e..c70ad021e 100644 --- a/zokrates_cli/examples/functions/no_args_multiple.zok +++ b/zokrates_cli/examples/functions/no_args_multiple.zok @@ -1,10 +1,10 @@ -def const() -> field: +def constant() -> field: return 123123 -def add(field a,field b) -> field: - a=const() - return a+b +def add(field a, field b) -> field: + a = constant() + return a + b -def main(field a,field b) -> field: - field c = add(a, b+const()) - return const() +def main(field a, field b) -> field: + field c = add(a, b + constant()) + return constant() diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 5fbed6643..d1aeffd5b 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -1,6 +1,7 @@ use crate::absy; use crate::imports; +use crate::absy::SymbolDefinition; use num::ToPrimitive; use num_bigint::BigUint; use zokrates_pest_ast as pest; @@ -11,6 +12,11 @@ impl<'ast> From> for absy::Module<'ast> { prog.structs .into_iter() .map(|t| absy::SymbolDeclarationNode::from(t)) + .chain( + prog.constants + .into_iter() + .map(|f| absy::SymbolDeclarationNode::from(f)), + ) .chain( prog.functions .into_iter() @@ -65,7 +71,7 @@ impl<'ast> From> for absy::SymbolDeclarationNode<'a absy::SymbolDeclaration { id, - symbol: absy::Symbol::HereType(ty), + symbol: absy::Symbol::Here(SymbolDefinition::Struct(ty)), } .span(span) } @@ -85,6 +91,28 @@ impl<'ast> From> for absy::StructDefinitionFieldNode<'as } } +impl<'ast> From> for absy::SymbolDeclarationNode<'ast> { + fn from(definition: pest::ConstantDefinition<'ast>) -> absy::SymbolDeclarationNode<'ast> { + use crate::absy::NodeValue; + + let span = definition.span; + let id = definition.id.span.as_str(); + + let ty = absy::ConstantDefinition { + id, + ty: definition.ty.into(), + expression: definition.expression.into(), + } + .span(span.clone()); + + absy::SymbolDeclaration { + id, + symbol: absy::Symbol::Here(SymbolDefinition::Constant(ty)), + } + .span(span) + } +} + impl<'ast> From> for absy::SymbolDeclarationNode<'ast> { fn from(function: pest::Function<'ast>) -> absy::SymbolDeclarationNode<'ast> { use crate::absy::NodeValue; @@ -128,7 +156,7 @@ impl<'ast> From> for absy::SymbolDeclarationNode<'ast> { absy::SymbolDeclaration { id, - symbol: absy::Symbol::HereFunction(function), + symbol: absy::Symbol::Here(SymbolDefinition::Function(function)), } .span(span) } @@ -683,7 +711,7 @@ mod tests { let expected: absy::Module = absy::Module { symbols: vec![absy::SymbolDeclaration { id: &source[4..8], - symbol: absy::Symbol::HereFunction( + symbol: absy::Symbol::Here(SymbolDefinition::Function( absy::Function { arguments: vec![], statements: vec![absy::Statement::Return( @@ -701,7 +729,7 @@ mod tests { .outputs(vec![UnresolvedType::FieldElement.mock()]), } .into(), - ), + )), } .into()], imports: vec![], @@ -716,7 +744,7 @@ mod tests { let expected: absy::Module = absy::Module { symbols: vec![absy::SymbolDeclaration { id: &source[4..8], - symbol: absy::Symbol::HereFunction( + symbol: absy::Symbol::Here(SymbolDefinition::Function( absy::Function { arguments: vec![], statements: vec![absy::Statement::Return( @@ -731,7 +759,7 @@ mod tests { .outputs(vec![UnresolvedType::Boolean.mock()]), } .into(), - ), + )), } .into()], imports: vec![], @@ -747,7 +775,7 @@ mod tests { let expected: absy::Module = absy::Module { symbols: vec![absy::SymbolDeclaration { id: &source[4..8], - symbol: absy::Symbol::HereFunction( + symbol: absy::Symbol::Here(SymbolDefinition::Function( absy::Function { arguments: vec![ absy::Parameter::private( @@ -785,7 +813,7 @@ mod tests { .outputs(vec![UnresolvedType::FieldElement.mock()]), } .into(), - ), + )), } .into()], imports: vec![], @@ -802,7 +830,7 @@ mod tests { absy::Module { symbols: vec![absy::SymbolDeclaration { id: "main", - symbol: absy::Symbol::HereFunction( + symbol: absy::Symbol::Here(SymbolDefinition::Function( absy::Function { arguments: vec![absy::Parameter::private( absy::Variable::new("a", ty.clone().mock()).into(), @@ -818,7 +846,7 @@ mod tests { signature: UnresolvedSignature::new().inputs(vec![ty.mock()]), } .into(), - ), + )), } .into()], imports: vec![], @@ -866,7 +894,7 @@ mod tests { absy::Module { symbols: vec![absy::SymbolDeclaration { id: "main", - symbol: absy::Symbol::HereFunction( + symbol: absy::Symbol::Here(SymbolDefinition::Function( absy::Function { arguments: vec![], statements: vec![absy::Statement::Return( @@ -879,7 +907,7 @@ mod tests { signature: UnresolvedSignature::new(), } .into(), - ), + )), } .into()], imports: vec![], diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index a497c3746..7be899c52 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -49,10 +49,26 @@ pub struct SymbolDeclaration<'ast> { pub symbol: Symbol<'ast>, } +#[derive(PartialEq, Clone)] +pub enum SymbolDefinition<'ast> { + Struct(StructDefinitionNode<'ast>), + Constant(ConstantDefinitionNode<'ast>), + Function(FunctionNode<'ast>), +} + +impl<'ast> fmt::Debug for SymbolDefinition<'ast> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + SymbolDefinition::Struct(s) => write!(f, "Struct({:?})", s), + SymbolDefinition::Constant(c) => write!(f, "Constant({:?})", c), + SymbolDefinition::Function(func) => write!(f, "Function({:?})", func), + } + } +} + #[derive(PartialEq, Clone)] pub enum Symbol<'ast> { - HereType(StructDefinitionNode<'ast>), - HereFunction(FunctionNode<'ast>), + Here(SymbolDefinition<'ast>), There(SymbolImportNode<'ast>), Flat(FlatEmbed), } @@ -60,9 +76,8 @@ pub enum Symbol<'ast> { impl<'ast> fmt::Debug for Symbol<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Symbol::HereType(t) => write!(f, "HereType({:?})", t), - Symbol::HereFunction(fun) => write!(f, "HereFunction({:?})", fun), - Symbol::There(t) => write!(f, "There({:?})", t), + Symbol::Here(k) => write!(f, "Here({:?})", k), + Symbol::There(i) => write!(f, "There({:?})", i), Symbol::Flat(flat) => write!(f, "Flat({:?})", flat), } } @@ -71,8 +86,11 @@ impl<'ast> fmt::Debug for Symbol<'ast> { impl<'ast> fmt::Display for SymbolDeclaration<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.symbol { - Symbol::HereType(ref t) => write!(f, "struct {} {}", self.id, t), - Symbol::HereFunction(ref fun) => write!(f, "def {}{}", self.id, fun), + Symbol::Here(ref kind) => match kind { + SymbolDefinition::Struct(t) => write!(f, "struct {} {}", self.id, t), + SymbolDefinition::Constant(c) => write!(f, "{}", c), + SymbolDefinition::Function(func) => write!(f, "def {}{}", self.id, func), + }, Symbol::There(ref import) => write!(f, "import {} as {}", import, self.id), Symbol::Flat(ref flat_fun) => { write!(f, "def {}{}:\n\t// hidden", self.id, flat_fun.signature()) @@ -216,6 +234,31 @@ impl<'ast> fmt::Debug for Module<'ast> { } } +#[derive(Clone, PartialEq)] +pub struct ConstantDefinition<'ast> { + pub id: Identifier<'ast>, + pub ty: UnresolvedTypeNode, + pub expression: ExpressionNode<'ast>, +} + +pub type ConstantDefinitionNode<'ast> = Node>; + +impl<'ast> fmt::Display for ConstantDefinition<'ast> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "const {} {} = {}", self.ty, self.id, self.expression) + } +} + +impl<'ast> fmt::Debug for ConstantDefinition<'ast> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "ConstantDefinition({:?}, {:?}, {:?})", + self.ty, self.id, self.expression + ) + } +} + /// A function defined locally #[derive(Clone, PartialEq)] pub struct Function<'ast> { diff --git a/zokrates_core/src/absy/node.rs b/zokrates_core/src/absy/node.rs index cf8d3fb4b..72607db16 100644 --- a/zokrates_core/src/absy/node.rs +++ b/zokrates_core/src/absy/node.rs @@ -84,6 +84,7 @@ impl<'ast> NodeValue for SymbolDeclaration<'ast> {} impl NodeValue for UnresolvedType {} impl<'ast> NodeValue for StructDefinition<'ast> {} impl<'ast> NodeValue for StructDefinitionField<'ast> {} +impl<'ast> NodeValue for ConstantDefinition<'ast> {} impl<'ast> NodeValue for Function<'ast> {} impl<'ast> NodeValue for Module<'ast> {} impl<'ast> NodeValue for SymbolImport<'ast> {} diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 4e0746452..71bdeb93c 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -59,6 +59,7 @@ struct State<'ast, T: Field> { #[derive(PartialEq, Hash, Eq, Debug)] enum SymbolType { Type, + Constant, Functions(BTreeSet), } @@ -69,14 +70,14 @@ struct SymbolUnifier { } impl SymbolUnifier { - fn insert_type>(&mut self, id: S) -> bool { + fn insert_symbol>(&mut self, id: S, ty: SymbolType) -> bool { let s_type = self.symbols.entry(id.into()); match s_type { // if anything is already called `id`, we cannot introduce this type Entry::Occupied(..) => false, // otherwise, we can! Entry::Vacant(v) => { - v.insert(SymbolType::Type); + v.insert(ty); true } } @@ -88,8 +89,8 @@ impl SymbolUnifier { // if anything is already called `id`, it depends what it is Entry::Occupied(mut o) => { match o.get_mut() { - // if it's a Type, then we can't introduce a function - SymbolType::Type => false, + // if it's a Type or a Constant, then we can't introduce a function + SymbolType::Type | SymbolType::Constant => false, // if it's a Function, we can introduce a new function only if it has a different signature SymbolType::Functions(signatures) => signatures.insert(signature), } @@ -205,6 +206,7 @@ impl<'ast> FunctionQuery<'ast> { pub struct ScopedVariable<'ast> { id: Variable<'ast>, level: usize, + constant: bool, } /// Identifiers of different `ScopedVariable`s should not conflict, so we define them as equivalent @@ -282,6 +284,35 @@ impl<'ast> Checker<'ast> { }) } + fn check_constant_definition( + &mut self, + c: ConstantDefinitionNode<'ast>, + module_id: &ModuleId, + types: &TypeMap, + ) -> Result, ErrorInner> { + let pos = c.pos(); + let ty = self.check_type(c.value.ty, module_id, &types)?; + let expression = self.check_expression(c.value.expression, module_id, types)?; + + match ty == expression.get_type() { + true => Ok(TypedConstant { + id: crate::typed_absy::Identifier::from(c.value.id), + ty, + expression, + }), + false => Err(ErrorInner { + pos: Some(pos), + message: format!( + "Expression `{}` of type `{}` cannot be assigned to constant `{}` of type `{}`", + expression, + expression.get_type(), + c.value.id, + ty + ), + }), + } + } + fn check_struct_type_declaration( &mut self, id: String, @@ -335,6 +366,7 @@ impl<'ast> Checker<'ast> { module_id: &ModuleId, state: &mut State<'ast, T>, functions: &mut HashMap, TypedFunctionSymbol<'ast, T>>, + constants: &mut HashMap, TypedConstant<'ast, T>>, symbol_unifier: &mut SymbolUnifier, ) -> Result<(), Vec> { let mut errors: Vec = vec![]; @@ -343,67 +375,99 @@ impl<'ast> Checker<'ast> { let declaration = declaration.value; match declaration.symbol.clone() { - Symbol::HereType(t) => { - match self.check_struct_type_declaration( - declaration.id.to_string(), - t.clone(), - module_id, - &state.types, - ) { - Ok(ty) => { - match symbol_unifier.insert_type(declaration.id) { - false => errors.push( - ErrorInner { - pos: Some(pos), - message: format!( - "{} conflicts with another symbol", - declaration.id, - ), - } - .in_file(module_id), - ), - true => {} - }; - state - .types - .entry(module_id.clone()) - .or_default() - .insert(declaration.id.to_string(), ty); + Symbol::Here(kind) => match kind { + SymbolDefinition::Struct(t) => { + match self.check_struct_type_declaration( + declaration.id.to_string(), + t.clone(), + module_id, + &state.types, + ) { + Ok(ty) => { + match symbol_unifier.insert_symbol(declaration.id, SymbolType::Type) { + false => errors.push( + ErrorInner { + pos: Some(pos), + message: format!( + "{} conflicts with another symbol", + declaration.id, + ), + } + .in_file(module_id), + ), + true => {} + }; + state + .types + .entry(module_id.clone()) + .or_default() + .insert(declaration.id.to_string(), ty); + } + Err(e) => errors.extend(e.into_iter().map(|inner| Error { + inner, + module_id: module_id.clone(), + })), } - Err(e) => errors.extend(e.into_iter().map(|inner| Error { - inner, - module_id: module_id.clone(), - })), } - } - Symbol::HereFunction(f) => match self.check_function(f, module_id, &state.types) { - Ok(funct) => { - match symbol_unifier.insert_function(declaration.id, funct.signature.clone()) { - false => errors.push( - ErrorInner { - pos: Some(pos), - message: format!( - "{} conflicts with another symbol", - declaration.id, + SymbolDefinition::Constant(c) => { + match self.check_constant_definition(c, module_id, &state.types) { + Ok(c) => { + match symbol_unifier.insert_symbol(declaration.id, SymbolType::Constant) + { + false => errors.push( + ErrorInner { + pos: Some(pos), + message: format!( + "{} conflicts with another symbol", + declaration.id, + ), + } + .in_file(module_id), ), - } - .in_file(module_id), - ), - true => {} - }; - - self.functions.insert( - FunctionKey::with_id(declaration.id.clone()) - .signature(funct.signature.clone()), - ); - functions.insert( - FunctionKey::with_id(declaration.id.clone()) - .signature(funct.signature.clone()), - TypedFunctionSymbol::Here(funct), - ); + true => {} + }; + constants + .insert(identifier::Identifier::from(declaration.id), c.clone()); + self.insert_into_scope(Variable::with_id_and_type(c.id, c.ty), true); + } + Err(e) => { + errors.push(e.in_file(module_id)); + } + } } - Err(e) => { - errors.extend(e.into_iter().map(|inner| inner.in_file(module_id))); + SymbolDefinition::Function(f) => { + match self.check_function(f, module_id, &state.types) { + Ok(funct) => { + match symbol_unifier + .insert_function(declaration.id, funct.signature.clone()) + { + false => errors.push( + ErrorInner { + pos: Some(pos), + message: format!( + "{} conflicts with another symbol", + declaration.id, + ), + } + .in_file(module_id), + ), + true => {} + }; + + self.functions.insert( + FunctionKey::with_id(declaration.id.clone()) + .signature(funct.signature.clone()), + ); + functions.insert( + FunctionKey::with_id(declaration.id.clone()) + .signature(funct.signature.clone()), + TypedFunctionSymbol::Here(funct), + ); + } + Err(e) => { + errors.extend(e.into_iter().map(|inner| inner.in_file(module_id))); + } + } } }, Symbol::There(import) => { @@ -450,7 +514,7 @@ impl<'ast> Checker<'ast> { }; // we imported a type, so the symbol it gets bound to should not already exist - match symbol_unifier.insert_type(declaration.id) { + match symbol_unifier.insert_symbol(declaration.id, SymbolType::Type) { false => { errors.push(Error { module_id: module_id.clone(), @@ -557,6 +621,7 @@ impl<'ast> Checker<'ast> { ) -> Result<(), Vec> { let mut errors = vec![]; let mut checked_functions = HashMap::new(); + let mut checked_constants = HashMap::new(); // check if the module was already removed from the untyped ones let to_insert = match state.modules.remove(module_id) { @@ -569,7 +634,7 @@ impl<'ast> Checker<'ast> { // we need to create an entry in the types map to store types for this module state.types.entry(module_id.clone()).or_default(); - // we keep track of the introduced symbols to avoid colisions between types and functions + // we keep track of the introduced symbols to avoid collisions between types and functions let mut symbol_unifier = SymbolUnifier::default(); // we go through symbol declarations and check them @@ -579,6 +644,7 @@ impl<'ast> Checker<'ast> { module_id, state, &mut checked_functions, + &mut checked_constants, &mut symbol_unifier, ) { Ok(()) => {} @@ -590,6 +656,7 @@ impl<'ast> Checker<'ast> { Some(TypedModule { functions: checked_functions, + constants: checked_constants, }) } }; @@ -663,7 +730,7 @@ impl<'ast> Checker<'ast> { for arg in funct.arguments { match self.check_parameter(arg, module_id, types) { Ok(a) => { - self.insert_into_scope(a.id.clone()); + self.insert_into_scope(a.id.clone(), false); arguments_checked.push(a); } Err(e) => errors.extend(e), @@ -873,7 +940,7 @@ impl<'ast> Checker<'ast> { } Statement::Declaration(var) => { let var = self.check_variable(var, module_id, types)?; - match self.insert_into_scope(var.clone()) { + match self.insert_into_scope(var.clone(), false) { true => Ok(TypedStatement::Declaration(var)), false => Err(ErrorInner { pos: Some(pos), @@ -909,7 +976,7 @@ impl<'ast> Checker<'ast> { false => Err(ErrorInner { pos: Some(pos), message: format!( - "Expression {} of type {} cannot be assigned to {} of type {}", + "Expression `{}` of type `{}` cannot be assigned to `{}` of type `{}`", checked_expr, expression_type, var, var_type ), }), @@ -972,7 +1039,7 @@ impl<'ast> Checker<'ast> { } .map_err(|e| vec![e])?; - self.insert_into_scope(var.clone()); + self.insert_into_scope(var.clone(), false); let mut checked_statements = vec![]; @@ -1045,10 +1112,16 @@ impl<'ast> Checker<'ast> { // check that the assignee is declared match assignee.value { Assignee::Identifier(variable_name) => match self.get_scope(&variable_name) { - Some(var) => Ok(TypedAssignee::Identifier(Variable::with_id_and_type( - variable_name, - var.id._type.clone(), - ))), + Some(var) => match var.constant { + false => Ok(TypedAssignee::Identifier(Variable::with_id_and_type( + variable_name, + var.id._type.clone(), + ))), + true => Err(ErrorInner { + pos: Some(assignee.pos()), + message: format!("Assignment to constant variable `{}`", variable_name), + }), + }, None => Err(ErrorInner { pos: Some(assignee.pos()), message: format!("Variable `{}` is undeclared", variable_name), @@ -2359,13 +2432,15 @@ impl<'ast> Checker<'ast> { Type::FieldElement, ), level: 0, + constant: false, }) } - fn insert_into_scope(&mut self, v: Variable<'ast>) -> bool { + fn insert_into_scope(&mut self, v: Variable<'ast>, constant: bool) -> bool { self.scope.insert(ScopedVariable { id: v, level: self.level, + constant, }) } @@ -2555,15 +2630,15 @@ mod tests { let mut unifier = SymbolUnifier::default(); - assert!(unifier.insert_type("foo")); - assert!(!unifier.insert_type("foo")); + assert!(unifier.insert_symbol("foo", SymbolType::Type)); + assert!(!unifier.insert_symbol("foo", SymbolType::Type)); assert!(!unifier.insert_function("foo", Signature::new())); assert!(unifier.insert_function("bar", Signature::new())); assert!(!unifier.insert_function("bar", Signature::new())); assert!( unifier.insert_function("bar", Signature::new().inputs(vec![Type::FieldElement])) ); - assert!(!unifier.insert_type("bar")); + assert!(!unifier.insert_symbol("bar", SymbolType::Type)); } #[test] @@ -2580,7 +2655,7 @@ mod tests { let foo: Module = Module { symbols: vec![SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(function0()), + symbol: Symbol::Here(SymbolDefinition::Function(function0())), } .mock()], imports: vec![], @@ -2616,6 +2691,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default() }) ); } @@ -2633,12 +2709,12 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(function0()), + symbol: Symbol::Here(SymbolDefinition::Function(function0())), } .mock(), SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(function0()), + symbol: Symbol::Here(SymbolDefinition::Function(function0())), } .mock(), ], @@ -2675,12 +2751,12 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(function0()), + symbol: Symbol::Here(SymbolDefinition::Function(function0())), } .mock(), SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(function1()), + symbol: Symbol::Here(SymbolDefinition::Function(function1())), } .mock(), ], @@ -2726,12 +2802,12 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereType(struct0()), + symbol: Symbol::Here(SymbolDefinition::Struct(struct0())), } .mock(), SymbolDeclaration { id: "foo", - symbol: Symbol::HereType(struct1()), + symbol: Symbol::Here(SymbolDefinition::Struct(struct1())), } .mock(), ], @@ -2764,12 +2840,14 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(function0()), + symbol: Symbol::Here(SymbolDefinition::Function(function0())), } .mock(), SymbolDeclaration { id: "foo", - symbol: Symbol::HereType(StructDefinition { fields: vec![] }.mock()), + symbol: Symbol::Here(SymbolDefinition::Struct( + StructDefinition { fields: vec![] }.mock(), + )), } .mock(), ], @@ -2805,7 +2883,7 @@ mod tests { let bar = Module::with_symbols(vec![SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(function0()), + symbol: Symbol::Here(SymbolDefinition::Function(function0())), } .mock()]); @@ -2820,7 +2898,7 @@ mod tests { .mock(), SymbolDeclaration { id: "foo", - symbol: Symbol::HereType(struct0()), + symbol: Symbol::Here(SymbolDefinition::Struct(struct0())), } .mock(), ], @@ -2856,7 +2934,7 @@ mod tests { let bar = Module::with_symbols(vec![SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(function0()), + symbol: Symbol::Here(SymbolDefinition::Function(function0())), } .mock()]); @@ -2864,7 +2942,7 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereType(struct0()), + symbol: Symbol::Here(SymbolDefinition::Struct(struct0())), } .mock(), SymbolDeclaration { @@ -2948,10 +3026,12 @@ mod tests { scope.insert(ScopedVariable { id: Variable::field_element("a"), level: 0, + constant: false, }); scope.insert(ScopedVariable { id: Variable::field_element("b"), level: 0, + constant: false, }); let mut checker = new_with_args(scope, 1, HashSet::new()); assert_eq!( @@ -3019,12 +3099,12 @@ mod tests { let symbols = vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(foo), + symbol: Symbol::Here(SymbolDefinition::Function(foo)), } .mock(), SymbolDeclaration { id: "bar", - symbol: Symbol::HereFunction(bar), + symbol: Symbol::Here(SymbolDefinition::Function(bar)), } .mock(), ]; @@ -3135,17 +3215,17 @@ mod tests { let symbols = vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(foo), + symbol: Symbol::Here(SymbolDefinition::Function(foo)), } .mock(), SymbolDeclaration { id: "bar", - symbol: Symbol::HereFunction(bar), + symbol: Symbol::Here(SymbolDefinition::Function(bar)), } .mock(), SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(main), + symbol: Symbol::Here(SymbolDefinition::Function(main)), } .mock(), ]; @@ -3529,12 +3609,12 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(foo), + symbol: Symbol::Here(SymbolDefinition::Function(foo)), } .mock(), SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(main), + symbol: Symbol::Here(SymbolDefinition::Function(main)), } .mock(), ], @@ -3622,12 +3702,12 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(foo), + symbol: Symbol::Here(SymbolDefinition::Function(foo)), } .mock(), SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(main), + symbol: Symbol::Here(SymbolDefinition::Function(main)), } .mock(), ], @@ -3738,12 +3818,12 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "foo", - symbol: Symbol::HereFunction(foo), + symbol: Symbol::Here(SymbolDefinition::Function(foo)), } .mock(), SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(main), + symbol: Symbol::Here(SymbolDefinition::Function(main)), } .mock(), ], @@ -4002,12 +4082,12 @@ mod tests { let symbols = vec![ SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(main1), + symbol: Symbol::Here(SymbolDefinition::Function(main1)), } .mock(), SymbolDeclaration { id: "main", - symbol: Symbol::HereFunction(main2), + symbol: Symbol::Here(SymbolDefinition::Function(main2)), } .mock(), ]; @@ -4121,7 +4201,7 @@ mod tests { imports: vec![], symbols: vec![SymbolDeclaration { id: "Foo", - symbol: Symbol::HereType(s.mock()), + symbol: Symbol::Here(SymbolDefinition::Struct(s.mock())), } .mock()], }; @@ -4305,7 +4385,7 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "Foo", - symbol: Symbol::HereType( + symbol: Symbol::Here(SymbolDefinition::Struct( StructDefinition { fields: vec![StructDefinitionField { id: "foo", @@ -4314,12 +4394,12 @@ mod tests { .mock()], } .mock(), - ), + )), } .mock(), SymbolDeclaration { id: "Bar", - symbol: Symbol::HereType( + symbol: Symbol::Here(SymbolDefinition::Struct( StructDefinition { fields: vec![StructDefinitionField { id: "foo", @@ -4328,7 +4408,7 @@ mod tests { .mock()], } .mock(), - ), + )), } .mock(), ], @@ -4373,7 +4453,7 @@ mod tests { imports: vec![], symbols: vec![SymbolDeclaration { id: "Bar", - symbol: Symbol::HereType( + symbol: Symbol::Here(SymbolDefinition::Struct( StructDefinition { fields: vec![StructDefinitionField { id: "foo", @@ -4382,7 +4462,7 @@ mod tests { .mock()], } .mock(), - ), + )), } .mock()], }; @@ -4406,7 +4486,7 @@ mod tests { imports: vec![], symbols: vec![SymbolDeclaration { id: "Foo", - symbol: Symbol::HereType( + symbol: Symbol::Here(SymbolDefinition::Struct( StructDefinition { fields: vec![StructDefinitionField { id: "foo", @@ -4415,7 +4495,7 @@ mod tests { .mock()], } .mock(), - ), + )), } .mock()], }; @@ -4441,7 +4521,7 @@ mod tests { symbols: vec![ SymbolDeclaration { id: "Foo", - symbol: Symbol::HereType( + symbol: Symbol::Here(SymbolDefinition::Struct( StructDefinition { fields: vec![StructDefinitionField { id: "bar", @@ -4450,12 +4530,12 @@ mod tests { .mock()], } .mock(), - ), + )), } .mock(), SymbolDeclaration { id: "Bar", - symbol: Symbol::HereType( + symbol: Symbol::Here(SymbolDefinition::Struct( StructDefinition { fields: vec![StructDefinitionField { id: "foo", @@ -4464,7 +4544,7 @@ mod tests { .mock()], } .mock(), - ), + )), } .mock(), ], @@ -4607,7 +4687,7 @@ mod tests { ) .mock(), &PathBuf::from(MODULE_ID).into(), - &state.types, + &state.types ), Ok(TypedStatement::Declaration(Variable::with_id_and_type( "a", diff --git a/zokrates_core/src/static_analysis/inline.rs b/zokrates_core/src/static_analysis/inline.rs index 4fad20a6e..6733ea3bf 100644 --- a/zokrates_core/src/static_analysis/inline.rs +++ b/zokrates_core/src/static_analysis/inline.rs @@ -19,6 +19,7 @@ use crate::typed_absy::types::{FunctionKey, FunctionKeyHash, Type, UBitwidth}; use crate::typed_absy::{folder::*, *}; use std::collections::HashMap; +use std::convert::TryInto; use zokrates_field::Field; #[derive(Debug, PartialEq, Eq, Hash, Clone)] @@ -145,6 +146,7 @@ impl<'ast, T: Field> Inliner<'ast, T> { ] .into_iter() .collect(), + constants: Default::default(), }, )] .into_iter() @@ -298,6 +300,12 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> { e: FieldElementExpression<'ast, T>, ) -> FieldElementExpression<'ast, T> { match e { + FieldElementExpression::Identifier(ref id) => { + match self.module().constants.get(id).cloned() { + Some(c) => fold_field_expression(self, c.expression.try_into().unwrap()), + None => fold_field_expression(self, e), + } + } FieldElementExpression::FunctionCall(key, exps) => { let exps: Vec<_> = exps.into_iter().map(|e| self.fold_expression(e)).collect(); @@ -344,6 +352,12 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> { e: BooleanExpression<'ast, T>, ) -> BooleanExpression<'ast, T> { match e { + BooleanExpression::Identifier(ref id) => { + match self.module().constants.get(id).cloned() { + Some(c) => fold_boolean_expression(self, c.expression.try_into().unwrap()), + None => fold_boolean_expression(self, e), + } + } BooleanExpression::FunctionCall(key, exps) => { let exps: Vec<_> = exps.into_iter().map(|e| self.fold_expression(e)).collect(); @@ -392,6 +406,15 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> { e: ArrayExpressionInner<'ast, T>, ) -> ArrayExpressionInner<'ast, T> { match e { + ArrayExpressionInner::Identifier(ref id) => { + match self.module().constants.get(id).cloned() { + Some(c) => { + let expr: ArrayExpression<'ast, T> = c.expression.try_into().unwrap(); + fold_array_expression(self, expr).into_inner() + } + None => fold_array_expression_inner(self, ty, size, e), + } + } ArrayExpressionInner::FunctionCall(key, exps) => { let exps: Vec<_> = exps.into_iter().map(|e| self.fold_expression(e)).collect(); @@ -439,6 +462,15 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> { e: StructExpressionInner<'ast, T>, ) -> StructExpressionInner<'ast, T> { match e { + StructExpressionInner::Identifier(ref id) => { + match self.module().constants.get(id).cloned() { + Some(c) => { + let expr: StructExpression<'ast, T> = c.expression.try_into().unwrap(); + fold_struct_expression(self, expr).into_inner() + } + None => fold_struct_expression_inner(self, ty, e), + } + } StructExpressionInner::FunctionCall(key, exps) => { let exps: Vec<_> = exps.into_iter().map(|e| self.fold_expression(e)).collect(); @@ -486,6 +518,15 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> { e: UExpressionInner<'ast, T>, ) -> UExpressionInner<'ast, T> { match e { + UExpressionInner::Identifier(ref id) => { + match self.module().constants.get(id).cloned() { + Some(c) => { + let expr: UExpression<'ast, T> = c.expression.try_into().unwrap(); + fold_uint_expression(self, expr).into_inner() + } + None => fold_uint_expression_inner(self, size, e), + } + } UExpressionInner::FunctionCall(key, exps) => { let exps: Vec<_> = exps.into_iter().map(|e| self.fold_expression(e)).collect(); @@ -581,6 +622,7 @@ mod tests { ] .into_iter() .collect(), + constants: Default::default(), }; let foo = TypedModule { @@ -597,6 +639,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default(), }; let modules: HashMap<_, _> = vec![("main".into(), main), ("foo".into(), foo)] @@ -696,6 +739,7 @@ mod tests { ] .into_iter() .collect(), + constants: Default::default(), }; let foo = TypedModule { @@ -719,6 +763,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default(), }; let modules: HashMap<_, _> = vec![("main".into(), main), ("foo".into(), foo)] @@ -875,6 +920,7 @@ mod tests { ] .into_iter() .collect(), + constants: Default::default(), }; let foo: TypedModule = TypedModule { @@ -893,6 +939,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default(), }; let modules: HashMap<_, _> = vec![("main".into(), main), ("foo".into(), foo)] @@ -1065,6 +1112,7 @@ mod tests { ] .into_iter() .collect(), + constants: Default::default(), }; let foo = TypedModule { @@ -1081,6 +1129,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default(), }; let modules: HashMap<_, _> = vec![("main".into(), main), ("foo".into(), foo)] @@ -1176,6 +1225,7 @@ mod tests { ] .into_iter() .collect(), + constants: Default::default(), }; let modules: HashMap<_, _> = vec![("main".into(), main)].into_iter().collect(); @@ -1283,6 +1333,7 @@ mod tests { ] .into_iter() .collect(), + constants: Default::default(), }; let id = TypedModule { @@ -1304,6 +1355,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default(), }; let modules = vec![("main".into(), main), ("id".into(), id)] diff --git a/zokrates_core/src/static_analysis/propagate_unroll.rs b/zokrates_core/src/static_analysis/propagate_unroll.rs index 67354b537..5a461206b 100644 --- a/zokrates_core/src/static_analysis/propagate_unroll.rs +++ b/zokrates_core/src/static_analysis/propagate_unroll.rs @@ -90,6 +90,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default(), }, )] .into_iter() @@ -215,6 +216,7 @@ mod tests { )] .into_iter() .collect(), + constants: Default::default(), }, )] .into_iter() diff --git a/zokrates_core/src/typed_absy/abi.rs b/zokrates_core/src/typed_absy/abi.rs index f8ff7a878..e9c25fbbd 100644 --- a/zokrates_core/src/typed_absy/abi.rs +++ b/zokrates_core/src/typed_absy/abi.rs @@ -61,7 +61,13 @@ mod tests { ); let mut modules = HashMap::new(); - modules.insert("main".into(), TypedModule { functions }); + modules.insert( + "main".into(), + TypedModule { + functions, + constants: Default::default(), + }, + ); let typed_ast: TypedProgram = TypedProgram { main: "main".into(), diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 0bb7f7c93..6ba33a9e5 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -45,6 +45,9 @@ pub type TypedModules<'ast, T> = HashMap>; /// in a given `TypedModule`, hence the use of a HashMap pub type TypedFunctionSymbols<'ast, T> = HashMap, TypedFunctionSymbol<'ast, T>>; +/// A collection of `TypedConstant`s +pub type TypedConstants<'ast, T> = HashMap, TypedConstant<'ast, T>>; + /// A typed program as a collection of modules, one of them being the main #[derive(PartialEq, Debug, Clone)] pub struct TypedProgram<'ast, T> { @@ -102,11 +105,13 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedProgram<'ast, T> { } } -/// A typed program as a collection of functions. Types have been resolved during semantic checking. +/// A typed module as a collection of functions. Types have been resolved during semantic checking. #[derive(PartialEq, Clone)] pub struct TypedModule<'ast, T> { - /// Functions of the program + /// Functions of the module pub functions: TypedFunctionSymbols<'ast, T>, + /// Constants defined in module + pub constants: TypedConstants<'ast, T>, } #[derive(Clone, PartialEq)] @@ -248,6 +253,25 @@ impl<'ast, T: fmt::Debug> fmt::Debug for TypedFunction<'ast, T> { } } +#[derive(Clone, PartialEq)] +pub struct TypedConstant<'ast, T> { + pub id: Identifier<'ast>, + pub ty: Type, + pub expression: TypedExpression<'ast, T>, +} + +impl<'ast, T: fmt::Debug> fmt::Debug for TypedConstant<'ast, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "TypedConstant({:?}, {:?}, ...)", self.id, self.ty) + } +} + +impl<'ast, T: fmt::Display> fmt::Display for TypedConstant<'ast, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "const {} {} = {}", self.ty, self.id, self.expression) + } +} + /// Something we can assign to. #[derive(Clone, PartialEq, Hash, Eq)] pub enum TypedAssignee<'ast, T> { diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index b6afdd04d..e896bed53 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -1,5 +1,5 @@ -file = { SOI ~ NEWLINE* ~ pragma? ~ NEWLINE* ~ import_directive* ~ NEWLINE* ~ ty_struct_definition* ~ NEWLINE* ~ function_definition* ~ EOI } +file = { SOI ~ NEWLINE* ~ pragma? ~ NEWLINE* ~ import_directive* ~ NEWLINE* ~ ty_struct_definition* ~ NEWLINE* ~ const_definition* ~ NEWLINE* ~ function_definition* ~ EOI } pragma = { "#pragma" ~ "curve" ~ curve } curve = @{ (ASCII_ALPHANUMERIC | "_") * } @@ -9,6 +9,7 @@ from_import_directive = { "from" ~ "\"" ~ import_source ~ "\"" ~ "import" ~ iden main_import_directive = {"import" ~ "\"" ~ import_source ~ "\"" ~ ("as" ~ identifier)? ~ NEWLINE+} import_source = @{(!"\"" ~ ANY)*} function_definition = {"def" ~ identifier ~ "(" ~ parameter_list ~ ")" ~ return_types ~ ":" ~ NEWLINE* ~ statement* } +const_definition = {"const" ~ ty ~ identifier ~ "=" ~ expression ~ NEWLINE*} return_types = _{ ( "->" ~ ( "(" ~ type_list ~ ")" | ty ))? } parameter_list = _{(parameter ~ ("," ~ parameter)*)?} @@ -128,6 +129,6 @@ COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) } // the ordering of reserved keywords matters: if "as" is before "assert", then "assert" gets parsed as (as)(sert) and incorrectly // accepted -keyword = @{"assert"|"as"|"bool"|"byte"|"def"|"do"|"else"|"endfor"|"export"|"false"|"field"|"for"|"if"|"then"|"fi"|"import"|"from"| +keyword = @{"assert"|"as"|"bool"|"byte"|"const"|"def"|"do"|"else"|"endfor"|"export"|"false"|"field"|"for"|"if"|"then"|"fi"|"import"|"from"| "in"|"private"|"public"|"return"|"struct"|"true"|"u8"|"u16"|"u32" } diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 4ba8e2991..66303b462 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -10,12 +10,13 @@ extern crate lazy_static; pub use ast::{ Access, ArrayAccess, ArrayInitializerExpression, ArrayType, AssertionStatement, Assignee, AssigneeAccess, BasicOrStructType, BasicType, BinaryExpression, BinaryOperator, CallAccess, - ConstantExpression, DecimalNumberExpression, DefinitionStatement, Expression, FieldType, File, - FromExpression, Function, IdentifierExpression, ImportDirective, ImportSource, - InlineArrayExpression, InlineStructExpression, InlineStructMember, IterationStatement, - OptionallyTypedAssignee, Parameter, PostfixExpression, Range, RangeOrExpression, - ReturnStatement, Span, Spread, SpreadOrExpression, Statement, StructDefinition, StructField, - TernaryExpression, ToExpression, Type, UnaryExpression, UnaryOperator, Visibility, + ConstantDefinition, ConstantExpression, DecimalNumberExpression, DefinitionStatement, + Expression, FieldType, File, FromExpression, Function, IdentifierExpression, ImportDirective, + ImportSource, InlineArrayExpression, InlineStructExpression, InlineStructMember, + IterationStatement, OptionallyTypedAssignee, Parameter, PostfixExpression, Range, + RangeOrExpression, ReturnStatement, Span, Spread, SpreadOrExpression, Statement, + StructDefinition, StructField, TernaryExpression, ToExpression, Type, UnaryExpression, + UnaryOperator, Visibility, }; mod ast { @@ -173,6 +174,7 @@ mod ast { pub pragma: Option>, pub imports: Vec>, pub structs: Vec>, + pub constants: Vec>, pub functions: Vec>, pub eoi: EOI, #[pest_ast(outer())] @@ -225,6 +227,16 @@ mod ast { pub span: Span<'ast>, } + #[derive(Debug, FromPest, PartialEq, Clone)] + #[pest_ast(rule(Rule::const_definition))] + pub struct ConstantDefinition<'ast> { + pub ty: Type<'ast>, + pub id: IdentifierExpression<'ast>, + pub expression: Expression<'ast>, + #[pest_ast(outer())] + pub span: Span<'ast>, + } + #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::import_directive))] pub enum ImportDirective<'ast> { @@ -866,6 +878,7 @@ mod tests { Ok(File { pragma: None, structs: vec![], + constants: vec![], functions: vec![Function { id: IdentifierExpression { value: String::from("main"), @@ -919,6 +932,7 @@ mod tests { Ok(File { pragma: None, structs: vec![], + constants: vec![], functions: vec![Function { id: IdentifierExpression { value: String::from("main"), @@ -990,6 +1004,7 @@ mod tests { Ok(File { pragma: None, structs: vec![], + constants: vec![], functions: vec![Function { id: IdentifierExpression { value: String::from("main"), @@ -1048,6 +1063,7 @@ mod tests { Ok(File { pragma: None, structs: vec![], + constants: vec![], functions: vec![Function { id: IdentifierExpression { value: String::from("main"), @@ -1084,6 +1100,7 @@ mod tests { Ok(File { pragma: None, structs: vec![], + constants: vec![], functions: vec![Function { id: IdentifierExpression { value: String::from("main"), From 1ca985809b6d2405dc20eca2e447d452a1facbac Mon Sep 17 00:00:00 2001 From: dark64 Date: Fri, 2 Apr 2021 17:55:58 +0200 Subject: [PATCH 05/95] fix clippy warning --- zokrates_core/src/absy/from_ast.rs | 2 +- zokrates_core/src/absy/mod.rs | 2 +- zokrates_core/src/semantics.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 64cddf2aa..0db771b3a 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -105,7 +105,7 @@ impl<'ast> From> for absy::SymbolDeclarationNode< absy::SymbolDeclaration { id, - symbol: absy::Symbol::Here(SymbolDefinition::Constant(ty)), + symbol: absy::Symbol::Here(SymbolDefinition::Constant(box ty)), } .span(span) } diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index 4df768581..a1bca4823 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -53,7 +53,7 @@ pub struct SymbolDeclaration<'ast> { #[derive(PartialEq, Clone)] pub enum SymbolDefinition<'ast> { Struct(StructDefinitionNode<'ast>), - Constant(ConstantDefinitionNode<'ast>), + Constant(Box>), Function(FunctionNode<'ast>), } diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 3901e3d2d..1e3f19d38 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -453,7 +453,7 @@ impl<'ast, T: Field> Checker<'ast, T> { })), } } - SymbolDefinition::Constant(c) => { + SymbolDefinition::Constant(box c) => { match self.check_constant_definition(c, module_id, &state.types) { Ok(c) => { match symbol_unifier.insert_symbol(declaration.id, SymbolType::Constant) From 8f4ee002762e9e4895f2784630699d374d71b612 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 5 Apr 2021 15:53:09 +0200 Subject: [PATCH 06/95] constant inliner tests --- changelogs/unreleased/792-dark64 | 1 + zokrates_core/src/semantics.rs | 4 +- .../src/static_analysis/constant_inliner.rs | 525 +++++++++++++++++- .../src/static_analysis/reducer/mod.rs | 20 +- zokrates_core/src/typed_absy/abi.rs | 2 +- zokrates_core/src/typed_absy/mod.rs | 2 +- 6 files changed, 538 insertions(+), 16 deletions(-) create mode 100644 changelogs/unreleased/792-dark64 diff --git a/changelogs/unreleased/792-dark64 b/changelogs/unreleased/792-dark64 new file mode 100644 index 000000000..fbc1a5dca --- /dev/null +++ b/changelogs/unreleased/792-dark64 @@ -0,0 +1 @@ +Introduce constant definitions to the language (`const` keyword) \ No newline at end of file diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 1e3f19d38..d7abd022c 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -701,7 +701,7 @@ impl<'ast, T: Field> Checker<'ast, T> { Some(TypedModule { functions: checked_functions, - constants: checked_constants, + constants: Some(checked_constants).filter(|m| !m.is_empty()), }) } }; @@ -3152,7 +3152,7 @@ mod tests { )] .into_iter() .collect(), - constants: Default::default() + constants: None }) ); } diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index ad643ec64..645dbc5e5 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -27,8 +27,11 @@ impl<'ast, T: Field> ConstantInliner<'ast, T> { impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { fn fold_module(&mut self, p: TypedModule<'ast, T>) -> TypedModule<'ast, T> { - self.constants = p.constants.clone(); - fold_module(self, p) + self.constants = p.constants.clone().unwrap_or_default(); + TypedModule { + functions: fold_module(self, p).functions, + constants: None, + } } fn fold_field_expression( @@ -111,3 +114,521 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::typed_absy::types::DeclarationSignature; + use crate::typed_absy::{ + DeclarationFunctionKey, DeclarationType, FieldElementExpression, GType, Identifier, + TypedConstant, TypedExpression, TypedFunction, TypedFunctionSymbol, TypedStatement, + }; + use zokrates_field::Bn128Field; + + #[test] + fn inline_const_field() { + // const field a = 1 + // + // def main() -> field: + // return a + + let const_id = Identifier::from("a"); + let main: TypedFunction = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![ + FieldElementExpression::Identifier(const_id.clone()).into(), + ])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }; + + let mut constants = TypedConstants::::new(); + constants.insert( + const_id.clone(), + TypedConstant { + id: const_id.clone(), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement(FieldElementExpression::Number( + Bn128Field::from(1), + ))), + }, + ); + + let program = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(main), + )] + .into_iter() + .collect(), + constants: Some(constants), + }, + )] + .into_iter() + .collect(), + }; + + let program = ConstantInliner::inline(program); + + let expected_main = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![ + FieldElementExpression::Number(Bn128Field::from(1)).into(), + ])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }; + + let expected_program: TypedProgram = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(expected_main), + )] + .into_iter() + .collect(), + constants: None, + }, + )] + .into_iter() + .collect(), + }; + + assert_eq!(program, expected_program) + } + + #[test] + fn inline_const_boolean() { + // const bool a = true + // + // def main() -> bool: + // return a + + let const_id = Identifier::from("a"); + let main: TypedFunction = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![BooleanExpression::Identifier( + const_id.clone(), + ) + .into()])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Boolean]), + }; + + let mut constants = TypedConstants::::new(); + constants.insert( + const_id.clone(), + TypedConstant { + id: const_id.clone(), + ty: GType::Boolean, + expression: (TypedExpression::Boolean(BooleanExpression::Value(true))), + }, + ); + + let program = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Boolean]), + ), + TypedFunctionSymbol::Here(main), + )] + .into_iter() + .collect(), + constants: Some(constants), + }, + )] + .into_iter() + .collect(), + }; + + let program = ConstantInliner::inline(program); + + let expected_main = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![ + BooleanExpression::Value(true).into() + ])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Boolean]), + }; + + let expected_program: TypedProgram = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Boolean]), + ), + TypedFunctionSymbol::Here(expected_main), + )] + .into_iter() + .collect(), + constants: None, + }, + )] + .into_iter() + .collect(), + }; + + assert_eq!(program, expected_program) + } + + #[test] + fn inline_const_uint() { + // const u32 a = 0x00000001 + // + // def main() -> u32: + // return a + + let const_id = Identifier::from("a"); + let main: TypedFunction = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![UExpressionInner::Identifier( + const_id.clone(), + ) + .annotate(UBitwidth::B32) + .into()])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Uint(UBitwidth::B32)]), + }; + + let mut constants = TypedConstants::::new(); + constants.insert( + const_id.clone(), + TypedConstant { + id: const_id.clone(), + ty: GType::Uint(UBitwidth::B32), + expression: (UExpressionInner::Value(1u128) + .annotate(UBitwidth::B32) + .into()), + }, + ); + + let program = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Uint(UBitwidth::B32)]), + ), + TypedFunctionSymbol::Here(main), + )] + .into_iter() + .collect(), + constants: Some(constants), + }, + )] + .into_iter() + .collect(), + }; + + let program = ConstantInliner::inline(program); + + let expected_main = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![UExpressionInner::Value(1u128) + .annotate(UBitwidth::B32) + .into()])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Uint(UBitwidth::B32)]), + }; + + let expected_program: TypedProgram = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::Uint(UBitwidth::B32)]), + ), + TypedFunctionSymbol::Here(expected_main), + )] + .into_iter() + .collect(), + constants: None, + }, + )] + .into_iter() + .collect(), + }; + + assert_eq!(program, expected_program) + } + + #[test] + fn inline_const_field_array() { + // const field[2] a = [2, 2] + // + // def main() -> field: + // return a[0] + a[1] + + let const_id = Identifier::from("a"); + let main: TypedFunction = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![FieldElementExpression::Add( + FieldElementExpression::Select( + box ArrayExpressionInner::Identifier(const_id.clone()) + .annotate(GType::FieldElement, 2usize), + box UExpressionInner::Value(0u128).annotate(UBitwidth::B32), + ) + .into(), + FieldElementExpression::Select( + box ArrayExpressionInner::Identifier(const_id.clone()) + .annotate(GType::FieldElement, 2usize), + box UExpressionInner::Value(1u128).annotate(UBitwidth::B32), + ) + .into(), + ) + .into()])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }; + + let mut constants = TypedConstants::::new(); + constants.insert( + const_id.clone(), + TypedConstant { + id: const_id.clone(), + ty: GType::FieldElement, + expression: TypedExpression::Array( + ArrayExpressionInner::Value( + vec![ + FieldElementExpression::Number(Bn128Field::from(2)).into(), + FieldElementExpression::Number(Bn128Field::from(2)).into(), + ] + .into(), + ) + .annotate(GType::FieldElement, 2usize), + ), + }, + ); + + let program = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(main), + )] + .into_iter() + .collect(), + constants: Some(constants), + }, + )] + .into_iter() + .collect(), + }; + + let program = ConstantInliner::inline(program); + + let expected_main = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![FieldElementExpression::Add( + FieldElementExpression::Select( + box ArrayExpressionInner::Value( + vec![ + FieldElementExpression::Number(Bn128Field::from(2)).into(), + FieldElementExpression::Number(Bn128Field::from(2)).into(), + ] + .into(), + ) + .annotate(GType::FieldElement, 2usize), + box UExpressionInner::Value(0u128).annotate(UBitwidth::B32), + ) + .into(), + FieldElementExpression::Select( + box ArrayExpressionInner::Value( + vec![ + FieldElementExpression::Number(Bn128Field::from(2)).into(), + FieldElementExpression::Number(Bn128Field::from(2)).into(), + ] + .into(), + ) + .annotate(GType::FieldElement, 2usize), + box UExpressionInner::Value(1u128).annotate(UBitwidth::B32), + ) + .into(), + ) + .into()])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }; + + let expected_program: TypedProgram = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(expected_main), + )] + .into_iter() + .collect(), + constants: None, + }, + )] + .into_iter() + .collect(), + }; + + assert_eq!(program, expected_program) + } + + #[test] + fn inline_nested_const_field() { + // const field a = 1 + // const field b = a + 1 + // + // def main() -> field: + // return b + + let const_a_id = Identifier::from("a"); + let const_b_id = Identifier::from("b"); + + let main: TypedFunction = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![ + FieldElementExpression::Identifier(const_b_id.clone()).into(), + ])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }; + + let mut constants = TypedConstants::::new(); + constants.extend(vec![ + ( + const_a_id.clone(), + TypedConstant { + id: const_a_id.clone(), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement(FieldElementExpression::Number( + Bn128Field::from(1), + ))), + }, + ), + ( + const_b_id.clone(), + TypedConstant { + id: const_b_id.clone(), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement(FieldElementExpression::Add( + box FieldElementExpression::Identifier(const_a_id.clone()), + box FieldElementExpression::Number(Bn128Field::from(1)), + ))), + }, + ), + ]); + + let program = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(main), + )] + .into_iter() + .collect(), + constants: Some(constants), + }, + )] + .into_iter() + .collect(), + }; + + let program = ConstantInliner::inline(program); + + let expected_main = TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![FieldElementExpression::Add( + box FieldElementExpression::Number(Bn128Field::from(1)), + box FieldElementExpression::Number(Bn128Field::from(1)), + ) + .into()])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }; + + let expected_program: TypedProgram = TypedProgram { + main: "main".into(), + modules: vec![( + "main".into(), + TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(expected_main), + )] + .into_iter() + .collect(), + constants: None, + }, + )] + .into_iter() + .collect(), + }; + + assert_eq!(program, expected_program) + } +} diff --git a/zokrates_core/src/static_analysis/reducer/mod.rs b/zokrates_core/src/static_analysis/reducer/mod.rs index 57e17db29..05191af1c 100644 --- a/zokrates_core/src/static_analysis/reducer/mod.rs +++ b/zokrates_core/src/static_analysis/reducer/mod.rs @@ -547,7 +547,7 @@ pub fn reduce_program(p: TypedProgram) -> Result, E )] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -769,7 +769,7 @@ mod tests { ] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -835,7 +835,7 @@ mod tests { )] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -964,7 +964,7 @@ mod tests { ] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -1045,7 +1045,7 @@ mod tests { )] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -1183,7 +1183,7 @@ mod tests { ] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -1264,7 +1264,7 @@ mod tests { )] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -1441,7 +1441,7 @@ mod tests { ] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -1545,7 +1545,7 @@ mod tests { )] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() @@ -1629,7 +1629,7 @@ mod tests { ] .into_iter() .collect(), - constants: Default::default(), + constants: None, }, )] .into_iter() diff --git a/zokrates_core/src/typed_absy/abi.rs b/zokrates_core/src/typed_absy/abi.rs index f3adbdea7..7b189e97d 100644 --- a/zokrates_core/src/typed_absy/abi.rs +++ b/zokrates_core/src/typed_absy/abi.rs @@ -69,7 +69,7 @@ mod tests { "main".into(), TypedModule { functions, - constants: Default::default(), + constants: None, }, ); diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index def99d031..759421e67 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -144,7 +144,7 @@ pub struct TypedModule<'ast, T> { /// Functions of the module pub functions: TypedFunctionSymbols<'ast, T>, /// Constants defined in module - pub constants: TypedConstants<'ast, T>, + pub constants: Option>, } #[derive(Clone, PartialEq)] From 5faee6a295c4e1c9cce832ac373480d1c77728e8 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 7 Apr 2021 16:39:40 +0200 Subject: [PATCH 07/95] accept explicit generics in return --- .../generics/infer_return_call_generics.zok | 5 +++++ .../examples/return_explicit_generic.zok | 5 +++++ zokrates_core/src/semantics.rs | 11 +++++++---- zokrates_core/src/typed_absy/types.rs | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok create mode 100644 zokrates_cli/examples/return_explicit_generic.zok diff --git a/zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok b/zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok new file mode 100644 index 000000000..19120945c --- /dev/null +++ b/zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok @@ -0,0 +1,5 @@ +def foo() -> field[N]: + return [42; N] + +def main() -> field[2]: + return foo() // N is currently not infered to 2 here \ No newline at end of file diff --git a/zokrates_cli/examples/return_explicit_generic.zok b/zokrates_cli/examples/return_explicit_generic.zok new file mode 100644 index 000000000..3177b9268 --- /dev/null +++ b/zokrates_cli/examples/return_explicit_generic.zok @@ -0,0 +1,5 @@ +def foo() -> field[N]: + return [42; N] + +def main() -> field[2]: + return foo::<2>() \ No newline at end of file diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 4f969bb5f..6b0e01ffa 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1862,16 +1862,19 @@ impl<'ast, T: Field> Checker<'ast, T> { message: format!("Expected function call argument to be of type {}, found {}", e.1, e.0) })?; - let output_types = signature.get_output_types(arguments_checked.iter().map(|a| a.get_type()).collect()).map_err(|e| ErrorInner { + let generics_checked = generics_checked.unwrap_or_else(|| vec![None; signature.generics.len()]); + + let output_types = signature.get_output_types( + generics_checked.clone(), + arguments_checked.iter().map(|a| a.get_type()).collect() + ).map_err(|e| ErrorInner { pos: Some(pos), message: format!( - "Failed to infer value for generic parameter `{}`, try being more explicit by using an intermediate variable", + "Failed to infer value for generic parameter `{}`, try providing an explicit value", e, ), })?; - let generics_checked = generics_checked.unwrap_or_else(|| vec![None; signature.generics.len()]); - // the return count has to be 1 match output_types.len() { 1 => match &output_types[0] { diff --git a/zokrates_core/src/typed_absy/types.rs b/zokrates_core/src/typed_absy/types.rs index 12ada63a2..4d0ecba9b 100644 --- a/zokrates_core/src/typed_absy/types.rs +++ b/zokrates_core/src/typed_absy/types.rs @@ -1021,11 +1021,28 @@ pub mod signature { pub fn get_output_types( &self, + generics: Vec>>, inputs: Vec>, ) -> Result>, GenericIdentifier<'ast>> { // we keep track of the value of constants in a map, as a given constant can only have one value let mut constants = GenericsAssignment::default(); + // initialise the map with the explicitly provided generics + constants + .0 + .extend(self.generics.iter().zip(generics).filter_map(|(g, v)| { + // only add to the map when there's indeed a generic value being provided + v.map(|v| { + ( + match g.clone().unwrap() { + Constant::Generic(g) => g, + _ => unreachable!(), + }, + v, + ) + }) + })); + // fill the map with the inputs let _ = self .inputs From e193546d8d40204b5a47abf6412bc0929fef8099 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 7 Apr 2021 18:56:55 +0200 Subject: [PATCH 08/95] check shifts are constant earlier, simplify zir --- .../compile_errors/variable_shift.zok | 2 + zokrates_core/src/flatten/mod.rs | 26 +----- .../static_analysis/flatten_complex_types.rs | 16 +++- zokrates_core/src/static_analysis/mod.rs | 4 + .../src/static_analysis/shift_checker.rs | 55 ++++++++++++ .../src/static_analysis/uint_optimizer.rs | 84 ++++++------------- zokrates_core/src/zir/folder.rs | 10 +-- zokrates_core/src/zir/uint.rs | 14 ++-- 8 files changed, 111 insertions(+), 100 deletions(-) create mode 100644 zokrates_cli/examples/compile_errors/variable_shift.zok create mode 100644 zokrates_core/src/static_analysis/shift_checker.rs diff --git a/zokrates_cli/examples/compile_errors/variable_shift.zok b/zokrates_cli/examples/compile_errors/variable_shift.zok new file mode 100644 index 000000000..ea7db3527 --- /dev/null +++ b/zokrates_cli/examples/compile_errors/variable_shift.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> u32: + return a >> b \ No newline at end of file diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 61c287aa1..e3e092381 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -1263,18 +1263,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { box FlatExpression::Sub(box new_left, box new_right), )) } - UExpressionInner::LeftShift(box e, box by) => { - assert_eq!(by.bitwidth(), UBitwidth::B32); - - let by = match by.into_inner() { - UExpressionInner::Value(n) => n, - by => unimplemented!( - "Variable shifts are unimplemented, found {} << {}", - e, - by.annotate(UBitwidth::B32) - ), - }; - + UExpressionInner::LeftShift(box e, by) => { let e = self.flatten_uint_expression(statements_flattened, e); let e_bits = e.bits.unwrap(); @@ -1292,18 +1281,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { .collect::>(), ) } - UExpressionInner::RightShift(box e, box by) => { - assert_eq!(by.bitwidth(), UBitwidth::B32); - - let by = match by.into_inner() { - UExpressionInner::Value(n) => n, - by => unimplemented!( - "Variable shifts are unimplemented, found {} >> {}", - e, - by.annotate(UBitwidth::B32) - ), - }; - + UExpressionInner::RightShift(box e, by) => { let e = self.flatten_uint_expression(statements_flattened, e); let e_bits = e.bits.unwrap(); diff --git a/zokrates_core/src/static_analysis/flatten_complex_types.rs b/zokrates_core/src/static_analysis/flatten_complex_types.rs index ca97b9599..9a902d815 100644 --- a/zokrates_core/src/static_analysis/flatten_complex_types.rs +++ b/zokrates_core/src/static_analysis/flatten_complex_types.rs @@ -855,15 +855,23 @@ pub fn fold_uint_expression_inner<'ast, T: Field>( } typed_absy::UExpressionInner::LeftShift(box e, box by) => { let e = f.fold_uint_expression(e); - let by = f.fold_uint_expression(by); - zir::UExpressionInner::LeftShift(box e, box by) + let by = match by.as_inner() { + typed_absy::UExpressionInner::Value(by) => by, + _ => unreachable!("static analysis should have made sure that this is constant"), + }; + + zir::UExpressionInner::LeftShift(box e, *by as u32) } typed_absy::UExpressionInner::RightShift(box e, box by) => { let e = f.fold_uint_expression(e); - let by = f.fold_uint_expression(by); - zir::UExpressionInner::RightShift(box e, box by) + let by = match by.as_inner() { + typed_absy::UExpressionInner::Value(by) => by, + _ => unreachable!("static analysis should have made sure that this is constant"), + }; + + zir::UExpressionInner::RightShift(box e, *by as u32) } typed_absy::UExpressionInner::Not(box e) => { let e = f.fold_uint_expression(e); diff --git a/zokrates_core/src/static_analysis/mod.rs b/zokrates_core/src/static_analysis/mod.rs index 7768ba56f..e30c5e54c 100644 --- a/zokrates_core/src/static_analysis/mod.rs +++ b/zokrates_core/src/static_analysis/mod.rs @@ -10,6 +10,7 @@ mod flatten_complex_types; mod propagation; mod redefinition; mod reducer; +mod shift_checker; mod uint_optimizer; mod unconstrained_vars; mod variable_read_remover; @@ -20,6 +21,7 @@ use self::flatten_complex_types::Flattener; use self::propagation::Propagator; use self::redefinition::RedefinitionOptimizer; use self::reducer::reduce_program; +use self::shift_checker::ShiftChecker; use self::uint_optimizer::UintOptimizer; use self::unconstrained_vars::UnconstrainedVariableDetector; use self::variable_read_remover::VariableReadRemover; @@ -85,6 +87,8 @@ impl<'ast, T: Field> TypedProgram<'ast, T> { let r = VariableReadRemover::apply(r); // check array accesses are in bounds let r = BoundsChecker::check(r).map_err(Error::from)?; + // detect non constant shifts + let r = ShiftChecker::check(r).map_err(Error::from)?; // convert to zir, removing complex types let zir = Flattener::flatten(r); // optimize uint expressions diff --git a/zokrates_core/src/static_analysis/shift_checker.rs b/zokrates_core/src/static_analysis/shift_checker.rs new file mode 100644 index 000000000..7e44ea525 --- /dev/null +++ b/zokrates_core/src/static_analysis/shift_checker.rs @@ -0,0 +1,55 @@ +use crate::typed_absy::TypedProgram; +use crate::typed_absy::{ + result_folder::fold_uint_expression_inner, result_folder::ResultFolder, UBitwidth, + UExpressionInner, +}; +use zokrates_field::Field; +pub struct ShiftChecker; + +impl ShiftChecker { + pub fn check(p: TypedProgram) -> Result, Error> { + ShiftChecker.fold_program(p) + } +} + +pub type Error = String; + +impl<'ast, T: Field> ResultFolder<'ast, T> for ShiftChecker { + type Error = Error; + + fn fold_uint_expression_inner( + &mut self, + bitwidth: UBitwidth, + e: UExpressionInner<'ast, T>, + ) -> Result, Error> { + match e { + UExpressionInner::LeftShift(box e, box by) => { + let e = self.fold_uint_expression(e)?; + let by = self.fold_uint_expression(by)?; + + match by.as_inner() { + UExpressionInner::Value(_) => Ok(UExpressionInner::LeftShift(box e, box by)), + by => Err(format!( + "Cannot shift by a variable value, found `{} << {}`", + e, + by.clone().annotate(UBitwidth::B32) + )), + } + } + UExpressionInner::RightShift(box e, box by) => { + let e = self.fold_uint_expression(e)?; + let by = self.fold_uint_expression(by)?; + + match by.as_inner() { + UExpressionInner::Value(_) => Ok(UExpressionInner::RightShift(box e, box by)), + by => Err(format!( + "Cannot shift by a variable value, found `{} >> {}`", + e, + by.clone().annotate(UBitwidth::B32) + )), + } + } + e => fold_uint_expression_inner(self, bitwidth, e), + } + } +} diff --git a/zokrates_core/src/static_analysis/uint_optimizer.rs b/zokrates_core/src/static_analysis/uint_optimizer.rs index 10296a203..a257a4891 100644 --- a/zokrates_core/src/static_analysis/uint_optimizer.rs +++ b/zokrates_core/src/static_analysis/uint_optimizer.rs @@ -314,19 +314,10 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { .annotate(range) .with_max(range_max) } - LeftShift(box e, box by) => { + LeftShift(box e, by) => { // reduce both terms let e = self.fold_uint_expression(e); - let by = self.fold_uint_expression(by); - let by_max: u128 = by - .metadata - .clone() - .unwrap() - .max - .to_dec_string() - .parse() - .unwrap(); let e_max: u128 = e .metadata .clone() @@ -336,20 +327,13 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { .parse() .unwrap(); - let max = T::from((e_max << by_max) & (2_u128.pow(range as u32) - 1)); + let max = T::from((e_max << by) & (2_u128.pow(range as u32) - 1)); - UExpression::left_shift(force_reduce(e), force_reduce(by)).with_max(max) + UExpression::left_shift(force_reduce(e), by).with_max(max) } - RightShift(box e, box by) => { + RightShift(box e, by) => { // reduce both terms let e = self.fold_uint_expression(e); - let by = self.fold_uint_expression(by); - - // if we don't know the amount by which we shift, the most conservative case (which leads to the biggest value) is 0 - let by_u = match by.as_inner() { - UExpressionInner::Value(by) => *by, - _ => 0, - }; let e_max: u128 = e .metadata @@ -360,11 +344,11 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { .parse() .unwrap(); - let max = (e_max & (2_u128.pow(range as u32) - 1)) >> by_u; + let max = (e_max & (2_u128.pow(range as u32) - 1)) >> by; let max = T::from(max); - UExpression::right_shift(force_reduce(e), force_reduce(by)).with_max(max) + UExpression::right_shift(force_reduce(e), by).with_max(max) } IfElse(box condition, box consequence, box alternative) => { let condition = self.fold_boolean_expression(condition); @@ -694,30 +678,14 @@ mod tests { #[test] fn right_shift() { - // left argument in range, we reduce (no effect) and the max is the original max, as we could be shifting by 0 - uint_test!(0xff_u32, true, 2, true, right_shift, 0xff_u32); - uint_test!(2, true, 2, true, right_shift, 2_u32); - - // left argument out of range, we reduce and the max is the type max, shifted - uint_test!( - 0xffffffffffff_u128, - true, - 2, - true, - right_shift, - 0xffffffff_u32 - ); - fn right_shift_test(e_max: u128, by: u32, output_max: u32) { let left = e_with_max(e_max); - let right = UExpressionInner::Value(by as u128) - .annotate(crate::zir::types::UBitwidth::B32) - .with_max(by); + let right = by; let left_expected = force_reduce(left.clone()); - let right_expected = force_reduce(right.clone()); + let right_expected = right; assert_eq!( UintOptimizer::new() @@ -733,25 +701,25 @@ mod tests { #[test] fn left_shift() { - uint_test!(0xff_u32, true, 2, true, left_shift, 0xff_u32 << 2); - uint_test!( - 0xffffffff_u32, - true, - 2, - true, - left_shift, - 0xffffffff_u32 << 2 - ); + fn left_shift_test(e_max: u128, by: u32, output_max: u32) { + let left = e_with_max(e_max); - // left argument out of range, we reduce and the max is the type max, shifted - uint_test!( - 0xffffffffffff_u128, - true, - 2, - true, - left_shift, - 0xffffffff_u32 << 2 - ) + let right = by; + + let left_expected = force_reduce(left.clone()); + + let right_expected = right; + + assert_eq!( + UintOptimizer::new() + .fold_uint_expression(UExpression::left_shift(left.clone(), right.clone())), + UExpression::left_shift(left_expected, right_expected).with_max(output_max) + ); + } + + left_shift_test(0xff_u128, 2, 0xff << 2); + left_shift_test(2, 2, 2 << 2); + left_shift_test(0xffffffffffff_u128, 2, 0xffffffff << 2); } #[test] diff --git a/zokrates_core/src/zir/folder.rs b/zokrates_core/src/zir/folder.rs index f82fbee1f..937108965 100644 --- a/zokrates_core/src/zir/folder.rs +++ b/zokrates_core/src/zir/folder.rs @@ -308,17 +308,15 @@ pub fn fold_uint_expression_inner<'ast, T: Field, F: Folder<'ast, T>>( UExpressionInner::Or(box left, box right) } - UExpressionInner::LeftShift(box e, box by) => { + UExpressionInner::LeftShift(box e, by) => { let e = f.fold_uint_expression(e); - let by = f.fold_uint_expression(by); - UExpressionInner::LeftShift(box e, box by) + UExpressionInner::LeftShift(box e, by) } - UExpressionInner::RightShift(box e, box by) => { + UExpressionInner::RightShift(box e, by) => { let e = f.fold_uint_expression(e); - let by = f.fold_uint_expression(by); - UExpressionInner::RightShift(box e, box by) + UExpressionInner::RightShift(box e, by) } UExpressionInner::Not(box e) => { let e = f.fold_uint_expression(e); diff --git a/zokrates_core/src/zir/uint.rs b/zokrates_core/src/zir/uint.rs index 660e4a549..006da33fe 100644 --- a/zokrates_core/src/zir/uint.rs +++ b/zokrates_core/src/zir/uint.rs @@ -57,16 +57,14 @@ impl<'ast, T: Field> UExpression<'ast, T> { UExpressionInner::And(box self, box other).annotate(bitwidth) } - pub fn left_shift(self, by: UExpression<'ast, T>) -> UExpression<'ast, T> { + pub fn left_shift(self, by: u32) -> UExpression<'ast, T> { let bitwidth = self.bitwidth; - assert_eq!(by.bitwidth(), UBitwidth::B32); - UExpressionInner::LeftShift(box self, box by).annotate(bitwidth) + UExpressionInner::LeftShift(box self, by).annotate(bitwidth) } - pub fn right_shift(self, by: UExpression<'ast, T>) -> UExpression<'ast, T> { + pub fn right_shift(self, by: u32) -> UExpression<'ast, T> { let bitwidth = self.bitwidth; - assert_eq!(by.bitwidth(), UBitwidth::B32); - UExpressionInner::RightShift(box self, box by).annotate(bitwidth) + UExpressionInner::RightShift(box self, by).annotate(bitwidth) } } @@ -170,8 +168,8 @@ pub enum UExpressionInner<'ast, T> { Xor(Box>, Box>), And(Box>, Box>), Or(Box>, Box>), - LeftShift(Box>, Box>), - RightShift(Box>, Box>), + LeftShift(Box>, u32), + RightShift(Box>, u32), Not(Box>), IfElse( Box>, From 7708331d55aa2b690dc043b7a668b36e7a9479a2 Mon Sep 17 00:00:00 2001 From: schaeff Date: Thu, 8 Apr 2021 11:25:26 +0200 Subject: [PATCH 09/95] use for in --- zokrates_core/src/flatten/mod.rs | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 7b7426aaf..aca401750 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -457,12 +457,12 @@ impl<'ast, T: Field> Flattener<'ast, T> { ))); // bitness checks - for i in 0..bit_width { + for bit in e_bits_be.iter().take(bit_width) { statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(e_bits_be[i]), + FlatExpression::Identifier(*bit), FlatExpression::Mult( - box FlatExpression::Identifier(e_bits_be[i]), - box FlatExpression::Identifier(e_bits_be[i]), + box FlatExpression::Identifier(*bit), + box FlatExpression::Identifier(*bit), ), )); } @@ -470,11 +470,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { // bit decomposition check let mut e_sum = FlatExpression::Number(T::from(0)); - for i in 0..bit_width { + for (i, bit) in e_bits_be.iter().take(bit_width).enumerate() { e_sum = FlatExpression::Add( box e_sum, box FlatExpression::Mult( - box FlatExpression::Identifier(e_bits_be[i]), + box FlatExpression::Identifier(*bit), box FlatExpression::Number(T::from(2).pow(bit_width - i - 1)), ), ); @@ -575,12 +575,12 @@ impl<'ast, T: Field> Flattener<'ast, T> { )); // bitness checks - for i in 0..safe_width { + for bit in lhs_bits_be.iter().take(safe_width) { statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(lhs_bits_be[i]), + FlatExpression::Identifier(*bit), FlatExpression::Mult( - box FlatExpression::Identifier(lhs_bits_be[i]), - box FlatExpression::Identifier(lhs_bits_be[i]), + box FlatExpression::Identifier(*bit), + box FlatExpression::Identifier(*bit), ), )); } @@ -588,11 +588,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { // bit decomposition check let mut lhs_sum = FlatExpression::Number(T::from(0)); - for i in 0..safe_width { + for (i, bit) in lhs_bits_be.iter().take(safe_width).enumerate() { lhs_sum = FlatExpression::Add( box lhs_sum, box FlatExpression::Mult( - box FlatExpression::Identifier(lhs_bits_be[i]), + box FlatExpression::Identifier(*bit), box FlatExpression::Number( T::from(2).pow(safe_width - i - 1), ), @@ -625,12 +625,12 @@ impl<'ast, T: Field> Flattener<'ast, T> { )); // bitness checks - for i in 0..safe_width { + for bit in rhs_bits_be.iter().take(safe_width) { statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(rhs_bits_be[i]), + FlatExpression::Identifier(*bit), FlatExpression::Mult( - box FlatExpression::Identifier(rhs_bits_be[i]), - box FlatExpression::Identifier(rhs_bits_be[i]), + box FlatExpression::Identifier(*bit), + box FlatExpression::Identifier(*bit), ), )); } @@ -638,11 +638,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { // bit decomposition check let mut rhs_sum = FlatExpression::Number(T::from(0)); - for i in 0..safe_width { + for (i, bit) in rhs_bits_be.iter().take(safe_width).enumerate() { rhs_sum = FlatExpression::Add( box rhs_sum, box FlatExpression::Mult( - box FlatExpression::Identifier(rhs_bits_be[i]), + box FlatExpression::Identifier(*bit), box FlatExpression::Number( T::from(2).pow(safe_width - i - 1), ), @@ -680,12 +680,12 @@ impl<'ast, T: Field> Flattener<'ast, T> { ))); // bitness checks - for i in 0..bit_width { + for bit in sub_bits_be.iter().take(bit_width) { statements_flattened.push(FlatStatement::Condition( - FlatExpression::Identifier(sub_bits_be[i]), + FlatExpression::Identifier(*bit), FlatExpression::Mult( - box FlatExpression::Identifier(sub_bits_be[i]), - box FlatExpression::Identifier(sub_bits_be[i]), + box FlatExpression::Identifier(*bit), + box FlatExpression::Identifier(*bit), ), )); } @@ -700,11 +700,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { // sum(sym_b{i} * 2**i) let mut expr = FlatExpression::Number(T::from(0)); - for i in 0..bit_width { + for (i, bit) in sub_bits_be.iter().take(bit_width).enumerate() { expr = FlatExpression::Add( box expr, box FlatExpression::Mult( - box FlatExpression::Identifier(sub_bits_be[i]), + box FlatExpression::Identifier(*bit), box FlatExpression::Number(T::from(2).pow(bit_width - i - 1)), ), ); From a5129fb8f03d07f8d695af349976ca6ca94860b8 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 8 Apr 2021 12:00:28 +0200 Subject: [PATCH 10/95] allow underscore before type suffix --- zokrates_parser/src/ace_mode/index.js | 3 ++- zokrates_parser/src/zokrates.pest | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/zokrates_parser/src/ace_mode/index.js b/zokrates_parser/src/ace_mode/index.js index 7855ab53b..ec77a4fbe 100644 --- a/zokrates_parser/src/ace_mode/index.js +++ b/zokrates_parser/src/ace_mode/index.js @@ -45,8 +45,9 @@ ace.define("ace/mode/zokrates_highlight_rules",["require","exports","module","ac }, "identifier"); var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))"; + var decimalSuffix = "(?:_?(?:f|u(?:8|16|32|64)))?"; var hexInteger = "(?:0[xX][\\dA-Fa-f]+)"; - var integer = "(?:" + decimalInteger + "|" + hexInteger + ")\\b"; + var integer = "(?:" + decimalInteger + decimalSuffix "|" + hexInteger + ")\\b"; this.$rules = { "start": [ diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index 50c12fbab..b6fdabc45 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -106,7 +106,7 @@ identifier = @{ ((!keyword ~ ASCII_ALPHA) | (keyword ~ (ASCII_ALPHANUMERIC | "_" literal = { hex_literal | decimal_literal | boolean_literal } -decimal_literal = ${ decimal_number ~ decimal_suffix? } +decimal_literal = ${ decimal_number ~ ("_"? ~ decimal_suffix)? } decimal_number = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } decimal_suffix = { decimal_suffix_u8 | decimal_suffix_u16 | decimal_suffix_u32 | decimal_suffix_u64 | decimal_suffix_field } decimal_suffix_u8 = { "u8" } From 33be94a984f8e658ce0f7c2489c70e91557f93af Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 8 Apr 2021 12:09:59 +0200 Subject: [PATCH 11/95] add changelog --- changelogs/unreleased/800-dark64 | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/800-dark64 diff --git a/changelogs/unreleased/800-dark64 b/changelogs/unreleased/800-dark64 new file mode 100644 index 000000000..36b13d678 --- /dev/null +++ b/changelogs/unreleased/800-dark64 @@ -0,0 +1 @@ +Allow optional underscore before type suffix (e.g. `42_u32`) \ No newline at end of file From b21e2e5a2bc371ac6c3ed18df4202fee827c7283 Mon Sep 17 00:00:00 2001 From: dark64 Date: Fri, 9 Apr 2021 22:56:32 +0200 Subject: [PATCH 12/95] add poseidon hash to stdlib --- .../stdlib/hashes/poseidon/constants.zok | 2082 +++++++++++++++++ .../stdlib/hashes/poseidon/poseidon.zok | 47 + .../tests/hashes/poseidon/poseidon_1.json | 25 + .../tests/hashes/poseidon/poseidon_1.zok | 7 + .../tests/hashes/poseidon/poseidon_2.json | 15 + .../tests/hashes/poseidon/poseidon_2.zok | 7 + .../tests/hashes/poseidon/poseidon_3.json | 15 + .../tests/hashes/poseidon/poseidon_3.zok | 7 + .../tests/hashes/poseidon/poseidon_4.json | 15 + .../tests/hashes/poseidon/poseidon_4.zok | 7 + .../tests/hashes/poseidon/poseidon_5.json | 35 + .../tests/hashes/poseidon/poseidon_5.zok | 7 + .../tests/hashes/poseidon/poseidon_6.json | 35 + .../tests/hashes/poseidon/poseidon_6.zok | 7 + 14 files changed, 2311 insertions(+) create mode 100644 zokrates_stdlib/stdlib/hashes/poseidon/constants.zok create mode 100644 zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.json create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.json create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.json create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.json create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.json create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.json create mode 100644 zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok diff --git a/zokrates_stdlib/stdlib/hashes/poseidon/constants.zok b/zokrates_stdlib/stdlib/hashes/poseidon/constants.zok new file mode 100644 index 000000000..4638e52d4 --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/poseidon/constants.zok @@ -0,0 +1,2082 @@ +// t = 2 (1 input), f = 8, p = 56 +// t * (f + p) = 128 +def poseidon_c_1() -> field[128]: + return [ + 4417881134626180770308697923359573201005643519861877412381846989312604493735, + 5433650512959517612316327474713065966758808864213826738576266661723522780033, + 13641176377184356099764086973022553863760045607496549923679278773208775739952, + 17949713444224994136330421782109149544629237834775211751417461773584374506783, + 13765628375339178273710281891027109699578766420463125835325926111705201856003, + 19179513468172002314585757290678967643352171735526887944518845346318719730387, + 5157412437176756884543472904098424903141745259452875378101256928559722612176, + 535160875740282236955320458485730000677124519901643397458212725410971557409, + 1050793453380762984940163090920066886770841063557081906093018330633089036729, + 10665495010329663932664894101216428400933984666065399374198502106997623173873, + 19965634623406616956648724894636666805991993496469370618546874926025059150737, + 13007250030070838431593222885902415182312449212965120303174723305710127422213, + 16877538715074991604507979123743768693428157847423939051086744213162455276374, + 18211747749504876135588847560312685184956239426147543810126553367063157141465, + 18151553319826126919739798892854572062191241985315767086020821632812331245635, + 19957033149976712666746140949846950406660099037474791840946955175819555930825, + 3469514863538261843186854830917934449567467100548474599735384052339577040841, + 989698510043911779243192466312362856042600749099921773896924315611668507708, + 12568377015646290945235387813564567111330046038050864455358059568128000172201, + 20856104135605479600325529349246932565148587186338606236677138505306779314172, + 8206918720503535523121349917159924938835810381723474192155637697065780938424, + 1309058477013932989380617265069188723120054926187607548493110334522527703566, + 14076116939332667074621703729512195584105250395163383769419390236426287710606, + 10153498892749751942204288991871286290442690932856658983589258153608012428674, + 18202499207234128286137597834010475797175973146805180988367589376893530181575, + 12739388830157083522877690211447248168864006284243907142044329113461613743052, + 15123358710467780770838026754240340042441262572309759635224051333176022613949, + 19925004701844594370904593774447343836015483888496504201331110250494635362184, + 10352416606816998476681131583320899030072315953910679608943150613208329645891, + 10567371822366244361703342347428230537114808440249611395507235283708966113221, + 5635498582763880627392290206431559361272660937399944184533035305989295959602, + 11866432933224219174041051738704352719163271639958083608224676028593315904909, + 5795020705294401441272215064554385591292330721703923167136157291459784140431, + 9482202378699252817564375087302794636287866584767523335624368774856230692758, + 4245237636894546151746468406560945873445548423466753843402086544922216329298, + 12000500941313982757584712677991730019124834399479314697467598397927435905133, + 7596790274058425558167520209857956363736666939016807569082239187494363541787, + 2484867918246116343205467273440098378820186751202461278013576281097918148877, + 18312645949449997391810445935615409295369169383463185688973803378104013950190, + 15320686572748723004980855263301182130424010735782762814513954166519592552733, + 12618438900597948888520621062416758747872180395546164387827245287017031303859, + 17438141672027706116733201008397064011774368832458707512367404736905021019585, + 6374197807230665998865688675365359100400438034755781666913068586172586548950, + 2189398913433273865510950346186699930188746169476472274335177556702504595264, + 6268495580028970231803791523870131137294646402347399003576649137450213034606, + 17896250365994900261202920044129628104272791547990619503076839618914047059275, + 13692156312448722528008862371944543449350293305158722920787736248435893008873, + 15234446864368744483209945022439268713300180233589581910497691316744177619376, + 1572426502623310766593681563281600503979671244997798691029595521622402217227, + 80103447810215150918585162168214870083573048458555897999822831203653996617, + 8228820324013669567851850635126713973797711779951230446503353812192849106342, + 5375851433746509614045812476958526065449377558695752132494533666370449415873, + 12115998939203497346386774317892338270561208357481805380546938146796257365018, + 9764067909645821279940531410531154041386008396840887338272986634350423466622, + 8538708244538850542384936174629541085495830544298260335345008245230827876882, + 7140127896620013355910287215441004676619168261422440177712039790284719613114, + 14297402962228458726038826185823085337698917275385741292940049024977027409762, + 6667115556431351074165934212337261254608231545257434281887966406956835140819, + 20226761165244293291042617464655196752671169026542832236139342122602741090001, + 12038289506489256655759141386763477208196694421666339040483042079632134429119, + 19027757334170818571203982241812412991528769934917288000224335655934473717551, + 16272152964456553579565580463468069884359929612321610357528838696790370074720, + 2500392889689246014710135696485946334448570271481948765283016105301740284071, + 8595254970528530312401637448610398388203855633951264114100575485022581946023, + 11635945688914011450976408058407206367914559009113158286982919675551688078198, + 614739068603482619581328040478536306925147663946742687395148680260956671871, + 18692271780377861570175282183255720350972693125537599213951106550953176268753, + 4987059230784976306647166378298632695585915319042844495357753339378260807164, + 21851403978498723616722415377430107676258664746210815234490134600998983955497, + 9830635451186415300891533983087800047564037813328875992115573428596207326204, + 4842706106434537116860242620706030229206345167233200482994958847436425185478, + 6422235064906823218421386871122109085799298052314922856340127798647926126490, + 4564364104986856861943331689105797031330091877115997069096365671501473357846, + 1944043894089780613038197112872830569538541856657037469098448708685350671343, + 21179865974855950600518216085229498748425990426231530451599322283119880194955, + 14296697761894107574369608843560006996183955751502547883167824879840894933162, + 12274619649702218570450581712439138337725246879938860735460378251639845671898, + 16371396450276899401411886674029075408418848209575273031725505038938314070356, + 3702561221750983937578095019779188631407216522704543451228773892695044653565, + 19721616877735564664624984774636557499099875603996426215495516594530838681980, + 6383350109027696789969911008057747025018308755462287526819231672217685282429, + 20860583956177367265984596617324237471765572961978977333122281041544719622905, + 5766390934595026947545001478457407504285452477687752470140790011329357286275, + 4043175758319898049344746138515323336207420888499903387536875603879441092484, + 15579382179133608217098622223834161692266188678101563820988612253342538956534, + 1864640783252634743892105383926602930909039567065240010338908865509831749824, + 15943719865023133586707144161652035291705809358178262514871056013754142625673, + 2326415993032390211558498780803238091925402878871059708106213703504162832999, + 19995326402773833553207196590622808505547443523750970375738981396588337910289, + 5143583711361588952673350526320181330406047695593201009385718506918735286622, + 15436006486881920976813738625999473183944244531070780793506388892313517319583, + 16660446760173633166698660166238066533278664023818938868110282615200613695857, + 4966065365695755376133119391352131079892396024584848298231004326013366253934, + 20683781957411705574951987677641476019618457561419278856689645563561076926702, + 17280836839165902792086432296371645107551519324565649849400948918605456875699, + 17045635513701208892073056357048619435743564064921155892004135325530808465371, + 17055032967194400710390142791334572297458033582458169295920670679093585707295, + 15727174639569115300068198908071514334002742825679221638729902577962862163505, + 1001755657610446661315902885492677747789366510875120894840818704741370398633, + 18638547332826171619311285502376343504539399518545103511265465604926625041234, + 6751954224763196429755298529194402870632445298969935050224267844020826420799, + 3526747115904224771452549517614107688674036840088422555827581348280834879405, + 15705897908180497062880001271426561999724005008972544196300715293701537574122, + 574386695213920937259007343820417029802510752426579750428758189312416867750, + 15973040855000600860816974646787367136127946402908768408978806375685439868553, + 20934130413948796333037139460875996342810005558806621330680156931816867321122, + 6918585327145564636398173845411579411526758237572034236476079610890705810764, + 14158163500813182062258176233162498241310167509137716527054939926126453647182, + 4164602626597695668474100217150111342272610479949122406544277384862187287433, + 12146526846507496913615390662823936206892812880963914267275606265272996025304, + 10153527926900017763244212043512822363696541810586522108597162891799345289938, + 13564663485965299104296214940873270349072051793008946663855767889066202733588, + 5612449256997576125867742696783020582952387615430650198777254717398552960096, + 12151885480032032868507892738683067544172874895736290365318623681886999930120, + 380452237704664384810613424095477896605414037288009963200982915188629772177, + 9067557551252570188533509616805287919563636482030947363841198066124642069518, + 21280306817619711661335268484199763923870315733198162896599997188206277056900, + 5567165819557297006750252582140767993422097822227408837378089569369734876257, + 10411936321072105429908396649383171465939606386380071222095155850987201580137, + 21338390051413922944780864872652000187403217966653363270851298678606449622266, + 12156296560457833712186127325312904760045212412680904475497938949653569234473, + 4271647814574748734312113971565139132510281260328947438246615707172526380757, + 9061738206062369647211128232833114177054715885442782773131292534862178874950, + 10134551893627587797380445583959894183158393780166496661696555422178052339133, + 8932270237664043612366044102088319242789325050842783721780970129656616386103, + 3339412934966886386194449782756711637636784424032779155216609410591712750636, + 9704903972004596791086522314847373103670545861209569267884026709445485704400, + 17467570179597572575614276429760169990940929887711661192333523245667228809456 + ] + +// t = 3 (2 inputs), f = 8, p = 57 +// t * (f + p) = 195 +def poseidon_c_2() -> field[195]: + return [ + 6745197990210204598374042828761989596302876299545964402857411729872131034734, + 426281677759936592021316809065178817848084678679510574715894138690250139748, + 4014188762916583598888942667424965430287497824629657219807941460227372577781, + 21328925083209914769191926116470334003273872494252651254811226518870906634704, + 19525217621804205041825319248827370085205895195618474548469181956339322154226, + 1402547928439424661186498190603111095981986484908825517071607587179649375482, + 18320863691943690091503704046057443633081959680694199244583676572077409194605, + 17709820605501892134371743295301255810542620360751268064484461849423726103416, + 15970119011175710804034336110979394557344217932580634635707518729185096681010, + 9818625905832534778628436765635714771300533913823445439412501514317783880744, + 6235167673500273618358172865171408902079591030551453531218774338170981503478, + 12575685815457815780909564540589853169226710664203625668068862277336357031324, + 7381963244739421891665696965695211188125933529845348367882277882370864309593, + 14214782117460029685087903971105962785460806586237411939435376993762368956406, + 13382692957873425730537487257409819532582973556007555550953772737680185788165, + 2203881792421502412097043743980777162333765109810562102330023625047867378813, + 2916799379096386059941979057020673941967403377243798575982519638429287573544, + 4341714036313630002881786446132415875360643644216758539961571543427269293497, + 2340590164268886572738332390117165591168622939528604352383836760095320678310, + 5222233506067684445011741833180208249846813936652202885155168684515636170204, + 7963328565263035669460582454204125526132426321764384712313576357234706922961, + 1394121618978136816716817287892553782094854454366447781505650417569234586889, + 20251767894547536128245030306810919879363877532719496013176573522769484883301, + 141695147295366035069589946372747683366709960920818122842195372849143476473, + 15919677773886738212551540894030218900525794162097204800782557234189587084981, + 2616624285043480955310772600732442182691089413248613225596630696960447611520, + 4740655602437503003625476760295930165628853341577914460831224100471301981787, + 19201590924623513311141753466125212569043677014481753075022686585593991810752, + 12116486795864712158501385780203500958268173542001460756053597574143933465696, + 8481222075475748672358154589993007112877289817336436741649507712124418867136, + 5181207870440376967537721398591028675236553829547043817076573656878024336014, + 1576305643467537308202593927724028147293702201461402534316403041563704263752, + 2555752030748925341265856133642532487884589978209403118872788051695546807407, + 18840924862590752659304250828416640310422888056457367520753407434927494649454, + 14593453114436356872569019099482380600010961031449147888385564231161572479535, + 20826991704411880672028799007667199259549645488279985687894219600551387252871, + 9159011389589751902277217485643457078922343616356921337993871236707687166408, + 5605846325255071220412087261490782205304876403716989785167758520729893194481, + 1148784255964739709393622058074925404369763692117037208398835319441214134867, + 20945896491956417459309978192328611958993484165135279604807006821513499894540, + 229312996389666104692157009189660162223783309871515463857687414818018508814, + 21184391300727296923488439338697060571987191396173649012875080956309403646776, + 21853424399738097885762888601689700621597911601971608617330124755808946442758, + 12776298811140222029408960445729157525018582422120161448937390282915768616621, + 7556638921712565671493830639474905252516049452878366640087648712509680826732, + 19042212131548710076857572964084011858520620377048961573689299061399932349935, + 12871359356889933725034558434803294882039795794349132643274844130484166679697, + 3313271555224009399457959221795880655466141771467177849716499564904543504032, + 15080780006046305940429266707255063673138269243146576829483541808378091931472, + 21300668809180077730195066774916591829321297484129506780637389508430384679582, + 20480395468049323836126447690964858840772494303543046543729776750771407319822, + 10034492246236387932307199011778078115444704411143703430822959320969550003883, + 19584962776865783763416938001503258436032522042569001300175637333222729790225, + 20155726818439649091211122042505326538030503429443841583127932647435472711802, + 13313554736139368941495919643765094930693458639277286513236143495391474916777, + 14606609055603079181113315307204024259649959674048912770003912154260692161833, + 5563317320536360357019805881367133322562055054443943486481491020841431450882, + 10535419877021741166931390532371024954143141727751832596925779759801808223060, + 12025323200952647772051708095132262602424463606315130667435888188024371598063, + 2906495834492762782415522961458044920178260121151056598901462871824771097354, + 19131970618309428864375891649512521128588657129006772405220584460225143887876, + 8896386073442729425831367074375892129571226824899294414632856215758860965449, + 7748212315898910829925509969895667732958278025359537472413515465768989125274, + 422974903473869924285294686399247660575841594104291551918957116218939002865, + 6398251826151191010634405259351528880538837895394722626439957170031528482771, + 18978082967849498068717608127246258727629855559346799025101476822814831852169, + 19150742296744826773994641927898928595714611370355487304294875666791554590142, + 12896891575271590393203506752066427004153880610948642373943666975402674068209, + 9546270356416926575977159110423162512143435321217584886616658624852959369669, + 2159256158967802519099187112783460402410585039950369442740637803310736339200, + 8911064487437952102278704807713767893452045491852457406400757953039127292263, + 745203718271072817124702263707270113474103371777640557877379939715613501668, + 19313999467876585876087962875809436559985619524211587308123441305315685710594, + 13254105126478921521101199309550428567648131468564858698707378705299481802310, + 1842081783060652110083740461228060164332599013503094142244413855982571335453, + 9630707582521938235113899367442877106957117302212260601089037887382200262598, + 5066637850921463603001689152130702510691309665971848984551789224031532240292, + 4222575506342961001052323857466868245596202202118237252286417317084494678062, + 2919565560395273474653456663643621058897649501626354982855207508310069954086, + 6828792324689892364977311977277548750189770865063718432946006481461319858171, + 2245543836264212411244499299744964607957732316191654500700776604707526766099, + 19602444885919216544870739287153239096493385668743835386720501338355679311704, + 8239538512351936341605373169291864076963368674911219628966947078336484944367, + 15053013456316196458870481299866861595818749671771356646798978105863499965417, + 7173615418515925804810790963571435428017065786053377450925733428353831789901, + 8239211677777829016346247446855147819062679124993100113886842075069166957042, + 15330855478780269194281285878526984092296288422420009233557393252489043181621, + 10014883178425964324400942419088813432808659204697623248101862794157084619079, + 14014440630268834826103915635277409547403899966106389064645466381170788813506, + 3580284508947993352601712737893796312152276667249521401778537893620670305946, + 2559754020964039399020874042785294258009596917335212876725104742182177996988, + 14898657953331064524657146359621913343900897440154577299309964768812788279359, + 2094037260225570753385567402013028115218264157081728958845544426054943497065, + 18051086536715129874440142649831636862614413764019212222493256578581754875930, + 21680659279808524976004872421382255670910633119979692059689680820959727969489, + 13950668739013333802529221454188102772764935019081479852094403697438884885176, + 9703845704528288130475698300068368924202959408694460208903346143576482802458, + 12064310080154762977097567536495874701200266107682637369509532768346427148165, + 16970760937630487134309762150133050221647250855182482010338640862111040175223, + 9790997389841527686594908620011261506072956332346095631818178387333642218087, + 16314772317774781682315680698375079500119933343877658265473913556101283387175, + 82044870826814863425230825851780076663078706675282523830353041968943811739, + 21696416499108261787701615667919260888528264686979598953977501999747075085778, + 327771579314982889069767086599893095509690747425186236545716715062234528958, + 4606746338794869835346679399457321301521448510419912225455957310754258695442, + 64499140292086295251085369317820027058256893294990556166497635237544139149, + 10455028514626281809317431738697215395754892241565963900707779591201786416553, + 10421411526406559029881814534127830959833724368842872558146891658647152404488, + 18848084335930758908929996602136129516563864917028006334090900573158639401697, + 13844582069112758573505569452838731733665881813247931940917033313637916625267, + 13488838454403536473492810836925746129625931018303120152441617863324950564617, + 15742141787658576773362201234656079648895020623294182888893044264221895077688, + 6756884846734501741323584200608866954194124526254904154220230538416015199997, + 7860026400080412708388991924996537435137213401947704476935669541906823414404, + 7871040688194276447149361970364037034145427598711982334898258974993423182255, + 20758972836260983284101736686981180669442461217558708348216227791678564394086, + 21723241881201839361054939276225528403036494340235482225557493179929400043949, + 19428469330241922173653014973246050805326196062205770999171646238586440011910, + 7969200143746252148180468265998213908636952110398450526104077406933642389443, + 10950417916542216146808986264475443189195561844878185034086477052349738113024, + 18149233917533571579549129116652755182249709970669448788972210488823719849654, + 3729796741814967444466779622727009306670204996071028061336690366291718751463, + 5172504399789702452458550583224415301790558941194337190035441508103183388987, + 6686473297578275808822003704722284278892335730899287687997898239052863590235, + 19426913098142877404613120616123695099909113097119499573837343516470853338513, + 5120337081764243150760446206763109494847464512045895114970710519826059751800, + 5055737465570446530938379301905385631528718027725177854815404507095601126720, + 14235578612970484492268974539959119923625505766550088220840324058885914976980, + 653592517890187950103239281291172267359747551606210609563961204572842639923, + 5507360526092411682502736946959369987101940689834541471605074817375175870579, + 7864202866011437199771472205361912625244234597659755013419363091895334445453, + 21294659996736305811805196472076519801392453844037698272479731199885739891648, + 13767183507040326119772335839274719411331242166231012705169069242737428254651, + 810181532076738148308457416289197585577119693706380535394811298325092337781, + 14232321930654703053193240133923161848171310212544136614525040874814292190478, + 16796904728299128263054838299534612533844352058851230375569421467352578781209, + 16256310366973209550759123431979563367001604350120872788217761535379268327259, + 19791658638819031543640174069980007021961272701723090073894685478509001321817, + 7046232469803978873754056165670086532908888046886780200907660308846356865119, + 16001732848952745747636754668380555263330934909183814105655567108556497219752, + 9737276123084413897604802930591512772593843242069849260396983774140735981896, + 11410895086919039954381533622971292904413121053792570364694836768885182251535, + 19098362474249267294548762387533474746422711206129028436248281690105483603471, + 11013788190750472643548844759298623898218957233582881400726340624764440203586, + 2206958256327295151076063922661677909471794458896944583339625762978736821035, + 7171889270225471948987523104033632910444398328090760036609063776968837717795, + 2510237900514902891152324520472140114359583819338640775472608119384714834368, + 8825275525296082671615660088137472022727508654813239986303576303490504107418, + 1481125575303576470988538039195271612778457110700618040436600537924912146613, + 16268684562967416784133317570130804847322980788316762518215429249893668424280, + 4681491452239189664806745521067158092729838954919425311759965958272644506354, + 3131438137839074317765338377823608627360421824842227925080193892542578675835, + 7930402370812046914611776451748034256998580373012248216998696754202474945793, + 8973151117361309058790078507956716669068786070949641445408234962176963060145, + 10223139291409280771165469989652431067575076252562753663259473331031932716923, + 2232089286698717316374057160056566551249777684520809735680538268209217819725, + 16930089744400890347392540468934821520000065594669279286854302439710657571308, + 21739597952486540111798430281275997558482064077591840966152905690279247146674, + 7508315029150148468008716674010060103310093296969466203204862163743615534994, + 11418894863682894988747041469969889669847284797234703818032750410328384432224, + 10895338268862022698088163806301557188640023613155321294365781481663489837917, + 18644184384117747990653304688839904082421784959872380449968500304556054962449, + 7414443845282852488299349772251184564170443662081877445177167932875038836497, + 5391299369598751507276083947272874512197023231529277107201098701900193273851, + 10329906873896253554985208009869159014028187242848161393978194008068001342262, + 4711719500416619550464783480084256452493890461073147512131129596065578741786, + 11943219201565014805519989716407790139241726526989183705078747065985453201504, + 4298705349772984837150885571712355513879480272326239023123910904259614053334, + 9999044003322463509208400801275356671266978396985433172455084837770460579627, + 4908416131442887573991189028182614782884545304889259793974797565686968097291, + 11963412684806827200577486696316210731159599844307091475104710684559519773777, + 20129916000261129180023520480843084814481184380399868943565043864970719708502, + 12884788430473747619080473633364244616344003003135883061507342348586143092592, + 20286808211545908191036106582330883564479538831989852602050135926112143921015, + 16282045180030846845043407450751207026423331632332114205316676731302016331498, + 4332932669439410887701725251009073017227450696965904037736403407953448682093, + 11105712698773407689561953778861118250080830258196150686012791790342360778288, + 21853934471586954540926699232107176721894655187276984175226220218852955976831, + 9807888223112768841912392164376763820266226276821186661925633831143729724792, + 13411808896854134882869416756427789378942943805153730705795307450368858622668, + 17906847067500673080192335286161014930416613104209700445088168479205894040011, + 14554387648466176616800733804942239711702169161888492380425023505790070369632, + 4264116751358967409634966292436919795665643055548061693088119780787376143967, + 2401104597023440271473786738539405349187326308074330930748109868990675625380, + 12251645483867233248963286274239998200789646392205783056343767189806123148785, + 15331181254680049984374210433775713530849624954688899814297733641575188164316, + 13108834590369183125338853868477110922788848506677889928217413952560148766472, + 6843160824078397950058285123048455551935389277899379615286104657075620692224, + 10151103286206275742153883485231683504642432930275602063393479013696349676320, + 7074320081443088514060123546121507442501369977071685257650287261047855962224, + 11413928794424774638606755585641504971720734248726394295158115188173278890938, + 7312756097842145322667451519888915975561412209738441762091369106604423801080, + 7181677521425162567568557182629489303281861794357882492140051324529826589361, + 15123155547166304758320442783720138372005699143801247333941013553002921430306, + 13409242754315411433193860530743374419854094495153957441316635981078068351329 + ] + +// t = 4 (3 inputs), f = 8, p = 56 +// t * (f + p) = 256 +def poseidon_c_3() -> field[256]: + return [ + 11633431549750490989983886834189948010834808234699737327785600195936805266405, + 17353750182810071758476407404624088842693631054828301270920107619055744005334, + 11575173631114898451293296430061690731976535592475236587664058405912382527658, + 9724643380371653925020965751082872123058642683375812487991079305063678725624, + 20936725237749945635418633443468987188819556232926135747685274666391889856770, + 6427758822462294912934022562310355233516927282963039741999349770315205779230, + 16782979953202249973699352594809882974187694538612412531558950864304931387798, + 8979171037234948998646722737761679613767384188475887657669871981433930833742, + 5428827536651017352121626533783677797977876323745420084354839999137145767736, + 507241738797493565802569310165979445570507129759637903167193063764556368390, + 6711578168107599474498163409443059675558516582274824463959700553865920673097, + 2197359304646916921018958991647650011119043556688567376178243393652789311643, + 4634703622846121403803831560584049007806112989824652272428991253572845447400, + 17008376818199175111793852447685303011746023680921106348278379453039148937791, + 18430784755956196942937899353653692286521408688385681805132578732731487278753, + 4573768376486344895797915946239137669624900197544620153250805961657870918727, + 5624865188680173294191042415227598609140934495743721047183803859030618890703, + 8228252753786907198149068514193371173033070694924002912950645971088002709521, + 17586714789554691446538331362711502394998837215506284064347036653995353304693, + 12985198716830497423350597750558817467658937953000235442251074063454897365701, + 13480076116139680784838493959937969792577589073830107110893279354229821035984, + 480609231761423388761863647137314056373740727639536352979673303078459561332, + 19503345496799249258956440299354839375920540225688429628121751361906635419276, + 16837818502122887883669221005435922946567532037624537243846974433811447595173, + 5492108497278641078569490709794391352213168666744080628008171695469579703581, + 11365311159988448419785032079155356000691294261495515880484003277443744617083, + 13876891705632851072613751905778242936713392247975808888614530203269491723653, + 10660388389107698747692475159023710744797290186015856503629656779989214850043, + 18876318870401623474401728758498150977988613254023317877612912724282285739292, + 15543349138237018307536452195922365893694804703361435879256942490123776892424, + 2839988449157209999638903652853828318645773519300826410959678570041742458201, + 7566039810305694135184226097163626060317478635973510706368412858136696413063, + 6344830340705033582410486810600848473125256338903726340728639711688240744220, + 12475357769019880256619207099578191648078162511547701737481203260317463892731, + 13337401254840718303633782478677852514218549070508887338718446132574012311307, + 21161869193849404954234950798647336336709035097706159414187214758702055364571, + 20671052961616073313397254362345395594858011165315285344464242404604146448678, + 2772189387845778213446441819361180378678387127454165972767013098872140927416, + 3339032002224218054945450150550795352855387702520990006196627537441898997147, + 14919705931281848425960108279746818433850049439186607267862213649460469542157, + 17056699976793486403099510941807022658662936611123286147276760381688934087770, + 16144580075268719403964467603213740327573316872987042261854346306108421013323, + 15582343953927413680541644067712456296539774919658221087452235772880573393376, + 17528510080741946423534916423363640132610906812668323263058626230135522155749, + 3190600034239022251529646836642735752388641846393941612827022280601486805721, + 8463814172152682468446984305780323150741498069701538916468821815030498611418, + 16533435971270903741871235576178437313873873358463959658178441562520661055273, + 11845696835505436397913764735273748291716405946246049903478361223369666046634, + 18391057370973634202531308463652130631065370546571735004701144829951670507215, + 262537877325812689820791215463881982531707709719292538608229687240243203710, + 2187234489894387585309965540987639130975753519805550941279098789852422770021, + 19189656350920455659006418422409390013967064310525314160026356916172976152967, + 15839474183930359560478122372067744245080413846070743460407578046890458719219, + 1805019124769763805045852541831585930225376844141668951787801647576910524592, + 323592203814803486950280155834638828455175703393817797003361354810251742052, + 9780393509796825017346015868945480913627956475147371732521398519483580624282, + 14009429785059642386335012561867511048847749030947687313594053997432177705759, + 13749550162460745037234826077137388777330401847577727796245150843898019635981, + 19497187499283431845443758879472819384797584633472792651343926414232528405311, + 3708428802547661961864524194762556064568867603968214870300574294082023305587, + 1339414413482882567499652761996854155383863472782829777976929310155400981782, + 6396261245879814100794661157306877072718690153118140891315137894471052482309, + 2069661495404347929962833138824526893650803079024564477269192079629046031674, + 15793521554502133342917616035884588152451122589545915605459159078589855944361, + 17053424498357819626596285492499512504457128907932827007302385782133229252374, + 13658536470391360399708067455536748955260723760813498481671323619545320978896, + 21546095668130239633971575351786704948662094117932406102037724221634677838565, + 21411726238386979516934941789127061362496195649331822900487557574597304399109, + 1944776378988765673004063363506638781964264107780425928778257145151172817981, + 15590719714223718537172639598316570285163081746016049278954513732528516468773, + 1351266421179051765004709939353170430290500926943038391678843253157009556309, + 6772476224477167317130064764757502335545080109882028900432703947986275397548, + 10670120969725161535937685539136065944959698664551200616467222887025111751992, + 4731853626374224678749618809759140702342195350742653173378450474772131006181, + 14473527495914528513885847341981310373531349450901830749157165104135412062812, + 16937191362061486658876740597821783333355021670608822932942683228741190786143, + 5656559696428674390125424316117443507583679061659043998559560535270557939546, + 8897648276515725841133578021896617755369443750194849587616503841335248902806, + 14938684446722672719637788054570691068799510611164812175626676768545923371470, + 15284149043690546115252102390417391226617211133644099356880071475803043461465, + 2623479025068612775740107497276979457946709347831661908218182874823658838107, + 6809791961761836061129379546794905411734858375517368211894790874813684813988, + 2417620338751920563196799065781703780495622795713803712576790485412779971775, + 4445143310792944321746901285176579692343442786777464604312772017806735512661, + 1429019233589939118995503267516676481141938536269008901607126781291273208629, + 19874283200702583165110559932895904979843482162236139561356679724680604144459, + 13426632171723830006915194799390005513190035492503509233177687891041405113055, + 10582332261829184460912611488470654685922576576939233092337240630493625631748, + 21233753931561918964692715735079738969202507286592442257083521969358109931739, + 15570526832729960536088203016939646235070527502823725736220985057263010426410, + 9379993197409194016084018867205217180276068758980710078281820842068357746159, + 20771047769547788232530761122022227554484215799917531852224053856574439035591, + 20468066117407230615347036860121267564735050776924839007390915936603720868039, + 5488458379783632930817704196671117722181776789793038046303454621235628350505, + 1394272944960494549436156060041871735938329188644910029274839018389507786995, + 5147716541319265558364686380685869814344975511061045836883803841066664401308, + 14583556014436264794011679557180458872925270147116325433110111823036572987256, + 11881598145635709076820802010238799308467020773223027240974808290357539410246, + 1566675577370566803714158020143436746360531503329117352692311127363508063658, + 212097210828847555076368799807292486212366234848453077606919035866276438405, + 7447795983723838393344606913699113402588250391491430720006009618589586043349, + 7626475329478847982857743246276194948757851985510858890691733676098590062312, + 148936322117705719734052984176402258788283488576388928671173547788498414614, + 15456385653678559339152734484033356164266089951521103188900320352052358038156, + 18207029603568083031075933940507782729612798852390383193518574746240484434885, + 2783356767974552799246444090988849933848968900471538294757665724820698962027, + 2721136724873145834448711197875719736776242904173494370334510875996324906822, + 2101139679159828164567502977338446902934095964116292264803779234163802308621, + 8995221857405946029753863203034191016106353727035116779995228902499254557482, + 502050382895618998241481591846956281507455925731652006822624065608151015665, + 4998642074447347292230083981705092465562944918178587362047610976950173759150, + 9349925422548495396957991080641322437286312278286826683803695584372829655908, + 11780347248050333407713097022607360765169543706092266937432199545936788840710, + 17875657248128792902343900636176628524337469245418171053476833541334867949063, + 10366707960411170224546487410133378396211437543372531210718212258701730218585, + 16918708725327525329474486073529093971911689155838787615544405646587858805834, + 18845394288827839099791436411179859406694814287249240544635770075956540806104, + 9838806160073701591447223014625214979004281138811495046618998465898136914308, + 10285680425916086863571101560978592912547567902925573205991454216988033815759, + 1292119286233210185026381033809498665433650491423040630240164455269575958565, + 2665524343601461489082054230426835550060387413710679950970616347092017688857, + 13502286133892103192305476866434484921895765252706158317341618311553476426306, + 686854655578191041672292972738875170071982317195092845673566320025160026512, + 9315942923163981372372434957632152754092082859001311184186702151150554806508, + 17166793131238158480636170455452575971861309825745828685724097210995239015581, + 4443784618760852757287735236046535266034706880634443644576653970979377878608, + 21470445782021672615018345703580059646973568891521510437236903770708690160080, + 6932852445473908850835611723958058203645654625170962537129706393570586565567, + 17078326120157725640173982185667969009350208542843294226397809921509565607842, + 19251873001736801921864956728611772738233338338726553113352118847732921831266, + 13062907978694932362695258750558734366820802962383346229947907261606619788585, + 16576609187793673559170206379939616900133457644695219057683704871664434872406, + 17140499059660867342372156843620845644831519603574612796639429147195776838516, + 16226688173010504218547945848523900236290532501559570164276462499487632388445, + 2806068123803905806401128967330263340459046260107112845068533446899070326517, + 17788735370835052317224182711467216134690146479710634688273650370951230404901, + 9840665370904113434661468973557421114403401847108482949465899631150766783733, + 17357287363046228581837055771327121704742940914150998420465281177406182088510, + 8956082469997974864521346025916496675956939495318858500685756691488425559998, + 10583741436561099911914917245130852199607666337956354910388730829023746895549, + 15241902639811607164983030447109332729761435946009172128089506810551693978973, + 10889882303914055687481932975789161945462141459528413507160087442461090813788, + 19789561133254944544821898921133697408237804586549835559829396563401674817160, + 20741336668287037026472434608739333171202674306575625457456116338034432647230, + 17864073449995977742930566850933082711031717858550870842712972350665650521079, + 6017691253505466300212182439349954426085752315661098358839308909771637792741, + 5209125836207196173669497054522582922896061838702136844305036341250990710540, + 8138726312837322624537330169363664364899441867118983214176695868443641051381, + 15491983986041746833254372934846748393213690608865689646440909282144232382678, + 5054332867608171303802774230688792431028169804536607979111644888500809938980, + 15427030776591294577308915282298854681562344215287630895931797573417982096417, + 21754057982677295571284116502193272661309010996970316384923307174180521790164, + 16265286590463120486705206231835953324076688991892805307349612983237844034032, + 17679791107777049796013011282788633179411040182820636236163074053597517790779, + 4281652562868629887097957174897458165728741859103571825874408386197225591996, + 9168010397863299719604788533602757515513214141450093775967322808686129400625, + 17584182367226175071087689123358883902969885218985589531538416263709138156515, + 15671512310414658663135385639435845966109237059155734764323312289873534719186, + 10536294659491685326297777845632759824567028904726211134518740400643540109527, + 13431319759608247201135260841651365578663315527795431484765940626659812285319, + 9584697124715190200241839387725546204368618031045071660911490086723434692561, + 5180327104839158483066851400960171505063442195966219343315555549982472660055, + 18888217223053385111625483360538133292128748730565502371803782424772027937822, + 19535732913737027522540340630296365525208404217634392013266346283017745945894, + 8577759627886344995887423695190093296190181539234301534326157005220006624466, + 16793670928407147476673650839110019799844249677846432113010280456483595763987, + 13926032620965299897272071104154310460519723329016284975305942957859374938463, + 4794697578055472890255676575927616606591024075768967985031137397587590174501, + 3529566190782060578446859853852791941913086545101307988176595267965876143250, + 3975008029239568933166738482470827494289192118694622729549964538823092192163, + 17739094873244464728483944474780943281491793683051033330476367597242349886622, + 7367136451127531266518046223598095299278392589059366687082785080179161005418, + 11175297939460631138047404082172242706491354303440776362693987984031241399771, + 21687543815463985355165197827968086406938428974327951792877419032069230058777, + 21156136641989461785420005321350884477682466566148802533375726181416623358719, + 17347558768803521970212188258074365309929638984714303299899732035040892048478, + 16293716234695956076322008955071091921491953458541407305955104663269677475740, + 4206144021605871396668976569508168522675546062304959729829228403361714668567, + 19988050626299122864942213847548542155670073758974734015174045163059179151544, + 747972634423324369570795147739377097591383105262743308036321386836856106229, + 4612470951309047869982067912468200581649949743307592869671537990797895413707, + 9630852913694079049153027193127278569487291430069466630362958024525616303220, + 17941539917430916523930519432495442476511211427972760202450248798031711471474, + 20332911350443969653703295317915788278109458962706923653715140186132935894113, + 21764801803055897327474057344100833670291402543384934706514147201527191846513, + 18792043166429470991157980448329308661526906138700725174612608941551872082876, + 12308177224490762720061048892842527800271687977085172836705858261595655154325, + 6234555076867437297776538521925679658360922070165740193866337972293380196151, + 4651047048822067434403056477377459986292934655827821636179452835839127581305, + 4762047093602693619418269784972874862577325737690375448572644958129932507374, + 12373514879531674477721132062882065826558811149582829246378921774344318418269, + 452512704634345955634014968317367844987135264395068376894497483188243356523, + 21642936370936057063268550589361090955573362743817395689260298777690935495218, + 16170209200627740434842090607802586195654207376087117044989637541681675086276, + 11682826760471401430136435257946377996085824742031456481961511737883954750045, + 20628055165039718158878805520495324869838279647796500565701893698896698211929, + 16438375313036818694140277721632185529697783132872683043559674569424388375143, + 4855690425141732729622202649174026736476144238882856677953515240716341676853, + 11680269552161854836013784579325442981497075865007420427279871128110023581360, + 7052688838948398479718163301866620773458411881591190572311273079833122884040, + 10339199500986679207942447430230758709198802637648680544816596214595887890122, + 16310974164366557619327768780809157500356605306298690718711623172209302167675, + 4572051236178600578566286373491186377601851723137133424312445102215267283375, + 20933392620931420860078756859763708025350478446661033451436796955762857910093, + 10145870387395991071594748880090507240612313913083518483680901820696866812598, + 11173854866888110108878560284050142518686158431744851782991510385755602063727, + 3895357290105797542988795070918100785105415165483657264407967118738833241858, + 16358886674154007883356717944805100413481233709808000948036974385803613296849, + 10544067501284177518983466437755150442726536257903869254459488412549270232123, + 10495171258604974589451578238018388630585794890815982293891430761424812600427, + 13820724103604550843562070971473423552484851063169471886037640613650155173554, + 2334954333435579600152488915208745055087482119087065911968347050969338669409, + 15100284614446277058846085121308897497066957549089629374506920751044105723791, + 8493821960754696376711287628276980042183127459347650448500304251148421115590, + 18612435536889941393944858783110719304584209891406420832295898519317994950798, + 362101794940079733974215941991047456600874474038781578925062694203564740952, + 11020033081956343850903875701444955317664141075326494650405276926536449284939, + 9396289482656518627529185765935649373549564165735162258912975312413185691167, + 6879055176150676925438486069371149089824290576271090206945130252868108043422, + 12466610601804566637227883322591924115458766539177061670432424956205788935144, + 6570302110526154075173287644133038486970998888099669190857256824048085590052, + 20997862990590350605775941983360263378441519274215787225587679916056749626824, + 2642485040919927233352421501444361753154137311893617974318977215281720542724, + 18832940311494549247524002614969382413324906834787422940144532352384742506504, + 18751288968473015103659806087408412890105261892140397690496125593160830694164, + 13938622158186434739533995447553824444480420613323252752005511269934155122652, + 12878982657080117316101160964182202074759312554860119090514406868768962707099, + 13757859113119127982418426758782225628393556023865807897214601826218702003247, + 11817871682869491875135867072669251115204978941736982465520516648114811792373, + 11336448548896065624515261709306933490181794458266726453198857687608284871020, + 194970717714150352477887371297168267861902418496792228400198694925721020795, + 4999282817977533227652305360183045040853565298259070645110453061034932285549, + 17094174197873140035316532568922652294881600587639905417701074492648767414173, + 8484251464872873032022789624790167173458682056313339863651348894878144808746, + 10260366716129057466862964875306868898686918428814373470382979997177852668590, + 549263552864476084904464374701167884060947403076520259964592729731619317724, + 10052714818439832487575851829190658679562445501271745818931448693381812170889, + 1735373362835209096342827192021124337509188507323448903608623506589963950966, + 7998373949540733111485892137806629484517602009122941425332571732658301689428, + 9035170288660659483243066011612158174896974797912618405030929911180945246244, + 6458619567307414386633203375143968061892762498463026121155477954682976784731, + 12314261817227551876673777186352972884847144237148169773300066404053441924532, + 19869454329688183813243851218196625862680921049019496233616575272637276975230, + 20326917073492686652690019138603910654692396590122884746951129061818467704300, + 20403270805536666081472738304916561119325397964511536801752236086414818653063, + 2865941730880218719188224311916978807415673142487507504983320505748719154068, + 20614246027521726470902405957496110178017768563127335842405314212897493119848, + 12060194341463088508348622863463208827312128863463014006529428845777217660299, + 1128906798719793375274166820235650701301189774851381709919492584451845983197, + 19670876372911656158743764425809421400123168087389888660308456184201759209723, + 5647230694522866559497222129254930524469944430191328619422533907417776118543, + 318629082509194371490189248876734616088516535434806492900653650176451776632, + 13685970881538585172319228162662520285656571966985351768743970447782846353365, + 8283840607829148567836919316142994745766280854211662326632930274668867638198, + 8968895518159422029900464138741638511289476298837958524156654785428413265371, + 10061801991000917366002570579819627134666386452411986168205986791283562415829 + ] + +// t = 5 (4 inputs), f = 8, p = 60 +// t * (f + p) = 340 +def poseidon_c_4() -> field[340]: + return [ + 6652655389322448471317061533546982911992554640679550674058582942754771150993, + 2411464732857349694082092299330329691469354396507353145272547491824343787723, + 21491443688002139478732659842894153142870918973450440713149176834049574486740, + 20196926676989483530222124573030747187074792043523478381149800153065505592963, + 12986278951352369831003505493892366673723882190521699331613883287145355738793, + 21126146258242782643168619000295062005037298340836817770565977031890883232034, + 15509665795506578582538177431401381655815033647735781734613703976071034655246, + 6989769181472743404364681671283889685042701491627165526899522083327752110839, + 7062179885254277466334896166987547257487047183881628199983668518000910197987, + 13842521112365108087725039904948872289730786568469683976372377853164252494752, + 3830559505943186272618534143266118508463381443414165428900505002474439179836, + 17704863473432653834041116667846189591617394753001613253930974854399793083900, + 875580502229441633079974792778818749112423694973231971690365132230865385439, + 1971134273535892826573832061354985059300866001765691176219451252512658771248, + 4865738840363990164915013008693722144676933915103280504727326977328013515878, + 1148603338028060679975883868174895825055359423662532941509525326937127571764, + 17506086433923270253695698017062834613463718526046463655503742220257039588796, + 21580033018107258179208198773211859664893072138803756118939260252922297665067, + 15411900706973212043830142913959920716501447427702082030760032355626616412240, + 12219699506725448409610279620972339448030565224304464695714944121760832152291, + 4525719544192047521328360848269156485222470829314314216955024799558286708479, + 19667371373588322336224317159113441765198420040800065314868656839300028747331, + 18916925604689704279265158984702141998345424765142129953154245912230835240445, + 12789343981741773931665143789673052782408749041041266509485929045869073416222, + 3094428508959717445577232225505810354980663487713729230015754183012845687401, + 18544590634480965569098056786078005630500574069468005220462377474861119476492, + 20990087440247450018723844204951613913840993427110495085701200965767234569705, + 17552251989761134508416634118845221324472178264364440017634233349418103869223, + 21000797802575507763447855752602183842956182733750968489641741136166640639409, + 19292751508591545849778577901067988044973302547209758604667395356943370737868, + 18314088316445539319869442180584299715533304874169767778761887632882728399870, + 15003745150856597539000559910957155642193629735521291045949652201905498569732, + 7839443900003691950104175747634267110464104444913379977500178134209666299140, + 13568305490393393394812598233983935295266242465548739772708079888867621061127, + 6453005227995051361096639028742707098785560656441339640433794156400437698140, + 1420171596348195609536167209221442141824294918625468780931400849866478645240, + 8347329128252205996443084339884155586061343024498283583400215109265013719709, + 7893774494551056447960817286805128884970061671041428326788899872964096959040, + 8970476243368194065341537088653900235777512204874037182428362347342487241690, + 239049405935404678508864874854718951364753739466303321590415544572014148257, + 15772878921699764223771017074289335629553777447709755479885293350677783703695, + 5416082112919155131434995906647355834510201879607888732259087164602171650389, + 4384524908062410354304345761652962203632712291085564157560146286207296352050, + 4210984612917608245844011498198864216639269565627982123611519493203177283139, + 18816442907032290878644773027005263628136050677095986565400687355912498966559, + 21443510232279945782338486087712914668515437675585863788610958361560172084515, + 3234314779308300525339049581669531363375743827111579883853941968586490182859, + 11029499234949696730080035941750777601416171837281021031653841244636590396063, + 11145210633226924132308292113124660576759662647204939721872338908644906571564, + 4583160563963432761409369246361117506465307518522062239686649163525543782173, + 9813992026757562966842771727657080117609486122615087352428596024939855084450, + 10084171857039480706430282187972782725948479260179367780776125786119489581409, + 3874212709197875589640151274548083098712939093643165182881681226579903752816, + 21595542491397091124739711708612983479307589335640792812157875295064235960610, + 2068530815441314105493629066002923150651375034543842424822712297257260726954, + 2673459852071215292298131389250564595426361004231758522146794940265552265806, + 8591046256746588406353455230465605224309754008961178558834659065898923355164, + 1020055192431352394776887540248098706183934464205704158014904833376067287118, + 11085709480582865378042656141271006552092494690130782253913953070642865919312, + 5673844083530503489429922596812992664928167369104420134641855283771127716005, + 10492199162275168254265892158402955076490959375050993042712629236807564461542, + 2280843393156259739329331366624245275580688891778782679394848304764573859886, + 6807797027131305026345508953353882265754363485246407959111359919046340709440, + 12692191384043938397944633973317584101723715998700063415107128429315536223446, + 19818676957110967644349139912613239435706480354664804036688552936554140369382, + 18055602608192644695569077694296748842203151828348990995792087204755925787339, + 20934555391215769430553078793246717148484784880715746179415906355043590089450, + 11420705181439111353998210442417752592951340005396931802449360401461783159557, + 19878854521263746227125001670931867821366047088989510542865511663910116386085, + 8568201846715449867087132677683368912214864824182424933182820310911278496552, + 19198701614488576617610339232794062430644024620523684127268879880793305460015, + 15262122764244854433806270478871594904740306012582364033343126589996733802868, + 6412758421155818207287638337822550233376667015263373809976157264137577776202, + 17371585001641430978766734501830788427263945848682170096055857509304472649262, + 20262970042379497707724791203314262108784948621691331141565359315001027736581, + 3859750447119748295302212198327542106766447958113540005985799287718502362717, + 1172269945800307665458943534144481495673510885455899148864236015097947176746, + 8164247467959680477306326470118519335673181279975551434197731340070491876250, + 4513977811114181395323888111232002391599397736872779927267726121435887238972, + 1075250595927474080680862736233039825365918646878264905022213616210377518447, + 18658420120424372681792175914064174056413842231969276203770574969914576681364, + 17769673440848360838244654765103041739044212539359630263894092078288342647801, + 4319086204044362848967484441065231939136453667264715596505827197873119273506, + 11221173270629292820060668122527062274557317856738971635698169204652845111606, + 8635411372759272135249379415383299350267629947167809163276219879514948820576, + 926977621651476360285369760355547766944001783780761167546467658394097283069, + 17702143780592866375901805387463459229828093905183622296234691441436877570082, + 629612289140842594504574984021125242351317893847688437087866691775821981724, + 19990548577495092294245865870717186004301934545721835081514347926537975465539, + 7124830628609719908679298707909792306162298058570958688501370177898647946696, + 14620227791860703231425817538142948793892390269806790476396226159679984968174, + 18495581997440241868332244230687799183899751339442721677540757155760745277888, + 16922065056093401385376103551657968760602009001905886435813054626317776258714, + 9969610601962874779035054685661667941954971427956866645694064022029705170229, + 15281641269114187762159685323068136816556739502211864119670902056596295644116, + 12114994625438879103001132949163961965524612903017200394727056658298824651596, + 4840986177718281128440833017205097196672382395936939379498412745183060615212, + 12847307562796769659308999092658905656250954898192781948610713494470441775991, + 20290096217351155282642224215178246911041509999959311313223857240001143893317, + 16151664509646153154405691138084115125600386733136285504828908979176781265710, + 13848845391482751436287906247470303487958950799995701248612703022979890932133, + 6335716166231441585596963683321661194889815181545222079376536449814718259931, + 1824302750039354704619545544386637317858342555634601563660279997221547953768, + 11327469654081586239268713126961534952233559223228327222485848924908493444712, + 10077703415170135154603829433031861799853903739210136452726077323833067256620, + 16368073884579385814331927334821006319227867093692644942500207970751483237405, + 10621580796499573269115131164341885791299038227955222944695715163010783205295, + 2099241376651019397894434242565225315652133572870234550073686122343103853816, + 17104632243449417396641550271977294699471083572885397875525767745512335891599, + 1935453754847256492223646005402770357836971113012418013930273797463411526183, + 7492761611332930896292052363224494314920390056637668407353957465667515477934, + 16836705924460095689555600825174696605443212968244843485187771119291716736958, + 16995495500678141665340056658079449793587669420913589967848082091551329904176, + 16097379973857697753436437302681608056543122759719328497348770844548177814262, + 17476569537128329379528694049566216604638194592812108658767104922628767500420, + 17997217989870184804787026924935938133194070033518938653831611194683423549591, + 17573343771046232580761295935281170028624495346579002725814597714902588657750, + 2450087639204541254902859018960918562514681200270997307467560465282168310665, + 17288084325555056222618040923753050382954155896826087372317882602328092535440, + 21837047676579063581498107773514419735425738753079336764356909012851439336687, + 370061273472837873736743292149368449614309676635341873070086681342317566380, + 420725183996224279379885018872359102189091670793820517618337092091910692771, + 4966571645678139143731798992823327185758562224229132271884647901363447388530, + 5039558223429273757296118284876763395391635773837549121798873235133698166026, + 14663152729953724779401067486012084029581847325524052152795817923033297673686, + 7201040456590575809960214033959496417566605177095808543357813677845263237276, + 16872945504528960415453618286121813996587432836152082188694652370255998768595, + 4914824783780909279212078186433590922437371437384817332713271291839616026466, + 17503018483514413315464207189113334433424965178631599286655188843769810245465, + 4087750571011463387872022799241315348852213278729592692674275176152296405923, + 4006961923780091252337105595934918049936238157468198971234322013673884171131, + 4481908842184366902145805444001507554481032302978790080019710161108326487967, + 13532316826436461968093937893872910736305115143550039673102602344678825540956, + 11602986656925867325907196773754426955346837006705269228226729102186031417465, + 15306992574062791537454541745213815567999895856471097922112648012979731636068, + 4497571735611504561173050536899411999551839050319538712220770383407135602945, + 2571242673174714867278075260451133687893879636121064640779554188161591611843, + 7070272070524747733177730083966686149849667613589868731851816020060781720851, + 1308310289745495626002351437755820460104812708071634598163946330870933261232, + 9483468192990391193401121929514821570714432121414330663623018046165053411090, + 7317568349845215930675847155716598288688799068821709820024570206796617676748, + 1918505733423704616434273602054555051755671749253598966287072464475922854850, + 15158168161084905689406532256983805923258003804476527617207287404280855731962, + 6855540174355511438343304861678411868002455139032857270673849263857877330771, + 5989863238360846166935911112885654223487221280254816980802479355446167746774, + 20283337058688740322296928691341300752003492063748410749625272920572074851396, + 18957132189629332408653055312790838576277703952267542471751593810468444454136, + 15764518568966520670995753676429154315765754748131847346608706222194564055358, + 7192524197002826721654253762628934164676539329903087107420445743247046038858, + 142950766663597487919643890566358241353679421113406309294925836697585309311, + 15012262168187689680572958978610204856600235635916074406168861726626292993057, + 20795666834671497603181209610179324236645779324677512349797033323222380300794, + 12650341271833683789775531792948185319868795529390391267833516836256688318306, + 5597700232877580665749288204589530549415282468176625525368428476461504532052, + 20949303924691159143653175365242293984396858344688574262804199947001630916385, + 10746523145835332938672833282581864816136388045771578294905302886974358762209, + 4998982766221590779170630035756820066555357949247521575936385387288356143784, + 6936999580131731861735955554005106460473097800566952971315565150681540640020, + 6670695360676548472482680016233507548657051302712214051977034166870814430578, + 12210816592786563975173850937247594401582085430897698766795696447223454826466, + 14933901149105284237676334791785996160108290333321693498322435129559137152007, + 3848529433916624869590379003597911090976938589461403388133685310398004369431, + 12778805225074604003024964969486878839359935515509480774809299341511161183802, + 3288267180428684202786697419666969564766921974531343432588030535602163038467, + 1272672432174256751826350693883913844502039730140570583479554071765667798207, + 21130828804874452930669244946376257892693846272313548250936991077452679117587, + 21254559353072473881932828401787134230282801383134765683324465204971002861493, + 4116075860631781527931204624078712926526805345818156200756399332393348685924, + 17435888597009729827411190999389277840088354756277916760187756022854497211746, + 15837398163415665169712832984380121382150588321621493928953938599666110830812, + 17988638446757562417082379159769772097890681265659458369075768452342579854303, + 8144561030363576879343874888624208577604401139613622673042754207987577727758, + 20020299925602421262203305284307419339160247406220693128040712457114283033661, + 2945951415037890626891130390523013930737768652394758977777336357159436605764, + 1505954324723537402640844232704189835623922400329086438898375859826553573763, + 11851584491756305117491374581845512067704002072833714119284164514457248861803, + 14471204965036278214508938537949717553799007630471016532866101610339050785912, + 7163557293233604902868673807221391042191134560333950452577270522828534690707, + 17291625782465108601367695465389799786592304061550212130987221355832952230827, + 10240907112109243116543462081552827576656826251172050843989873656917271396422, + 20702261919346727858635106264046787321170414155594199951578791234276181642650, + 16678253307828004252292273162411388452019952018258857370242272543091326285541, + 19810917631941180098047817620026253706643400683524412974923209268916769874447, + 3357220165225360610202375608872621445880880830154732998557832689480921421791, + 4392285438534542495332422274902727975330102148971785438164412161504066619105, + 14642025133729666610167675086855441462580619607677226879159952689184960379911, + 18142623439987890999821892559271093087005885278955082040377769578204898750505, + 11769399023330099592616157336702104329646487200891911089287290893650532639221, + 7261353756299584174448625214367175510387913706095214313669922259027644778060, + 10406994568199070863112470594593301582798997458844791396920771226539013327304, + 7475277967562870216712397220016587384793504784585573136176313471517144184018, + 9598064630327104406929367986473441777975480987434868213697837347643980267620, + 21137410002545951849752865514437404724653771608225272412595423069852350320648, + 12345612867231779996383303763804719815752861524077922121654106906093103051400, + 16461750199070055335468534730937701659470268635084522644824623393184528879703, + 7829250842543018165409887731515254191943527926556191989558018633300783421935, + 19801151644322693878208767560968285812646931156576102755771403150148125880648, + 808770634664491371274943928223981161442027957963181999892266696287962813461, + 2298122748772261447929855283951027113218922003687701626762072351622993276571, + 17407798064458858450209051887305178872029674498718760624162479511390762310526, + 18585562277464562541666582720366573863334618817908062612923861658144918595030, + 733976598693219656339731904831283238690050114241501938501377743874139460889, + 11316063986696838098122262534148335669847478050407756877728672233736962269417, + 17614529714381496379478130066245111825610297227468263851608027100133421612826, + 12110694197729365219340374599835523099651939156213930558791147158357810646901, + 4337343008663255658976574468931581484970687989356019720784093082313510905405, + 1379188959674402095268172673987199124815512095460112504778179157481327937561, + 3116148242507754420428768481157196067508084836097458698846114802493377512591, + 13306507137873332434793374848948087993544118494881134631519748904811343155566, + 18496878480807017010077624766326681523549495609998881196570603040242554712562, + 3940126764022508707486095199473913866137718790062498893812401335738707507732, + 10030078765792498033316282784150304209584388923549357286679864120250994473810, + 18519871685760382462428068450331593474924737719734568498029727699878543899254, + 12599428893576891013523136950822667754415283296587096197120138265392279834128, + 16038578953099895530943034305356008247313649524436132877362941968861459073483, + 14319233878082524834510736727226054073026413911339853399113450188859080424272, + 13710161613540579690732775978855380876556751245265568031703536595040993113748, + 14958726446649273856607176275240008023824615720456760403465034344703779274727, + 20935428111942360630758629263346308597806819928838924586682307174931367773605, + 5826394436548487315966647466017047216786257295199620110266250301500717796281, + 31401797997389676486806123612280306684597605608110075525648021056710776011, + 10784171495708237485952707518956314344821522727746927291389338644844400581452, + 11604345371765580191117799693565193618158448665352599382713281103552305960442, + 1378145039624937931836538950217364481423707761527018494355648047365613434790, + 10284294167221806561993937798090888689421933711157676807977401896199778472860, + 8233695574758520342808807499924062869636681352769371531557726871630696672029, + 6570581391072134029876349038190171593169496519436674767949949730275868319732, + 4026501263908027819614805027945064360196399012004574117767831931274788631138, + 21091098569404004244061462065218203986433580687172854429523306262593782053656, + 20711772916118045406356429185975897495222240215931761100801599257137350834799, + 3165519312799351250309462589160165591299333587158531489859211268084164422251, + 16470663723473939739601217501478624726068461799539012562455639586886033078064, + 15672299304945968727435591100602007503785845873606917887638890765525875123857, + 21393538327627889838198844493522533627143658125568123117776524944297103649079, + 7688819203734248199049004650451546300187194458173935784579101984183800649342, + 6609663518412297884695057080546416278366560290439222127471462938252865438638, + 3476303650597281786976907813110835564442121684386467570637538230409080744769, + 20633582549754495054832414039299188930065286005370053173386561254823483851717, + 18067076834611402459142612082327591538480657933568191619109271502102126814407, + 157209609820117793892254328219308970217366919934739036156851508233236414461, + 1848396116513925340973398423998379465460554039715233953825786874352442451413, + 188642786730195655565401615804782553245486295156304142809552609651873793325, + 540089254487190924787439362270708251103955915909358626209177199653451469720, + 12796274768956950589847157187031845061404119522843128177103898080653493269942, + 1785666356337148874573621868025910291826158842346617719666738769156993598966, + 20649919247042517528354490854561347316237285929352042389729444382153378749538, + 9568390566108569727471722677925269460696523515877621230569682954652430518787, + 8590683334740232786825518158771304803451657249486419816607179533515442407283, + 9321198393538172042803957409292145345834077448228642847843261373640165958582, + 3651905214805616378360839954289447530035139753215923648216350128870943481828, + 1324345422558073117779462079218851558068746895262914344818945294328678893083, + 6666363895154434021620869731925915051086919707989020578203743660669796175288, + 9850757893972463103359995012900314323213006625927501272997539940766979170137, + 10214293226445704940138790188111862069675188797488928722469679760666574484266, + 16862124085118494177559484642483513597285992646267864845521573612482278871023, + 9172340118369291059693735314505606817316211450324955429310200429408035954801, + 1968992755714619414656181112336357119271845800144345284299978250769356388249, + 17192498940296212027365280042755701662136570107224000496521552617655679821443, + 10063385968535643122430064779260670089120686456635080613693015398478175344193, + 20101961459945738562625328882763768836449780661345042148985756598106706734632, + 12704305975772252539534386080950631076046431529894091327218544197389260775334, + 3008242816727585639441748210631464697850194693570485141354082562181236010097, + 7797705698071555811456747812384107102104184812467361013142453143842134807658, + 19323240331433203844038522035479659453946066968727795017745942269828428751105, + 1698137797127320576751729191866734754105401103859852376273763815257758421427, + 17656850887825900397821271738817912328294075224643535784810269137125067875996, + 20755447986835730799031196367323817361150623932048563112034040627213597261325, + 6221130271964372280138992636208062417325313096379273438539556580491430711297, + 11042709376363248213366896208587241517252100440844476816212498352999929578287, + 987361321094619571176752720390429919723900732295551211263814448408232028205, + 15077982986114392945859048373768437818569856001604485167476360943078774679228, + 6278894644165961404521866714059972066255652200107181684047812674333675794053, + 2649747800006903047073625320829560088088800522557851927539477888486006072675, + 2636278052351769676017824297717609512488651850924228608531372135635042762078, + 816232991472315395984098922575496846552245086608787214581606973359616326446, + 14372687274434205592004117128588852491871014819273428668840779210928924573820, + 7351401720390274950322621121981079413650308506660552567079785209176949174210, + 10275293929161727274572318228903710245677747557851999483919909420098936352013, + 14869686444606195206734119702227763209172799407142930791211203702643805341518, + 937617196362766626935279232045712623531859540210120280128165029613358941709, + 21331527351771920568751070369057714014285398281585036009305608379072813379081, + 4305436470381074948146072259605215282335211631970525440530773004228212378618, + 5894273721571292784412707230481346442881109207745969297947253583203466014760, + 6512250441044591603946512492071171861967500633638753443182294740883123881284, + 20863871952569294813936866452848141274047362082838805921071316386912981651979, + 18788566662709810970880679984141390717017951403407913908833463086244783373013, + 7784927597396249543149135503684024377171301321636804832597181795981969626201, + 13818519831569592521516488188127966399245767953522268350556654747680372036664, + 10515208647860053151690062640705322684876580250632027862984821874343071549235, + 797604926079325807488629085866693514275115789253871397971708541758696512985, + 8741784289526985522570446847275649913333939699807282742190607491216732972386, + 20966712704043418981047968701828936463778140093909973286855779694780086635828, + 11359697297415630167449040380538108774924967116147664240213257348125754475868, + 8070907838094569287067982462230761680706116783989613960066342967469297961118, + 1868550288036217638713133945402464194193242298015503906068429633793800456561, + 198709459347510170000840600179608479136663571567208109852828485236018304733, + 1601154135701845545733926027872374554514541574822026314034696802419388627041, + 4363994778006302991481199477873248350039564117453810275561422974475581105893, + 773054378219982710451611471050404495804413666789496412742983455527754059148, + 5209426340109575519362014651321132459061755868557415513439993327176584352934, + 16124961412020675839394907565568143713078242978522632778625312854364651991011, + 20812496670075231301471694692369245988519082317145989298573032859079075730004, + 3312489967581906638742585802390894285073229440039144559060030129184388053832, + 2967475373447822846542676378804990140732835322255774209561143670843223463335, + 19744585401442299381952694102570931935735276268739851233412754166721728873141, + 20026293345566344685499234599699178313754630774489046573312844763673073616936, + 2611303659034102517884318354550433047021831422518437228002960700934925644951, + 6230291832603218406134986471162106408091661326026848531605999413028246206577, + 9126162046556730019959291776456914453189657463686708035601186672661595109020, + 18827736146609035067773173111376739253733288103277133456626928961785293662143, + 2328703958261360872869074208611873245571971231035163763965210852182760438390, + 13796410059666172174899788866809560044715551934510722965495280798363043241416, + 1593663256684781552813616365605526150610454082601584196604084376715746899324, + 1565874145189898288764434737762721576951043839540107044892767693968417810945, + 8709849304563896945461696717753976956465219721409993781555147204068634555572, + 2994256803561260177499267243802460581941891553208150783951937342406846377191, + 10452746656507347152042187616753027475507881362159944564077673851918869542550, + 20130580998875572619695450234900655050996104101008767761546912649074040426200, + 18926933358104691474037431437316089682088433006245222723356764715400831411716, + 3783551594057498940671877156409957274854990650480535806320220142873170375307, + 7919031943604095374667473717154511882451510130166237539514111182596247372692, + 14518552587329209714850286012780632801030157943402419401997576700600952906519, + 4770764028263701271241862755569969531641408032906982530346384375773459918490, + 10866502826034731763529371496585294375373238783964914673031891984092997621879, + 4234148117462322266937279401468367908013627589417699250592523530383852950379, + 10747942066055887965185603234524367638106812660210378090215017248140719240336, + 2587411532912868255102795810490361867789634574022411742057853375399270197531, + 17350061113113681344498080520518808976916692173267298878258722510332360424059, + 16490282364669098969805528215926442920328903121380947471680517193373377657129, + 9274691782659584680377375192682066090127280485689527337429804211265749864190, + 7630965482352419767782717986075793694403609453648729580916814032587325374653, + 9483872310024003776681196467845329825094379763716541754956796450187787638623, + 12182966986735661215639970080491757244218854808156498220088212871061979325833, + 1853790963611367149183440339188924598268644281518961106776656221408171642714, + 17425077915972423995335545370701802959607559878032910147159424242864219303096, + 14571075346526399549826264845894977639678567831720652860528738036970272895919, + 5627701855249158721927849603102149698163511782011562166637339712383551336091, + 3620805686755372260289125555061886982808014642356719556961142525373021656729, + 11556995641752009899073583627136467840237831247117281278719511600076965602980, + 18960242154096055221658318882298412299294886669455506299567210308762501113202 + ] + +// t = 6 (5 inputs), f = 8, p = 60 +// t * (f + p) = 408 +def poseidon_c_5() -> field[408]: + return [ + 9174141306060971809979631725764298697615039980311809306145004207410652431953, + 4847693924685156250211477469465516228032151306221739650606132660616428517315, + 19669833054057639609249840291533340493211768292967819468538893000195036768991, + 19800508893433268850924828171290876015556093796000695603651522426066333836892, + 8244699449852279148780456022144420353408196866113049322676048275081354214716, + 1563672068712965454176533719400672258364596155638916268717470967009721945171, + 12723223712027468580318230235559705540011996847167975439677647504573149248849, + 19944398841194165937952509356635863229327574447452745793253427406349161295763, + 21218058308392585368594275702746106483411305671883946244077923955757637296177, + 18442884961885927579732373746933397748806426938144021013884176466434407012116, + 11138408360119814115926439449668526422561003790198269766757675305576549475808, + 12724564576884231109847024566806896391934587839830522481308995309797961575379, + 4897733190252075532660075013731462724561461746919488679609618967302541674417, + 4797748331306263412471031924618974997396620231469532262170060449304337691527, + 8626839560132907403537141283531395025838110825355541158539075100658769738351, + 6096293906324574249636975851522292408228519044739444932687579741964974917617, + 2351617695830568421216396081605990689071283678701192113347036659596049514149, + 3045682390398203085155257535118136303069379656645406266260961816947178911890, + 6935829264874515341379952008241845470659188886156484974987865751370715745075, + 19847439266968955911971997829840067368072860877451092633069920565944933744280, + 12795097343831149148337906863235678514689648096503928066579129201713661539889, + 10424580232112390318877053133877999442988769389050776486274146627765228950235, + 11651452649618223740363812212607761589812354035139843126315028745587570714609, + 21307929358023177131550002602820591970791247513576735567457471459920519084552, + 2579908580162153663820021562014873149811195641589016321720930006635393981680, + 8198198178555784054784079137247244121807775986273563786249987394640289859893, + 17176088986876377315956611075288620878117708836881362200541916957398026761276, + 671389874397910339333118510595007038137908096657753354622355890021074216004, + 19161949137729278558310070194809106779119877882343914445178348849980058405327, + 10827554013954037091657804154642286174226562252063767377995268439458401752538, + 11693672899474469123468133710607776304784343543318650064064636202512816205843, + 7026547767612627656560992117440221331093280829523426249915938274837157551621, + 14422968137896343032446633683271253661000603582016449215470992885331170459671, + 7685352543184863430081115767111935982586458632527708735083385591291346555502, + 14089009391529192464370954954330128327830078875414722902347666490457756695535, + 8424161061743752192085022963953944100289245618074575727145394775891645849043, + 9809236779073852557054640507912802523501426410996355424610807253990040160483, + 14100245203768962710288059230665566265892855964739454261791429988929622355986, + 7775683622333704945225255741567928967674629526812606133980425422182282014012, + 8739247215686497264451630351996892836638898510934389758205488381695687859658, + 9431876969679115468275053745264413939426444105271849398322497961102606290132, + 257914055321743732506701382989022126153391940932933566664491918941925247878, + 21801414068435960590201256257290267142214176965736081788536576642934903066059, + 9465495933537134443327560834432669768951376466867005153580146079082722525723, + 7862366214258716333873810314803222267215825847232397599183717032713290878315, + 10701164906390193792620967030790214270231326273599373762943959252633779929633, + 11951628827727068395937910010248864431667047516686609553745879936868276916066, + 14268744039571470490378560085356767818183790841094115879980723591887874138419, + 14468215915818797151199796266933432577607248341385185700017147731054148927023, + 1523824033338639123415809477892820349580561577160869448927791050266158538520, + 13559991428776910947424645696251487328999214391124402586267086012691140984198, + 18151203063828433535061866995346135260543721730169485344610433976436663085882, + 13436242600153492361692256644258899977135098134175123174795293078081801647137, + 9384556671429507406657070680351030238568956203341356106463890924933167416522, + 20321079285577981781556986944841048777999006905303986053275199507771332527205, + 13510502130738135726695195328780836716597947131948116750163533622597187969844, + 20903049289119144354363108865308751668897757360882852151457514926552553533040, + 5611953645512225417723205546533389174830971368309601830751921473015551069534, + 8816886019615642422040038431962872654062471314244185285424018745071289038220, + 16751828354835345790163611999302863949792305206769993810746019449909446216365, + 10421654749141018171116296259626916395875529220250947127973888230084671091757, + 6065225315766552671037285757918350882361743810888619479819895087632281975681, + 5737755346739850738724717271213687543479332312420206954339242459110768587128, + 14770522272891919220644639305274656491731294860310497013287297810648680944682, + 2777394791070450473479179489594969793054480209411136328689318984981401732197, + 10039559932930709555975364107098145624058027439566384376771787183526929807647, + 20757756003754261934858081777796652436155530474748550156383127600004580439167, + 13253166894715452480712170898662712132411702335275401581167208877688374856806, + 2037004052447343668129085129987646907388123739343356363273464870501805506884, + 21829471491172175426560705585746893969222010633542962882847909490991398830669, + 5130395545419191392223692116621486075405299333195732914002649716762739787586, + 20333821730990393095934147177227294218344864602777744425090741435432040213391, + 13629653802252084129446975515814037702423511189484562534040643669977716900228, + 18489091892360842692678715136565494502607711254719045543684163289077857041829, + 21380328601365035012832876315565064374684993115210423862017233170195286906080, + 2280052193465635727584791148501382679094142036232980037838088033232747821762, + 21415541711468815972744677841317235994302058341802530962394281077076174148777, + 17146992672828650459975820445250769505470616910596779130798889014378635881076, + 21676475584514120109058208398560066698690773910598518925936412952356431597439, + 18337052978997482578725645166749278142628133291693686105612531426715865276143, + 14864089429815580405957698645045711801464462794754089671996837547347950054532, + 10834607317840698149140890207826430113987295440254355899459691878793978994131, + 1157143498448645320415276909137008396665083714591338741616893578930275511205, + 5027542104048754930085470328670427788489455916338375169351586496298129661248, + 1922685817237874482932428650501872692326329693528175054457715565489676406535, + 3071473720617798005831658342971536643616129392641449174655528578463370685788, + 21091078808046042460442535848913779439792606439995062001271357804782672390627, + 19773167374024045118471391738750949555178717045037157435777574972149053404157, + 6418695831178793575992210834992785624340084513619644969535805236049937971859, + 6317875495482489567338519005308431806047606843913867465201005132273298011425, + 18001249545956637376455848019549801116909661454019565655561439372098476761813, + 15530167556609139699164228289904946047951254183080358784988008899829027775935, + 8702757129830652230304011519426558036441096750485189115358314568895250616455, + 6369986882953061252605652398893489899416599935424066958291402945530517772170, + 6842894437627604179732847187262933342846269043996061072487488027804029200046, + 20951621154051947571647917571547811655800779287153833018533872651413529893817, + 1219277535080749134805291725937516331501172121638812333911793209536894469364, + 11704605822590166851511022757496386950530399074796545751042566537118336773236, + 5983427701962592508775640503988144495847156070437130549832329402380170245893, + 20169091361583397776908351163571343158517532527313940288212943504015977979442, + 3347733015762117176159731683196584632702931062411889821726902331981723958255, + 16217509027282489850987935065936382820558307489954122630844029918951230268972, + 10781269196927764524006466217779648732772805761839205677745819812868343369087, + 10568911823766972365218731330080733630028238366288098114239172953421915095075, + 5568774544682750792074131352530555554984876659733959079036284517928264996437, + 17854353469028651373397049175548228061144941710027186166132671198740388767529, + 6573034112757039329551886086829829282007989555105157401271097204633906940776, + 14069627287078359391137554212536883450595451640858724555679971658981340584258, + 21119713641590541511025673864154852875977162278614553796484277752677323191505, + 12802116677235410441672624559825044917295689876859311183079161588690810005363, + 16037054471696658545113065872215787085337497333273419984439267709950724531124, + 11698654309680908244303850432833183602706804558317993513795996394673734185716, + 15147889780127043019188099948246961619198549928908180192590946633702778981583, + 3657342516407201801006680507925024451922115018712017224805778401726428603983, + 19776786467141868744713630352693556348834540992018636838044610844396164981103, + 7980994848490005281733955776875257044050741738176865989521982608944874160873, + 12415191330803073018395217955802011585094769098717180100014182475381600382452, + 9300986814650530426668152137665814177758578011365736727321578452726378799933, + 4412208980274764197258090802604347599791567698589180187154608728755887977460, + 2582317668924231956058541757507620542434237159213236485179804217989764223164, + 19860814395849792324574773787600734118308975251437485131415273418632757301303, + 2765909129639570206766170018363951893338720647679193401532780051354569922989, + 5402210382809272147099442645489124829067576777592680891367494969197685281513, + 21011104174655621871977821285307554463403659856745964274018020456838460357574, + 7018364707286303918877589672878574811337524823085078243421192184715151775983, + 136380103284908296988715215087018020601815024625535396780012012453684253071, + 15953315437474610448052466140270091879233956524793052736202793153707558909889, + 5912305909658884889781037379491781973092020933879206417274479331390062715252, + 21575635295587180789566592951559325743281772394055590203112195979769645712827, + 1541325805478255472079288730846072146731241030100908414806224735345400173350, + 17207219201921814683730773200330679841907450967511507012179337438654141678023, + 18266907794578843029196926509122804272900478710738403531664855427655744759655, + 1204224895193276222782842236712348692319665277014183965830735736728887994581, + 4023246588034712778784328407820569751989619386134504404739514704773521558127, + 9064437981037864995763386367268294611921404895425171966596873454090899491243, + 18733802217274421976148972926716884457128521840010001893311936746027998476583, + 684088380644531080099595788833220377905013807951051638705160997709156627273, + 11994830816367980341637110785269531718699655485484715851375754143223090344544, + 1831724566362300629700078416489434571462666430381219293205871349415506993475, + 476710745682537342427691635955087951551678644045621275039835625280220347951, + 3586272766499559446129476613035465343616602918105042144185864609818186807939, + 21220348736799044560439132291243370111879983677197111626309132298278891334631, + 13683795063599185801186093771702503913590598475095473714851383723199050309401, + 16118007386401646906425171859166434660243697555307927508268622819509657450614, + 20930641024767526790605168032291665313905337763598128831404465184891980632233, + 8098646212401100552303711812039666794078834386731698810205195111722330322418, + 11585783577173465460243373201831086724911159484415020913089605532852648999143, + 6939053275662244505087635417541857793206828446247848992283188764105131966721, + 12798043540382494855660472922674138947867597503468216532170157050160462426199, + 20713389801600667412553956346192236970217099413304167366340548074880917096741, + 8708207547232102069057776099666995672015399188924281674772351753887161579745, + 16016293152251662056020528248861487281148011452459422778601663166015837379163, + 14324897997637439510797191208789711173129460994362368408063402682894248793270, + 5652996184880208428967511742390474289004021508049280419259474250332590598159, + 9877106633097964013050071703002221796318046172981334418310092241450453368579, + 5385816971548914185604875069230499528103133871233951354186676373318036241822, + 8683091293306949708478955451280670950858818602696102489349595054818146782362, + 16854975838650963077652189417311897888852709425835763860743171659164792100482, + 2485160816649177905834265823672532710299580013309324666453183278408904845122, + 13571692148185502188613896013359942531817915076247598483272449919094247957149, + 11899399615412173136098732970606292047945698835588882297719609812145308198009, + 16827672312681684936590464376780346837611857292837989006980972390576065571472, + 15588237822592586948064701827497915157359094833395277985658706133691498343174, + 18356642512438827417103800170157877145465512961188328254773957819312191285168, + 21642368145757804795143182901389223409544979732781450480847315495418822041608, + 13104082060493963869934085622104709047787444250961437496674916673804812287386, + 1561532086277971111804773016487251313460788916643968126116038406859074212104, + 2718320602791009266532615731130512762296058687816604986701989820504700684864, + 6182683520717583142027400659687593712743548729948584058329789905227082638908, + 5757242145794370726637363237313640925174531077560764545993554185332488520899, + 13688467192244237790806289073845563960119021610896694359815485764764608925981, + 12528461541936459922472167643986446262977222390263675720335825628163511159437, + 4897268894447399415795897967133432014527122426051771866816059363418177665482, + 764332419588242767884018802335623760055144509861323437945071732931233600264, + 11755468878196093893190753985692714003062307843033761257593209352165323938879, + 6006022813561851182403581780143813226749481175437001910923100661321563995672, + 13901542382190510449243772206670622017835690746895066410475076631498053123535, + 17648853891656481911225897080296737974064729032668806126284849597245044343224, + 15106333841965710929952896897521673254279668876709612770907537801609875568099, + 20899315415025260484895459315726322363345188136910564549344894025053466430346, + 1409310408943258102775009950750654615881913956151269414096059752250092035807, + 3899088673345731523976816322438172722785832982334214339521575164464706226294, + 21406686765584824639201351330529610299177537976609066339927938099572420696135, + 9121591670793901722224770893633585291275002987585289305307167711146944200595, + 10711764678410479049841945177317023555168593838022414378232020467195337241279, + 6599257303974597452501135281719536074294806740553273627128065549267140155175, + 2142616913275380526921597026822750992917222975992774063376747381991404337593, + 16361086527663411948363284957489078505159658832010445114438602510508720771278, + 17122647864721668762640781848678028227021534122268561738445496382823789619088, + 21708018685042482318786273055293241752114005312590172460099480713746031274624, + 8303630654111760473056607545365338851734309857718959193970615705292826806179, + 3658686547507488906491014260011151850549759409901579684176172268581462329020, + 7720024124908065424512743488999250878143598904717873371853608249805302871508, + 8805244918657836956533473437651380347005779399042661429698187314657501156241, + 6303681354794120075893215838935586592706844702088252970663343726024171795351, + 21512507181643408509426104627003618425209526633080701556628608990726677651135, + 11835373417333287523801757951049679177935522717858158305516568595764125190183, + 13059698839045014411602727811400239840163533672024084777768305507840091151855, + 17635240655824524168378284083397931667938326555447077097306236826752492079430, + 3374412791113107178205006579112630099131939030015047870738873452427211677886, + 649711083340882271985565833699379436167716866997851102439037906608755280128, + 20002805138014565226408902156524463368767807620908543995020210484077706418135, + 11071355197960433041624284534649121637702414580710232237233568479006159191217, + 1105441595020980635809093220782460032826849883993030969714432603468135735502, + 9652765957610682812348919340146799318537766051849796416434577860126024594091, + 19248299650856496267902926731608572596705132576830681367365128976226233392929, + 15285802367070100569572399512275861017714681455564415244982064571963339715277, + 19970416835730683993734843405673457882587154729456022607061085470691843864556, + 1017865638757684714433500504002748241987153668285974836527484933462490771227, + 17284848056169793253916338792235498052654877955690514601079806604278964099314, + 11718277105372928962350331838305733149270432706448484259807630484543527733952, + 6670793378364949883511003949124179112275066568088468958915163969545409700112, + 17088789393958965094855662340742013087397643056458490270185660553870734946796, + 1930788514812600942005320214284180860980345276633471423966020111188605196111, + 8844343159753729614645407314580317697758296041737296276765583948670245312842, + 16657939543606018325703787748629433167511611178952563626096990460124133990109, + 15333343644239485619497914931918504163396626751908652058758135581206765801100, + 16533875915742793452819179569144271760125646811168930162441077117553849625884, + 19679534317472082858641184998487299940737032844519038845860980362664393659234, + 16385719932525604857740698205965045007053424961009717093945644387917936681719, + 14490521084213123170781774542655088188106794646066074998587858678154251198444, + 6386781978322405984893078797365492485297499058328348606653460996474947075858, + 17508047533433736707046937662428611868296556965172642086594091783148965906980, + 14904597000414815084666285064575232635645852687797347860862157463159487771060, + 14979972442969995336727018758631782107138089738395941038626891064816880204567, + 5299243186271864957800928637599294208954109271450189950375274196644046222516, + 16189884555052883188473617525411302750109401983487269295700675997730645714379, + 1645560170870292006287241616671417605853047420339675073261660626733726665673, + 17866745974872498136933906591373095763114066893081150553715211393380040095383, + 5744849574386643500716045532645657520001448510343827372577217716983339773799, + 14021966200238971589811034967347517039341058556783068950884921208853167419283, + 1201178089866013320759085637098781870734315826415474628546655403142858044361, + 5875644793836087035760988842421852197052681650818034527831700615895391179258, + 10875065950479466897559006840696567433921014267247530366235539292597441428702, + 2221662399199449388725697795500999209427453463134383582414172135385907744785, + 9758513532658579204941116584445291102215928928145103503086996542188799521709, + 20879593323317766577775570558015407573466986714590017262168011643343469361329, + 17225846522404915080676699509636264825833159640824918876741681229188434930856, + 15189442986691997434021855855358620506645387296294217783597931695143376252483, + 15973617135551858849206811241799666696907820418171736027820254766840973764431, + 11888113439449420418408437784450952639345990804839507528208325036625374967083, + 12365920814385241227394825974928370916184942218042429533600397623369545597697, + 11966175169612449906889690852332416255478894176917636726028104087408060623141, + 11163554022908212145274813635928762748847331295589087669583554722521180712379, + 15273476004030808005186443499782264987539818978741159793745891769358221570633, + 2013969196885866182480519514425192091338553670034650196068995589691938248955, + 5008975446746271526106846692137145404766553748264648461545948417006052208130, + 3926749194225734582453671614337621250954608160208554883789519551411469033731, + 1635544156808471185144068767649088695307748439189898784051754434524720057896, + 17144944482517962143604430553750908864860079758005337246916094084534304051981, + 13823503533305241872793740090687668844401004819859520464168798913603662683770, + 16335911272023134851779534303717879370955813837529588982953758998930285394340, + 14467284210444150699969889681308566002886261365990840091849371665183151060295, + 10578205764525658336257882813734672799527733392763965031628376897794294290414, + 18771425328697137255453620743509164311086906349726510394566012237817674245865, + 21804626093983212038528370352039806004465345685985435415809095637323683466452, + 12056805308954301132385034564357716323176447186932453788072119595595483786736, + 14307195735327805282612857510308008767450554777122724855715789120735513378827, + 6848201070063637295416045855906784325422580350462489495889308309540335269587, + 631364713487758647973016689203003205602593076699875191323345338325349259049, + 16214655556434201961140525501007839859074077768660052713461045928979956365067, + 20940788212183642266181811368870506130164462254923655617893660245551698033523, + 8257440848494309435270838240795567828478627302119374684511017376568090372435, + 13701089242130867705897643891164147923878521147124165292045879194108024940909, + 6895272953337895406509859406973110417619874994579965619097329249292199573333, + 530437169778092455975584310016745919549274205817234464915791595041990209639, + 9008612822403008353420189298381046023002474279157557733428254452507266389025, + 14863423501786052071018008300345884780479084379412157784789951872243409629758, + 20091026239041315645045502002997446404106877721183777765607724358538559881231, + 11103877261161399045807234470901399725912406134008627937945079980590775715243, + 21529163495181909351665093277427712610965764606448489357319207727176092439794, + 19540446772694448035410067193880900774391072899517686330271100773183944540294, + 17549510450820803306426739851959754252204444648959723652883552677325100583689, + 12252518814610348662318155253547558779974557529822012236107550517806390105567, + 8058115132085119666951861652409945532276905989404523986413207631657437321956, + 15916100116790431839835734530362130437167135501074855072245598938219364570910, + 14256533476494466694764843270015662315303617568641801280831873052211753536970, + 17865471381417606502707639037418669122823481329049436020149405646709537112534, + 14015711483636570179335132940981982618090553643653746531174110949872682031017, + 6075776171664976866533080327142904134938121198707020111533599997509054627652, + 6357981809351565370498807027309828058036389418343890944791766504532174516243, + 15145296985037303761634018005118672316118004891352906450983918852209191841446, + 2473672396516437070485250176897956191104549656554290725379242542480862701754, + 11059085933391482002269653121188853142706883316754376424538662772943167665341, + 14804069155713123448375113552227724310276294677318593116834685772120057819258, + 10146378656966122923223443263705119557842694560695035707977826044606938090895, + 21828309590915152213768434346306434851424116996828875020020066586363340244814, + 15568879616082229996551157805731419126872501425454775741945679993142071548779, + 17504079509060638501918729619244098692140123800571022969294759717277257664716, + 2998311560047298465700351970612785742605093777116697796464434026101441410385, + 20229972737818088327107446854254558628041027965197447598027135778783710740259, + 14884874200763033520375899992902136897590350894844904733314191389520252900641, + 9619409751736964504139815024141276029474791187139050183491749032619248817404, + 11534029087676783672833531415041588991838838078174102967049055562568798961925, + 17106297093375816944137015955705541133308466659538554159312635106186252148471, + 21676736161168806529097919794022110433487869702564846859065695507460463414524, + 12596447704589377083704857810305080195761099125652005594925931498073219198049, + 310943124066162607352831846280730445558498286205117614171844835745706684432, + 16013029710570597613246104892930389004941711962070683476555063566372534206859, + 14282564976066063966062366540992448474634085812789771416509095817495183298269, + 20757241092771652500911491636894210910134068426068355089789205706892703219255, + 17084251309147907751212619949757520468224028014308500329099194408342072624132, + 14680350698112448759886861002622963534698534998651150537754386791270019720748, + 17739512731440543100681958009173086667000199263945053345384367808940651002571, + 8967486063900234709994801661246451094429250620940593387993430620369318619734, + 3906067814916986286272005884942051451306945488494283077675304366798199289520, + 2517004675157816404807349457307096161030587393097616279110332574293494030636, + 9995302877359286298434340810356550712107485295049220989690824504445305103587, + 12849909876017357260683411536833847986127911582040960825577300322066595609115, + 18074515800779889507358182860997188274134395074469953155084226981497567860114, + 6692811728183968363967959295970424292426462800383828091752006855360167264617, + 17859827663908740084792157440799065184931609649811664442236242315795442091367, + 12243409340804252499520308602187370739653046835019551522661290645230850934962, + 3009118420068966587115224335717185828292538080040896739662684632413054772046, + 15856202298588272962175258696610233941787471472716811521132004805327415486141, + 7549804594729480554341356998842376772514802673462970334329441043324983960866, + 6390806437030742378988258255983502109201709511321162596105974797942236431761, + 17370236522182003753669946647208335160124999930136364231371998757664000198520, + 2261672244214630177095236704932243497157963117166120717011661647779055001646, + 17325026196605130064689259977831126468940872193987407658419640959345091161632, + 3631641025220845885502691330008982895233731506600778684638817282531001457735, + 8656561399441987116927438675277763317789561532507396244334062468892541066084, + 4069166732330197412844703565599514109399373916243310212229125901351402003915, + 19808198732373520522982274785888742523226720967259539531129335924093928174880, + 8555796834031869022510134190573521699378201702450788201649007358450530423866, + 17759660636058865290579521740750449606781204755231964378855563896473545202303, + 1335826395218609619260020055566056869243760115287254209950063597653055872566, + 21596200365241795669701682696176077888309278223833581800772036945674858315765, + 12619752319673193899296833725747186284394167228468888029626464753793997178599, + 17420588547980145067421969830249755561311178399975476925894947008643385243007, + 10337481272389772505654575850886249605422739785111225132545740838911222864209, + 17928431631046752749930349099366498612885288622404560316665023363985966878427, + 3075798659324203306711977985120251896073145961913793478792728028765206521425, + 4639500613932181914847461422373341918892878975546430906324216810326467690534, + 15396322795715441250300995201889120935591602515487993982711884319616897970533, + 6391276937505284102735701938724106665734769352007891548547667448647832351929, + 6811373320779057384916660178551330838095673247430496448933336925226142036083, + 6590973140323934807800215988687710942074412987201753370126190631819398102173, + 19364648614154949386936259588484266535262135334799266379433252509193375956715, + 4702754284612371917466042550086249683933140314858807272591351280832918881874, + 1081036249074169248236179367049085684430282426446509768147097371368406374049, + 18548093223441988703029589168425055383154624592689171393242936199350770119589, + 11098999608073377668352846814752381891400020647878345005629685447730764310163, + 16001262992680194260590639872321865154716987495605624862471107193457192704714, + 21696229443869118415905915570780926763029898831113534481730746953640692230062, + 11716215712634983607563947056324900205144202447594949676250978337464771243867, + 1778908113733035314726603632369389424542091991692308812147944884836647395775, + 4019081204388123040098634987844274011285321286777408246805308194144238418480, + 3473266952388383063447927231564219811787341139731701190625605897592140631276, + 10457881304788072618845101933412333126160339089704353596608910674508961127232, + 14926101732700077295531234099443522459232814784151318061435025890154852791802, + 4036967072197259618286839959572768559469665646019907384624959071646231971399, + 12776716624632228928613396031717959431597335742467953143594165782617234803915, + 18894783424164609284436913400522166453255844750192864579927645453695213022195, + 6303809107919167113924303987533838414137996606980561570652539716097058487126, + 4729698693443803882717817492985796053343431875965792864932005291979914613160, + 1645790034267553926884568714540144778649055395816210525904813567839945991808, + 8138260225269705405100573121045873922755899939885385491610389913906979427176, + 680936760009829486282006800072001712155424246576949107399338687767760991887, + 17240357869291182045663678468827695873425113788704614245279840174870850373113, + 19100963939745621863641468371111320143895293700517367016077996431570157414340, + 16188989656090417148189510820963186890780289777598053654241741803194118100843, + 18027402882394597868782011288920739982398714370069420860949975937357531046151, + 17780529984916796963712255733293310230026423072958099290880849386941451922559, + 20004531511171838591303710792081846238092292916166965045929062171308088520097, + 13855731634251510230399834192704620793850325654395687428672253016405315169901, + 16872938837392115669581040432902657478544143723662502779821325505282093696739, + 2541555081244462826761076743762714962901590548271316707071685417008817634653, + 5136424039269088350807839181761422963254683236279333039713142751702136147963, + 19216238128964101420135465007632926445321991494181045543846024053552797518994, + 18868537488540023742258053821537824724371813776839672880900985865823137839953, + 18246710415801024039719497716350501105591286880983169809863166130543617917249, + 20608694004331631709610739723463009412162748201282986294016482926528443868949, + 11318113915971658853560322943565673154831611543653209084299774855226816037778, + 16240989418312335385576389959938922684406585560688799437547298624184839261343, + 16171299673760267132909753100946681733778389681324959987573199154235691694977, + 8036823955656422391918380552495301547890420665617977624790236120392727764522, + 20269862530534739231936251654244170650781428788816658397167110617927916774329, + 2368678892744667199202318323282128737449992006513656480477288092472671147090, + 4618078962163037429845764284139891171861860687111566735174912070413086829215, + 12695350627501306162901105159009497730633599768443844225981772758225613194238, + 16356283146491744069785034066388746989409816380917535719898337817088223419024, + 6407893217596287850421377738867081146106659458551198123106454022096864887316, + 18168868018352364136212098098453930600797374324006271488950341490483455519349, + 18352629174410142476418438008157117497168118524562206830585500251463010761689, + 4344169393287991961961456515301754172943022039566219343212376057129143739343, + 19424839806870716108478074501405697296961947409763509419111261767390677718987, + 5796037897847804302272999466834285170265203646465480652521088328457333766863, + 17402105801450379889120987010453669096275392789725153915905747267778100864362, + 15540989618743824352651126288511222263828123668208146479603617243655978402205, + 945810410725426921570254447269595873973858272778720657523509910503434094174, + 6962323734045776666289031609372270190654631739266635759799844631053633876675, + 11382945272742312954364642163371436855283161775445664525053938433459897196647, + 18940251871958826726849623572811640436342841713786099464305053400421580490631, + 13969540696178305383564753026163726563325318478290740131984853424331762285147, + 4841983966001277917879506889862519614692143906356361564304719688757862622407, + 8939049562492171082419559182596894186639203815268680721033389307282239000385, + 19265363396776097866041313346787101192508520582744521467413665478819721956884, + 337106861429123598189388456471513480497137213511877011021531147545809512194, + 251367482782327915297484770356856386307188967585026711663629212746150191478, + 19506616511267234489421548744907283107923549136620297132842391511025844759064, + 20633589633280372440758096707466273580151526293980868749421563697429194761212, + 18833062060138888612708634036427140134887774731041742144004707524569102994071, + 2927291160590267909596732410727396533948837350308818016906834558527125752899, + 7095572562193114209617459307511041110255341231707924363346373597653253806883, + 14274988113217913224290208839851596837329960221329537670822013510325939323091, + 9965830780560026128320556230399915681196410289456547935188741323403719404039, + 10333365845496980935202034863900757172839454015352626511769637076650624839070 + ] + +// t = 7 (6 inputs), f = 8, p = 63 +// t * (f + p) = 497 +def poseidon_c_6() -> field[497]: + return [ + 15193892625865514930501893609026366493846449603945567488151250645948827690215, + 8655680243784803430516500496316192098841666200175185895457692057709359214457, + 11710807066713707084726423334946631888369490193496350458331067367713412617049, + 15442364818086019103203999366702499670382575019009657513015496640703659810202, + 1358747428976145481402682338881091555771254635226375581638965497131373838774, + 15658002471767984962034589730824699545808755102240624650914676102923421241582, + 6420480504329990097173256112095253518339231893829818344055438052479612135029, + 15457172495394305353698644252424643614748461590123908880271021612601244389162, + 5745943350537490600340174787616110056830333091917248931684290284533019091654, + 3877253492903478989342845512796806320713689655633086736499730391667425329322, + 11257677301507982757739320943403112189613848490812422490591766717141506751601, + 16906586852467953445509312290627525856126394969718997799028223470195783329296, + 15263589725854108297280528692120758129000336125328939290924952731952242586386, + 21735940039489460025710098364749096267519151075908323637361429746399161905338, + 20023056608360522105358681147781839024069418874082333862551226466128829664291, + 5677500725280079960679484373333947430817198394184436922575072427342643665917, + 3080516739494460477657748111767941482024045797587058388950619118994388252853, + 21486496065617100719537932626843898998311175055335457507845650282870586541596, + 5371049178920102602305531530023787518286335086323221270202212974241707302466, + 3074817222296007572297581554183445947239252698770067839721345984255386069425, + 19180807038569629573914331337874446591506172622522351734982093457681161813141, + 16937785199372956273358037645552299688842385008757508130180245705952406225194, + 1688218397616770248184651775433764527272029131542529408516364801909017591719, + 16315958669815317541884966612581197291281164499674338063931623110684590850347, + 6218230753007070123505625054833158632732536069700963073464625252554943737669, + 17774528060285257656595928889288330429565059134928074258373583886985960212139, + 16197131592052727313460949906369199026477758140133103701908949020106767192893, + 13418604038232148873269488320329340508522225417123160144993642839875173062296, + 7265658443160253752317166706266927598319661172006072732797351716897681315157, + 17200150079219747370109251547638276280610591698078334228421747259741754887, + 8627121890622175767416692555014275717515106888840919734160364408960047296494, + 14546964505431549758350267964924534495477687922558528647552728692912697049247, + 17132720822762740343718421124251772119916072270451579802112353604446214831761, + 234333065870376500756753915306346778417056884715946003873280290982247600083, + 18375643491701271245209094287106352436174133929245169725584150600992143374298, + 5158448692161567615645197008737390561357077078129599243188536485308363800282, + 614161645152783610732075198073600394068518413590650990586931263981193439341, + 12661793104597977909223565537293318966803153852970198322604479648383643541371, + 13041905650419760925682179803296711066088286278603171065755078690359168540579, + 15006023590144168506070897325649191051975999212058008674224953860265667513015, + 4983349941266961584317889823965291023669365981564144622292227613558024302012, + 482274340065333833495445682213681402212945945150526736364263233985449810602, + 3966893131006556898236790392613869798057510088913626163333804949895810673044, + 20923301526284527685000591080290190641416245135554916208054502046381491809443, + 20838692384005825835959734210506718428443540957544929066941550833051093000166, + 8282357714606447781782716442854085217089572080066047419459610560432999443766, + 5410651444876169088887579490283094453001167796545260026969919887357676973543, + 15276966646285075387317940436655285872037988805762800567413073418506412856419, + 15066911464727337689573664613158712498015597773345106524271610486257089622849, + 14583790985054968382519116885383608902981814292128186470697458065499359610203, + 12059090796146479535492139954279038037217093044815277624197659219529427760034, + 7273811886044732271171500579064359282424476926867187108258957006777685922641, + 1463086899665237074608503061872751147444637332808872866814340325832200880984, + 4403177494620214359779479537027014449448686844655371530169401219256448130398, + 10860968418848589590932601250051274256181778387706764281989724391784015147562, + 5268786978207139542368199165627108325282167169564314266747401266496556301775, + 10683355823176907476704511935094343405052640940909677712096702771871787224727, + 12998090263935761477316698114799901126086030852595294916463464609721875730852, + 21401280461419124637791689956622923839426783908187419462727763377498739154778, + 9827224472048063173905906705579289843819400982583185823840008976971109664519, + 6215804144039763858354471461864183189301201862376216122255322421321775987311, + 15461308489200344015891625455653488930440613755785081602434124530381300882814, + 19336334695450889400681207491394600659946256404722006637851709906131899294790, + 1712331165786355540802697725399423752392267480553199895882357858951999960061, + 18153038525983970702748717571053178456148003321236490384959117581005013333018, + 1080183517033034908031748897211289245459330899463186432840251241943892326023, + 8948022108193679628295152361559653763100984324221629445749311939820327674857, + 9553342289560502306921915013446606435600388298465288181461633559299564421155, + 12714965617376828547637017050548818007690047452402682720666099310241001848988, + 10945704657865102635748104464461970844653553427083981539165832149959193156197, + 17511714411688352203059545713591160825310809755917403629838415797949261359373, + 9253691969419856285051096287845246422848295397226841130282244592511676512433, + 12218945350859454581754463621617733341764245716874083264842931063272433793037, + 15268139709971695434346690496076067658968455677120655340969837725391575270485, + 7948825129295102283421620705853168119104356217418364837218892682579042520651, + 6887299291348589691868712194070626390224806410428583073294593431810559288717, + 3610235157455454109573625364057240708256027358184031380521552355839155549623, + 16532488069063334064099666525339953823111673083177894678898823509406678724969, + 19317517725107761280217103201908049748015068578935276576200982249386084367574, + 14980901224290526859762385599553818204548992110637275324411078408232697158492, + 7741797285700915051013289492475875831764653137095445146268474269974647962596, + 11964233864746181868467810392101989052496076326472717372132104394243614334823, + 12746657111181947224582102380049766839578185276220682311596480990298620200286, + 6408726946032901840418309506578019708113712492100046332894630652186614300568, + 20959261828945984489015610988397031913577918654575078054490013338416801523934, + 3173674599420546165852740604987014294355430358334465189504551707066179193914, + 16110281513253204315524614633789708146700074483476149119440509845258215816735, + 17135377580103690088853370572199271964414896742342749305424508776150797285064, + 1405769920008485935711505753346340073052795087429311991287498566024570212365, + 19088073362945853867763169651582894739272002359692597239222895238839593467749, + 19897231284455588615416169252449008151349728648961637517447194842672488184146, + 20476415629812014715153863754869742189693986277342067785614833846523246536739, + 11074321446706734150375041020583051611133090415774365192315805856051215270782, + 15231367549323128694183572409135806408519505225209496441892541205465727777072, + 10515952069292929457050921929301902464262874744159361114100398880194109971971, + 3216370118771824418364829250073852356774095079734089790620447714552849459645, + 1940445924652458480775282556203659335417827058983719042726494187979000691704, + 7899310668555694144370607061960060230071621529123669746309839400642332452086, + 3125410912833939638823760577011271607678545358020637189655641109813198731542, + 2980079409624774815878860133121670095839651294537928173829312563570356348730, + 3766498515736372882285796238406751547889526137955288498682767455795237989580, + 21751217522789414135074956130080241003845828660310903627224390345319859795839, + 4947229586642010378772262640583556676497656670779800090478805824039760706318, + 2168676839236948809859825591626629233985269801981092020040909992251312517552, + 21172906642114648036685108008020762271569381607092920279879047961076646303327, + 882675742500939602754673078407141697482716600335919344527751158504426951699, + 20942968937722199705624825492102184647835614761458159157410261242387423597787, + 21880640497503102067412608072166388563991106464538369680846671301780353850077, + 17593472026567804917122179982860735087124786197105685847979050530954084564297, + 4492875530722152383516030266828166766820778742874238188105265500984280376666, + 6799763500412433367637987497601148507907071065930142757525839585946238894092, + 7812331664758167657763399273963290017340604299019483750344476103319142702775, + 2222332747647756867926707541092465789402467819000336747029352557749400316077, + 20438798382149666667185974604464532451975024544676922060351031604444896151494, + 16155157103796724378615022758633778903205872772589663310774455593497441785913, + 20281325298063880945091623185126257485818350714264176365501683813650871716911, + 4922178080989486450454493110764936742315495846015561426329316977670113220071, + 19579063976700768282784922967523980346960151903154507737857728349662090787824, + 2458828873355000645851832396764221987760639423132968569631493912353159373462, + 21166618206785010755521994106737991950548963896649678270059527421944129497211, + 9131643699583013708059191290958290089892787165715294157378879201986981390031, + 1820371114511473946932363841206094088983972935646887524223011276305844153307, + 7264184404232663540867032945940974372967974872966180860960243405462016972362, + 11228656105550475045610757902396386402555430893045183008968975441800824215261, + 7151503559113638565935009743218857812859208253653498318591469659718664783964, + 16876040581364499037941813142092448836399042253618385783944016186340703846779, + 10334125383426918152464737478646460879481305348617711177774418125714273980769, + 18900559046103390399749767994653107625464807708680067464279674225251110804100, + 18685667289312169245526749652972366835289568864080726348092618145885982989561, + 19970582871354083670567197978171723431124602481748785146813441774826500485907, + 15873472427137024971035326229485784626398898771525077832924901475242073457867, + 9090803292122260583635467396769157643561973206888822931647063181944243467413, + 10156295009710074552070572489422360071526675259143523597882131082376797944708, + 18600630374968456966046654667577076758720435487386724419578803020365834014000, + 21292291483064245088298314957584631356250347533568992016547598449487977536460, + 2784266893057214755054197979675795184619614089277590464548240934105557638370, + 21206743389683892419024645604723431382001453245850423743581664552645211926469, + 7915761821775326316473924816837591351530533394717381318596295803119061411675, + 21881095237485064870468603451853549262304643738646051878343976465227744077912, + 2011784725603622472271597952122938645154942022107573948889667939904597454410, + 21059869383015715705096974077910228193608826877524913363323189378554601804559, + 13660545486380051482020817701263881806531607595506890631732662177505270213284, + 10831091042775967380899180760062457635694790868286967266013231823406639854653, + 149288128407476550494800886735600251983375852319258454101603889073198917321, + 4032475033542195421623899365282946172767274020529645277615759958662043553317, + 17860535012887415629230166789742533149365132198763199254812432302158542514395, + 611194463774512114860065022851497908950074400927073001695280142990812150583, + 5518364261187313845085346561539515049557757056751872639492957432879259341390, + 783263978868449790737487156609432867806742277074765259237378374864740012575, + 19059339826992310300213673274315612374137067865428300882729551175173242291657, + 3179709304184015397125565132235783368222831063701934511986753856772139349894, + 10954198701843076039176000728742415722273043852061382139560487789741501275316, + 16411266672500930935370066093245284646483148609897099268661795671514664627451, + 14614816948231085620934132277599546641612327229810158468490195811014141518325, + 2458257206135880430320027516329707989817636936777744813891328347210486074414, + 13549483340434455515002570470395006683062583844603627042649952800864870013910, + 14465927800403373425828183741641078057513049263889255157342086762479739044711, + 4039391352709218793104596256671892882216573882631238721514928981154171136548, + 12750457082077152291009387792121930725761848879916565703854704756389714536037, + 20703941646953337308096638741387402857948436803334980867971163138332859477843, + 20148755487317949638981041809982361196106823990400472213765926589941031736503, + 19035096428824471222963574043396024781574056587456391309795571372815435282399, + 13597108420431213178364236660710194375344287228654817880431599113069659963625, + 16737817219786305757887002253067607822378794077688837656791543060369162185533, + 5164935079689729145670846016031605160169301936105766707946436049006171651941, + 21653381930704765824477248798502813954284378782353810890869232482999795586793, + 2062605478140760101860087118379474541965619844748678233207247884294051836812, + 6841505950265078437298089354417829781031272459823272323626556598403583002674, + 18723551101558427097952125661588457059960574026361073828482106612260297969553, + 7898804490983679270754258611113569895515918945891808074921872907759024464249, + 10882278698112390755842292529204069263813359338030917602809789513528936860051, + 19447560013395173052961224723195565400117958329259001072560983848146677205053, + 6251288025262210726686494480483550276704856797649458538460443509657307219922, + 13176666617050786358406074057104742181338809005466316548399895981897535342946, + 20703225796049910173111490454489910459787604528779911406172217267261190895618, + 20336720518722954780604743873837334696992422089627753769439653667292899832714, + 21420427865372074512365684526694872695798980614525900481233709853915806389425, + 2498895690812694987926199054702295457557454143930759961192198950277119149872, + 18753512301709603592612141197073246313430368834576850495154922324845448997662, + 13229612292359498096055458608547157785066962647476451239567069089111704445000, + 2690879919643532184588441383789963956137193400890598777054187145581183393168, + 14142396602342548413722428497204107502988046500369932366351553161157672540408, + 20448725195660080278132534867269279218381543910636641344871383714386318629041, + 2559459540570011016181396098001618067535109329950570139376049832813577592045, + 2209294835847631004298393339896770055851570184195462947318472391473531519454, + 14610669112573509857774678749257346364319969641690596877040685661582231189775, + 15281088465087253563674405311018738676067395725444151577815750152538449780965, + 8600553033773805414817363397077178137667131851961144771667772828459236208319, + 2748346039979601666392027583251905158817539034260921486084376270967628661657, + 6854960712378511006304629447898292218014632388505703802374806527561178043857, + 20207552563190343462280438839438087615024485494479390954719687107061991587248, + 10281541252271366635718295778088948309847900730867531177275273130071062184625, + 18855605847424121529776135453072696981767402526737712879984848146282568841809, + 4160214035780913418097601322951078913381556877408879904436917334405689553255, + 2122867135885631508183413043949777333811557914428796322029495785048111325437, + 18793959580906171893053069386015945646795465354959679615181136313144978078417, + 1043591673717355695648236328597936528752358227297053230241551190351813693314, + 15686469257015275311444450012704351019335987785561570672026138336552980987277, + 14048856209379833670666148034655599475317994357805584661156301746235313941815, + 1011563953969880478397969933799483261900428580241502003261587014788238280391, + 19240556623066672446907714818724971233422104071815927265423017590508305430997, + 2121904286573815063480388650799381683473766736407678915747169455786741101182, + 6724437969134367395210139771738563153857495313330774537559578422672993498270, + 20206855573383441961836932177838081339503382415601366823182724056749038447809, + 3659051978213562322887447057085386386485486575515693147713900345497451171308, + 21246119528547168535908718411570119652856799993958321864163737649108920924448, + 10446114322905404392321651684574668727564081327779662579984472408056125404335, + 10052242287865403393859620372179811039720807230902452334457123873762222543944, + 6373462744579965543231173757071025010089494620309953425653057223643612177083, + 11716070974813426833631730493593924834405915845847679294742728105127112594434, + 6451284530793440411577197006976867289209413848762574411101073727224316913966, + 20143217291446069633369261481904349401356557325260758866598205109039367201468, + 7741896897172494958877302103827661518814930985518070029789560123401964418102, + 7414486245715284930410091802521351113719159777210731898112598211035848096490, + 6480506916211642204624111742530825907262535747743645014149694168805302825019, + 18349725066341807634895742572304899830893334427067633858521634672944685466440, + 1838291082333887710851505844271184097051704051003105078056248035350245616867, + 19201915197596065583046168024521824662441686729039260890206806469763190071269, + 11253788423541320580105520117231178489492440242200599071301755928628199128159, + 6048832714406694444296771635481934823208451249770515560893368035838759154821, + 6398008918881249487422929614611145638894557821587972164243877575640548705346, + 7013037564266297435879776776659289982125632651326438965546874242685502904730, + 5942504790082366811245813670914617310604940200824079289270465669331434165301, + 14344789199380317440464969138686896230070901882253997360605407637865754361287, + 19920212380356573378521292048728904573841049083972983190424200459025557666792, + 8983390577894750782268266038315113359711163721228398686939390484499979421166, + 14953991148867572055684497824790735528852361750007063016470842397064705671772, + 5592033578501586280289038012647352732276003389059749788953239057845882297561, + 14076883072716069263619564306953450824526010844333044566762059693672378725675, + 11108270411921226463443318601950168860230077781212396032908932369105145901793, + 3681277588815101350213324449908372578846563884174807724121308021640034446476, + 7194753190480156904207319938161903897566477363779122267985209483435838216959, + 21241255448366937244332942306324590869759761073985963892514045368815880517382, + 6203071960722514588958553813186803009742459823360660333787981951206442471249, + 19041823565851118046937769551785013706136778514067168239416647071096062639366, + 4928136619692555022185087228378238193895894009623071873887735418398682287593, + 16266329364886004534411977872528706660422476743809029518681886596981922182359, + 8814684891729998059175829142248330760704444206534875755023421115211106199303, + 11072277000652722690981202459933101924925520292174200155471966778637063588914, + 15889576313969861857250394875354819627977602318110620311480656842740292435237, + 6934515229262494305594741689326968268143898236690173897991110238064230886755, + 16212991575388366798683594066983659236103186124339324856776288894513503543244, + 21100508914867482363389012032457112622475533432309937238082785660233880354422, + 10381104469089401657446748653199843213201270332853172509558263968565255702795, + 8849389605935865968361613766905708889092097013638425059146677490704442276611, + 4826404934194100291623537890117339503344940312401101713754206109744511979962, + 9981819567268652304810465083896863711149056310505889216307212434682251812603, + 16218484218588441290424553684558267080330286201433140852298971691458926313766, + 21317661296916247018967238829275056855142711494630067664736600708605437812892, + 19523923008662567951910986132173659591346561824926093935331274289896011695634, + 21439241836891927940168832009944210084078628922824257988298290967895179737163, + 3818036890597976956138669961319975835941979944306305168232209375279960168960, + 10212547715001519604442389033695156945619060410131175896383181616280631586732, + 956283172524544133830416114111944076629240232397666924807554743752464221045, + 8545109273807246425343308224167362024331960554428088718932211551700420545275, + 5647769597708100114837534314408246331518385631750569421373379085922684908872, + 21776221280695269311212391423788179027868152904973644113087833004348746215729, + 15989020831232836203074762591626149244364214836699154611339161287030952623233, + 9384665943619921791886218744024370375464874104981653298499433530463000935024, + 15469006121097295841026542766455781293432005131673839148320165243166330403027, + 16103671377537767724271717097892044266704736999841135349844319906338275108222, + 842367229428650719054831004741080336526228967970570607897528985803108607790, + 8752325400224955775788313769797750158375262384121380328719514077259567119347, + 4803861091350023344885030428100876947830986453029412601567992550504530969575, + 7917553047944370948250445233027936387189889293110390303835890604428798853681, + 16378323148632546424902611135263436821435778030958161546757828745002247975096, + 19873719885630097137106352132870659633926425645300622070145979694717581586592, + 20324790419158243246762098227260178678767896786893299456278167341205663612964, + 4358908354524026935988729716331497263147669784003421920394531784876541301801, + 14403952632095852077754539203207047943619815438482171213105824864831554185165, + 16410713482142323347391147127545553384558868490870150984280601225023662513809, + 7304216341846662695189617252648753140769311862815448449926830269690397729157, + 16792943782280077475956215580025612636120139194657275471595325031090407485768, + 18494329391227402645175320826355306995912366111176422593669423022411884295357, + 3277597348237827068690736756050060740435013727549848360800059544123155276133, + 9396765756719511114743964794180256605700037182617127755220919249774110852382, + 5637053961584389263881381098869862042993858662768294676971865632259649027245, + 1752142832257643043564515360000718468888861086573246457619082905919623770956, + 14504506574384680785750882507533398260948836347427103366421836731538357314790, + 18947994518078004413210940685748534988014581551965984303066903086446389273117, + 8931855168578615387850254663107425567403115805663142600825724478150698936342, + 10982092525200624040399870568387498905840578524691489797530932831401946309626, + 4738907023206802373255186532236849256768509848242049657234258536668430260775, + 10888145285628319545262252531874405309329869513560101920454793431198094714989, + 4767721624212785367044047554655794533816937807005608600525762243335180089923, + 4054394679973840378112083329204220302222586590732553688297938891619998137578, + 15390471663419625573793381445844013245022413344196724396864223784781333233143, + 690498740448849288977645176879593806019080276382495160049117613302192708860, + 3326968907274045758110436838010900592335267522219473049427145975873344598768, + 19461545874830130561487975864151403334363998126023624462211037468138940028328, + 2255249425919459031033123095731665691066980364231819200773725596456576056043, + 17139538647342063569964264947811360956712827863014723985947727876623459280539, + 262834317961189780923232082352297808796511874872711860311746704570027370416, + 17784213646586812350819691264737755884800773322574478474130308351003659945289, + 9206479615073686723914227166450906925650471865894639492301222855979337534393, + 5955379232184076713510750681781395826148323482009739159408415185190732125682, + 16345512244217240951729073298135981012471478596479891072149124888060645303490, + 20053701095030547796310908765544502773063879272854547881438596069907281565287, + 11519146559536679602608982593432194283609736022486509747046459824035493513614, + 10868663839942247532249591973192159672852196011910414460124452013501564199585, + 12668355291693420029179738224611760713369106517542315102687346083105601320689, + 4091011252347209563858280520339886760216002486858313383741839652119084430270, + 11416347683590132388448480763970462739172261435271326798646502987745949753371, + 4462763980178675172541782335457125059884067698347130082276003539434128058577, + 21728891122467658477520865529973242372850367356840114983386033432316519759391, + 9556106604731806817435679463077765288658189491612307664294729425381901530224, + 5086982973132652080709554654284904229374030594786774699435814748257879554118, + 2278505454992311041650060186856758463754878439802195559533882189615578260695, + 16123495070352975934848591912315341924608875638550779884194576881433498909405, + 13177225503435100563531015597038445430211235761527278782674200718068329833622, + 11626932451843299545922103072142674578946680165802341368625957942237790110177, + 8872973246419344365802198448930136062421718851114220299577394844231810068090, + 11920016786052130191738519934437207519332291620474831138559948859328822621221, + 2773753221970604083383541092979093729869734021029185810064937974430862835870, + 1194583082499114147792330367943150006952486615245506995832323057119894886077, + 15293312601348482070373672684782686300692505365845870624263228679370968807837, + 2292156760291800990693425534213440357167359161992251338587906324724034592198, + 20920049766730284147153707151387304988393631464951398563908410768221002588086, + 3587899345078220957148828249287269521408604837648269936718299413697642586126, + 5857527906708110948691023855516662527925762284342493618496858248142623857037, + 18312267494676788897591109008609888960798722042916784593521762607767538629817, + 18354455618287562133438807735729369657256664914390381320892039403006410339493, + 18594037435499535688023807489676900345345731643180370940972090155512943637000, + 6361231157299815359812386352981667048590510979947935475914610076041390336883, + 6503045850716008738909204934356093641022474278658078426701342798380459107813, + 15826908470360778431798326530563200301151807861414464213699967513881040969457, + 913167165738148713876672473302437265273760468892350716109373788573860454641, + 5163418960719047707254162004625467116036830361107107814320243058319914687515, + 1852750695670141634014249062360862036043602867770163972096325792863710036947, + 16164029969996795952250343426848596535809001568622155377829217918121790073916, + 42291476149937488089591434144089904529405222471677684973768504172369443350, + 1329340386229357940610579826659090359930768580941108555938139535621252899508, + 14087936453397725507000489457270864434699508074557952952329368237400407748133, + 11454917885298514922755456675259734718428103879515668717779418480236210705323, + 17749966508430836878443008025013283275306943216523661550528505419303121693213, + 16617298839486771009961431205770630163409905047728421465641369616889696635464, + 5622873871440608391107520706189063847917690892897751818294742462879871297589, + 13537715561706278379083684257583804567523085149672090320983273122424669242274, + 12609629910090871112615676094781247031353826207267723991911250780907380059468, + 11881347692420971451998583525696964339513193164613288356598017302547676912004, + 3620434358220496198439193226313617496907852030586214671337652678218740406153, + 16586456872124455799862826347901525401871594428044067424833235946565396779382, + 19602593015746956165116919928045364895525104709835703557292833702385934632182, + 2465427491077301663150648330772125184470808854603184374760649420983178107738, + 12521323976712195518272978277895155774288446093713549157148428964880747896725, + 361951232333654306694462853852464888974834703718677826403016226307188397185, + 20048343816024297162848487251896481827914904696805156112188099141327595641104, + 997638030405613623344188782838773314122493364653596616029491564227193697621, + 10932007654988104622042938184134556963651043067553327861790671211490960094259, + 47171599193060570819891696279547021610376047998583333086685382152080932821, + 14669115378939104862697280661831896914139331878760241858539421915983017116504, + 17868874372855679948405169936193924176514630305572838555185339642210810710203, + 10178296575837129106771098084407669500326673901243393867574658658064222502028, + 11497182727976130924559852428316615034304736115488257034951588831868596612725, + 18847036158089242140209840241495282890278502700082131513222116906134183113862, + 15514518995390761662346743876733004358408187550386554449789531199638765348953, + 11474102901522012346251529527050392650125347221410246734211005177721289856415, + 6612195415835443084676700243243174090072629504450965229103970796390091290688, + 11572474094368358234669561324969692616275099241307798860733942350364532366113, + 3855324911963410548772360326122995145790506408472649961229511965629894550308, + 8802640003128749594245736338745752744580147773009816234644244502373660889677, + 15676839305513015047736600040932186843826469281853634239081282896349443894145, + 11124722103091011602185413968164672678635980457394627450785290630813993266691, + 15087674670944618980358596427703842917302233637812357643695687556421910213028, + 457555060782651847600218200815104907046227486293278645126081160142069992497, + 5340353060455057701755599760342180989590806327490432497082435572367648024359, + 3289809733259936118731355294329652879189400852472418229718273887860572748363, + 1821386174933044868215348232606758690922944887434531299978498726875279584854, + 17399236630582894158137572250502674699298844870791766041927951699287421557453, + 16772722824042046255416248879357647708113647471330900665176012648038469814744, + 331374066696126093678097185404981758791664151917354547180452342655690460271, + 5482079579065945934120471179616600325379965440378196448353560421120276746028, + 11861638874356162254375133266687016527365630872709665703116365332534843803431, + 19751278476934230895840638614095718373810690662562196455711240141902305648888, + 21017623330912840225230534280017695045717261514215145256795880310933667407841, + 9692530233397639077769939390011937602190121885296235066426091743618448584134, + 7914031992737639503490179289412369887137436318696390718781298556229610513180, + 5046304088054212585035723354298412694927209198400753780585596829596665931980, + 12735457541003664856181534137486291132119134214862779086936585300598349629287, + 8144204472889944485922664106370529127382213990656088602566223875490414163362, + 5526161442679804982165840590640681348630369336752481706044759543203459722566, + 4665464612431440885211271075488840033628676516298384234452346107374012633528, + 8451965709652752887539585363308640999657377914501438391781526068371105983117, + 18990458193856163728406448194111866469438835810342179114684453609893347662421, + 14602960690767985987882800342208585041637986661619503513589079723840776294824, + 294650277854196485752526848096008214721988745350555311479128101695333774927, + 9930361494944692931597991649915857642608730961125454734483697613693272941776, + 17972565769620820679641368732920396905240248490243886868922250461473059009007, + 11842743032528966560856860268344505094861546674985872961254820091273444880060, + 2260251491209762630871337015316066081541066308706934094017641769176593121838, + 21336986809148977544823484666876006147697590184356254785752148187171367963063, + 15637234083283356311249527335446193685599985235080555266374006156231977517227, + 7637477891046186378249227336975234440873859617986704147458186423096226771577, + 10435340982947407847927678888878882924793449778165415690957335683641419176012, + 21071574044063633264442120715854514033847137356154103023224485568597330648075, + 20085745552872944745120547909310789275453780111307008151203836541147270866122, + 2369255222739182549768488367357061329939116877812397072967912842660453854658, + 3320710154094663715463854219978294133429318041799642537800174050047893035878, + 2437552820481788519744888712380245016748276158860265401041560980354471184914, + 6687580113987208531705167517979176727449238324356562435678492283111952291541, + 13835828959457330678345759960614663723017667326485961761361157914420441377430, + 1823843951353887792473925888956554516299304358703549730900495356152013614424, + 18229384804985230011714562427207966412342158903455811854157839446374012856695, + 4983049472282717134994110428470567601005310848076496400503178535459679438524, + 2047051967230753763135778305592853785901616983565528680886843131244871631064, + 17059505494771925862841990046823342770591010831955480339095397897088168520686, + 5845823714127413134610517798305104245114036685335948729450609519089263487144, + 19810252752845594230307894817800427820113926573704856490871938876757561680148, + 20741340243371419379519807725035036726040739024854919427690724405113594586449, + 17305746835229988220561638584011917989169628535378748397361130724475478785704, + 16273970657972145440112726408308019138099820274904080726219726815138597785735, + 4927605725478881247988642936459897069651251926499343645614635597380235002430, + 4076655226193629464789557616268492785057128805549395585385432329518368497686, + 18134767316186963456589895259454813585756254459227058992203617493951135964914, + 20798436806114056077588608064161229365173163847083955162560624566238528904361, + 8811900287453512972593412116532745098600991077158875340182906101108258578231, + 1611466530857794066271650650204918615746591649578992581483080164777650137733, + 19520757346022691586967284723955378385034675472244175822936613026597514818901, + 8258287931139503595713718829279050060190693609290797346704848518381891359704, + 13807143439443425137076128013998009581746894329904809421858222329599144124143, + 2034200548964915935625429760202284220693125881760822084201315022529206424506, + 20594375914400911567795140472107624446159181622166676420027082349633992663301, + 17773828019575037451999782968066986504577459910353828196403976545023426528432, + 10645884969014005687699860915213473815514464399964009808411811895545112650817, + 3135829883501342672772973577699379927756997243617424917654928164800203666496, + 21807676600134151299257078976418813484444183016737321278512745883771478511369, + 14168063038909284721702678019083222059818438340503980617872573468231611140141, + 19022539506931505257153342575586362988716958060936788031721967221986624233067, + 919797128086310623571009200546035983274688764270933413427846490906074137487, + 10651353481391913627770814216074873532920753703051075188645774021198634943682, + 21601553598752750925049978818528421110707879819831249175157596816870100048288, + 9544964974935674319204796617933096476421551193682156030394816088243121582636, + 17113833205578964054057051521784698139661258340576694677296240312431808476286, + 9889647672195559279745677506312894570402108521106900082889976819798270827735, + 16028191999932520938901585234936954312994452706490572504997534210876573833649, + 19224701772787524647172128751148104366752057774529591812815327738829591289117, + 8065294760892477625290114823800398061529770004833832691347498933238361039736, + 8385011404987806129246014860479833290406969218526611328586242951296814426438, + 17626526623257098006524211054563886193098683828265081734658432468695686509315, + 9760584950604786147191288118087660976225563461953070125437519145090832114537, + 3282956645059793949082172795607530130101621492305193365378997603911833418463, + 3788543541342252822847978185963388795825378340921321139695221828685330606335, + 5728277403393912877393143174229934529937061751983246730506397742038949251701, + 20532577038632159357383817240596922896191478140446876998140515404169184846609, + 6138500779693128517529525961343097735306947649093633133232282430353593175172, + 16387038830089541476468870208162294639575042754761542956218362331966004300870, + 10184264376398708852688445921404363179240954227345322711923845040842165453208, + 12576299651793170522912156101640799825541149618303513174146382191633847258859, + 1340015400080181141720946234858756484323564628916867888877667239334982793481, + 733959369856163480135680991009606990817015555938726628110611986599242143578, + 11467033813562140192244869512537566463715027496952375979909160849747976831918, + 4619667645046391146577435774790188488541561222783010406420406869960248783331, + 58552761198135931030902257754896948615688045302818928845814661296914920622, + 1199849881730507352706524556330002080538296688430736582840314007371442152147, + 7124502590511184113044595527748024819132713282667933641439666531514739645089, + 8623660134669459112474551498616256867375253975034970808437732784494772311361, + 12655669439191191182341423414424342421477486764113555800095493091893820045534, + 18432703875775002490514477493898870315422995231506677048275960580528644904682, + 15467220287938881354678249472400749704814316816035426814619089032223454845193, + 2851120240492392321044027263769720216640877441121430445737594074121655318176, + 20519914249934881206828098454303256358482675671718589102535780334267934987941, + 17275124961392392047135728713829752470490098022504524438869454049765356211723, + 3323710067527231515807603961736782048796606296990840839366613937968342331886, + 4468708240622802562056471128793253296493002925988003094771284205007772045098, + 9006494818135081033869830730030943407240565201693254355620348420258773924028, + 2624130417875598753127999576825019766166727976335690685433712946223008520912, + 164131399455376615654870570697119442360078693174350746600132391198500093412, + 14931668887432843139264972187415200544679230597820424081936926034478502874299, + 1638753880783574431267395352024193675000113296497173968722590753809640941864, + 15505380865926802396097545843811910443367233632805651511272732002583232431557, + 17973744614207669251901495093091561913998272050499760575282030108740677066624, + 6137688223696761009295745609563284204827706564566466060484103844265403078408, + 14774243062532823236792831566222119634320864630838624098798648826842418775856, + 15864970393171078370207775103899428499600152663946379517190945807315353544891, + 19010063123357565300336230971672519561204810737546730911549311353159512986740, + 12607162829921425080830052984475623157169603642577010527391007035133383807243, + 17803108634879437217723652777640120469990779759700458421844361066182881628345, + 10065874953507223318296028499872542865030107611981933577973812883589535269142, + 3276471432535144390388324850641020151392959100393035635141206272558418581928, + 7532054601401798035926415744768772852833516520318445183340725930886329458991, + 18893822928119227829016544343228228897166113682019317256005502643243867377334, + 15940597493253236451533839310728876441657428995464658827726295547815292644378, + 4268009387843764409267791203070919313017052533005657826253994943184768120896, + 21611251949238422413354051947529388972078300717392131751061464498329326474580, + 12516447001729804412674006874184731098280474050775388553768469608793631490618, + 49838549447142926741568525697026885045023997277705726329780325103507790978, + 19763902910323896567698991616245963026306943100978479625077573937114135803058, + 12029297973430627253212633299020402005457460023136429653800185001711727387314, + 17676997725594777991384952086633589048516371093397126876621255518370680168503, + 10567543371894667303450346380722020266352683222046730266924342174164712049360, + 14583364850544999818712646438016435003942847076919084667364987497592599663937, + 17348091487238815837308569582101875357715798351834275089190053280855958465528, + 8743083090296259283603789316855921930102444739264013461469099560398359267240, + 15114064505647935792598848256320570567717917317803629185764147361301698519005, + 18332675991829764561879941291908436508530604635608341316693114747813051532006, + 1757567731797951053080580099911774643896363235228742197150882457231133285549, + 6526388717947413328592956348507481629843816325885832861915399601868279124246 + ] + +// t = 2 (1 input) +def poseidon_m_1() -> field[2][2]: + return [ + [ + 2910766817845651019878574839501801340070030115151021261302834310722729507541, + 19727366863391167538122140361473584127147630672623100827934084310230022599144 + ], + [ + 5776684794125549462448597414050232243778680302179439492664047328281728356345, + 8348174920934122550483593999453880006756108121341067172388445916328941978568 + ] + ] + +// t = 3 (2 inputs) +def poseidon_m_2() -> field[3][3]: + return [ + [ + 7511745149465107256748700652201246547602992235352608707588321460060273774987, + 10370080108974718697676803824769673834027675643658433702224577712625900127200, + 19705173408229649878903981084052839426532978878058043055305024233888854471533 + ], + [ + 18732019378264290557468133440468564866454307626475683536618613112504878618481, + 20870176810702568768751421378473869562658540583882454726129544628203806653987, + 7266061498423634438633389053804536045105766754026813321943009179476902321146 + ], + [ + 9131299761947733513298312097611845208338517739621853568979632113419485819303, + 10595341252162738537912664445405114076324478519622938027420701542910180337937, + 11597556804922396090267472882856054602429588299176362916247939723151043581408 + ] + ] + +// t = 4 (3 inputs) +def poseidon_m_3() -> field[4][4]: + return [ + [ + 16023668707004248971294664614290028914393192768609916554276071736843535714477, + 17849615858846139011678879517964683507928512741474025695659909954675835121177, + 1013663139540921998616312712475594638459213772728467613870351821911056489570, + 13211800058103802189838759488224684841774731021206389709687693993627918500545 + ], + [ + 19204974983793400699898444372535256207646557857575315905278218870961389967884, + 3722304780857845144568029505892077496425786544014166938942516810831732569870, + 11920634922168932145084219049241528148129057802067880076377897257847125830511, + 6085682566123812000257211683010755099394491689511511633947011263229442977967 + ], + [ + 14672613178263529785795301930884172260797190868602674472542654261498546023746, + 20850178060552184587113773087797340350525370429749200838012809627359404457643, + 7082289538076771741936674361200789891432311337766695368327626572220036527624, + 1787876543469562003404632310460227730887431311758627706450615128255538398187 + ], + [ + 21407770160218607278833379114951608489910182969042472165261557405353704846967, + 16058955581309173858487265533260133430557379878452348481750737813742488209262, + 593311177550138061601452020934455734040559402531605836278498327468203888086, + 341662423637860635938968460722645910313598807845686354625820505885069260074 + ] + ] + +// t = 5 (4 inputs) +def poseidon_m_4() -> field[5][5]: + return [ + [ + 16789463359527776692258765063233607350971630674230623383979223533600140787105, + 17179611066821656668705197789232102741366879862607190942874777813024566441829, + 18653277315487164762584377009009109585010878033606596417396490909822722930739, + 7373070639853668650581790286343199505413793790160702463077019294817051722180, + 4823864393442908763804841692709014014130031798360007432734996408628916373879 + ], + [ + 19196309854577132760746782449135315310664418272926255500908899397538686486585, + 18123132816088485879885148351452823314623055244145916622592591084094232513914, + 18436594886553181913092702411547018228276047601279727265790147051821171174455, + 15167500404313194506503404655898040457721633218143681920692711693000769735187, + 9437986152015460505719924283993842205604222075968464846270136901243896809793 + ], + [ + 21445376105821232747280055223032050399373725161014449207033808524504027971613, + 49684738714301073369749035791061182456037935161360748355432247732088942674, + 9826409059947591908303145327284336313371973037536805760095514429930589897515, + 8494798325496773219358794086647759478982958403252584257436898618394561204124, + 21251937175072447337747316555423152807036003235223125066270735279039060889959 + ], + [ + 5539100337780919206842837176908516952801756637410959104376645017856664270896, + 6297628909516159190915174165284309160976659474973668336571577778869958189934, + 12792263637464508665199868777503118105486490400267592501708855807938962470650, + 17254685306085558791725544672172906900581495686070720065168939143671412445514, + 3590396502942934679818900672232030233017710909687947858184099000783280809247 + ], + [ + 19055249881366445073616526879263250763682650596233071589085239500077496415637, + 7367697936402141224946246030743627391716576575953707640061577218995381577033, + 1322791522030759131093883057746095061798181102708855007233180025036972924046, + 20456741074925985565499300081580917471340328842103779922028754640077047587707, + 9059147312071680695674575245237100802111605600478121517359780850134328696420 + ] + ] + +// t = 6 (5 inputs) +def poseidon_m_5() -> field[6][6]: + return [ + [ + 8266021233794274332054729525918686051968756165685671155584565440479247355160, + 7947823415909040438587565055355894256799314737783432792935458921778371169026, + 16508811191852041977017821887204137955816331040385276110261643892701458724933, + 1804800467126006102677564831888710635194614232739335985819349312754063580223, + 11189892034806587650995829160516587240879881493093022855087765921356611070470, + 20567450145123179140729389574352706949280207113956641415022972885523439610844 + ], + [ + 4666756311257455192796774305229624459258864488677689058174087310651786875914, + 11389253665835451896363091846189307652796786468610595637047377864063404843117, + 18793736599347263150867965517898541872137378991464725717839931503944801692688, + 4206344588923325482680116848820594823631536459347642329098796888497153867720, + 1739462481670645248707834504605096139894257554120906850613041004917967456145, + 18514227342636266640333254638454588508118462110178719555586534011641424431745 + ], + [ + 17887039315911403193186866703775654467672391491657957999455462537283842145802, + 2824959020572825365047639014537190268717891749361604043531643698340708119767, + 12521547103713919592301476538318318223836047611311454785951907894055964264287, + 8658146183671258251984364885894342376430874614261222570603159082682815800788, + 154390145585284450772861151318029820117470958184878116158462181541183085587, + 7593705166056392393963956710828665339496927193740869686529339432486182720653 + ], + [ + 5529559239163081088908568555890212324771345012509269613465629182165427812002, + 3729910453162885538930719732708124491456460687048972152311428493400220125686, + 11942815243552870715777415109008273807076911177089425348095503288499102855779, + 498938524453430895689241565973888863905147713935369405079343247530256066618, + 3976257517234324421403708035200810671331954932478384823208414346189926720724, + 723540703523219510043977323240437576248315561543814629392162302024056718473 + ], + [ + 13306548824219676333032339487546407241767961556934015003605485324283250885682, + 7970147269291664639740298762956131361316495463191268382513594527221399186752, + 20633313939958767604804835838065337107615699351647541991788258289962727735454, + 17162090859520817529294904484646695645841022315617926715432606252643123848792, + 9181379842957190051440498041153333325098774266789773971685141362947015398641, + 7051606617662816798224904133351061549832959857069896192072217769241273559278 + ], + [ + 16619522548478824222688310091434959542211899852679631815023615875678448806029, + 14965311177811968100298579672135357167599499478246106482433786066289128683961, + 9792733250919070275775594069208673385381167169182805600474820364274865306108, + 2069253833779081039049908513863485270550301879399727430830923273191877809560, + 15847298987712771667136245955631872888473964330474501593909263901393348546986, + 12244443532166430060291409356011430759892629145539185535677568234713942157668 + ] + ] + +// t = 7 (6 inputs) +def poseidon_m_6() -> field[7][7]: + return [ + [ + 19332164824128329382868318451458022991369413618825711961282217322674570624669, + 12346323761995603285640868741615937712088302657627126374070962894016296466118, + 3913895681115272361294397190916803190924061797587910478563401817340941991811, + 7048322889096718105055545382948709082135086733564574465991576956878202831861, + 10375086910057323893637057154182902576957472442368661576421122036461645295833, + 12765622911241487148932810040772504127756393086809438933166282251044289864727, + 266900212758702307861826326591090138389415348463003233900705815890364224151 + ], + [ + 14435131616556129905356866638030823183270286404767286105643513738132789033353, + 5780976801287540146775934937953368730928109502001687434229528186520268917700, + 1618320442446662026869390273942730786145909339107736579759397243640902802126, + 3818399583522206096165108192531271582827953520684743806492664825009577810261, + 11764506724346386316602508039052965575734225646587104133777798242528580374987, + 2414215974836165993714858157462355581258152126063378817495129367240311967136, + 17609437036230923129211608175600293197801044251801590649435913902851695334081 + ], + [ + 363438080029711424794236047863047716381155074181485245036621530063262917196, + 535766679023716739184211613469394818313893958493710642899297971974381051070, + 5305068908469731303772738758164870877638068032868328180355958394150421214337, + 10807632568240507366657354568432178961148417327580695024415275247652313539292, + 15964415873358391713354948903242729080763777490509563223190335273158191600135, + 20700362719972015883260687302741075186857660623182772413609788566925949033885, + 10135127975676256977820296631533839366076919827597067890970660746228807376456 + ], + [ + 4251490167543116819728642817282216847143714366441358372252125244838181656331, + 7745587495915033527847242564710473705100826890903278244320948416581724663023, + 11741113129223221800185946819924457344647035336264986754437921049066977440806, + 11630296782890656599545188109639399768829653360050213193782325240600583381364, + 16861140446185941149398487176581839232380972247302922484807333229513905651035, + 365879246117123675211400356410703684399715291171114630107795112994207447819, + 21725607857580053522363567649763546934441685061337033780528788383243719579033 + ], + [ + 9222866548596464928765000608129177609426964853736257576074550520759533736918, + 10261578281201197531384003420612639018011405529775212563256392340336951230146, + 15644037447921591571869862919382888810859308861783088910843592577202362807673, + 12752004188139535619565478547449108772137477456363099481095747591698702436636, + 4205805109630387448825516813913983509046636797101589615147198457314360427718, + 21047095155106717901091873146599497621258071512562421967648909471775919992713, + 15624165295872926124160584750951090817255240214488120310950503163805737026315 + ], + [ + 15064589937731741958666763896598138037875460434244947486199623542160035749721, + 1801577872277160959016940766173040841160105238799805406938450020949902989173, + 2896766420608048344829901127120623317655260981420052771341833288256800199953, + 12828791469509204618898135640019714232831708508424682785876476343251730674999, + 21363471986981372923191391880511344708743312828234098289107697080824665183315, + 21372706354350795416381912271616633829725494570576895047490974943034914894898, + 16006531510217730955981102005088687858079561573088629102219485906666961331083 + ], + [ + 2389357602244845938251345005183369360523566673990464798041306722747500447645, + 15275955107196234672088664710679934029171843237458844492987233368659104714648, + 8038797517535218686870517662905230585331773059774130312418943649247287196930, + 17923922393436914864421862212181654800719733137689602673604754147078808030201, + 12890519745320143484176500044628647247549456778462652469313611980363507314914, + 8058516556024397257577081553178859094042894928866720408652077334516681924252, + 768425396034382182896247252731538808045254601036758108993106260984310129743 + ] + ] \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok b/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok new file mode 100644 index 000000000..454213ebd --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok @@ -0,0 +1,47 @@ +// https://eprint.iacr.org/2019/458.pdf + +def ark(field[N] state, field[C] c, u32 it) -> field[N]: + for u32 i in 0..N do + state[i] = state[i] + c[it + i] + endfor + return state + +def sbox(field[N] state, u32 f, u32 p, u32 r) -> field[N]: + state[0] = state[0]**5 + for u32 i in 1..N do + state[i] = if ((r < f/2) || (r >= f/2 + p)) then state[i]**5 else state[i] fi + endfor + return state + +def mix(field[N] state, field[N][N] m) -> field[N]: + field[N] out = [0; N] + for u32 i in 0..N do + field acc = 0 + for u32 j in 0..N do + acc = acc + (state[j] * m[i][j]) + endfor + out[i] = acc + endfor + return out + +def main(field[N] inputs, field[C] c, field[M][M] m) -> field: + assert(N > 0 && N <= 6) + + u32 t = N + 1 + u32[8] rounds_p = [56, 57, 56, 60, 60, 63, 64, 63] + + u32 f = 8 + u32 p = rounds_p[(t - 2)] + + field[t] state = [0; t] + for u32 i in 1..t do + state[i] = inputs[i - 1] + endfor + + for u32 r in 0..f+p do + state = ark(state, c, r * t) + state = sbox(state, f, p, r) + state = mix(state, m) + endfor + + return state[0] \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.json b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.json new file mode 100644 index 000000000..a434472d9 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.json @@ -0,0 +1,25 @@ +{ + "entry_point": "./tests/tests/hashes/poseidon/poseidon_1.zok", + "tests": [ + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["18586133768512220936620570745912940619677854269274689475585506675881198879027"] + } + } + }, + { + "input": { + "values": ["42"] + }, + "output": { + "Ok": { + "values": ["12326503012965816391338144612242952408728683609716147019497703475006801258307"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok new file mode 100644 index 000000000..e846e3796 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok @@ -0,0 +1,7 @@ +from "hashes/poseidon/constants" import poseidon_c_1 +from "hashes/poseidon/constants" import poseidon_m_1 +import "hashes/poseidon/poseidon" as poseidon + +def main(field i) -> field: + field output = poseidon([i], poseidon_c_1(), poseidon_m_1()) + return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.json b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.json new file mode 100644 index 000000000..f6a28443f --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/poseidon/poseidon_2.zok", + "tests": [ + { + "input": { + "values": ["1", "2"] + }, + "output": { + "Ok": { + "values": ["7853200120776062878684798364095072458815029376092732009249414926327459813530"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok new file mode 100644 index 000000000..29e196fb5 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok @@ -0,0 +1,7 @@ +from "hashes/poseidon/constants" import poseidon_c_2 +from "hashes/poseidon/constants" import poseidon_m_2 +import "hashes/poseidon/poseidon" as poseidon + +def main(field[2] i) -> field: + field output = poseidon(i, poseidon_c_2(), poseidon_m_2()) + return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.json b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.json new file mode 100644 index 000000000..b735c07e9 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/poseidon/poseidon_3.zok", + "tests": [ + { + "input": { + "values": ["1", "2", "3"] + }, + "output": { + "Ok": { + "values": ["6542985608222806190361240322586112750744169038454362455181422643027100751666"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok new file mode 100644 index 000000000..ddc2130c4 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok @@ -0,0 +1,7 @@ +from "hashes/poseidon/constants" import poseidon_c_3 +from "hashes/poseidon/constants" import poseidon_m_3 +import "hashes/poseidon/poseidon" as poseidon + +def main(field[3] i) -> field: + field output = poseidon(i, poseidon_c_3(), poseidon_m_3()) + return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.json b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.json new file mode 100644 index 000000000..16f289b2d --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/poseidon/poseidon_4.zok", + "tests": [ + { + "input": { + "values": ["1", "2", "3", "4"] + }, + "output": { + "Ok": { + "values": ["18821383157269793795438455681495246036402687001665670618754263018637548127333"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok new file mode 100644 index 000000000..eeef269c5 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok @@ -0,0 +1,7 @@ +from "hashes/poseidon/constants" import poseidon_c_4 +from "hashes/poseidon/constants" import poseidon_m_4 +import "hashes/poseidon/poseidon" as poseidon + +def main(field[4] i) -> field: + field output = poseidon(i, poseidon_c_4(), poseidon_m_4()) + return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.json b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.json new file mode 100644 index 000000000..4a4a7ddf1 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.json @@ -0,0 +1,35 @@ +{ + "entry_point": "./tests/tests/hashes/poseidon/poseidon_5.zok", + "tests": [ + { + "input": { + "values": ["1", "2", "3", "4", "5"] + }, + "output": { + "Ok": { + "values": ["6183221330272524995739186171720101788151706631170188140075976616310159254464"] + } + } + }, + { + "input": { + "values": ["1", "2", "0", "0", "0"] + }, + "output": { + "Ok": { + "values": ["1018317224307729531995786483840663576608797660851238720571059489595066344487"] + } + } + }, + { + "input": { + "values": ["3", "4", "0", "0", "0"] + }, + "output": { + "Ok": { + "values": ["5811595552068139067952687508729883632420015185677766880877743348592482390548"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok new file mode 100644 index 000000000..586ad7690 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok @@ -0,0 +1,7 @@ +from "hashes/poseidon/constants" import poseidon_c_5 +from "hashes/poseidon/constants" import poseidon_m_5 +import "hashes/poseidon/poseidon" as poseidon + +def main(field[5] i) -> field: + field output = poseidon(i, poseidon_c_5(), poseidon_m_5()) + return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.json b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.json new file mode 100644 index 000000000..b5ea024fc --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.json @@ -0,0 +1,35 @@ +{ + "entry_point": "./tests/tests/hashes/poseidon/poseidon_6.zok", + "tests": [ + { + "input": { + "values": ["1", "2", "3", "4", "5", "6"] + }, + "output": { + "Ok": { + "values": ["20400040500897583745843009878988256314335038853985262692600694741116813247201"] + } + } + }, + { + "input": { + "values": ["1", "2", "0", "0", "0", "0"] + }, + "output": { + "Ok": { + "values": ["15336558801450556532856248569924170992202208561737609669134139141992924267169"] + } + } + }, + { + "input": { + "values": ["3", "4", "0", "0", "0", "0"] + }, + "output": { + "Ok": { + "values": ["12263118664590987767234828103155242843640892839966517009184493198782366909018"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok new file mode 100644 index 000000000..b9f101d94 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok @@ -0,0 +1,7 @@ +from "hashes/poseidon/constants" import poseidon_c_6 +from "hashes/poseidon/constants" import poseidon_m_6 +import "hashes/poseidon/poseidon" as poseidon + +def main(field[6] i) -> field: + field output = poseidon(i, poseidon_c_6(), poseidon_m_6()) + return output \ No newline at end of file From 6a1952c7711d1fd8ab1975d484742c6f75fadd5a Mon Sep 17 00:00:00 2001 From: dark64 Date: Fri, 9 Apr 2021 23:00:19 +0200 Subject: [PATCH 13/95] add changelog --- changelogs/unreleased/806-dark64 | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/806-dark64 diff --git a/changelogs/unreleased/806-dark64 b/changelogs/unreleased/806-dark64 new file mode 100644 index 000000000..fd1cbd944 --- /dev/null +++ b/changelogs/unreleased/806-dark64 @@ -0,0 +1 @@ +Add [poseidon](https://www.poseidon-hash.info/) zk-friendly hashing algorithm to stdlib \ No newline at end of file From 856a78a378affdbc3a0f0a7cd0b7777d07a4a0ec Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 12 Apr 2021 10:05:11 +0200 Subject: [PATCH 14/95] add decimal suffix test --- zokrates_cli/examples/decimal_literal.zok | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 zokrates_cli/examples/decimal_literal.zok diff --git a/zokrates_cli/examples/decimal_literal.zok b/zokrates_cli/examples/decimal_literal.zok new file mode 100644 index 000000000..86ddc938d --- /dev/null +++ b/zokrates_cli/examples/decimal_literal.zok @@ -0,0 +1,4 @@ +def main() -> field: + field a = 1f + field b = 1_f // allow underscore between the literal and the suffix + return a + b \ No newline at end of file From 61833d70c47d1e7ab7a7c81a8df73ccdd083adee Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 12 Apr 2021 18:49:58 +0200 Subject: [PATCH 15/95] import multiple symbols in a single from-import statement --- .../examples/imports/import_multiple.zok | 5 ++ zokrates_core/src/absy/from_ast.rs | 47 ++++++++++++------- zokrates_core/src/absy/mod.rs | 1 + zokrates_core/src/imports.rs | 19 ++++++++ zokrates_parser/src/zokrates.pest | 6 ++- zokrates_pest_ast/src/lib.rs | 18 +++++-- 6 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 zokrates_cli/examples/imports/import_multiple.zok diff --git a/zokrates_cli/examples/imports/import_multiple.zok b/zokrates_cli/examples/imports/import_multiple.zok new file mode 100644 index 000000000..7f5b1f6ac --- /dev/null +++ b/zokrates_cli/examples/imports/import_multiple.zok @@ -0,0 +1,5 @@ +from "./bar" import Bar, main as f + +def main() -> field: + Bar bar = Bar {} + return f() \ No newline at end of file diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index ccf3a55ba..7b29db1b3 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -16,30 +16,45 @@ impl<'ast> From> for absy::Module<'ast> { .map(absy::SymbolDeclarationNode::from), ), ) - .imports(prog.imports.into_iter().map(absy::ImportNode::from)) + .imports( + prog.imports + .into_iter() + .map(absy::ImportKind::from) + .flatten(), + ) } } -impl<'ast> From> for absy::ImportNode<'ast> { - fn from(import: pest::ImportDirective<'ast>) -> absy::ImportNode<'ast> { +impl<'ast> From> for absy::ImportKind<'ast> { + fn from(import: pest::ImportDirective<'ast>) -> absy::ImportKind<'ast> { use crate::absy::NodeValue; match import { - pest::ImportDirective::Main(import) => { + pest::ImportDirective::Main(import) => absy::ImportKind::Single( imports::Import::new(None, std::path::Path::new(import.source.span.as_str())) .alias(import.alias.map(|a| a.span.as_str())) - .span(import.span) - } - pest::ImportDirective::From(import) => { - let symbol_str = import.symbol.span.as_str(); - - imports::Import::new( - Some(import.symbol.span.as_str()), - std::path::Path::new(import.source.span.as_str()), - ) - .alias(import.alias.map(|a| a.span.as_str()).or(Some(symbol_str))) - .span(import.span) - } + .span(import.span), + ), + pest::ImportDirective::From(import) => absy::ImportKind::Multiple( + import + .symbols + .iter() + .map(|symbol| { + imports::Import::new( + Some(symbol.symbol.span.as_str()), + std::path::Path::new(import.source.span.as_str()), + ) + .alias( + symbol + .alias + .as_ref() + .map(|a| a.span.as_str()) + .or_else(|| Some(symbol.symbol.span.as_str())), + ) + .span(symbol.span.clone()) + }) + .collect(), + ), } } } diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index 0eccc1345..82c009e29 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -18,6 +18,7 @@ pub use crate::absy::variable::{Variable, VariableNode}; use crate::embed::FlatEmbed; use std::path::{Path, PathBuf}; +use crate::imports::ImportKind; use crate::imports::ImportNode; use std::fmt; diff --git a/zokrates_core/src/imports.rs b/zokrates_core/src/imports.rs index 0794645cb..38a03ad77 100644 --- a/zokrates_core/src/imports.rs +++ b/zokrates_core/src/imports.rs @@ -56,6 +56,25 @@ impl From for Error { } } +#[derive(PartialEq, Clone)] +pub enum ImportKind<'ast> { + Single(ImportNode<'ast>), + Multiple(Vec>), +} + +impl<'ast> IntoIterator for ImportKind<'ast> { + type Item = ImportNode<'ast>; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + let vec = match self { + ImportKind::Single(v) => vec![v], + ImportKind::Multiple(v) => v, + }; + vec.into_iter() + } +} + type ImportPath<'ast> = &'ast Path; #[derive(PartialEq, Clone)] diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index 50c12fbab..f55e7c3f0 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -5,9 +5,11 @@ pragma = { "#pragma" ~ "curve" ~ curve } curve = @{ (ASCII_ALPHANUMERIC | "_") * } import_directive = { main_import_directive | from_import_directive } -from_import_directive = { "from" ~ "\"" ~ import_source ~ "\"" ~ "import" ~ identifier ~ ("as" ~ identifier)? ~ NEWLINE*} -main_import_directive = {"import" ~ "\"" ~ import_source ~ "\"" ~ ("as" ~ identifier)? ~ NEWLINE+} +from_import_directive = { "from" ~ "\"" ~ import_source ~ "\"" ~ "import" ~ import_symbol_list ~ NEWLINE* } +main_import_directive = { "import" ~ "\"" ~ import_source ~ "\"" ~ ("as" ~ identifier)? ~ NEWLINE+ } import_source = @{(!"\"" ~ ANY)*} +import_symbol = { identifier ~ ("as" ~ identifier)? } +import_symbol_list = _{ import_symbol ~ ("," ~ import_symbol)* } function_definition = {"def" ~ identifier ~ constant_generics_declaration? ~ "(" ~ parameter_list ~ ")" ~ return_types ~ ":" ~ NEWLINE* ~ statement* } return_types = _{ ( "->" ~ ( "(" ~ type_list ~ ")" | ty ))? } constant_generics_declaration = _{ "<" ~ constant_generics_list ~ ">" } diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 3f1ea138d..31fae3b4d 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -13,9 +13,9 @@ pub use ast::{ CallAccess, ConstantGenericValue, DecimalLiteralExpression, DecimalNumber, DecimalSuffix, DefinitionStatement, ExplicitGenerics, Expression, FieldType, File, FromExpression, Function, HexLiteralExpression, HexNumberExpression, IdentifierExpression, ImportDirective, ImportSource, - InlineArrayExpression, InlineStructExpression, InlineStructMember, IterationStatement, - LiteralExpression, OptionallyTypedAssignee, Parameter, PostfixExpression, Range, - RangeOrExpression, ReturnStatement, Span, Spread, SpreadOrExpression, Statement, + ImportSymbol, InlineArrayExpression, InlineStructExpression, InlineStructMember, + IterationStatement, LiteralExpression, OptionallyTypedAssignee, Parameter, PostfixExpression, + Range, RangeOrExpression, ReturnStatement, Span, Spread, SpreadOrExpression, Statement, StructDefinition, StructField, TernaryExpression, ToExpression, Type, UnaryExpression, UnaryOperator, Underscore, Visibility, }; @@ -180,12 +180,20 @@ mod ast { pub span: Span<'ast>, } + #[derive(Debug, FromPest, PartialEq, Clone)] + #[pest_ast(rule(Rule::import_symbol))] + pub struct ImportSymbol<'ast> { + pub symbol: IdentifierExpression<'ast>, + pub alias: Option>, + #[pest_ast(outer())] + pub span: Span<'ast>, + } + #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::from_import_directive))] pub struct FromImportDirective<'ast> { pub source: ImportSource<'ast>, - pub symbol: IdentifierExpression<'ast>, - pub alias: Option>, + pub symbols: Vec>, #[pest_ast(outer())] pub span: Span<'ast>, } From 8b050d8c4417ae1d1876375ebcd6af64689c781f Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 12 Apr 2021 18:56:22 +0200 Subject: [PATCH 16/95] update book, add changelog --- changelogs/unreleased/809-dark64 | 1 + zokrates_book/src/language/imports.md | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 changelogs/unreleased/809-dark64 diff --git a/changelogs/unreleased/809-dark64 b/changelogs/unreleased/809-dark64 new file mode 100644 index 000000000..3481fc4b6 --- /dev/null +++ b/changelogs/unreleased/809-dark64 @@ -0,0 +1 @@ +Add ability to import multiple symbols in a single import statement \ No newline at end of file diff --git a/zokrates_book/src/language/imports.md b/zokrates_book/src/language/imports.md index 3f6995fac..f8592c0ef 100644 --- a/zokrates_book/src/language/imports.md +++ b/zokrates_book/src/language/imports.md @@ -13,6 +13,12 @@ from "./path/to/my/module" import MySymbol // `MySymbol` is now in scope. ``` +To import multiple modules with a single import statement, separate the module names with commas: + +```zokrates +from "./path/to/my/module" import MySymbol, MyOtherSymbol +``` + #### Aliasing The `as` keyword enables renaming symbols: From 98f697b3d0706450a73cccdd02bdae0e74d8cc20 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 13 Apr 2021 14:41:29 +0200 Subject: [PATCH 17/95] refactor constants --- .../stdlib/hashes/poseidon/constants.zok | 4102 ++++++++--------- .../stdlib/hashes/poseidon/poseidon.zok | 14 +- .../tests/hashes/poseidon/poseidon_1.zok | 4 +- .../tests/hashes/poseidon/poseidon_2.zok | 4 +- .../tests/hashes/poseidon/poseidon_3.zok | 4 +- .../tests/hashes/poseidon/poseidon_4.zok | 4 +- .../tests/hashes/poseidon/poseidon_5.zok | 4 +- .../tests/hashes/poseidon/poseidon_6.zok | 4 +- 8 files changed, 2065 insertions(+), 2075 deletions(-) diff --git a/zokrates_stdlib/stdlib/hashes/poseidon/constants.zok b/zokrates_stdlib/stdlib/hashes/poseidon/constants.zok index 4638e52d4..5c8040a02 100644 --- a/zokrates_stdlib/stdlib/hashes/poseidon/constants.zok +++ b/zokrates_stdlib/stdlib/hashes/poseidon/constants.zok @@ -1,2082 +1,2078 @@ -// t = 2 (1 input), f = 8, p = 56 -// t * (f + p) = 128 -def poseidon_c_1() -> field[128]: - return [ - 4417881134626180770308697923359573201005643519861877412381846989312604493735, - 5433650512959517612316327474713065966758808864213826738576266661723522780033, - 13641176377184356099764086973022553863760045607496549923679278773208775739952, - 17949713444224994136330421782109149544629237834775211751417461773584374506783, - 13765628375339178273710281891027109699578766420463125835325926111705201856003, - 19179513468172002314585757290678967643352171735526887944518845346318719730387, - 5157412437176756884543472904098424903141745259452875378101256928559722612176, - 535160875740282236955320458485730000677124519901643397458212725410971557409, - 1050793453380762984940163090920066886770841063557081906093018330633089036729, - 10665495010329663932664894101216428400933984666065399374198502106997623173873, - 19965634623406616956648724894636666805991993496469370618546874926025059150737, - 13007250030070838431593222885902415182312449212965120303174723305710127422213, - 16877538715074991604507979123743768693428157847423939051086744213162455276374, - 18211747749504876135588847560312685184956239426147543810126553367063157141465, - 18151553319826126919739798892854572062191241985315767086020821632812331245635, - 19957033149976712666746140949846950406660099037474791840946955175819555930825, - 3469514863538261843186854830917934449567467100548474599735384052339577040841, - 989698510043911779243192466312362856042600749099921773896924315611668507708, - 12568377015646290945235387813564567111330046038050864455358059568128000172201, - 20856104135605479600325529349246932565148587186338606236677138505306779314172, - 8206918720503535523121349917159924938835810381723474192155637697065780938424, - 1309058477013932989380617265069188723120054926187607548493110334522527703566, - 14076116939332667074621703729512195584105250395163383769419390236426287710606, - 10153498892749751942204288991871286290442690932856658983589258153608012428674, - 18202499207234128286137597834010475797175973146805180988367589376893530181575, - 12739388830157083522877690211447248168864006284243907142044329113461613743052, - 15123358710467780770838026754240340042441262572309759635224051333176022613949, - 19925004701844594370904593774447343836015483888496504201331110250494635362184, - 10352416606816998476681131583320899030072315953910679608943150613208329645891, - 10567371822366244361703342347428230537114808440249611395507235283708966113221, - 5635498582763880627392290206431559361272660937399944184533035305989295959602, - 11866432933224219174041051738704352719163271639958083608224676028593315904909, - 5795020705294401441272215064554385591292330721703923167136157291459784140431, - 9482202378699252817564375087302794636287866584767523335624368774856230692758, - 4245237636894546151746468406560945873445548423466753843402086544922216329298, - 12000500941313982757584712677991730019124834399479314697467598397927435905133, - 7596790274058425558167520209857956363736666939016807569082239187494363541787, - 2484867918246116343205467273440098378820186751202461278013576281097918148877, - 18312645949449997391810445935615409295369169383463185688973803378104013950190, - 15320686572748723004980855263301182130424010735782762814513954166519592552733, - 12618438900597948888520621062416758747872180395546164387827245287017031303859, - 17438141672027706116733201008397064011774368832458707512367404736905021019585, - 6374197807230665998865688675365359100400438034755781666913068586172586548950, - 2189398913433273865510950346186699930188746169476472274335177556702504595264, - 6268495580028970231803791523870131137294646402347399003576649137450213034606, - 17896250365994900261202920044129628104272791547990619503076839618914047059275, - 13692156312448722528008862371944543449350293305158722920787736248435893008873, - 15234446864368744483209945022439268713300180233589581910497691316744177619376, - 1572426502623310766593681563281600503979671244997798691029595521622402217227, - 80103447810215150918585162168214870083573048458555897999822831203653996617, - 8228820324013669567851850635126713973797711779951230446503353812192849106342, - 5375851433746509614045812476958526065449377558695752132494533666370449415873, - 12115998939203497346386774317892338270561208357481805380546938146796257365018, - 9764067909645821279940531410531154041386008396840887338272986634350423466622, - 8538708244538850542384936174629541085495830544298260335345008245230827876882, - 7140127896620013355910287215441004676619168261422440177712039790284719613114, - 14297402962228458726038826185823085337698917275385741292940049024977027409762, - 6667115556431351074165934212337261254608231545257434281887966406956835140819, - 20226761165244293291042617464655196752671169026542832236139342122602741090001, - 12038289506489256655759141386763477208196694421666339040483042079632134429119, - 19027757334170818571203982241812412991528769934917288000224335655934473717551, - 16272152964456553579565580463468069884359929612321610357528838696790370074720, - 2500392889689246014710135696485946334448570271481948765283016105301740284071, - 8595254970528530312401637448610398388203855633951264114100575485022581946023, - 11635945688914011450976408058407206367914559009113158286982919675551688078198, - 614739068603482619581328040478536306925147663946742687395148680260956671871, - 18692271780377861570175282183255720350972693125537599213951106550953176268753, - 4987059230784976306647166378298632695585915319042844495357753339378260807164, - 21851403978498723616722415377430107676258664746210815234490134600998983955497, - 9830635451186415300891533983087800047564037813328875992115573428596207326204, - 4842706106434537116860242620706030229206345167233200482994958847436425185478, - 6422235064906823218421386871122109085799298052314922856340127798647926126490, - 4564364104986856861943331689105797031330091877115997069096365671501473357846, - 1944043894089780613038197112872830569538541856657037469098448708685350671343, - 21179865974855950600518216085229498748425990426231530451599322283119880194955, - 14296697761894107574369608843560006996183955751502547883167824879840894933162, - 12274619649702218570450581712439138337725246879938860735460378251639845671898, - 16371396450276899401411886674029075408418848209575273031725505038938314070356, - 3702561221750983937578095019779188631407216522704543451228773892695044653565, - 19721616877735564664624984774636557499099875603996426215495516594530838681980, - 6383350109027696789969911008057747025018308755462287526819231672217685282429, - 20860583956177367265984596617324237471765572961978977333122281041544719622905, - 5766390934595026947545001478457407504285452477687752470140790011329357286275, - 4043175758319898049344746138515323336207420888499903387536875603879441092484, - 15579382179133608217098622223834161692266188678101563820988612253342538956534, - 1864640783252634743892105383926602930909039567065240010338908865509831749824, - 15943719865023133586707144161652035291705809358178262514871056013754142625673, - 2326415993032390211558498780803238091925402878871059708106213703504162832999, - 19995326402773833553207196590622808505547443523750970375738981396588337910289, - 5143583711361588952673350526320181330406047695593201009385718506918735286622, - 15436006486881920976813738625999473183944244531070780793506388892313517319583, - 16660446760173633166698660166238066533278664023818938868110282615200613695857, - 4966065365695755376133119391352131079892396024584848298231004326013366253934, - 20683781957411705574951987677641476019618457561419278856689645563561076926702, - 17280836839165902792086432296371645107551519324565649849400948918605456875699, - 17045635513701208892073056357048619435743564064921155892004135325530808465371, - 17055032967194400710390142791334572297458033582458169295920670679093585707295, - 15727174639569115300068198908071514334002742825679221638729902577962862163505, - 1001755657610446661315902885492677747789366510875120894840818704741370398633, - 18638547332826171619311285502376343504539399518545103511265465604926625041234, - 6751954224763196429755298529194402870632445298969935050224267844020826420799, - 3526747115904224771452549517614107688674036840088422555827581348280834879405, - 15705897908180497062880001271426561999724005008972544196300715293701537574122, - 574386695213920937259007343820417029802510752426579750428758189312416867750, - 15973040855000600860816974646787367136127946402908768408978806375685439868553, - 20934130413948796333037139460875996342810005558806621330680156931816867321122, - 6918585327145564636398173845411579411526758237572034236476079610890705810764, - 14158163500813182062258176233162498241310167509137716527054939926126453647182, - 4164602626597695668474100217150111342272610479949122406544277384862187287433, - 12146526846507496913615390662823936206892812880963914267275606265272996025304, - 10153527926900017763244212043512822363696541810586522108597162891799345289938, - 13564663485965299104296214940873270349072051793008946663855767889066202733588, - 5612449256997576125867742696783020582952387615430650198777254717398552960096, - 12151885480032032868507892738683067544172874895736290365318623681886999930120, - 380452237704664384810613424095477896605414037288009963200982915188629772177, - 9067557551252570188533509616805287919563636482030947363841198066124642069518, - 21280306817619711661335268484199763923870315733198162896599997188206277056900, - 5567165819557297006750252582140767993422097822227408837378089569369734876257, - 10411936321072105429908396649383171465939606386380071222095155850987201580137, - 21338390051413922944780864872652000187403217966653363270851298678606449622266, - 12156296560457833712186127325312904760045212412680904475497938949653569234473, - 4271647814574748734312113971565139132510281260328947438246615707172526380757, - 9061738206062369647211128232833114177054715885442782773131292534862178874950, - 10134551893627587797380445583959894183158393780166496661696555422178052339133, - 8932270237664043612366044102088319242789325050842783721780970129656616386103, - 3339412934966886386194449782756711637636784424032779155216609410591712750636, - 9704903972004596791086522314847373103670545861209569267884026709445485704400, - 17467570179597572575614276429760169990940929887711661192333523245667228809456 - ] - -// t = 3 (2 inputs), f = 8, p = 57 -// t * (f + p) = 195 -def poseidon_c_2() -> field[195]: - return [ - 6745197990210204598374042828761989596302876299545964402857411729872131034734, - 426281677759936592021316809065178817848084678679510574715894138690250139748, - 4014188762916583598888942667424965430287497824629657219807941460227372577781, - 21328925083209914769191926116470334003273872494252651254811226518870906634704, - 19525217621804205041825319248827370085205895195618474548469181956339322154226, - 1402547928439424661186498190603111095981986484908825517071607587179649375482, - 18320863691943690091503704046057443633081959680694199244583676572077409194605, - 17709820605501892134371743295301255810542620360751268064484461849423726103416, - 15970119011175710804034336110979394557344217932580634635707518729185096681010, - 9818625905832534778628436765635714771300533913823445439412501514317783880744, - 6235167673500273618358172865171408902079591030551453531218774338170981503478, - 12575685815457815780909564540589853169226710664203625668068862277336357031324, - 7381963244739421891665696965695211188125933529845348367882277882370864309593, - 14214782117460029685087903971105962785460806586237411939435376993762368956406, - 13382692957873425730537487257409819532582973556007555550953772737680185788165, - 2203881792421502412097043743980777162333765109810562102330023625047867378813, - 2916799379096386059941979057020673941967403377243798575982519638429287573544, - 4341714036313630002881786446132415875360643644216758539961571543427269293497, - 2340590164268886572738332390117165591168622939528604352383836760095320678310, - 5222233506067684445011741833180208249846813936652202885155168684515636170204, - 7963328565263035669460582454204125526132426321764384712313576357234706922961, - 1394121618978136816716817287892553782094854454366447781505650417569234586889, - 20251767894547536128245030306810919879363877532719496013176573522769484883301, - 141695147295366035069589946372747683366709960920818122842195372849143476473, - 15919677773886738212551540894030218900525794162097204800782557234189587084981, - 2616624285043480955310772600732442182691089413248613225596630696960447611520, - 4740655602437503003625476760295930165628853341577914460831224100471301981787, - 19201590924623513311141753466125212569043677014481753075022686585593991810752, - 12116486795864712158501385780203500958268173542001460756053597574143933465696, - 8481222075475748672358154589993007112877289817336436741649507712124418867136, - 5181207870440376967537721398591028675236553829547043817076573656878024336014, - 1576305643467537308202593927724028147293702201461402534316403041563704263752, - 2555752030748925341265856133642532487884589978209403118872788051695546807407, - 18840924862590752659304250828416640310422888056457367520753407434927494649454, - 14593453114436356872569019099482380600010961031449147888385564231161572479535, - 20826991704411880672028799007667199259549645488279985687894219600551387252871, - 9159011389589751902277217485643457078922343616356921337993871236707687166408, - 5605846325255071220412087261490782205304876403716989785167758520729893194481, - 1148784255964739709393622058074925404369763692117037208398835319441214134867, - 20945896491956417459309978192328611958993484165135279604807006821513499894540, - 229312996389666104692157009189660162223783309871515463857687414818018508814, - 21184391300727296923488439338697060571987191396173649012875080956309403646776, - 21853424399738097885762888601689700621597911601971608617330124755808946442758, - 12776298811140222029408960445729157525018582422120161448937390282915768616621, - 7556638921712565671493830639474905252516049452878366640087648712509680826732, - 19042212131548710076857572964084011858520620377048961573689299061399932349935, - 12871359356889933725034558434803294882039795794349132643274844130484166679697, - 3313271555224009399457959221795880655466141771467177849716499564904543504032, - 15080780006046305940429266707255063673138269243146576829483541808378091931472, - 21300668809180077730195066774916591829321297484129506780637389508430384679582, - 20480395468049323836126447690964858840772494303543046543729776750771407319822, - 10034492246236387932307199011778078115444704411143703430822959320969550003883, - 19584962776865783763416938001503258436032522042569001300175637333222729790225, - 20155726818439649091211122042505326538030503429443841583127932647435472711802, - 13313554736139368941495919643765094930693458639277286513236143495391474916777, - 14606609055603079181113315307204024259649959674048912770003912154260692161833, - 5563317320536360357019805881367133322562055054443943486481491020841431450882, - 10535419877021741166931390532371024954143141727751832596925779759801808223060, - 12025323200952647772051708095132262602424463606315130667435888188024371598063, - 2906495834492762782415522961458044920178260121151056598901462871824771097354, - 19131970618309428864375891649512521128588657129006772405220584460225143887876, - 8896386073442729425831367074375892129571226824899294414632856215758860965449, - 7748212315898910829925509969895667732958278025359537472413515465768989125274, - 422974903473869924285294686399247660575841594104291551918957116218939002865, - 6398251826151191010634405259351528880538837895394722626439957170031528482771, - 18978082967849498068717608127246258727629855559346799025101476822814831852169, - 19150742296744826773994641927898928595714611370355487304294875666791554590142, - 12896891575271590393203506752066427004153880610948642373943666975402674068209, - 9546270356416926575977159110423162512143435321217584886616658624852959369669, - 2159256158967802519099187112783460402410585039950369442740637803310736339200, - 8911064487437952102278704807713767893452045491852457406400757953039127292263, - 745203718271072817124702263707270113474103371777640557877379939715613501668, - 19313999467876585876087962875809436559985619524211587308123441305315685710594, - 13254105126478921521101199309550428567648131468564858698707378705299481802310, - 1842081783060652110083740461228060164332599013503094142244413855982571335453, - 9630707582521938235113899367442877106957117302212260601089037887382200262598, - 5066637850921463603001689152130702510691309665971848984551789224031532240292, - 4222575506342961001052323857466868245596202202118237252286417317084494678062, - 2919565560395273474653456663643621058897649501626354982855207508310069954086, - 6828792324689892364977311977277548750189770865063718432946006481461319858171, - 2245543836264212411244499299744964607957732316191654500700776604707526766099, - 19602444885919216544870739287153239096493385668743835386720501338355679311704, - 8239538512351936341605373169291864076963368674911219628966947078336484944367, - 15053013456316196458870481299866861595818749671771356646798978105863499965417, - 7173615418515925804810790963571435428017065786053377450925733428353831789901, - 8239211677777829016346247446855147819062679124993100113886842075069166957042, - 15330855478780269194281285878526984092296288422420009233557393252489043181621, - 10014883178425964324400942419088813432808659204697623248101862794157084619079, - 14014440630268834826103915635277409547403899966106389064645466381170788813506, - 3580284508947993352601712737893796312152276667249521401778537893620670305946, - 2559754020964039399020874042785294258009596917335212876725104742182177996988, - 14898657953331064524657146359621913343900897440154577299309964768812788279359, - 2094037260225570753385567402013028115218264157081728958845544426054943497065, - 18051086536715129874440142649831636862614413764019212222493256578581754875930, - 21680659279808524976004872421382255670910633119979692059689680820959727969489, - 13950668739013333802529221454188102772764935019081479852094403697438884885176, - 9703845704528288130475698300068368924202959408694460208903346143576482802458, - 12064310080154762977097567536495874701200266107682637369509532768346427148165, - 16970760937630487134309762150133050221647250855182482010338640862111040175223, - 9790997389841527686594908620011261506072956332346095631818178387333642218087, - 16314772317774781682315680698375079500119933343877658265473913556101283387175, - 82044870826814863425230825851780076663078706675282523830353041968943811739, - 21696416499108261787701615667919260888528264686979598953977501999747075085778, - 327771579314982889069767086599893095509690747425186236545716715062234528958, - 4606746338794869835346679399457321301521448510419912225455957310754258695442, - 64499140292086295251085369317820027058256893294990556166497635237544139149, - 10455028514626281809317431738697215395754892241565963900707779591201786416553, - 10421411526406559029881814534127830959833724368842872558146891658647152404488, - 18848084335930758908929996602136129516563864917028006334090900573158639401697, - 13844582069112758573505569452838731733665881813247931940917033313637916625267, - 13488838454403536473492810836925746129625931018303120152441617863324950564617, - 15742141787658576773362201234656079648895020623294182888893044264221895077688, - 6756884846734501741323584200608866954194124526254904154220230538416015199997, - 7860026400080412708388991924996537435137213401947704476935669541906823414404, - 7871040688194276447149361970364037034145427598711982334898258974993423182255, - 20758972836260983284101736686981180669442461217558708348216227791678564394086, - 21723241881201839361054939276225528403036494340235482225557493179929400043949, - 19428469330241922173653014973246050805326196062205770999171646238586440011910, - 7969200143746252148180468265998213908636952110398450526104077406933642389443, - 10950417916542216146808986264475443189195561844878185034086477052349738113024, - 18149233917533571579549129116652755182249709970669448788972210488823719849654, - 3729796741814967444466779622727009306670204996071028061336690366291718751463, - 5172504399789702452458550583224415301790558941194337190035441508103183388987, - 6686473297578275808822003704722284278892335730899287687997898239052863590235, - 19426913098142877404613120616123695099909113097119499573837343516470853338513, - 5120337081764243150760446206763109494847464512045895114970710519826059751800, - 5055737465570446530938379301905385631528718027725177854815404507095601126720, - 14235578612970484492268974539959119923625505766550088220840324058885914976980, - 653592517890187950103239281291172267359747551606210609563961204572842639923, - 5507360526092411682502736946959369987101940689834541471605074817375175870579, - 7864202866011437199771472205361912625244234597659755013419363091895334445453, - 21294659996736305811805196472076519801392453844037698272479731199885739891648, - 13767183507040326119772335839274719411331242166231012705169069242737428254651, - 810181532076738148308457416289197585577119693706380535394811298325092337781, - 14232321930654703053193240133923161848171310212544136614525040874814292190478, - 16796904728299128263054838299534612533844352058851230375569421467352578781209, - 16256310366973209550759123431979563367001604350120872788217761535379268327259, - 19791658638819031543640174069980007021961272701723090073894685478509001321817, - 7046232469803978873754056165670086532908888046886780200907660308846356865119, - 16001732848952745747636754668380555263330934909183814105655567108556497219752, - 9737276123084413897604802930591512772593843242069849260396983774140735981896, - 11410895086919039954381533622971292904413121053792570364694836768885182251535, - 19098362474249267294548762387533474746422711206129028436248281690105483603471, - 11013788190750472643548844759298623898218957233582881400726340624764440203586, - 2206958256327295151076063922661677909471794458896944583339625762978736821035, - 7171889270225471948987523104033632910444398328090760036609063776968837717795, - 2510237900514902891152324520472140114359583819338640775472608119384714834368, - 8825275525296082671615660088137472022727508654813239986303576303490504107418, - 1481125575303576470988538039195271612778457110700618040436600537924912146613, - 16268684562967416784133317570130804847322980788316762518215429249893668424280, - 4681491452239189664806745521067158092729838954919425311759965958272644506354, - 3131438137839074317765338377823608627360421824842227925080193892542578675835, - 7930402370812046914611776451748034256998580373012248216998696754202474945793, - 8973151117361309058790078507956716669068786070949641445408234962176963060145, - 10223139291409280771165469989652431067575076252562753663259473331031932716923, - 2232089286698717316374057160056566551249777684520809735680538268209217819725, - 16930089744400890347392540468934821520000065594669279286854302439710657571308, - 21739597952486540111798430281275997558482064077591840966152905690279247146674, - 7508315029150148468008716674010060103310093296969466203204862163743615534994, - 11418894863682894988747041469969889669847284797234703818032750410328384432224, - 10895338268862022698088163806301557188640023613155321294365781481663489837917, - 18644184384117747990653304688839904082421784959872380449968500304556054962449, - 7414443845282852488299349772251184564170443662081877445177167932875038836497, - 5391299369598751507276083947272874512197023231529277107201098701900193273851, - 10329906873896253554985208009869159014028187242848161393978194008068001342262, - 4711719500416619550464783480084256452493890461073147512131129596065578741786, - 11943219201565014805519989716407790139241726526989183705078747065985453201504, - 4298705349772984837150885571712355513879480272326239023123910904259614053334, - 9999044003322463509208400801275356671266978396985433172455084837770460579627, - 4908416131442887573991189028182614782884545304889259793974797565686968097291, - 11963412684806827200577486696316210731159599844307091475104710684559519773777, - 20129916000261129180023520480843084814481184380399868943565043864970719708502, - 12884788430473747619080473633364244616344003003135883061507342348586143092592, - 20286808211545908191036106582330883564479538831989852602050135926112143921015, - 16282045180030846845043407450751207026423331632332114205316676731302016331498, - 4332932669439410887701725251009073017227450696965904037736403407953448682093, - 11105712698773407689561953778861118250080830258196150686012791790342360778288, - 21853934471586954540926699232107176721894655187276984175226220218852955976831, - 9807888223112768841912392164376763820266226276821186661925633831143729724792, - 13411808896854134882869416756427789378942943805153730705795307450368858622668, - 17906847067500673080192335286161014930416613104209700445088168479205894040011, - 14554387648466176616800733804942239711702169161888492380425023505790070369632, - 4264116751358967409634966292436919795665643055548061693088119780787376143967, - 2401104597023440271473786738539405349187326308074330930748109868990675625380, - 12251645483867233248963286274239998200789646392205783056343767189806123148785, - 15331181254680049984374210433775713530849624954688899814297733641575188164316, - 13108834590369183125338853868477110922788848506677889928217413952560148766472, - 6843160824078397950058285123048455551935389277899379615286104657075620692224, - 10151103286206275742153883485231683504642432930275602063393479013696349676320, - 7074320081443088514060123546121507442501369977071685257650287261047855962224, - 11413928794424774638606755585641504971720734248726394295158115188173278890938, - 7312756097842145322667451519888915975561412209738441762091369106604423801080, - 7181677521425162567568557182629489303281861794357882492140051324529826589361, - 15123155547166304758320442783720138372005699143801247333941013553002921430306, - 13409242754315411433193860530743374419854094495153957441316635981078068351329 - ] - -// t = 4 (3 inputs), f = 8, p = 56 -// t * (f + p) = 256 -def poseidon_c_3() -> field[256]: - return [ - 11633431549750490989983886834189948010834808234699737327785600195936805266405, - 17353750182810071758476407404624088842693631054828301270920107619055744005334, - 11575173631114898451293296430061690731976535592475236587664058405912382527658, - 9724643380371653925020965751082872123058642683375812487991079305063678725624, - 20936725237749945635418633443468987188819556232926135747685274666391889856770, - 6427758822462294912934022562310355233516927282963039741999349770315205779230, - 16782979953202249973699352594809882974187694538612412531558950864304931387798, - 8979171037234948998646722737761679613767384188475887657669871981433930833742, - 5428827536651017352121626533783677797977876323745420084354839999137145767736, - 507241738797493565802569310165979445570507129759637903167193063764556368390, - 6711578168107599474498163409443059675558516582274824463959700553865920673097, - 2197359304646916921018958991647650011119043556688567376178243393652789311643, - 4634703622846121403803831560584049007806112989824652272428991253572845447400, - 17008376818199175111793852447685303011746023680921106348278379453039148937791, - 18430784755956196942937899353653692286521408688385681805132578732731487278753, - 4573768376486344895797915946239137669624900197544620153250805961657870918727, - 5624865188680173294191042415227598609140934495743721047183803859030618890703, - 8228252753786907198149068514193371173033070694924002912950645971088002709521, - 17586714789554691446538331362711502394998837215506284064347036653995353304693, - 12985198716830497423350597750558817467658937953000235442251074063454897365701, - 13480076116139680784838493959937969792577589073830107110893279354229821035984, - 480609231761423388761863647137314056373740727639536352979673303078459561332, - 19503345496799249258956440299354839375920540225688429628121751361906635419276, - 16837818502122887883669221005435922946567532037624537243846974433811447595173, - 5492108497278641078569490709794391352213168666744080628008171695469579703581, - 11365311159988448419785032079155356000691294261495515880484003277443744617083, - 13876891705632851072613751905778242936713392247975808888614530203269491723653, - 10660388389107698747692475159023710744797290186015856503629656779989214850043, - 18876318870401623474401728758498150977988613254023317877612912724282285739292, - 15543349138237018307536452195922365893694804703361435879256942490123776892424, - 2839988449157209999638903652853828318645773519300826410959678570041742458201, - 7566039810305694135184226097163626060317478635973510706368412858136696413063, - 6344830340705033582410486810600848473125256338903726340728639711688240744220, - 12475357769019880256619207099578191648078162511547701737481203260317463892731, - 13337401254840718303633782478677852514218549070508887338718446132574012311307, - 21161869193849404954234950798647336336709035097706159414187214758702055364571, - 20671052961616073313397254362345395594858011165315285344464242404604146448678, - 2772189387845778213446441819361180378678387127454165972767013098872140927416, - 3339032002224218054945450150550795352855387702520990006196627537441898997147, - 14919705931281848425960108279746818433850049439186607267862213649460469542157, - 17056699976793486403099510941807022658662936611123286147276760381688934087770, - 16144580075268719403964467603213740327573316872987042261854346306108421013323, - 15582343953927413680541644067712456296539774919658221087452235772880573393376, - 17528510080741946423534916423363640132610906812668323263058626230135522155749, - 3190600034239022251529646836642735752388641846393941612827022280601486805721, - 8463814172152682468446984305780323150741498069701538916468821815030498611418, - 16533435971270903741871235576178437313873873358463959658178441562520661055273, - 11845696835505436397913764735273748291716405946246049903478361223369666046634, - 18391057370973634202531308463652130631065370546571735004701144829951670507215, - 262537877325812689820791215463881982531707709719292538608229687240243203710, - 2187234489894387585309965540987639130975753519805550941279098789852422770021, - 19189656350920455659006418422409390013967064310525314160026356916172976152967, - 15839474183930359560478122372067744245080413846070743460407578046890458719219, - 1805019124769763805045852541831585930225376844141668951787801647576910524592, - 323592203814803486950280155834638828455175703393817797003361354810251742052, - 9780393509796825017346015868945480913627956475147371732521398519483580624282, - 14009429785059642386335012561867511048847749030947687313594053997432177705759, - 13749550162460745037234826077137388777330401847577727796245150843898019635981, - 19497187499283431845443758879472819384797584633472792651343926414232528405311, - 3708428802547661961864524194762556064568867603968214870300574294082023305587, - 1339414413482882567499652761996854155383863472782829777976929310155400981782, - 6396261245879814100794661157306877072718690153118140891315137894471052482309, - 2069661495404347929962833138824526893650803079024564477269192079629046031674, - 15793521554502133342917616035884588152451122589545915605459159078589855944361, - 17053424498357819626596285492499512504457128907932827007302385782133229252374, - 13658536470391360399708067455536748955260723760813498481671323619545320978896, - 21546095668130239633971575351786704948662094117932406102037724221634677838565, - 21411726238386979516934941789127061362496195649331822900487557574597304399109, - 1944776378988765673004063363506638781964264107780425928778257145151172817981, - 15590719714223718537172639598316570285163081746016049278954513732528516468773, - 1351266421179051765004709939353170430290500926943038391678843253157009556309, - 6772476224477167317130064764757502335545080109882028900432703947986275397548, - 10670120969725161535937685539136065944959698664551200616467222887025111751992, - 4731853626374224678749618809759140702342195350742653173378450474772131006181, - 14473527495914528513885847341981310373531349450901830749157165104135412062812, - 16937191362061486658876740597821783333355021670608822932942683228741190786143, - 5656559696428674390125424316117443507583679061659043998559560535270557939546, - 8897648276515725841133578021896617755369443750194849587616503841335248902806, - 14938684446722672719637788054570691068799510611164812175626676768545923371470, - 15284149043690546115252102390417391226617211133644099356880071475803043461465, - 2623479025068612775740107497276979457946709347831661908218182874823658838107, - 6809791961761836061129379546794905411734858375517368211894790874813684813988, - 2417620338751920563196799065781703780495622795713803712576790485412779971775, - 4445143310792944321746901285176579692343442786777464604312772017806735512661, - 1429019233589939118995503267516676481141938536269008901607126781291273208629, - 19874283200702583165110559932895904979843482162236139561356679724680604144459, - 13426632171723830006915194799390005513190035492503509233177687891041405113055, - 10582332261829184460912611488470654685922576576939233092337240630493625631748, - 21233753931561918964692715735079738969202507286592442257083521969358109931739, - 15570526832729960536088203016939646235070527502823725736220985057263010426410, - 9379993197409194016084018867205217180276068758980710078281820842068357746159, - 20771047769547788232530761122022227554484215799917531852224053856574439035591, - 20468066117407230615347036860121267564735050776924839007390915936603720868039, - 5488458379783632930817704196671117722181776789793038046303454621235628350505, - 1394272944960494549436156060041871735938329188644910029274839018389507786995, - 5147716541319265558364686380685869814344975511061045836883803841066664401308, - 14583556014436264794011679557180458872925270147116325433110111823036572987256, - 11881598145635709076820802010238799308467020773223027240974808290357539410246, - 1566675577370566803714158020143436746360531503329117352692311127363508063658, - 212097210828847555076368799807292486212366234848453077606919035866276438405, - 7447795983723838393344606913699113402588250391491430720006009618589586043349, - 7626475329478847982857743246276194948757851985510858890691733676098590062312, - 148936322117705719734052984176402258788283488576388928671173547788498414614, - 15456385653678559339152734484033356164266089951521103188900320352052358038156, - 18207029603568083031075933940507782729612798852390383193518574746240484434885, - 2783356767974552799246444090988849933848968900471538294757665724820698962027, - 2721136724873145834448711197875719736776242904173494370334510875996324906822, - 2101139679159828164567502977338446902934095964116292264803779234163802308621, - 8995221857405946029753863203034191016106353727035116779995228902499254557482, - 502050382895618998241481591846956281507455925731652006822624065608151015665, - 4998642074447347292230083981705092465562944918178587362047610976950173759150, - 9349925422548495396957991080641322437286312278286826683803695584372829655908, - 11780347248050333407713097022607360765169543706092266937432199545936788840710, - 17875657248128792902343900636176628524337469245418171053476833541334867949063, - 10366707960411170224546487410133378396211437543372531210718212258701730218585, - 16918708725327525329474486073529093971911689155838787615544405646587858805834, - 18845394288827839099791436411179859406694814287249240544635770075956540806104, - 9838806160073701591447223014625214979004281138811495046618998465898136914308, - 10285680425916086863571101560978592912547567902925573205991454216988033815759, - 1292119286233210185026381033809498665433650491423040630240164455269575958565, - 2665524343601461489082054230426835550060387413710679950970616347092017688857, - 13502286133892103192305476866434484921895765252706158317341618311553476426306, - 686854655578191041672292972738875170071982317195092845673566320025160026512, - 9315942923163981372372434957632152754092082859001311184186702151150554806508, - 17166793131238158480636170455452575971861309825745828685724097210995239015581, - 4443784618760852757287735236046535266034706880634443644576653970979377878608, - 21470445782021672615018345703580059646973568891521510437236903770708690160080, - 6932852445473908850835611723958058203645654625170962537129706393570586565567, - 17078326120157725640173982185667969009350208542843294226397809921509565607842, - 19251873001736801921864956728611772738233338338726553113352118847732921831266, - 13062907978694932362695258750558734366820802962383346229947907261606619788585, - 16576609187793673559170206379939616900133457644695219057683704871664434872406, - 17140499059660867342372156843620845644831519603574612796639429147195776838516, - 16226688173010504218547945848523900236290532501559570164276462499487632388445, - 2806068123803905806401128967330263340459046260107112845068533446899070326517, - 17788735370835052317224182711467216134690146479710634688273650370951230404901, - 9840665370904113434661468973557421114403401847108482949465899631150766783733, - 17357287363046228581837055771327121704742940914150998420465281177406182088510, - 8956082469997974864521346025916496675956939495318858500685756691488425559998, - 10583741436561099911914917245130852199607666337956354910388730829023746895549, - 15241902639811607164983030447109332729761435946009172128089506810551693978973, - 10889882303914055687481932975789161945462141459528413507160087442461090813788, - 19789561133254944544821898921133697408237804586549835559829396563401674817160, - 20741336668287037026472434608739333171202674306575625457456116338034432647230, - 17864073449995977742930566850933082711031717858550870842712972350665650521079, - 6017691253505466300212182439349954426085752315661098358839308909771637792741, - 5209125836207196173669497054522582922896061838702136844305036341250990710540, - 8138726312837322624537330169363664364899441867118983214176695868443641051381, - 15491983986041746833254372934846748393213690608865689646440909282144232382678, - 5054332867608171303802774230688792431028169804536607979111644888500809938980, - 15427030776591294577308915282298854681562344215287630895931797573417982096417, - 21754057982677295571284116502193272661309010996970316384923307174180521790164, - 16265286590463120486705206231835953324076688991892805307349612983237844034032, - 17679791107777049796013011282788633179411040182820636236163074053597517790779, - 4281652562868629887097957174897458165728741859103571825874408386197225591996, - 9168010397863299719604788533602757515513214141450093775967322808686129400625, - 17584182367226175071087689123358883902969885218985589531538416263709138156515, - 15671512310414658663135385639435845966109237059155734764323312289873534719186, - 10536294659491685326297777845632759824567028904726211134518740400643540109527, - 13431319759608247201135260841651365578663315527795431484765940626659812285319, - 9584697124715190200241839387725546204368618031045071660911490086723434692561, - 5180327104839158483066851400960171505063442195966219343315555549982472660055, - 18888217223053385111625483360538133292128748730565502371803782424772027937822, - 19535732913737027522540340630296365525208404217634392013266346283017745945894, - 8577759627886344995887423695190093296190181539234301534326157005220006624466, - 16793670928407147476673650839110019799844249677846432113010280456483595763987, - 13926032620965299897272071104154310460519723329016284975305942957859374938463, - 4794697578055472890255676575927616606591024075768967985031137397587590174501, - 3529566190782060578446859853852791941913086545101307988176595267965876143250, - 3975008029239568933166738482470827494289192118694622729549964538823092192163, - 17739094873244464728483944474780943281491793683051033330476367597242349886622, - 7367136451127531266518046223598095299278392589059366687082785080179161005418, - 11175297939460631138047404082172242706491354303440776362693987984031241399771, - 21687543815463985355165197827968086406938428974327951792877419032069230058777, - 21156136641989461785420005321350884477682466566148802533375726181416623358719, - 17347558768803521970212188258074365309929638984714303299899732035040892048478, - 16293716234695956076322008955071091921491953458541407305955104663269677475740, - 4206144021605871396668976569508168522675546062304959729829228403361714668567, - 19988050626299122864942213847548542155670073758974734015174045163059179151544, - 747972634423324369570795147739377097591383105262743308036321386836856106229, - 4612470951309047869982067912468200581649949743307592869671537990797895413707, - 9630852913694079049153027193127278569487291430069466630362958024525616303220, - 17941539917430916523930519432495442476511211427972760202450248798031711471474, - 20332911350443969653703295317915788278109458962706923653715140186132935894113, - 21764801803055897327474057344100833670291402543384934706514147201527191846513, - 18792043166429470991157980448329308661526906138700725174612608941551872082876, - 12308177224490762720061048892842527800271687977085172836705858261595655154325, - 6234555076867437297776538521925679658360922070165740193866337972293380196151, - 4651047048822067434403056477377459986292934655827821636179452835839127581305, - 4762047093602693619418269784972874862577325737690375448572644958129932507374, - 12373514879531674477721132062882065826558811149582829246378921774344318418269, - 452512704634345955634014968317367844987135264395068376894497483188243356523, - 21642936370936057063268550589361090955573362743817395689260298777690935495218, - 16170209200627740434842090607802586195654207376087117044989637541681675086276, - 11682826760471401430136435257946377996085824742031456481961511737883954750045, - 20628055165039718158878805520495324869838279647796500565701893698896698211929, - 16438375313036818694140277721632185529697783132872683043559674569424388375143, - 4855690425141732729622202649174026736476144238882856677953515240716341676853, - 11680269552161854836013784579325442981497075865007420427279871128110023581360, - 7052688838948398479718163301866620773458411881591190572311273079833122884040, - 10339199500986679207942447430230758709198802637648680544816596214595887890122, - 16310974164366557619327768780809157500356605306298690718711623172209302167675, - 4572051236178600578566286373491186377601851723137133424312445102215267283375, - 20933392620931420860078756859763708025350478446661033451436796955762857910093, - 10145870387395991071594748880090507240612313913083518483680901820696866812598, - 11173854866888110108878560284050142518686158431744851782991510385755602063727, - 3895357290105797542988795070918100785105415165483657264407967118738833241858, - 16358886674154007883356717944805100413481233709808000948036974385803613296849, - 10544067501284177518983466437755150442726536257903869254459488412549270232123, - 10495171258604974589451578238018388630585794890815982293891430761424812600427, - 13820724103604550843562070971473423552484851063169471886037640613650155173554, - 2334954333435579600152488915208745055087482119087065911968347050969338669409, - 15100284614446277058846085121308897497066957549089629374506920751044105723791, - 8493821960754696376711287628276980042183127459347650448500304251148421115590, - 18612435536889941393944858783110719304584209891406420832295898519317994950798, - 362101794940079733974215941991047456600874474038781578925062694203564740952, - 11020033081956343850903875701444955317664141075326494650405276926536449284939, - 9396289482656518627529185765935649373549564165735162258912975312413185691167, - 6879055176150676925438486069371149089824290576271090206945130252868108043422, - 12466610601804566637227883322591924115458766539177061670432424956205788935144, - 6570302110526154075173287644133038486970998888099669190857256824048085590052, - 20997862990590350605775941983360263378441519274215787225587679916056749626824, - 2642485040919927233352421501444361753154137311893617974318977215281720542724, - 18832940311494549247524002614969382413324906834787422940144532352384742506504, - 18751288968473015103659806087408412890105261892140397690496125593160830694164, - 13938622158186434739533995447553824444480420613323252752005511269934155122652, - 12878982657080117316101160964182202074759312554860119090514406868768962707099, - 13757859113119127982418426758782225628393556023865807897214601826218702003247, - 11817871682869491875135867072669251115204978941736982465520516648114811792373, - 11336448548896065624515261709306933490181794458266726453198857687608284871020, - 194970717714150352477887371297168267861902418496792228400198694925721020795, - 4999282817977533227652305360183045040853565298259070645110453061034932285549, - 17094174197873140035316532568922652294881600587639905417701074492648767414173, - 8484251464872873032022789624790167173458682056313339863651348894878144808746, - 10260366716129057466862964875306868898686918428814373470382979997177852668590, - 549263552864476084904464374701167884060947403076520259964592729731619317724, - 10052714818439832487575851829190658679562445501271745818931448693381812170889, - 1735373362835209096342827192021124337509188507323448903608623506589963950966, - 7998373949540733111485892137806629484517602009122941425332571732658301689428, - 9035170288660659483243066011612158174896974797912618405030929911180945246244, - 6458619567307414386633203375143968061892762498463026121155477954682976784731, - 12314261817227551876673777186352972884847144237148169773300066404053441924532, - 19869454329688183813243851218196625862680921049019496233616575272637276975230, - 20326917073492686652690019138603910654692396590122884746951129061818467704300, - 20403270805536666081472738304916561119325397964511536801752236086414818653063, - 2865941730880218719188224311916978807415673142487507504983320505748719154068, - 20614246027521726470902405957496110178017768563127335842405314212897493119848, - 12060194341463088508348622863463208827312128863463014006529428845777217660299, - 1128906798719793375274166820235650701301189774851381709919492584451845983197, - 19670876372911656158743764425809421400123168087389888660308456184201759209723, - 5647230694522866559497222129254930524469944430191328619422533907417776118543, - 318629082509194371490189248876734616088516535434806492900653650176451776632, - 13685970881538585172319228162662520285656571966985351768743970447782846353365, - 8283840607829148567836919316142994745766280854211662326632930274668867638198, - 8968895518159422029900464138741638511289476298837958524156654785428413265371, - 10061801991000917366002570579819627134666386452411986168205986791283562415829 - ] - -// t = 5 (4 inputs), f = 8, p = 60 -// t * (f + p) = 340 -def poseidon_c_4() -> field[340]: - return [ - 6652655389322448471317061533546982911992554640679550674058582942754771150993, - 2411464732857349694082092299330329691469354396507353145272547491824343787723, - 21491443688002139478732659842894153142870918973450440713149176834049574486740, - 20196926676989483530222124573030747187074792043523478381149800153065505592963, - 12986278951352369831003505493892366673723882190521699331613883287145355738793, - 21126146258242782643168619000295062005037298340836817770565977031890883232034, - 15509665795506578582538177431401381655815033647735781734613703976071034655246, - 6989769181472743404364681671283889685042701491627165526899522083327752110839, - 7062179885254277466334896166987547257487047183881628199983668518000910197987, - 13842521112365108087725039904948872289730786568469683976372377853164252494752, - 3830559505943186272618534143266118508463381443414165428900505002474439179836, - 17704863473432653834041116667846189591617394753001613253930974854399793083900, - 875580502229441633079974792778818749112423694973231971690365132230865385439, - 1971134273535892826573832061354985059300866001765691176219451252512658771248, - 4865738840363990164915013008693722144676933915103280504727326977328013515878, - 1148603338028060679975883868174895825055359423662532941509525326937127571764, - 17506086433923270253695698017062834613463718526046463655503742220257039588796, - 21580033018107258179208198773211859664893072138803756118939260252922297665067, - 15411900706973212043830142913959920716501447427702082030760032355626616412240, - 12219699506725448409610279620972339448030565224304464695714944121760832152291, - 4525719544192047521328360848269156485222470829314314216955024799558286708479, - 19667371373588322336224317159113441765198420040800065314868656839300028747331, - 18916925604689704279265158984702141998345424765142129953154245912230835240445, - 12789343981741773931665143789673052782408749041041266509485929045869073416222, - 3094428508959717445577232225505810354980663487713729230015754183012845687401, - 18544590634480965569098056786078005630500574069468005220462377474861119476492, - 20990087440247450018723844204951613913840993427110495085701200965767234569705, - 17552251989761134508416634118845221324472178264364440017634233349418103869223, - 21000797802575507763447855752602183842956182733750968489641741136166640639409, - 19292751508591545849778577901067988044973302547209758604667395356943370737868, - 18314088316445539319869442180584299715533304874169767778761887632882728399870, - 15003745150856597539000559910957155642193629735521291045949652201905498569732, - 7839443900003691950104175747634267110464104444913379977500178134209666299140, - 13568305490393393394812598233983935295266242465548739772708079888867621061127, - 6453005227995051361096639028742707098785560656441339640433794156400437698140, - 1420171596348195609536167209221442141824294918625468780931400849866478645240, - 8347329128252205996443084339884155586061343024498283583400215109265013719709, - 7893774494551056447960817286805128884970061671041428326788899872964096959040, - 8970476243368194065341537088653900235777512204874037182428362347342487241690, - 239049405935404678508864874854718951364753739466303321590415544572014148257, - 15772878921699764223771017074289335629553777447709755479885293350677783703695, - 5416082112919155131434995906647355834510201879607888732259087164602171650389, - 4384524908062410354304345761652962203632712291085564157560146286207296352050, - 4210984612917608245844011498198864216639269565627982123611519493203177283139, - 18816442907032290878644773027005263628136050677095986565400687355912498966559, - 21443510232279945782338486087712914668515437675585863788610958361560172084515, - 3234314779308300525339049581669531363375743827111579883853941968586490182859, - 11029499234949696730080035941750777601416171837281021031653841244636590396063, - 11145210633226924132308292113124660576759662647204939721872338908644906571564, - 4583160563963432761409369246361117506465307518522062239686649163525543782173, - 9813992026757562966842771727657080117609486122615087352428596024939855084450, - 10084171857039480706430282187972782725948479260179367780776125786119489581409, - 3874212709197875589640151274548083098712939093643165182881681226579903752816, - 21595542491397091124739711708612983479307589335640792812157875295064235960610, - 2068530815441314105493629066002923150651375034543842424822712297257260726954, - 2673459852071215292298131389250564595426361004231758522146794940265552265806, - 8591046256746588406353455230465605224309754008961178558834659065898923355164, - 1020055192431352394776887540248098706183934464205704158014904833376067287118, - 11085709480582865378042656141271006552092494690130782253913953070642865919312, - 5673844083530503489429922596812992664928167369104420134641855283771127716005, - 10492199162275168254265892158402955076490959375050993042712629236807564461542, - 2280843393156259739329331366624245275580688891778782679394848304764573859886, - 6807797027131305026345508953353882265754363485246407959111359919046340709440, - 12692191384043938397944633973317584101723715998700063415107128429315536223446, - 19818676957110967644349139912613239435706480354664804036688552936554140369382, - 18055602608192644695569077694296748842203151828348990995792087204755925787339, - 20934555391215769430553078793246717148484784880715746179415906355043590089450, - 11420705181439111353998210442417752592951340005396931802449360401461783159557, - 19878854521263746227125001670931867821366047088989510542865511663910116386085, - 8568201846715449867087132677683368912214864824182424933182820310911278496552, - 19198701614488576617610339232794062430644024620523684127268879880793305460015, - 15262122764244854433806270478871594904740306012582364033343126589996733802868, - 6412758421155818207287638337822550233376667015263373809976157264137577776202, - 17371585001641430978766734501830788427263945848682170096055857509304472649262, - 20262970042379497707724791203314262108784948621691331141565359315001027736581, - 3859750447119748295302212198327542106766447958113540005985799287718502362717, - 1172269945800307665458943534144481495673510885455899148864236015097947176746, - 8164247467959680477306326470118519335673181279975551434197731340070491876250, - 4513977811114181395323888111232002391599397736872779927267726121435887238972, - 1075250595927474080680862736233039825365918646878264905022213616210377518447, - 18658420120424372681792175914064174056413842231969276203770574969914576681364, - 17769673440848360838244654765103041739044212539359630263894092078288342647801, - 4319086204044362848967484441065231939136453667264715596505827197873119273506, - 11221173270629292820060668122527062274557317856738971635698169204652845111606, - 8635411372759272135249379415383299350267629947167809163276219879514948820576, - 926977621651476360285369760355547766944001783780761167546467658394097283069, - 17702143780592866375901805387463459229828093905183622296234691441436877570082, - 629612289140842594504574984021125242351317893847688437087866691775821981724, - 19990548577495092294245865870717186004301934545721835081514347926537975465539, - 7124830628609719908679298707909792306162298058570958688501370177898647946696, - 14620227791860703231425817538142948793892390269806790476396226159679984968174, - 18495581997440241868332244230687799183899751339442721677540757155760745277888, - 16922065056093401385376103551657968760602009001905886435813054626317776258714, - 9969610601962874779035054685661667941954971427956866645694064022029705170229, - 15281641269114187762159685323068136816556739502211864119670902056596295644116, - 12114994625438879103001132949163961965524612903017200394727056658298824651596, - 4840986177718281128440833017205097196672382395936939379498412745183060615212, - 12847307562796769659308999092658905656250954898192781948610713494470441775991, - 20290096217351155282642224215178246911041509999959311313223857240001143893317, - 16151664509646153154405691138084115125600386733136285504828908979176781265710, - 13848845391482751436287906247470303487958950799995701248612703022979890932133, - 6335716166231441585596963683321661194889815181545222079376536449814718259931, - 1824302750039354704619545544386637317858342555634601563660279997221547953768, - 11327469654081586239268713126961534952233559223228327222485848924908493444712, - 10077703415170135154603829433031861799853903739210136452726077323833067256620, - 16368073884579385814331927334821006319227867093692644942500207970751483237405, - 10621580796499573269115131164341885791299038227955222944695715163010783205295, - 2099241376651019397894434242565225315652133572870234550073686122343103853816, - 17104632243449417396641550271977294699471083572885397875525767745512335891599, - 1935453754847256492223646005402770357836971113012418013930273797463411526183, - 7492761611332930896292052363224494314920390056637668407353957465667515477934, - 16836705924460095689555600825174696605443212968244843485187771119291716736958, - 16995495500678141665340056658079449793587669420913589967848082091551329904176, - 16097379973857697753436437302681608056543122759719328497348770844548177814262, - 17476569537128329379528694049566216604638194592812108658767104922628767500420, - 17997217989870184804787026924935938133194070033518938653831611194683423549591, - 17573343771046232580761295935281170028624495346579002725814597714902588657750, - 2450087639204541254902859018960918562514681200270997307467560465282168310665, - 17288084325555056222618040923753050382954155896826087372317882602328092535440, - 21837047676579063581498107773514419735425738753079336764356909012851439336687, - 370061273472837873736743292149368449614309676635341873070086681342317566380, - 420725183996224279379885018872359102189091670793820517618337092091910692771, - 4966571645678139143731798992823327185758562224229132271884647901363447388530, - 5039558223429273757296118284876763395391635773837549121798873235133698166026, - 14663152729953724779401067486012084029581847325524052152795817923033297673686, - 7201040456590575809960214033959496417566605177095808543357813677845263237276, - 16872945504528960415453618286121813996587432836152082188694652370255998768595, - 4914824783780909279212078186433590922437371437384817332713271291839616026466, - 17503018483514413315464207189113334433424965178631599286655188843769810245465, - 4087750571011463387872022799241315348852213278729592692674275176152296405923, - 4006961923780091252337105595934918049936238157468198971234322013673884171131, - 4481908842184366902145805444001507554481032302978790080019710161108326487967, - 13532316826436461968093937893872910736305115143550039673102602344678825540956, - 11602986656925867325907196773754426955346837006705269228226729102186031417465, - 15306992574062791537454541745213815567999895856471097922112648012979731636068, - 4497571735611504561173050536899411999551839050319538712220770383407135602945, - 2571242673174714867278075260451133687893879636121064640779554188161591611843, - 7070272070524747733177730083966686149849667613589868731851816020060781720851, - 1308310289745495626002351437755820460104812708071634598163946330870933261232, - 9483468192990391193401121929514821570714432121414330663623018046165053411090, - 7317568349845215930675847155716598288688799068821709820024570206796617676748, - 1918505733423704616434273602054555051755671749253598966287072464475922854850, - 15158168161084905689406532256983805923258003804476527617207287404280855731962, - 6855540174355511438343304861678411868002455139032857270673849263857877330771, - 5989863238360846166935911112885654223487221280254816980802479355446167746774, - 20283337058688740322296928691341300752003492063748410749625272920572074851396, - 18957132189629332408653055312790838576277703952267542471751593810468444454136, - 15764518568966520670995753676429154315765754748131847346608706222194564055358, - 7192524197002826721654253762628934164676539329903087107420445743247046038858, - 142950766663597487919643890566358241353679421113406309294925836697585309311, - 15012262168187689680572958978610204856600235635916074406168861726626292993057, - 20795666834671497603181209610179324236645779324677512349797033323222380300794, - 12650341271833683789775531792948185319868795529390391267833516836256688318306, - 5597700232877580665749288204589530549415282468176625525368428476461504532052, - 20949303924691159143653175365242293984396858344688574262804199947001630916385, - 10746523145835332938672833282581864816136388045771578294905302886974358762209, - 4998982766221590779170630035756820066555357949247521575936385387288356143784, - 6936999580131731861735955554005106460473097800566952971315565150681540640020, - 6670695360676548472482680016233507548657051302712214051977034166870814430578, - 12210816592786563975173850937247594401582085430897698766795696447223454826466, - 14933901149105284237676334791785996160108290333321693498322435129559137152007, - 3848529433916624869590379003597911090976938589461403388133685310398004369431, - 12778805225074604003024964969486878839359935515509480774809299341511161183802, - 3288267180428684202786697419666969564766921974531343432588030535602163038467, - 1272672432174256751826350693883913844502039730140570583479554071765667798207, - 21130828804874452930669244946376257892693846272313548250936991077452679117587, - 21254559353072473881932828401787134230282801383134765683324465204971002861493, - 4116075860631781527931204624078712926526805345818156200756399332393348685924, - 17435888597009729827411190999389277840088354756277916760187756022854497211746, - 15837398163415665169712832984380121382150588321621493928953938599666110830812, - 17988638446757562417082379159769772097890681265659458369075768452342579854303, - 8144561030363576879343874888624208577604401139613622673042754207987577727758, - 20020299925602421262203305284307419339160247406220693128040712457114283033661, - 2945951415037890626891130390523013930737768652394758977777336357159436605764, - 1505954324723537402640844232704189835623922400329086438898375859826553573763, - 11851584491756305117491374581845512067704002072833714119284164514457248861803, - 14471204965036278214508938537949717553799007630471016532866101610339050785912, - 7163557293233604902868673807221391042191134560333950452577270522828534690707, - 17291625782465108601367695465389799786592304061550212130987221355832952230827, - 10240907112109243116543462081552827576656826251172050843989873656917271396422, - 20702261919346727858635106264046787321170414155594199951578791234276181642650, - 16678253307828004252292273162411388452019952018258857370242272543091326285541, - 19810917631941180098047817620026253706643400683524412974923209268916769874447, - 3357220165225360610202375608872621445880880830154732998557832689480921421791, - 4392285438534542495332422274902727975330102148971785438164412161504066619105, - 14642025133729666610167675086855441462580619607677226879159952689184960379911, - 18142623439987890999821892559271093087005885278955082040377769578204898750505, - 11769399023330099592616157336702104329646487200891911089287290893650532639221, - 7261353756299584174448625214367175510387913706095214313669922259027644778060, - 10406994568199070863112470594593301582798997458844791396920771226539013327304, - 7475277967562870216712397220016587384793504784585573136176313471517144184018, - 9598064630327104406929367986473441777975480987434868213697837347643980267620, - 21137410002545951849752865514437404724653771608225272412595423069852350320648, - 12345612867231779996383303763804719815752861524077922121654106906093103051400, - 16461750199070055335468534730937701659470268635084522644824623393184528879703, - 7829250842543018165409887731515254191943527926556191989558018633300783421935, - 19801151644322693878208767560968285812646931156576102755771403150148125880648, - 808770634664491371274943928223981161442027957963181999892266696287962813461, - 2298122748772261447929855283951027113218922003687701626762072351622993276571, - 17407798064458858450209051887305178872029674498718760624162479511390762310526, - 18585562277464562541666582720366573863334618817908062612923861658144918595030, - 733976598693219656339731904831283238690050114241501938501377743874139460889, - 11316063986696838098122262534148335669847478050407756877728672233736962269417, - 17614529714381496379478130066245111825610297227468263851608027100133421612826, - 12110694197729365219340374599835523099651939156213930558791147158357810646901, - 4337343008663255658976574468931581484970687989356019720784093082313510905405, - 1379188959674402095268172673987199124815512095460112504778179157481327937561, - 3116148242507754420428768481157196067508084836097458698846114802493377512591, - 13306507137873332434793374848948087993544118494881134631519748904811343155566, - 18496878480807017010077624766326681523549495609998881196570603040242554712562, - 3940126764022508707486095199473913866137718790062498893812401335738707507732, - 10030078765792498033316282784150304209584388923549357286679864120250994473810, - 18519871685760382462428068450331593474924737719734568498029727699878543899254, - 12599428893576891013523136950822667754415283296587096197120138265392279834128, - 16038578953099895530943034305356008247313649524436132877362941968861459073483, - 14319233878082524834510736727226054073026413911339853399113450188859080424272, - 13710161613540579690732775978855380876556751245265568031703536595040993113748, - 14958726446649273856607176275240008023824615720456760403465034344703779274727, - 20935428111942360630758629263346308597806819928838924586682307174931367773605, - 5826394436548487315966647466017047216786257295199620110266250301500717796281, - 31401797997389676486806123612280306684597605608110075525648021056710776011, - 10784171495708237485952707518956314344821522727746927291389338644844400581452, - 11604345371765580191117799693565193618158448665352599382713281103552305960442, - 1378145039624937931836538950217364481423707761527018494355648047365613434790, - 10284294167221806561993937798090888689421933711157676807977401896199778472860, - 8233695574758520342808807499924062869636681352769371531557726871630696672029, - 6570581391072134029876349038190171593169496519436674767949949730275868319732, - 4026501263908027819614805027945064360196399012004574117767831931274788631138, - 21091098569404004244061462065218203986433580687172854429523306262593782053656, - 20711772916118045406356429185975897495222240215931761100801599257137350834799, - 3165519312799351250309462589160165591299333587158531489859211268084164422251, - 16470663723473939739601217501478624726068461799539012562455639586886033078064, - 15672299304945968727435591100602007503785845873606917887638890765525875123857, - 21393538327627889838198844493522533627143658125568123117776524944297103649079, - 7688819203734248199049004650451546300187194458173935784579101984183800649342, - 6609663518412297884695057080546416278366560290439222127471462938252865438638, - 3476303650597281786976907813110835564442121684386467570637538230409080744769, - 20633582549754495054832414039299188930065286005370053173386561254823483851717, - 18067076834611402459142612082327591538480657933568191619109271502102126814407, - 157209609820117793892254328219308970217366919934739036156851508233236414461, - 1848396116513925340973398423998379465460554039715233953825786874352442451413, - 188642786730195655565401615804782553245486295156304142809552609651873793325, - 540089254487190924787439362270708251103955915909358626209177199653451469720, - 12796274768956950589847157187031845061404119522843128177103898080653493269942, - 1785666356337148874573621868025910291826158842346617719666738769156993598966, - 20649919247042517528354490854561347316237285929352042389729444382153378749538, - 9568390566108569727471722677925269460696523515877621230569682954652430518787, - 8590683334740232786825518158771304803451657249486419816607179533515442407283, - 9321198393538172042803957409292145345834077448228642847843261373640165958582, - 3651905214805616378360839954289447530035139753215923648216350128870943481828, - 1324345422558073117779462079218851558068746895262914344818945294328678893083, - 6666363895154434021620869731925915051086919707989020578203743660669796175288, - 9850757893972463103359995012900314323213006625927501272997539940766979170137, - 10214293226445704940138790188111862069675188797488928722469679760666574484266, - 16862124085118494177559484642483513597285992646267864845521573612482278871023, - 9172340118369291059693735314505606817316211450324955429310200429408035954801, - 1968992755714619414656181112336357119271845800144345284299978250769356388249, - 17192498940296212027365280042755701662136570107224000496521552617655679821443, - 10063385968535643122430064779260670089120686456635080613693015398478175344193, - 20101961459945738562625328882763768836449780661345042148985756598106706734632, - 12704305975772252539534386080950631076046431529894091327218544197389260775334, - 3008242816727585639441748210631464697850194693570485141354082562181236010097, - 7797705698071555811456747812384107102104184812467361013142453143842134807658, - 19323240331433203844038522035479659453946066968727795017745942269828428751105, - 1698137797127320576751729191866734754105401103859852376273763815257758421427, - 17656850887825900397821271738817912328294075224643535784810269137125067875996, - 20755447986835730799031196367323817361150623932048563112034040627213597261325, - 6221130271964372280138992636208062417325313096379273438539556580491430711297, - 11042709376363248213366896208587241517252100440844476816212498352999929578287, - 987361321094619571176752720390429919723900732295551211263814448408232028205, - 15077982986114392945859048373768437818569856001604485167476360943078774679228, - 6278894644165961404521866714059972066255652200107181684047812674333675794053, - 2649747800006903047073625320829560088088800522557851927539477888486006072675, - 2636278052351769676017824297717609512488651850924228608531372135635042762078, - 816232991472315395984098922575496846552245086608787214581606973359616326446, - 14372687274434205592004117128588852491871014819273428668840779210928924573820, - 7351401720390274950322621121981079413650308506660552567079785209176949174210, - 10275293929161727274572318228903710245677747557851999483919909420098936352013, - 14869686444606195206734119702227763209172799407142930791211203702643805341518, - 937617196362766626935279232045712623531859540210120280128165029613358941709, - 21331527351771920568751070369057714014285398281585036009305608379072813379081, - 4305436470381074948146072259605215282335211631970525440530773004228212378618, - 5894273721571292784412707230481346442881109207745969297947253583203466014760, - 6512250441044591603946512492071171861967500633638753443182294740883123881284, - 20863871952569294813936866452848141274047362082838805921071316386912981651979, - 18788566662709810970880679984141390717017951403407913908833463086244783373013, - 7784927597396249543149135503684024377171301321636804832597181795981969626201, - 13818519831569592521516488188127966399245767953522268350556654747680372036664, - 10515208647860053151690062640705322684876580250632027862984821874343071549235, - 797604926079325807488629085866693514275115789253871397971708541758696512985, - 8741784289526985522570446847275649913333939699807282742190607491216732972386, - 20966712704043418981047968701828936463778140093909973286855779694780086635828, - 11359697297415630167449040380538108774924967116147664240213257348125754475868, - 8070907838094569287067982462230761680706116783989613960066342967469297961118, - 1868550288036217638713133945402464194193242298015503906068429633793800456561, - 198709459347510170000840600179608479136663571567208109852828485236018304733, - 1601154135701845545733926027872374554514541574822026314034696802419388627041, - 4363994778006302991481199477873248350039564117453810275561422974475581105893, - 773054378219982710451611471050404495804413666789496412742983455527754059148, - 5209426340109575519362014651321132459061755868557415513439993327176584352934, - 16124961412020675839394907565568143713078242978522632778625312854364651991011, - 20812496670075231301471694692369245988519082317145989298573032859079075730004, - 3312489967581906638742585802390894285073229440039144559060030129184388053832, - 2967475373447822846542676378804990140732835322255774209561143670843223463335, - 19744585401442299381952694102570931935735276268739851233412754166721728873141, - 20026293345566344685499234599699178313754630774489046573312844763673073616936, - 2611303659034102517884318354550433047021831422518437228002960700934925644951, - 6230291832603218406134986471162106408091661326026848531605999413028246206577, - 9126162046556730019959291776456914453189657463686708035601186672661595109020, - 18827736146609035067773173111376739253733288103277133456626928961785293662143, - 2328703958261360872869074208611873245571971231035163763965210852182760438390, - 13796410059666172174899788866809560044715551934510722965495280798363043241416, - 1593663256684781552813616365605526150610454082601584196604084376715746899324, - 1565874145189898288764434737762721576951043839540107044892767693968417810945, - 8709849304563896945461696717753976956465219721409993781555147204068634555572, - 2994256803561260177499267243802460581941891553208150783951937342406846377191, - 10452746656507347152042187616753027475507881362159944564077673851918869542550, - 20130580998875572619695450234900655050996104101008767761546912649074040426200, - 18926933358104691474037431437316089682088433006245222723356764715400831411716, - 3783551594057498940671877156409957274854990650480535806320220142873170375307, - 7919031943604095374667473717154511882451510130166237539514111182596247372692, - 14518552587329209714850286012780632801030157943402419401997576700600952906519, - 4770764028263701271241862755569969531641408032906982530346384375773459918490, - 10866502826034731763529371496585294375373238783964914673031891984092997621879, - 4234148117462322266937279401468367908013627589417699250592523530383852950379, - 10747942066055887965185603234524367638106812660210378090215017248140719240336, - 2587411532912868255102795810490361867789634574022411742057853375399270197531, - 17350061113113681344498080520518808976916692173267298878258722510332360424059, - 16490282364669098969805528215926442920328903121380947471680517193373377657129, - 9274691782659584680377375192682066090127280485689527337429804211265749864190, - 7630965482352419767782717986075793694403609453648729580916814032587325374653, - 9483872310024003776681196467845329825094379763716541754956796450187787638623, - 12182966986735661215639970080491757244218854808156498220088212871061979325833, - 1853790963611367149183440339188924598268644281518961106776656221408171642714, - 17425077915972423995335545370701802959607559878032910147159424242864219303096, - 14571075346526399549826264845894977639678567831720652860528738036970272895919, - 5627701855249158721927849603102149698163511782011562166637339712383551336091, - 3620805686755372260289125555061886982808014642356719556961142525373021656729, - 11556995641752009899073583627136467840237831247117281278719511600076965602980, - 18960242154096055221658318882298412299294886669455506299567210308762501113202 - ] - -// t = 6 (5 inputs), f = 8, p = 60 -// t * (f + p) = 408 -def poseidon_c_5() -> field[408]: - return [ - 9174141306060971809979631725764298697615039980311809306145004207410652431953, - 4847693924685156250211477469465516228032151306221739650606132660616428517315, - 19669833054057639609249840291533340493211768292967819468538893000195036768991, - 19800508893433268850924828171290876015556093796000695603651522426066333836892, - 8244699449852279148780456022144420353408196866113049322676048275081354214716, - 1563672068712965454176533719400672258364596155638916268717470967009721945171, - 12723223712027468580318230235559705540011996847167975439677647504573149248849, - 19944398841194165937952509356635863229327574447452745793253427406349161295763, - 21218058308392585368594275702746106483411305671883946244077923955757637296177, - 18442884961885927579732373746933397748806426938144021013884176466434407012116, - 11138408360119814115926439449668526422561003790198269766757675305576549475808, - 12724564576884231109847024566806896391934587839830522481308995309797961575379, - 4897733190252075532660075013731462724561461746919488679609618967302541674417, - 4797748331306263412471031924618974997396620231469532262170060449304337691527, - 8626839560132907403537141283531395025838110825355541158539075100658769738351, - 6096293906324574249636975851522292408228519044739444932687579741964974917617, - 2351617695830568421216396081605990689071283678701192113347036659596049514149, - 3045682390398203085155257535118136303069379656645406266260961816947178911890, - 6935829264874515341379952008241845470659188886156484974987865751370715745075, - 19847439266968955911971997829840067368072860877451092633069920565944933744280, - 12795097343831149148337906863235678514689648096503928066579129201713661539889, - 10424580232112390318877053133877999442988769389050776486274146627765228950235, - 11651452649618223740363812212607761589812354035139843126315028745587570714609, - 21307929358023177131550002602820591970791247513576735567457471459920519084552, - 2579908580162153663820021562014873149811195641589016321720930006635393981680, - 8198198178555784054784079137247244121807775986273563786249987394640289859893, - 17176088986876377315956611075288620878117708836881362200541916957398026761276, - 671389874397910339333118510595007038137908096657753354622355890021074216004, - 19161949137729278558310070194809106779119877882343914445178348849980058405327, - 10827554013954037091657804154642286174226562252063767377995268439458401752538, - 11693672899474469123468133710607776304784343543318650064064636202512816205843, - 7026547767612627656560992117440221331093280829523426249915938274837157551621, - 14422968137896343032446633683271253661000603582016449215470992885331170459671, - 7685352543184863430081115767111935982586458632527708735083385591291346555502, - 14089009391529192464370954954330128327830078875414722902347666490457756695535, - 8424161061743752192085022963953944100289245618074575727145394775891645849043, - 9809236779073852557054640507912802523501426410996355424610807253990040160483, - 14100245203768962710288059230665566265892855964739454261791429988929622355986, - 7775683622333704945225255741567928967674629526812606133980425422182282014012, - 8739247215686497264451630351996892836638898510934389758205488381695687859658, - 9431876969679115468275053745264413939426444105271849398322497961102606290132, - 257914055321743732506701382989022126153391940932933566664491918941925247878, - 21801414068435960590201256257290267142214176965736081788536576642934903066059, - 9465495933537134443327560834432669768951376466867005153580146079082722525723, - 7862366214258716333873810314803222267215825847232397599183717032713290878315, - 10701164906390193792620967030790214270231326273599373762943959252633779929633, - 11951628827727068395937910010248864431667047516686609553745879936868276916066, - 14268744039571470490378560085356767818183790841094115879980723591887874138419, - 14468215915818797151199796266933432577607248341385185700017147731054148927023, - 1523824033338639123415809477892820349580561577160869448927791050266158538520, - 13559991428776910947424645696251487328999214391124402586267086012691140984198, - 18151203063828433535061866995346135260543721730169485344610433976436663085882, - 13436242600153492361692256644258899977135098134175123174795293078081801647137, - 9384556671429507406657070680351030238568956203341356106463890924933167416522, - 20321079285577981781556986944841048777999006905303986053275199507771332527205, - 13510502130738135726695195328780836716597947131948116750163533622597187969844, - 20903049289119144354363108865308751668897757360882852151457514926552553533040, - 5611953645512225417723205546533389174830971368309601830751921473015551069534, - 8816886019615642422040038431962872654062471314244185285424018745071289038220, - 16751828354835345790163611999302863949792305206769993810746019449909446216365, - 10421654749141018171116296259626916395875529220250947127973888230084671091757, - 6065225315766552671037285757918350882361743810888619479819895087632281975681, - 5737755346739850738724717271213687543479332312420206954339242459110768587128, - 14770522272891919220644639305274656491731294860310497013287297810648680944682, - 2777394791070450473479179489594969793054480209411136328689318984981401732197, - 10039559932930709555975364107098145624058027439566384376771787183526929807647, - 20757756003754261934858081777796652436155530474748550156383127600004580439167, - 13253166894715452480712170898662712132411702335275401581167208877688374856806, - 2037004052447343668129085129987646907388123739343356363273464870501805506884, - 21829471491172175426560705585746893969222010633542962882847909490991398830669, - 5130395545419191392223692116621486075405299333195732914002649716762739787586, - 20333821730990393095934147177227294218344864602777744425090741435432040213391, - 13629653802252084129446975515814037702423511189484562534040643669977716900228, - 18489091892360842692678715136565494502607711254719045543684163289077857041829, - 21380328601365035012832876315565064374684993115210423862017233170195286906080, - 2280052193465635727584791148501382679094142036232980037838088033232747821762, - 21415541711468815972744677841317235994302058341802530962394281077076174148777, - 17146992672828650459975820445250769505470616910596779130798889014378635881076, - 21676475584514120109058208398560066698690773910598518925936412952356431597439, - 18337052978997482578725645166749278142628133291693686105612531426715865276143, - 14864089429815580405957698645045711801464462794754089671996837547347950054532, - 10834607317840698149140890207826430113987295440254355899459691878793978994131, - 1157143498448645320415276909137008396665083714591338741616893578930275511205, - 5027542104048754930085470328670427788489455916338375169351586496298129661248, - 1922685817237874482932428650501872692326329693528175054457715565489676406535, - 3071473720617798005831658342971536643616129392641449174655528578463370685788, - 21091078808046042460442535848913779439792606439995062001271357804782672390627, - 19773167374024045118471391738750949555178717045037157435777574972149053404157, - 6418695831178793575992210834992785624340084513619644969535805236049937971859, - 6317875495482489567338519005308431806047606843913867465201005132273298011425, - 18001249545956637376455848019549801116909661454019565655561439372098476761813, - 15530167556609139699164228289904946047951254183080358784988008899829027775935, - 8702757129830652230304011519426558036441096750485189115358314568895250616455, - 6369986882953061252605652398893489899416599935424066958291402945530517772170, - 6842894437627604179732847187262933342846269043996061072487488027804029200046, - 20951621154051947571647917571547811655800779287153833018533872651413529893817, - 1219277535080749134805291725937516331501172121638812333911793209536894469364, - 11704605822590166851511022757496386950530399074796545751042566537118336773236, - 5983427701962592508775640503988144495847156070437130549832329402380170245893, - 20169091361583397776908351163571343158517532527313940288212943504015977979442, - 3347733015762117176159731683196584632702931062411889821726902331981723958255, - 16217509027282489850987935065936382820558307489954122630844029918951230268972, - 10781269196927764524006466217779648732772805761839205677745819812868343369087, - 10568911823766972365218731330080733630028238366288098114239172953421915095075, - 5568774544682750792074131352530555554984876659733959079036284517928264996437, - 17854353469028651373397049175548228061144941710027186166132671198740388767529, - 6573034112757039329551886086829829282007989555105157401271097204633906940776, - 14069627287078359391137554212536883450595451640858724555679971658981340584258, - 21119713641590541511025673864154852875977162278614553796484277752677323191505, - 12802116677235410441672624559825044917295689876859311183079161588690810005363, - 16037054471696658545113065872215787085337497333273419984439267709950724531124, - 11698654309680908244303850432833183602706804558317993513795996394673734185716, - 15147889780127043019188099948246961619198549928908180192590946633702778981583, - 3657342516407201801006680507925024451922115018712017224805778401726428603983, - 19776786467141868744713630352693556348834540992018636838044610844396164981103, - 7980994848490005281733955776875257044050741738176865989521982608944874160873, - 12415191330803073018395217955802011585094769098717180100014182475381600382452, - 9300986814650530426668152137665814177758578011365736727321578452726378799933, - 4412208980274764197258090802604347599791567698589180187154608728755887977460, - 2582317668924231956058541757507620542434237159213236485179804217989764223164, - 19860814395849792324574773787600734118308975251437485131415273418632757301303, - 2765909129639570206766170018363951893338720647679193401532780051354569922989, - 5402210382809272147099442645489124829067576777592680891367494969197685281513, - 21011104174655621871977821285307554463403659856745964274018020456838460357574, - 7018364707286303918877589672878574811337524823085078243421192184715151775983, - 136380103284908296988715215087018020601815024625535396780012012453684253071, - 15953315437474610448052466140270091879233956524793052736202793153707558909889, - 5912305909658884889781037379491781973092020933879206417274479331390062715252, - 21575635295587180789566592951559325743281772394055590203112195979769645712827, - 1541325805478255472079288730846072146731241030100908414806224735345400173350, - 17207219201921814683730773200330679841907450967511507012179337438654141678023, - 18266907794578843029196926509122804272900478710738403531664855427655744759655, - 1204224895193276222782842236712348692319665277014183965830735736728887994581, - 4023246588034712778784328407820569751989619386134504404739514704773521558127, - 9064437981037864995763386367268294611921404895425171966596873454090899491243, - 18733802217274421976148972926716884457128521840010001893311936746027998476583, - 684088380644531080099595788833220377905013807951051638705160997709156627273, - 11994830816367980341637110785269531718699655485484715851375754143223090344544, - 1831724566362300629700078416489434571462666430381219293205871349415506993475, - 476710745682537342427691635955087951551678644045621275039835625280220347951, - 3586272766499559446129476613035465343616602918105042144185864609818186807939, - 21220348736799044560439132291243370111879983677197111626309132298278891334631, - 13683795063599185801186093771702503913590598475095473714851383723199050309401, - 16118007386401646906425171859166434660243697555307927508268622819509657450614, - 20930641024767526790605168032291665313905337763598128831404465184891980632233, - 8098646212401100552303711812039666794078834386731698810205195111722330322418, - 11585783577173465460243373201831086724911159484415020913089605532852648999143, - 6939053275662244505087635417541857793206828446247848992283188764105131966721, - 12798043540382494855660472922674138947867597503468216532170157050160462426199, - 20713389801600667412553956346192236970217099413304167366340548074880917096741, - 8708207547232102069057776099666995672015399188924281674772351753887161579745, - 16016293152251662056020528248861487281148011452459422778601663166015837379163, - 14324897997637439510797191208789711173129460994362368408063402682894248793270, - 5652996184880208428967511742390474289004021508049280419259474250332590598159, - 9877106633097964013050071703002221796318046172981334418310092241450453368579, - 5385816971548914185604875069230499528103133871233951354186676373318036241822, - 8683091293306949708478955451280670950858818602696102489349595054818146782362, - 16854975838650963077652189417311897888852709425835763860743171659164792100482, - 2485160816649177905834265823672532710299580013309324666453183278408904845122, - 13571692148185502188613896013359942531817915076247598483272449919094247957149, - 11899399615412173136098732970606292047945698835588882297719609812145308198009, - 16827672312681684936590464376780346837611857292837989006980972390576065571472, - 15588237822592586948064701827497915157359094833395277985658706133691498343174, - 18356642512438827417103800170157877145465512961188328254773957819312191285168, - 21642368145757804795143182901389223409544979732781450480847315495418822041608, - 13104082060493963869934085622104709047787444250961437496674916673804812287386, - 1561532086277971111804773016487251313460788916643968126116038406859074212104, - 2718320602791009266532615731130512762296058687816604986701989820504700684864, - 6182683520717583142027400659687593712743548729948584058329789905227082638908, - 5757242145794370726637363237313640925174531077560764545993554185332488520899, - 13688467192244237790806289073845563960119021610896694359815485764764608925981, - 12528461541936459922472167643986446262977222390263675720335825628163511159437, - 4897268894447399415795897967133432014527122426051771866816059363418177665482, - 764332419588242767884018802335623760055144509861323437945071732931233600264, - 11755468878196093893190753985692714003062307843033761257593209352165323938879, - 6006022813561851182403581780143813226749481175437001910923100661321563995672, - 13901542382190510449243772206670622017835690746895066410475076631498053123535, - 17648853891656481911225897080296737974064729032668806126284849597245044343224, - 15106333841965710929952896897521673254279668876709612770907537801609875568099, - 20899315415025260484895459315726322363345188136910564549344894025053466430346, - 1409310408943258102775009950750654615881913956151269414096059752250092035807, - 3899088673345731523976816322438172722785832982334214339521575164464706226294, - 21406686765584824639201351330529610299177537976609066339927938099572420696135, - 9121591670793901722224770893633585291275002987585289305307167711146944200595, - 10711764678410479049841945177317023555168593838022414378232020467195337241279, - 6599257303974597452501135281719536074294806740553273627128065549267140155175, - 2142616913275380526921597026822750992917222975992774063376747381991404337593, - 16361086527663411948363284957489078505159658832010445114438602510508720771278, - 17122647864721668762640781848678028227021534122268561738445496382823789619088, - 21708018685042482318786273055293241752114005312590172460099480713746031274624, - 8303630654111760473056607545365338851734309857718959193970615705292826806179, - 3658686547507488906491014260011151850549759409901579684176172268581462329020, - 7720024124908065424512743488999250878143598904717873371853608249805302871508, - 8805244918657836956533473437651380347005779399042661429698187314657501156241, - 6303681354794120075893215838935586592706844702088252970663343726024171795351, - 21512507181643408509426104627003618425209526633080701556628608990726677651135, - 11835373417333287523801757951049679177935522717858158305516568595764125190183, - 13059698839045014411602727811400239840163533672024084777768305507840091151855, - 17635240655824524168378284083397931667938326555447077097306236826752492079430, - 3374412791113107178205006579112630099131939030015047870738873452427211677886, - 649711083340882271985565833699379436167716866997851102439037906608755280128, - 20002805138014565226408902156524463368767807620908543995020210484077706418135, - 11071355197960433041624284534649121637702414580710232237233568479006159191217, - 1105441595020980635809093220782460032826849883993030969714432603468135735502, - 9652765957610682812348919340146799318537766051849796416434577860126024594091, - 19248299650856496267902926731608572596705132576830681367365128976226233392929, - 15285802367070100569572399512275861017714681455564415244982064571963339715277, - 19970416835730683993734843405673457882587154729456022607061085470691843864556, - 1017865638757684714433500504002748241987153668285974836527484933462490771227, - 17284848056169793253916338792235498052654877955690514601079806604278964099314, - 11718277105372928962350331838305733149270432706448484259807630484543527733952, - 6670793378364949883511003949124179112275066568088468958915163969545409700112, - 17088789393958965094855662340742013087397643056458490270185660553870734946796, - 1930788514812600942005320214284180860980345276633471423966020111188605196111, - 8844343159753729614645407314580317697758296041737296276765583948670245312842, - 16657939543606018325703787748629433167511611178952563626096990460124133990109, - 15333343644239485619497914931918504163396626751908652058758135581206765801100, - 16533875915742793452819179569144271760125646811168930162441077117553849625884, - 19679534317472082858641184998487299940737032844519038845860980362664393659234, - 16385719932525604857740698205965045007053424961009717093945644387917936681719, - 14490521084213123170781774542655088188106794646066074998587858678154251198444, - 6386781978322405984893078797365492485297499058328348606653460996474947075858, - 17508047533433736707046937662428611868296556965172642086594091783148965906980, - 14904597000414815084666285064575232635645852687797347860862157463159487771060, - 14979972442969995336727018758631782107138089738395941038626891064816880204567, - 5299243186271864957800928637599294208954109271450189950375274196644046222516, - 16189884555052883188473617525411302750109401983487269295700675997730645714379, - 1645560170870292006287241616671417605853047420339675073261660626733726665673, - 17866745974872498136933906591373095763114066893081150553715211393380040095383, - 5744849574386643500716045532645657520001448510343827372577217716983339773799, - 14021966200238971589811034967347517039341058556783068950884921208853167419283, - 1201178089866013320759085637098781870734315826415474628546655403142858044361, - 5875644793836087035760988842421852197052681650818034527831700615895391179258, - 10875065950479466897559006840696567433921014267247530366235539292597441428702, - 2221662399199449388725697795500999209427453463134383582414172135385907744785, - 9758513532658579204941116584445291102215928928145103503086996542188799521709, - 20879593323317766577775570558015407573466986714590017262168011643343469361329, - 17225846522404915080676699509636264825833159640824918876741681229188434930856, - 15189442986691997434021855855358620506645387296294217783597931695143376252483, - 15973617135551858849206811241799666696907820418171736027820254766840973764431, - 11888113439449420418408437784450952639345990804839507528208325036625374967083, - 12365920814385241227394825974928370916184942218042429533600397623369545597697, - 11966175169612449906889690852332416255478894176917636726028104087408060623141, - 11163554022908212145274813635928762748847331295589087669583554722521180712379, - 15273476004030808005186443499782264987539818978741159793745891769358221570633, - 2013969196885866182480519514425192091338553670034650196068995589691938248955, - 5008975446746271526106846692137145404766553748264648461545948417006052208130, - 3926749194225734582453671614337621250954608160208554883789519551411469033731, - 1635544156808471185144068767649088695307748439189898784051754434524720057896, - 17144944482517962143604430553750908864860079758005337246916094084534304051981, - 13823503533305241872793740090687668844401004819859520464168798913603662683770, - 16335911272023134851779534303717879370955813837529588982953758998930285394340, - 14467284210444150699969889681308566002886261365990840091849371665183151060295, - 10578205764525658336257882813734672799527733392763965031628376897794294290414, - 18771425328697137255453620743509164311086906349726510394566012237817674245865, - 21804626093983212038528370352039806004465345685985435415809095637323683466452, - 12056805308954301132385034564357716323176447186932453788072119595595483786736, - 14307195735327805282612857510308008767450554777122724855715789120735513378827, - 6848201070063637295416045855906784325422580350462489495889308309540335269587, - 631364713487758647973016689203003205602593076699875191323345338325349259049, - 16214655556434201961140525501007839859074077768660052713461045928979956365067, - 20940788212183642266181811368870506130164462254923655617893660245551698033523, - 8257440848494309435270838240795567828478627302119374684511017376568090372435, - 13701089242130867705897643891164147923878521147124165292045879194108024940909, - 6895272953337895406509859406973110417619874994579965619097329249292199573333, - 530437169778092455975584310016745919549274205817234464915791595041990209639, - 9008612822403008353420189298381046023002474279157557733428254452507266389025, - 14863423501786052071018008300345884780479084379412157784789951872243409629758, - 20091026239041315645045502002997446404106877721183777765607724358538559881231, - 11103877261161399045807234470901399725912406134008627937945079980590775715243, - 21529163495181909351665093277427712610965764606448489357319207727176092439794, - 19540446772694448035410067193880900774391072899517686330271100773183944540294, - 17549510450820803306426739851959754252204444648959723652883552677325100583689, - 12252518814610348662318155253547558779974557529822012236107550517806390105567, - 8058115132085119666951861652409945532276905989404523986413207631657437321956, - 15916100116790431839835734530362130437167135501074855072245598938219364570910, - 14256533476494466694764843270015662315303617568641801280831873052211753536970, - 17865471381417606502707639037418669122823481329049436020149405646709537112534, - 14015711483636570179335132940981982618090553643653746531174110949872682031017, - 6075776171664976866533080327142904134938121198707020111533599997509054627652, - 6357981809351565370498807027309828058036389418343890944791766504532174516243, - 15145296985037303761634018005118672316118004891352906450983918852209191841446, - 2473672396516437070485250176897956191104549656554290725379242542480862701754, - 11059085933391482002269653121188853142706883316754376424538662772943167665341, - 14804069155713123448375113552227724310276294677318593116834685772120057819258, - 10146378656966122923223443263705119557842694560695035707977826044606938090895, - 21828309590915152213768434346306434851424116996828875020020066586363340244814, - 15568879616082229996551157805731419126872501425454775741945679993142071548779, - 17504079509060638501918729619244098692140123800571022969294759717277257664716, - 2998311560047298465700351970612785742605093777116697796464434026101441410385, - 20229972737818088327107446854254558628041027965197447598027135778783710740259, - 14884874200763033520375899992902136897590350894844904733314191389520252900641, - 9619409751736964504139815024141276029474791187139050183491749032619248817404, - 11534029087676783672833531415041588991838838078174102967049055562568798961925, - 17106297093375816944137015955705541133308466659538554159312635106186252148471, - 21676736161168806529097919794022110433487869702564846859065695507460463414524, - 12596447704589377083704857810305080195761099125652005594925931498073219198049, - 310943124066162607352831846280730445558498286205117614171844835745706684432, - 16013029710570597613246104892930389004941711962070683476555063566372534206859, - 14282564976066063966062366540992448474634085812789771416509095817495183298269, - 20757241092771652500911491636894210910134068426068355089789205706892703219255, - 17084251309147907751212619949757520468224028014308500329099194408342072624132, - 14680350698112448759886861002622963534698534998651150537754386791270019720748, - 17739512731440543100681958009173086667000199263945053345384367808940651002571, - 8967486063900234709994801661246451094429250620940593387993430620369318619734, - 3906067814916986286272005884942051451306945488494283077675304366798199289520, - 2517004675157816404807349457307096161030587393097616279110332574293494030636, - 9995302877359286298434340810356550712107485295049220989690824504445305103587, - 12849909876017357260683411536833847986127911582040960825577300322066595609115, - 18074515800779889507358182860997188274134395074469953155084226981497567860114, - 6692811728183968363967959295970424292426462800383828091752006855360167264617, - 17859827663908740084792157440799065184931609649811664442236242315795442091367, - 12243409340804252499520308602187370739653046835019551522661290645230850934962, - 3009118420068966587115224335717185828292538080040896739662684632413054772046, - 15856202298588272962175258696610233941787471472716811521132004805327415486141, - 7549804594729480554341356998842376772514802673462970334329441043324983960866, - 6390806437030742378988258255983502109201709511321162596105974797942236431761, - 17370236522182003753669946647208335160124999930136364231371998757664000198520, - 2261672244214630177095236704932243497157963117166120717011661647779055001646, - 17325026196605130064689259977831126468940872193987407658419640959345091161632, - 3631641025220845885502691330008982895233731506600778684638817282531001457735, - 8656561399441987116927438675277763317789561532507396244334062468892541066084, - 4069166732330197412844703565599514109399373916243310212229125901351402003915, - 19808198732373520522982274785888742523226720967259539531129335924093928174880, - 8555796834031869022510134190573521699378201702450788201649007358450530423866, - 17759660636058865290579521740750449606781204755231964378855563896473545202303, - 1335826395218609619260020055566056869243760115287254209950063597653055872566, - 21596200365241795669701682696176077888309278223833581800772036945674858315765, - 12619752319673193899296833725747186284394167228468888029626464753793997178599, - 17420588547980145067421969830249755561311178399975476925894947008643385243007, - 10337481272389772505654575850886249605422739785111225132545740838911222864209, - 17928431631046752749930349099366498612885288622404560316665023363985966878427, - 3075798659324203306711977985120251896073145961913793478792728028765206521425, - 4639500613932181914847461422373341918892878975546430906324216810326467690534, - 15396322795715441250300995201889120935591602515487993982711884319616897970533, - 6391276937505284102735701938724106665734769352007891548547667448647832351929, - 6811373320779057384916660178551330838095673247430496448933336925226142036083, - 6590973140323934807800215988687710942074412987201753370126190631819398102173, - 19364648614154949386936259588484266535262135334799266379433252509193375956715, - 4702754284612371917466042550086249683933140314858807272591351280832918881874, - 1081036249074169248236179367049085684430282426446509768147097371368406374049, - 18548093223441988703029589168425055383154624592689171393242936199350770119589, - 11098999608073377668352846814752381891400020647878345005629685447730764310163, - 16001262992680194260590639872321865154716987495605624862471107193457192704714, - 21696229443869118415905915570780926763029898831113534481730746953640692230062, - 11716215712634983607563947056324900205144202447594949676250978337464771243867, - 1778908113733035314726603632369389424542091991692308812147944884836647395775, - 4019081204388123040098634987844274011285321286777408246805308194144238418480, - 3473266952388383063447927231564219811787341139731701190625605897592140631276, - 10457881304788072618845101933412333126160339089704353596608910674508961127232, - 14926101732700077295531234099443522459232814784151318061435025890154852791802, - 4036967072197259618286839959572768559469665646019907384624959071646231971399, - 12776716624632228928613396031717959431597335742467953143594165782617234803915, - 18894783424164609284436913400522166453255844750192864579927645453695213022195, - 6303809107919167113924303987533838414137996606980561570652539716097058487126, - 4729698693443803882717817492985796053343431875965792864932005291979914613160, - 1645790034267553926884568714540144778649055395816210525904813567839945991808, - 8138260225269705405100573121045873922755899939885385491610389913906979427176, - 680936760009829486282006800072001712155424246576949107399338687767760991887, - 17240357869291182045663678468827695873425113788704614245279840174870850373113, - 19100963939745621863641468371111320143895293700517367016077996431570157414340, - 16188989656090417148189510820963186890780289777598053654241741803194118100843, - 18027402882394597868782011288920739982398714370069420860949975937357531046151, - 17780529984916796963712255733293310230026423072958099290880849386941451922559, - 20004531511171838591303710792081846238092292916166965045929062171308088520097, - 13855731634251510230399834192704620793850325654395687428672253016405315169901, - 16872938837392115669581040432902657478544143723662502779821325505282093696739, - 2541555081244462826761076743762714962901590548271316707071685417008817634653, - 5136424039269088350807839181761422963254683236279333039713142751702136147963, - 19216238128964101420135465007632926445321991494181045543846024053552797518994, - 18868537488540023742258053821537824724371813776839672880900985865823137839953, - 18246710415801024039719497716350501105591286880983169809863166130543617917249, - 20608694004331631709610739723463009412162748201282986294016482926528443868949, - 11318113915971658853560322943565673154831611543653209084299774855226816037778, - 16240989418312335385576389959938922684406585560688799437547298624184839261343, - 16171299673760267132909753100946681733778389681324959987573199154235691694977, - 8036823955656422391918380552495301547890420665617977624790236120392727764522, - 20269862530534739231936251654244170650781428788816658397167110617927916774329, - 2368678892744667199202318323282128737449992006513656480477288092472671147090, - 4618078962163037429845764284139891171861860687111566735174912070413086829215, - 12695350627501306162901105159009497730633599768443844225981772758225613194238, - 16356283146491744069785034066388746989409816380917535719898337817088223419024, - 6407893217596287850421377738867081146106659458551198123106454022096864887316, - 18168868018352364136212098098453930600797374324006271488950341490483455519349, - 18352629174410142476418438008157117497168118524562206830585500251463010761689, - 4344169393287991961961456515301754172943022039566219343212376057129143739343, - 19424839806870716108478074501405697296961947409763509419111261767390677718987, - 5796037897847804302272999466834285170265203646465480652521088328457333766863, - 17402105801450379889120987010453669096275392789725153915905747267778100864362, - 15540989618743824352651126288511222263828123668208146479603617243655978402205, - 945810410725426921570254447269595873973858272778720657523509910503434094174, - 6962323734045776666289031609372270190654631739266635759799844631053633876675, - 11382945272742312954364642163371436855283161775445664525053938433459897196647, - 18940251871958826726849623572811640436342841713786099464305053400421580490631, - 13969540696178305383564753026163726563325318478290740131984853424331762285147, - 4841983966001277917879506889862519614692143906356361564304719688757862622407, - 8939049562492171082419559182596894186639203815268680721033389307282239000385, - 19265363396776097866041313346787101192508520582744521467413665478819721956884, - 337106861429123598189388456471513480497137213511877011021531147545809512194, - 251367482782327915297484770356856386307188967585026711663629212746150191478, - 19506616511267234489421548744907283107923549136620297132842391511025844759064, - 20633589633280372440758096707466273580151526293980868749421563697429194761212, - 18833062060138888612708634036427140134887774731041742144004707524569102994071, - 2927291160590267909596732410727396533948837350308818016906834558527125752899, - 7095572562193114209617459307511041110255341231707924363346373597653253806883, - 14274988113217913224290208839851596837329960221329537670822013510325939323091, - 9965830780560026128320556230399915681196410289456547935188741323403719404039, - 10333365845496980935202034863900757172839454015352626511769637076650624839070 - ] - -// t = 7 (6 inputs), f = 8, p = 63 -// t * (f + p) = 497 -def poseidon_c_6() -> field[497]: - return [ - 15193892625865514930501893609026366493846449603945567488151250645948827690215, - 8655680243784803430516500496316192098841666200175185895457692057709359214457, - 11710807066713707084726423334946631888369490193496350458331067367713412617049, - 15442364818086019103203999366702499670382575019009657513015496640703659810202, - 1358747428976145481402682338881091555771254635226375581638965497131373838774, - 15658002471767984962034589730824699545808755102240624650914676102923421241582, - 6420480504329990097173256112095253518339231893829818344055438052479612135029, - 15457172495394305353698644252424643614748461590123908880271021612601244389162, - 5745943350537490600340174787616110056830333091917248931684290284533019091654, - 3877253492903478989342845512796806320713689655633086736499730391667425329322, - 11257677301507982757739320943403112189613848490812422490591766717141506751601, - 16906586852467953445509312290627525856126394969718997799028223470195783329296, - 15263589725854108297280528692120758129000336125328939290924952731952242586386, - 21735940039489460025710098364749096267519151075908323637361429746399161905338, - 20023056608360522105358681147781839024069418874082333862551226466128829664291, - 5677500725280079960679484373333947430817198394184436922575072427342643665917, - 3080516739494460477657748111767941482024045797587058388950619118994388252853, - 21486496065617100719537932626843898998311175055335457507845650282870586541596, - 5371049178920102602305531530023787518286335086323221270202212974241707302466, - 3074817222296007572297581554183445947239252698770067839721345984255386069425, - 19180807038569629573914331337874446591506172622522351734982093457681161813141, - 16937785199372956273358037645552299688842385008757508130180245705952406225194, - 1688218397616770248184651775433764527272029131542529408516364801909017591719, - 16315958669815317541884966612581197291281164499674338063931623110684590850347, - 6218230753007070123505625054833158632732536069700963073464625252554943737669, - 17774528060285257656595928889288330429565059134928074258373583886985960212139, - 16197131592052727313460949906369199026477758140133103701908949020106767192893, - 13418604038232148873269488320329340508522225417123160144993642839875173062296, - 7265658443160253752317166706266927598319661172006072732797351716897681315157, - 17200150079219747370109251547638276280610591698078334228421747259741754887, - 8627121890622175767416692555014275717515106888840919734160364408960047296494, - 14546964505431549758350267964924534495477687922558528647552728692912697049247, - 17132720822762740343718421124251772119916072270451579802112353604446214831761, - 234333065870376500756753915306346778417056884715946003873280290982247600083, - 18375643491701271245209094287106352436174133929245169725584150600992143374298, - 5158448692161567615645197008737390561357077078129599243188536485308363800282, - 614161645152783610732075198073600394068518413590650990586931263981193439341, - 12661793104597977909223565537293318966803153852970198322604479648383643541371, - 13041905650419760925682179803296711066088286278603171065755078690359168540579, - 15006023590144168506070897325649191051975999212058008674224953860265667513015, - 4983349941266961584317889823965291023669365981564144622292227613558024302012, - 482274340065333833495445682213681402212945945150526736364263233985449810602, - 3966893131006556898236790392613869798057510088913626163333804949895810673044, - 20923301526284527685000591080290190641416245135554916208054502046381491809443, - 20838692384005825835959734210506718428443540957544929066941550833051093000166, - 8282357714606447781782716442854085217089572080066047419459610560432999443766, - 5410651444876169088887579490283094453001167796545260026969919887357676973543, - 15276966646285075387317940436655285872037988805762800567413073418506412856419, - 15066911464727337689573664613158712498015597773345106524271610486257089622849, - 14583790985054968382519116885383608902981814292128186470697458065499359610203, - 12059090796146479535492139954279038037217093044815277624197659219529427760034, - 7273811886044732271171500579064359282424476926867187108258957006777685922641, - 1463086899665237074608503061872751147444637332808872866814340325832200880984, - 4403177494620214359779479537027014449448686844655371530169401219256448130398, - 10860968418848589590932601250051274256181778387706764281989724391784015147562, - 5268786978207139542368199165627108325282167169564314266747401266496556301775, - 10683355823176907476704511935094343405052640940909677712096702771871787224727, - 12998090263935761477316698114799901126086030852595294916463464609721875730852, - 21401280461419124637791689956622923839426783908187419462727763377498739154778, - 9827224472048063173905906705579289843819400982583185823840008976971109664519, - 6215804144039763858354471461864183189301201862376216122255322421321775987311, - 15461308489200344015891625455653488930440613755785081602434124530381300882814, - 19336334695450889400681207491394600659946256404722006637851709906131899294790, - 1712331165786355540802697725399423752392267480553199895882357858951999960061, - 18153038525983970702748717571053178456148003321236490384959117581005013333018, - 1080183517033034908031748897211289245459330899463186432840251241943892326023, - 8948022108193679628295152361559653763100984324221629445749311939820327674857, - 9553342289560502306921915013446606435600388298465288181461633559299564421155, - 12714965617376828547637017050548818007690047452402682720666099310241001848988, - 10945704657865102635748104464461970844653553427083981539165832149959193156197, - 17511714411688352203059545713591160825310809755917403629838415797949261359373, - 9253691969419856285051096287845246422848295397226841130282244592511676512433, - 12218945350859454581754463621617733341764245716874083264842931063272433793037, - 15268139709971695434346690496076067658968455677120655340969837725391575270485, - 7948825129295102283421620705853168119104356217418364837218892682579042520651, - 6887299291348589691868712194070626390224806410428583073294593431810559288717, - 3610235157455454109573625364057240708256027358184031380521552355839155549623, - 16532488069063334064099666525339953823111673083177894678898823509406678724969, - 19317517725107761280217103201908049748015068578935276576200982249386084367574, - 14980901224290526859762385599553818204548992110637275324411078408232697158492, - 7741797285700915051013289492475875831764653137095445146268474269974647962596, - 11964233864746181868467810392101989052496076326472717372132104394243614334823, - 12746657111181947224582102380049766839578185276220682311596480990298620200286, - 6408726946032901840418309506578019708113712492100046332894630652186614300568, - 20959261828945984489015610988397031913577918654575078054490013338416801523934, - 3173674599420546165852740604987014294355430358334465189504551707066179193914, - 16110281513253204315524614633789708146700074483476149119440509845258215816735, - 17135377580103690088853370572199271964414896742342749305424508776150797285064, - 1405769920008485935711505753346340073052795087429311991287498566024570212365, - 19088073362945853867763169651582894739272002359692597239222895238839593467749, - 19897231284455588615416169252449008151349728648961637517447194842672488184146, - 20476415629812014715153863754869742189693986277342067785614833846523246536739, - 11074321446706734150375041020583051611133090415774365192315805856051215270782, - 15231367549323128694183572409135806408519505225209496441892541205465727777072, - 10515952069292929457050921929301902464262874744159361114100398880194109971971, - 3216370118771824418364829250073852356774095079734089790620447714552849459645, - 1940445924652458480775282556203659335417827058983719042726494187979000691704, - 7899310668555694144370607061960060230071621529123669746309839400642332452086, - 3125410912833939638823760577011271607678545358020637189655641109813198731542, - 2980079409624774815878860133121670095839651294537928173829312563570356348730, - 3766498515736372882285796238406751547889526137955288498682767455795237989580, - 21751217522789414135074956130080241003845828660310903627224390345319859795839, - 4947229586642010378772262640583556676497656670779800090478805824039760706318, - 2168676839236948809859825591626629233985269801981092020040909992251312517552, - 21172906642114648036685108008020762271569381607092920279879047961076646303327, - 882675742500939602754673078407141697482716600335919344527751158504426951699, - 20942968937722199705624825492102184647835614761458159157410261242387423597787, - 21880640497503102067412608072166388563991106464538369680846671301780353850077, - 17593472026567804917122179982860735087124786197105685847979050530954084564297, - 4492875530722152383516030266828166766820778742874238188105265500984280376666, - 6799763500412433367637987497601148507907071065930142757525839585946238894092, - 7812331664758167657763399273963290017340604299019483750344476103319142702775, - 2222332747647756867926707541092465789402467819000336747029352557749400316077, - 20438798382149666667185974604464532451975024544676922060351031604444896151494, - 16155157103796724378615022758633778903205872772589663310774455593497441785913, - 20281325298063880945091623185126257485818350714264176365501683813650871716911, - 4922178080989486450454493110764936742315495846015561426329316977670113220071, - 19579063976700768282784922967523980346960151903154507737857728349662090787824, - 2458828873355000645851832396764221987760639423132968569631493912353159373462, - 21166618206785010755521994106737991950548963896649678270059527421944129497211, - 9131643699583013708059191290958290089892787165715294157378879201986981390031, - 1820371114511473946932363841206094088983972935646887524223011276305844153307, - 7264184404232663540867032945940974372967974872966180860960243405462016972362, - 11228656105550475045610757902396386402555430893045183008968975441800824215261, - 7151503559113638565935009743218857812859208253653498318591469659718664783964, - 16876040581364499037941813142092448836399042253618385783944016186340703846779, - 10334125383426918152464737478646460879481305348617711177774418125714273980769, - 18900559046103390399749767994653107625464807708680067464279674225251110804100, - 18685667289312169245526749652972366835289568864080726348092618145885982989561, - 19970582871354083670567197978171723431124602481748785146813441774826500485907, - 15873472427137024971035326229485784626398898771525077832924901475242073457867, - 9090803292122260583635467396769157643561973206888822931647063181944243467413, - 10156295009710074552070572489422360071526675259143523597882131082376797944708, - 18600630374968456966046654667577076758720435487386724419578803020365834014000, - 21292291483064245088298314957584631356250347533568992016547598449487977536460, - 2784266893057214755054197979675795184619614089277590464548240934105557638370, - 21206743389683892419024645604723431382001453245850423743581664552645211926469, - 7915761821775326316473924816837591351530533394717381318596295803119061411675, - 21881095237485064870468603451853549262304643738646051878343976465227744077912, - 2011784725603622472271597952122938645154942022107573948889667939904597454410, - 21059869383015715705096974077910228193608826877524913363323189378554601804559, - 13660545486380051482020817701263881806531607595506890631732662177505270213284, - 10831091042775967380899180760062457635694790868286967266013231823406639854653, - 149288128407476550494800886735600251983375852319258454101603889073198917321, - 4032475033542195421623899365282946172767274020529645277615759958662043553317, - 17860535012887415629230166789742533149365132198763199254812432302158542514395, - 611194463774512114860065022851497908950074400927073001695280142990812150583, - 5518364261187313845085346561539515049557757056751872639492957432879259341390, - 783263978868449790737487156609432867806742277074765259237378374864740012575, - 19059339826992310300213673274315612374137067865428300882729551175173242291657, - 3179709304184015397125565132235783368222831063701934511986753856772139349894, - 10954198701843076039176000728742415722273043852061382139560487789741501275316, - 16411266672500930935370066093245284646483148609897099268661795671514664627451, - 14614816948231085620934132277599546641612327229810158468490195811014141518325, - 2458257206135880430320027516329707989817636936777744813891328347210486074414, - 13549483340434455515002570470395006683062583844603627042649952800864870013910, - 14465927800403373425828183741641078057513049263889255157342086762479739044711, - 4039391352709218793104596256671892882216573882631238721514928981154171136548, - 12750457082077152291009387792121930725761848879916565703854704756389714536037, - 20703941646953337308096638741387402857948436803334980867971163138332859477843, - 20148755487317949638981041809982361196106823990400472213765926589941031736503, - 19035096428824471222963574043396024781574056587456391309795571372815435282399, - 13597108420431213178364236660710194375344287228654817880431599113069659963625, - 16737817219786305757887002253067607822378794077688837656791543060369162185533, - 5164935079689729145670846016031605160169301936105766707946436049006171651941, - 21653381930704765824477248798502813954284378782353810890869232482999795586793, - 2062605478140760101860087118379474541965619844748678233207247884294051836812, - 6841505950265078437298089354417829781031272459823272323626556598403583002674, - 18723551101558427097952125661588457059960574026361073828482106612260297969553, - 7898804490983679270754258611113569895515918945891808074921872907759024464249, - 10882278698112390755842292529204069263813359338030917602809789513528936860051, - 19447560013395173052961224723195565400117958329259001072560983848146677205053, - 6251288025262210726686494480483550276704856797649458538460443509657307219922, - 13176666617050786358406074057104742181338809005466316548399895981897535342946, - 20703225796049910173111490454489910459787604528779911406172217267261190895618, - 20336720518722954780604743873837334696992422089627753769439653667292899832714, - 21420427865372074512365684526694872695798980614525900481233709853915806389425, - 2498895690812694987926199054702295457557454143930759961192198950277119149872, - 18753512301709603592612141197073246313430368834576850495154922324845448997662, - 13229612292359498096055458608547157785066962647476451239567069089111704445000, - 2690879919643532184588441383789963956137193400890598777054187145581183393168, - 14142396602342548413722428497204107502988046500369932366351553161157672540408, - 20448725195660080278132534867269279218381543910636641344871383714386318629041, - 2559459540570011016181396098001618067535109329950570139376049832813577592045, - 2209294835847631004298393339896770055851570184195462947318472391473531519454, - 14610669112573509857774678749257346364319969641690596877040685661582231189775, - 15281088465087253563674405311018738676067395725444151577815750152538449780965, - 8600553033773805414817363397077178137667131851961144771667772828459236208319, - 2748346039979601666392027583251905158817539034260921486084376270967628661657, - 6854960712378511006304629447898292218014632388505703802374806527561178043857, - 20207552563190343462280438839438087615024485494479390954719687107061991587248, - 10281541252271366635718295778088948309847900730867531177275273130071062184625, - 18855605847424121529776135453072696981767402526737712879984848146282568841809, - 4160214035780913418097601322951078913381556877408879904436917334405689553255, - 2122867135885631508183413043949777333811557914428796322029495785048111325437, - 18793959580906171893053069386015945646795465354959679615181136313144978078417, - 1043591673717355695648236328597936528752358227297053230241551190351813693314, - 15686469257015275311444450012704351019335987785561570672026138336552980987277, - 14048856209379833670666148034655599475317994357805584661156301746235313941815, - 1011563953969880478397969933799483261900428580241502003261587014788238280391, - 19240556623066672446907714818724971233422104071815927265423017590508305430997, - 2121904286573815063480388650799381683473766736407678915747169455786741101182, - 6724437969134367395210139771738563153857495313330774537559578422672993498270, - 20206855573383441961836932177838081339503382415601366823182724056749038447809, - 3659051978213562322887447057085386386485486575515693147713900345497451171308, - 21246119528547168535908718411570119652856799993958321864163737649108920924448, - 10446114322905404392321651684574668727564081327779662579984472408056125404335, - 10052242287865403393859620372179811039720807230902452334457123873762222543944, - 6373462744579965543231173757071025010089494620309953425653057223643612177083, - 11716070974813426833631730493593924834405915845847679294742728105127112594434, - 6451284530793440411577197006976867289209413848762574411101073727224316913966, - 20143217291446069633369261481904349401356557325260758866598205109039367201468, - 7741896897172494958877302103827661518814930985518070029789560123401964418102, - 7414486245715284930410091802521351113719159777210731898112598211035848096490, - 6480506916211642204624111742530825907262535747743645014149694168805302825019, - 18349725066341807634895742572304899830893334427067633858521634672944685466440, - 1838291082333887710851505844271184097051704051003105078056248035350245616867, - 19201915197596065583046168024521824662441686729039260890206806469763190071269, - 11253788423541320580105520117231178489492440242200599071301755928628199128159, - 6048832714406694444296771635481934823208451249770515560893368035838759154821, - 6398008918881249487422929614611145638894557821587972164243877575640548705346, - 7013037564266297435879776776659289982125632651326438965546874242685502904730, - 5942504790082366811245813670914617310604940200824079289270465669331434165301, - 14344789199380317440464969138686896230070901882253997360605407637865754361287, - 19920212380356573378521292048728904573841049083972983190424200459025557666792, - 8983390577894750782268266038315113359711163721228398686939390484499979421166, - 14953991148867572055684497824790735528852361750007063016470842397064705671772, - 5592033578501586280289038012647352732276003389059749788953239057845882297561, - 14076883072716069263619564306953450824526010844333044566762059693672378725675, - 11108270411921226463443318601950168860230077781212396032908932369105145901793, - 3681277588815101350213324449908372578846563884174807724121308021640034446476, - 7194753190480156904207319938161903897566477363779122267985209483435838216959, - 21241255448366937244332942306324590869759761073985963892514045368815880517382, - 6203071960722514588958553813186803009742459823360660333787981951206442471249, - 19041823565851118046937769551785013706136778514067168239416647071096062639366, - 4928136619692555022185087228378238193895894009623071873887735418398682287593, - 16266329364886004534411977872528706660422476743809029518681886596981922182359, - 8814684891729998059175829142248330760704444206534875755023421115211106199303, - 11072277000652722690981202459933101924925520292174200155471966778637063588914, - 15889576313969861857250394875354819627977602318110620311480656842740292435237, - 6934515229262494305594741689326968268143898236690173897991110238064230886755, - 16212991575388366798683594066983659236103186124339324856776288894513503543244, - 21100508914867482363389012032457112622475533432309937238082785660233880354422, - 10381104469089401657446748653199843213201270332853172509558263968565255702795, - 8849389605935865968361613766905708889092097013638425059146677490704442276611, - 4826404934194100291623537890117339503344940312401101713754206109744511979962, - 9981819567268652304810465083896863711149056310505889216307212434682251812603, - 16218484218588441290424553684558267080330286201433140852298971691458926313766, - 21317661296916247018967238829275056855142711494630067664736600708605437812892, - 19523923008662567951910986132173659591346561824926093935331274289896011695634, - 21439241836891927940168832009944210084078628922824257988298290967895179737163, - 3818036890597976956138669961319975835941979944306305168232209375279960168960, - 10212547715001519604442389033695156945619060410131175896383181616280631586732, - 956283172524544133830416114111944076629240232397666924807554743752464221045, - 8545109273807246425343308224167362024331960554428088718932211551700420545275, - 5647769597708100114837534314408246331518385631750569421373379085922684908872, - 21776221280695269311212391423788179027868152904973644113087833004348746215729, - 15989020831232836203074762591626149244364214836699154611339161287030952623233, - 9384665943619921791886218744024370375464874104981653298499433530463000935024, - 15469006121097295841026542766455781293432005131673839148320165243166330403027, - 16103671377537767724271717097892044266704736999841135349844319906338275108222, - 842367229428650719054831004741080336526228967970570607897528985803108607790, - 8752325400224955775788313769797750158375262384121380328719514077259567119347, - 4803861091350023344885030428100876947830986453029412601567992550504530969575, - 7917553047944370948250445233027936387189889293110390303835890604428798853681, - 16378323148632546424902611135263436821435778030958161546757828745002247975096, - 19873719885630097137106352132870659633926425645300622070145979694717581586592, - 20324790419158243246762098227260178678767896786893299456278167341205663612964, - 4358908354524026935988729716331497263147669784003421920394531784876541301801, - 14403952632095852077754539203207047943619815438482171213105824864831554185165, - 16410713482142323347391147127545553384558868490870150984280601225023662513809, - 7304216341846662695189617252648753140769311862815448449926830269690397729157, - 16792943782280077475956215580025612636120139194657275471595325031090407485768, - 18494329391227402645175320826355306995912366111176422593669423022411884295357, - 3277597348237827068690736756050060740435013727549848360800059544123155276133, - 9396765756719511114743964794180256605700037182617127755220919249774110852382, - 5637053961584389263881381098869862042993858662768294676971865632259649027245, - 1752142832257643043564515360000718468888861086573246457619082905919623770956, - 14504506574384680785750882507533398260948836347427103366421836731538357314790, - 18947994518078004413210940685748534988014581551965984303066903086446389273117, - 8931855168578615387850254663107425567403115805663142600825724478150698936342, - 10982092525200624040399870568387498905840578524691489797530932831401946309626, - 4738907023206802373255186532236849256768509848242049657234258536668430260775, - 10888145285628319545262252531874405309329869513560101920454793431198094714989, - 4767721624212785367044047554655794533816937807005608600525762243335180089923, - 4054394679973840378112083329204220302222586590732553688297938891619998137578, - 15390471663419625573793381445844013245022413344196724396864223784781333233143, - 690498740448849288977645176879593806019080276382495160049117613302192708860, - 3326968907274045758110436838010900592335267522219473049427145975873344598768, - 19461545874830130561487975864151403334363998126023624462211037468138940028328, - 2255249425919459031033123095731665691066980364231819200773725596456576056043, - 17139538647342063569964264947811360956712827863014723985947727876623459280539, - 262834317961189780923232082352297808796511874872711860311746704570027370416, - 17784213646586812350819691264737755884800773322574478474130308351003659945289, - 9206479615073686723914227166450906925650471865894639492301222855979337534393, - 5955379232184076713510750681781395826148323482009739159408415185190732125682, - 16345512244217240951729073298135981012471478596479891072149124888060645303490, - 20053701095030547796310908765544502773063879272854547881438596069907281565287, - 11519146559536679602608982593432194283609736022486509747046459824035493513614, - 10868663839942247532249591973192159672852196011910414460124452013501564199585, - 12668355291693420029179738224611760713369106517542315102687346083105601320689, - 4091011252347209563858280520339886760216002486858313383741839652119084430270, - 11416347683590132388448480763970462739172261435271326798646502987745949753371, - 4462763980178675172541782335457125059884067698347130082276003539434128058577, - 21728891122467658477520865529973242372850367356840114983386033432316519759391, - 9556106604731806817435679463077765288658189491612307664294729425381901530224, - 5086982973132652080709554654284904229374030594786774699435814748257879554118, - 2278505454992311041650060186856758463754878439802195559533882189615578260695, - 16123495070352975934848591912315341924608875638550779884194576881433498909405, - 13177225503435100563531015597038445430211235761527278782674200718068329833622, - 11626932451843299545922103072142674578946680165802341368625957942237790110177, - 8872973246419344365802198448930136062421718851114220299577394844231810068090, - 11920016786052130191738519934437207519332291620474831138559948859328822621221, - 2773753221970604083383541092979093729869734021029185810064937974430862835870, - 1194583082499114147792330367943150006952486615245506995832323057119894886077, - 15293312601348482070373672684782686300692505365845870624263228679370968807837, - 2292156760291800990693425534213440357167359161992251338587906324724034592198, - 20920049766730284147153707151387304988393631464951398563908410768221002588086, - 3587899345078220957148828249287269521408604837648269936718299413697642586126, - 5857527906708110948691023855516662527925762284342493618496858248142623857037, - 18312267494676788897591109008609888960798722042916784593521762607767538629817, - 18354455618287562133438807735729369657256664914390381320892039403006410339493, - 18594037435499535688023807489676900345345731643180370940972090155512943637000, - 6361231157299815359812386352981667048590510979947935475914610076041390336883, - 6503045850716008738909204934356093641022474278658078426701342798380459107813, - 15826908470360778431798326530563200301151807861414464213699967513881040969457, - 913167165738148713876672473302437265273760468892350716109373788573860454641, - 5163418960719047707254162004625467116036830361107107814320243058319914687515, - 1852750695670141634014249062360862036043602867770163972096325792863710036947, - 16164029969996795952250343426848596535809001568622155377829217918121790073916, - 42291476149937488089591434144089904529405222471677684973768504172369443350, - 1329340386229357940610579826659090359930768580941108555938139535621252899508, - 14087936453397725507000489457270864434699508074557952952329368237400407748133, - 11454917885298514922755456675259734718428103879515668717779418480236210705323, - 17749966508430836878443008025013283275306943216523661550528505419303121693213, - 16617298839486771009961431205770630163409905047728421465641369616889696635464, - 5622873871440608391107520706189063847917690892897751818294742462879871297589, - 13537715561706278379083684257583804567523085149672090320983273122424669242274, - 12609629910090871112615676094781247031353826207267723991911250780907380059468, - 11881347692420971451998583525696964339513193164613288356598017302547676912004, - 3620434358220496198439193226313617496907852030586214671337652678218740406153, - 16586456872124455799862826347901525401871594428044067424833235946565396779382, - 19602593015746956165116919928045364895525104709835703557292833702385934632182, - 2465427491077301663150648330772125184470808854603184374760649420983178107738, - 12521323976712195518272978277895155774288446093713549157148428964880747896725, - 361951232333654306694462853852464888974834703718677826403016226307188397185, - 20048343816024297162848487251896481827914904696805156112188099141327595641104, - 997638030405613623344188782838773314122493364653596616029491564227193697621, - 10932007654988104622042938184134556963651043067553327861790671211490960094259, - 47171599193060570819891696279547021610376047998583333086685382152080932821, - 14669115378939104862697280661831896914139331878760241858539421915983017116504, - 17868874372855679948405169936193924176514630305572838555185339642210810710203, - 10178296575837129106771098084407669500326673901243393867574658658064222502028, - 11497182727976130924559852428316615034304736115488257034951588831868596612725, - 18847036158089242140209840241495282890278502700082131513222116906134183113862, - 15514518995390761662346743876733004358408187550386554449789531199638765348953, - 11474102901522012346251529527050392650125347221410246734211005177721289856415, - 6612195415835443084676700243243174090072629504450965229103970796390091290688, - 11572474094368358234669561324969692616275099241307798860733942350364532366113, - 3855324911963410548772360326122995145790506408472649961229511965629894550308, - 8802640003128749594245736338745752744580147773009816234644244502373660889677, - 15676839305513015047736600040932186843826469281853634239081282896349443894145, - 11124722103091011602185413968164672678635980457394627450785290630813993266691, - 15087674670944618980358596427703842917302233637812357643695687556421910213028, - 457555060782651847600218200815104907046227486293278645126081160142069992497, - 5340353060455057701755599760342180989590806327490432497082435572367648024359, - 3289809733259936118731355294329652879189400852472418229718273887860572748363, - 1821386174933044868215348232606758690922944887434531299978498726875279584854, - 17399236630582894158137572250502674699298844870791766041927951699287421557453, - 16772722824042046255416248879357647708113647471330900665176012648038469814744, - 331374066696126093678097185404981758791664151917354547180452342655690460271, - 5482079579065945934120471179616600325379965440378196448353560421120276746028, - 11861638874356162254375133266687016527365630872709665703116365332534843803431, - 19751278476934230895840638614095718373810690662562196455711240141902305648888, - 21017623330912840225230534280017695045717261514215145256795880310933667407841, - 9692530233397639077769939390011937602190121885296235066426091743618448584134, - 7914031992737639503490179289412369887137436318696390718781298556229610513180, - 5046304088054212585035723354298412694927209198400753780585596829596665931980, - 12735457541003664856181534137486291132119134214862779086936585300598349629287, - 8144204472889944485922664106370529127382213990656088602566223875490414163362, - 5526161442679804982165840590640681348630369336752481706044759543203459722566, - 4665464612431440885211271075488840033628676516298384234452346107374012633528, - 8451965709652752887539585363308640999657377914501438391781526068371105983117, - 18990458193856163728406448194111866469438835810342179114684453609893347662421, - 14602960690767985987882800342208585041637986661619503513589079723840776294824, - 294650277854196485752526848096008214721988745350555311479128101695333774927, - 9930361494944692931597991649915857642608730961125454734483697613693272941776, - 17972565769620820679641368732920396905240248490243886868922250461473059009007, - 11842743032528966560856860268344505094861546674985872961254820091273444880060, - 2260251491209762630871337015316066081541066308706934094017641769176593121838, - 21336986809148977544823484666876006147697590184356254785752148187171367963063, - 15637234083283356311249527335446193685599985235080555266374006156231977517227, - 7637477891046186378249227336975234440873859617986704147458186423096226771577, - 10435340982947407847927678888878882924793449778165415690957335683641419176012, - 21071574044063633264442120715854514033847137356154103023224485568597330648075, - 20085745552872944745120547909310789275453780111307008151203836541147270866122, - 2369255222739182549768488367357061329939116877812397072967912842660453854658, - 3320710154094663715463854219978294133429318041799642537800174050047893035878, - 2437552820481788519744888712380245016748276158860265401041560980354471184914, - 6687580113987208531705167517979176727449238324356562435678492283111952291541, - 13835828959457330678345759960614663723017667326485961761361157914420441377430, - 1823843951353887792473925888956554516299304358703549730900495356152013614424, - 18229384804985230011714562427207966412342158903455811854157839446374012856695, - 4983049472282717134994110428470567601005310848076496400503178535459679438524, - 2047051967230753763135778305592853785901616983565528680886843131244871631064, - 17059505494771925862841990046823342770591010831955480339095397897088168520686, - 5845823714127413134610517798305104245114036685335948729450609519089263487144, - 19810252752845594230307894817800427820113926573704856490871938876757561680148, - 20741340243371419379519807725035036726040739024854919427690724405113594586449, - 17305746835229988220561638584011917989169628535378748397361130724475478785704, - 16273970657972145440112726408308019138099820274904080726219726815138597785735, - 4927605725478881247988642936459897069651251926499343645614635597380235002430, - 4076655226193629464789557616268492785057128805549395585385432329518368497686, - 18134767316186963456589895259454813585756254459227058992203617493951135964914, - 20798436806114056077588608064161229365173163847083955162560624566238528904361, - 8811900287453512972593412116532745098600991077158875340182906101108258578231, - 1611466530857794066271650650204918615746591649578992581483080164777650137733, - 19520757346022691586967284723955378385034675472244175822936613026597514818901, - 8258287931139503595713718829279050060190693609290797346704848518381891359704, - 13807143439443425137076128013998009581746894329904809421858222329599144124143, - 2034200548964915935625429760202284220693125881760822084201315022529206424506, - 20594375914400911567795140472107624446159181622166676420027082349633992663301, - 17773828019575037451999782968066986504577459910353828196403976545023426528432, - 10645884969014005687699860915213473815514464399964009808411811895545112650817, - 3135829883501342672772973577699379927756997243617424917654928164800203666496, - 21807676600134151299257078976418813484444183016737321278512745883771478511369, - 14168063038909284721702678019083222059818438340503980617872573468231611140141, - 19022539506931505257153342575586362988716958060936788031721967221986624233067, - 919797128086310623571009200546035983274688764270933413427846490906074137487, - 10651353481391913627770814216074873532920753703051075188645774021198634943682, - 21601553598752750925049978818528421110707879819831249175157596816870100048288, - 9544964974935674319204796617933096476421551193682156030394816088243121582636, - 17113833205578964054057051521784698139661258340576694677296240312431808476286, - 9889647672195559279745677506312894570402108521106900082889976819798270827735, - 16028191999932520938901585234936954312994452706490572504997534210876573833649, - 19224701772787524647172128751148104366752057774529591812815327738829591289117, - 8065294760892477625290114823800398061529770004833832691347498933238361039736, - 8385011404987806129246014860479833290406969218526611328586242951296814426438, - 17626526623257098006524211054563886193098683828265081734658432468695686509315, - 9760584950604786147191288118087660976225563461953070125437519145090832114537, - 3282956645059793949082172795607530130101621492305193365378997603911833418463, - 3788543541342252822847978185963388795825378340921321139695221828685330606335, - 5728277403393912877393143174229934529937061751983246730506397742038949251701, - 20532577038632159357383817240596922896191478140446876998140515404169184846609, - 6138500779693128517529525961343097735306947649093633133232282430353593175172, - 16387038830089541476468870208162294639575042754761542956218362331966004300870, - 10184264376398708852688445921404363179240954227345322711923845040842165453208, - 12576299651793170522912156101640799825541149618303513174146382191633847258859, - 1340015400080181141720946234858756484323564628916867888877667239334982793481, - 733959369856163480135680991009606990817015555938726628110611986599242143578, - 11467033813562140192244869512537566463715027496952375979909160849747976831918, - 4619667645046391146577435774790188488541561222783010406420406869960248783331, - 58552761198135931030902257754896948615688045302818928845814661296914920622, - 1199849881730507352706524556330002080538296688430736582840314007371442152147, - 7124502590511184113044595527748024819132713282667933641439666531514739645089, - 8623660134669459112474551498616256867375253975034970808437732784494772311361, - 12655669439191191182341423414424342421477486764113555800095493091893820045534, - 18432703875775002490514477493898870315422995231506677048275960580528644904682, - 15467220287938881354678249472400749704814316816035426814619089032223454845193, - 2851120240492392321044027263769720216640877441121430445737594074121655318176, - 20519914249934881206828098454303256358482675671718589102535780334267934987941, - 17275124961392392047135728713829752470490098022504524438869454049765356211723, - 3323710067527231515807603961736782048796606296990840839366613937968342331886, - 4468708240622802562056471128793253296493002925988003094771284205007772045098, - 9006494818135081033869830730030943407240565201693254355620348420258773924028, - 2624130417875598753127999576825019766166727976335690685433712946223008520912, - 164131399455376615654870570697119442360078693174350746600132391198500093412, - 14931668887432843139264972187415200544679230597820424081936926034478502874299, - 1638753880783574431267395352024193675000113296497173968722590753809640941864, - 15505380865926802396097545843811910443367233632805651511272732002583232431557, - 17973744614207669251901495093091561913998272050499760575282030108740677066624, - 6137688223696761009295745609563284204827706564566466060484103844265403078408, - 14774243062532823236792831566222119634320864630838624098798648826842418775856, - 15864970393171078370207775103899428499600152663946379517190945807315353544891, - 19010063123357565300336230971672519561204810737546730911549311353159512986740, - 12607162829921425080830052984475623157169603642577010527391007035133383807243, - 17803108634879437217723652777640120469990779759700458421844361066182881628345, - 10065874953507223318296028499872542865030107611981933577973812883589535269142, - 3276471432535144390388324850641020151392959100393035635141206272558418581928, - 7532054601401798035926415744768772852833516520318445183340725930886329458991, - 18893822928119227829016544343228228897166113682019317256005502643243867377334, - 15940597493253236451533839310728876441657428995464658827726295547815292644378, - 4268009387843764409267791203070919313017052533005657826253994943184768120896, - 21611251949238422413354051947529388972078300717392131751061464498329326474580, - 12516447001729804412674006874184731098280474050775388553768469608793631490618, - 49838549447142926741568525697026885045023997277705726329780325103507790978, - 19763902910323896567698991616245963026306943100978479625077573937114135803058, - 12029297973430627253212633299020402005457460023136429653800185001711727387314, - 17676997725594777991384952086633589048516371093397126876621255518370680168503, - 10567543371894667303450346380722020266352683222046730266924342174164712049360, - 14583364850544999818712646438016435003942847076919084667364987497592599663937, - 17348091487238815837308569582101875357715798351834275089190053280855958465528, - 8743083090296259283603789316855921930102444739264013461469099560398359267240, - 15114064505647935792598848256320570567717917317803629185764147361301698519005, - 18332675991829764561879941291908436508530604635608341316693114747813051532006, - 1757567731797951053080580099911774643896363235228742197150882457231133285549, - 6526388717947413328592956348507481629843816325885832861915399601868279124246 - ] - -// t = 2 (1 input) -def poseidon_m_1() -> field[2][2]: - return [ - [ - 2910766817845651019878574839501801340070030115151021261302834310722729507541, - 19727366863391167538122140361473584127147630672623100827934084310230022599144 - ], - [ - 5776684794125549462448597414050232243778680302179439492664047328281728356345, - 8348174920934122550483593999453880006756108121341067172388445916328941978568 - ] - ] - -// t = 3 (2 inputs) -def poseidon_m_2() -> field[3][3]: - return [ - [ - 7511745149465107256748700652201246547602992235352608707588321460060273774987, - 10370080108974718697676803824769673834027675643658433702224577712625900127200, - 19705173408229649878903981084052839426532978878058043055305024233888854471533 - ], - [ - 18732019378264290557468133440468564866454307626475683536618613112504878618481, - 20870176810702568768751421378473869562658540583882454726129544628203806653987, - 7266061498423634438633389053804536045105766754026813321943009179476902321146 - ], - [ - 9131299761947733513298312097611845208338517739621853568979632113419485819303, - 10595341252162738537912664445405114076324478519622938027420701542910180337937, - 11597556804922396090267472882856054602429588299176362916247939723151043581408 - ] - ] - -// t = 4 (3 inputs) -def poseidon_m_3() -> field[4][4]: - return [ - [ - 16023668707004248971294664614290028914393192768609916554276071736843535714477, - 17849615858846139011678879517964683507928512741474025695659909954675835121177, - 1013663139540921998616312712475594638459213772728467613870351821911056489570, - 13211800058103802189838759488224684841774731021206389709687693993627918500545 - ], - [ - 19204974983793400699898444372535256207646557857575315905278218870961389967884, - 3722304780857845144568029505892077496425786544014166938942516810831732569870, - 11920634922168932145084219049241528148129057802067880076377897257847125830511, - 6085682566123812000257211683010755099394491689511511633947011263229442977967 - ], - [ - 14672613178263529785795301930884172260797190868602674472542654261498546023746, - 20850178060552184587113773087797340350525370429749200838012809627359404457643, - 7082289538076771741936674361200789891432311337766695368327626572220036527624, - 1787876543469562003404632310460227730887431311758627706450615128255538398187 - ], - [ - 21407770160218607278833379114951608489910182969042472165261557405353704846967, - 16058955581309173858487265533260133430557379878452348481750737813742488209262, - 593311177550138061601452020934455734040559402531605836278498327468203888086, - 341662423637860635938968460722645910313598807845686354625820505885069260074 - ] - ] - -// t = 5 (4 inputs) -def poseidon_m_4() -> field[5][5]: +def poseidon_c() -> field[6][497]: return [ [ - 16789463359527776692258765063233607350971630674230623383979223533600140787105, - 17179611066821656668705197789232102741366879862607190942874777813024566441829, - 18653277315487164762584377009009109585010878033606596417396490909822722930739, - 7373070639853668650581790286343199505413793790160702463077019294817051722180, - 4823864393442908763804841692709014014130031798360007432734996408628916373879 + 4417881134626180770308697923359573201005643519861877412381846989312604493735, + 5433650512959517612316327474713065966758808864213826738576266661723522780033, + 13641176377184356099764086973022553863760045607496549923679278773208775739952, + 17949713444224994136330421782109149544629237834775211751417461773584374506783, + 13765628375339178273710281891027109699578766420463125835325926111705201856003, + 19179513468172002314585757290678967643352171735526887944518845346318719730387, + 5157412437176756884543472904098424903141745259452875378101256928559722612176, + 535160875740282236955320458485730000677124519901643397458212725410971557409, + 1050793453380762984940163090920066886770841063557081906093018330633089036729, + 10665495010329663932664894101216428400933984666065399374198502106997623173873, + 19965634623406616956648724894636666805991993496469370618546874926025059150737, + 13007250030070838431593222885902415182312449212965120303174723305710127422213, + 16877538715074991604507979123743768693428157847423939051086744213162455276374, + 18211747749504876135588847560312685184956239426147543810126553367063157141465, + 18151553319826126919739798892854572062191241985315767086020821632812331245635, + 19957033149976712666746140949846950406660099037474791840946955175819555930825, + 3469514863538261843186854830917934449567467100548474599735384052339577040841, + 989698510043911779243192466312362856042600749099921773896924315611668507708, + 12568377015646290945235387813564567111330046038050864455358059568128000172201, + 20856104135605479600325529349246932565148587186338606236677138505306779314172, + 8206918720503535523121349917159924938835810381723474192155637697065780938424, + 1309058477013932989380617265069188723120054926187607548493110334522527703566, + 14076116939332667074621703729512195584105250395163383769419390236426287710606, + 10153498892749751942204288991871286290442690932856658983589258153608012428674, + 18202499207234128286137597834010475797175973146805180988367589376893530181575, + 12739388830157083522877690211447248168864006284243907142044329113461613743052, + 15123358710467780770838026754240340042441262572309759635224051333176022613949, + 19925004701844594370904593774447343836015483888496504201331110250494635362184, + 10352416606816998476681131583320899030072315953910679608943150613208329645891, + 10567371822366244361703342347428230537114808440249611395507235283708966113221, + 5635498582763880627392290206431559361272660937399944184533035305989295959602, + 11866432933224219174041051738704352719163271639958083608224676028593315904909, + 5795020705294401441272215064554385591292330721703923167136157291459784140431, + 9482202378699252817564375087302794636287866584767523335624368774856230692758, + 4245237636894546151746468406560945873445548423466753843402086544922216329298, + 12000500941313982757584712677991730019124834399479314697467598397927435905133, + 7596790274058425558167520209857956363736666939016807569082239187494363541787, + 2484867918246116343205467273440098378820186751202461278013576281097918148877, + 18312645949449997391810445935615409295369169383463185688973803378104013950190, + 15320686572748723004980855263301182130424010735782762814513954166519592552733, + 12618438900597948888520621062416758747872180395546164387827245287017031303859, + 17438141672027706116733201008397064011774368832458707512367404736905021019585, + 6374197807230665998865688675365359100400438034755781666913068586172586548950, + 2189398913433273865510950346186699930188746169476472274335177556702504595264, + 6268495580028970231803791523870131137294646402347399003576649137450213034606, + 17896250365994900261202920044129628104272791547990619503076839618914047059275, + 13692156312448722528008862371944543449350293305158722920787736248435893008873, + 15234446864368744483209945022439268713300180233589581910497691316744177619376, + 1572426502623310766593681563281600503979671244997798691029595521622402217227, + 80103447810215150918585162168214870083573048458555897999822831203653996617, + 8228820324013669567851850635126713973797711779951230446503353812192849106342, + 5375851433746509614045812476958526065449377558695752132494533666370449415873, + 12115998939203497346386774317892338270561208357481805380546938146796257365018, + 9764067909645821279940531410531154041386008396840887338272986634350423466622, + 8538708244538850542384936174629541085495830544298260335345008245230827876882, + 7140127896620013355910287215441004676619168261422440177712039790284719613114, + 14297402962228458726038826185823085337698917275385741292940049024977027409762, + 6667115556431351074165934212337261254608231545257434281887966406956835140819, + 20226761165244293291042617464655196752671169026542832236139342122602741090001, + 12038289506489256655759141386763477208196694421666339040483042079632134429119, + 19027757334170818571203982241812412991528769934917288000224335655934473717551, + 16272152964456553579565580463468069884359929612321610357528838696790370074720, + 2500392889689246014710135696485946334448570271481948765283016105301740284071, + 8595254970528530312401637448610398388203855633951264114100575485022581946023, + 11635945688914011450976408058407206367914559009113158286982919675551688078198, + 614739068603482619581328040478536306925147663946742687395148680260956671871, + 18692271780377861570175282183255720350972693125537599213951106550953176268753, + 4987059230784976306647166378298632695585915319042844495357753339378260807164, + 21851403978498723616722415377430107676258664746210815234490134600998983955497, + 9830635451186415300891533983087800047564037813328875992115573428596207326204, + 4842706106434537116860242620706030229206345167233200482994958847436425185478, + 6422235064906823218421386871122109085799298052314922856340127798647926126490, + 4564364104986856861943331689105797031330091877115997069096365671501473357846, + 1944043894089780613038197112872830569538541856657037469098448708685350671343, + 21179865974855950600518216085229498748425990426231530451599322283119880194955, + 14296697761894107574369608843560006996183955751502547883167824879840894933162, + 12274619649702218570450581712439138337725246879938860735460378251639845671898, + 16371396450276899401411886674029075408418848209575273031725505038938314070356, + 3702561221750983937578095019779188631407216522704543451228773892695044653565, + 19721616877735564664624984774636557499099875603996426215495516594530838681980, + 6383350109027696789969911008057747025018308755462287526819231672217685282429, + 20860583956177367265984596617324237471765572961978977333122281041544719622905, + 5766390934595026947545001478457407504285452477687752470140790011329357286275, + 4043175758319898049344746138515323336207420888499903387536875603879441092484, + 15579382179133608217098622223834161692266188678101563820988612253342538956534, + 1864640783252634743892105383926602930909039567065240010338908865509831749824, + 15943719865023133586707144161652035291705809358178262514871056013754142625673, + 2326415993032390211558498780803238091925402878871059708106213703504162832999, + 19995326402773833553207196590622808505547443523750970375738981396588337910289, + 5143583711361588952673350526320181330406047695593201009385718506918735286622, + 15436006486881920976813738625999473183944244531070780793506388892313517319583, + 16660446760173633166698660166238066533278664023818938868110282615200613695857, + 4966065365695755376133119391352131079892396024584848298231004326013366253934, + 20683781957411705574951987677641476019618457561419278856689645563561076926702, + 17280836839165902792086432296371645107551519324565649849400948918605456875699, + 17045635513701208892073056357048619435743564064921155892004135325530808465371, + 17055032967194400710390142791334572297458033582458169295920670679093585707295, + 15727174639569115300068198908071514334002742825679221638729902577962862163505, + 1001755657610446661315902885492677747789366510875120894840818704741370398633, + 18638547332826171619311285502376343504539399518545103511265465604926625041234, + 6751954224763196429755298529194402870632445298969935050224267844020826420799, + 3526747115904224771452549517614107688674036840088422555827581348280834879405, + 15705897908180497062880001271426561999724005008972544196300715293701537574122, + 574386695213920937259007343820417029802510752426579750428758189312416867750, + 15973040855000600860816974646787367136127946402908768408978806375685439868553, + 20934130413948796333037139460875996342810005558806621330680156931816867321122, + 6918585327145564636398173845411579411526758237572034236476079610890705810764, + 14158163500813182062258176233162498241310167509137716527054939926126453647182, + 4164602626597695668474100217150111342272610479949122406544277384862187287433, + 12146526846507496913615390662823936206892812880963914267275606265272996025304, + 10153527926900017763244212043512822363696541810586522108597162891799345289938, + 13564663485965299104296214940873270349072051793008946663855767889066202733588, + 5612449256997576125867742696783020582952387615430650198777254717398552960096, + 12151885480032032868507892738683067544172874895736290365318623681886999930120, + 380452237704664384810613424095477896605414037288009963200982915188629772177, + 9067557551252570188533509616805287919563636482030947363841198066124642069518, + 21280306817619711661335268484199763923870315733198162896599997188206277056900, + 5567165819557297006750252582140767993422097822227408837378089569369734876257, + 10411936321072105429908396649383171465939606386380071222095155850987201580137, + 21338390051413922944780864872652000187403217966653363270851298678606449622266, + 12156296560457833712186127325312904760045212412680904475497938949653569234473, + 4271647814574748734312113971565139132510281260328947438246615707172526380757, + 9061738206062369647211128232833114177054715885442782773131292534862178874950, + 10134551893627587797380445583959894183158393780166496661696555422178052339133, + 8932270237664043612366044102088319242789325050842783721780970129656616386103, + 3339412934966886386194449782756711637636784424032779155216609410591712750636, + 9704903972004596791086522314847373103670545861209569267884026709445485704400, + 17467570179597572575614276429760169990940929887711661192333523245667228809456, + ...[0; 369] ], [ - 19196309854577132760746782449135315310664418272926255500908899397538686486585, - 18123132816088485879885148351452823314623055244145916622592591084094232513914, - 18436594886553181913092702411547018228276047601279727265790147051821171174455, - 15167500404313194506503404655898040457721633218143681920692711693000769735187, - 9437986152015460505719924283993842205604222075968464846270136901243896809793 + 6745197990210204598374042828761989596302876299545964402857411729872131034734, + 426281677759936592021316809065178817848084678679510574715894138690250139748, + 4014188762916583598888942667424965430287497824629657219807941460227372577781, + 21328925083209914769191926116470334003273872494252651254811226518870906634704, + 19525217621804205041825319248827370085205895195618474548469181956339322154226, + 1402547928439424661186498190603111095981986484908825517071607587179649375482, + 18320863691943690091503704046057443633081959680694199244583676572077409194605, + 17709820605501892134371743295301255810542620360751268064484461849423726103416, + 15970119011175710804034336110979394557344217932580634635707518729185096681010, + 9818625905832534778628436765635714771300533913823445439412501514317783880744, + 6235167673500273618358172865171408902079591030551453531218774338170981503478, + 12575685815457815780909564540589853169226710664203625668068862277336357031324, + 7381963244739421891665696965695211188125933529845348367882277882370864309593, + 14214782117460029685087903971105962785460806586237411939435376993762368956406, + 13382692957873425730537487257409819532582973556007555550953772737680185788165, + 2203881792421502412097043743980777162333765109810562102330023625047867378813, + 2916799379096386059941979057020673941967403377243798575982519638429287573544, + 4341714036313630002881786446132415875360643644216758539961571543427269293497, + 2340590164268886572738332390117165591168622939528604352383836760095320678310, + 5222233506067684445011741833180208249846813936652202885155168684515636170204, + 7963328565263035669460582454204125526132426321764384712313576357234706922961, + 1394121618978136816716817287892553782094854454366447781505650417569234586889, + 20251767894547536128245030306810919879363877532719496013176573522769484883301, + 141695147295366035069589946372747683366709960920818122842195372849143476473, + 15919677773886738212551540894030218900525794162097204800782557234189587084981, + 2616624285043480955310772600732442182691089413248613225596630696960447611520, + 4740655602437503003625476760295930165628853341577914460831224100471301981787, + 19201590924623513311141753466125212569043677014481753075022686585593991810752, + 12116486795864712158501385780203500958268173542001460756053597574143933465696, + 8481222075475748672358154589993007112877289817336436741649507712124418867136, + 5181207870440376967537721398591028675236553829547043817076573656878024336014, + 1576305643467537308202593927724028147293702201461402534316403041563704263752, + 2555752030748925341265856133642532487884589978209403118872788051695546807407, + 18840924862590752659304250828416640310422888056457367520753407434927494649454, + 14593453114436356872569019099482380600010961031449147888385564231161572479535, + 20826991704411880672028799007667199259549645488279985687894219600551387252871, + 9159011389589751902277217485643457078922343616356921337993871236707687166408, + 5605846325255071220412087261490782205304876403716989785167758520729893194481, + 1148784255964739709393622058074925404369763692117037208398835319441214134867, + 20945896491956417459309978192328611958993484165135279604807006821513499894540, + 229312996389666104692157009189660162223783309871515463857687414818018508814, + 21184391300727296923488439338697060571987191396173649012875080956309403646776, + 21853424399738097885762888601689700621597911601971608617330124755808946442758, + 12776298811140222029408960445729157525018582422120161448937390282915768616621, + 7556638921712565671493830639474905252516049452878366640087648712509680826732, + 19042212131548710076857572964084011858520620377048961573689299061399932349935, + 12871359356889933725034558434803294882039795794349132643274844130484166679697, + 3313271555224009399457959221795880655466141771467177849716499564904543504032, + 15080780006046305940429266707255063673138269243146576829483541808378091931472, + 21300668809180077730195066774916591829321297484129506780637389508430384679582, + 20480395468049323836126447690964858840772494303543046543729776750771407319822, + 10034492246236387932307199011778078115444704411143703430822959320969550003883, + 19584962776865783763416938001503258436032522042569001300175637333222729790225, + 20155726818439649091211122042505326538030503429443841583127932647435472711802, + 13313554736139368941495919643765094930693458639277286513236143495391474916777, + 14606609055603079181113315307204024259649959674048912770003912154260692161833, + 5563317320536360357019805881367133322562055054443943486481491020841431450882, + 10535419877021741166931390532371024954143141727751832596925779759801808223060, + 12025323200952647772051708095132262602424463606315130667435888188024371598063, + 2906495834492762782415522961458044920178260121151056598901462871824771097354, + 19131970618309428864375891649512521128588657129006772405220584460225143887876, + 8896386073442729425831367074375892129571226824899294414632856215758860965449, + 7748212315898910829925509969895667732958278025359537472413515465768989125274, + 422974903473869924285294686399247660575841594104291551918957116218939002865, + 6398251826151191010634405259351528880538837895394722626439957170031528482771, + 18978082967849498068717608127246258727629855559346799025101476822814831852169, + 19150742296744826773994641927898928595714611370355487304294875666791554590142, + 12896891575271590393203506752066427004153880610948642373943666975402674068209, + 9546270356416926575977159110423162512143435321217584886616658624852959369669, + 2159256158967802519099187112783460402410585039950369442740637803310736339200, + 8911064487437952102278704807713767893452045491852457406400757953039127292263, + 745203718271072817124702263707270113474103371777640557877379939715613501668, + 19313999467876585876087962875809436559985619524211587308123441305315685710594, + 13254105126478921521101199309550428567648131468564858698707378705299481802310, + 1842081783060652110083740461228060164332599013503094142244413855982571335453, + 9630707582521938235113899367442877106957117302212260601089037887382200262598, + 5066637850921463603001689152130702510691309665971848984551789224031532240292, + 4222575506342961001052323857466868245596202202118237252286417317084494678062, + 2919565560395273474653456663643621058897649501626354982855207508310069954086, + 6828792324689892364977311977277548750189770865063718432946006481461319858171, + 2245543836264212411244499299744964607957732316191654500700776604707526766099, + 19602444885919216544870739287153239096493385668743835386720501338355679311704, + 8239538512351936341605373169291864076963368674911219628966947078336484944367, + 15053013456316196458870481299866861595818749671771356646798978105863499965417, + 7173615418515925804810790963571435428017065786053377450925733428353831789901, + 8239211677777829016346247446855147819062679124993100113886842075069166957042, + 15330855478780269194281285878526984092296288422420009233557393252489043181621, + 10014883178425964324400942419088813432808659204697623248101862794157084619079, + 14014440630268834826103915635277409547403899966106389064645466381170788813506, + 3580284508947993352601712737893796312152276667249521401778537893620670305946, + 2559754020964039399020874042785294258009596917335212876725104742182177996988, + 14898657953331064524657146359621913343900897440154577299309964768812788279359, + 2094037260225570753385567402013028115218264157081728958845544426054943497065, + 18051086536715129874440142649831636862614413764019212222493256578581754875930, + 21680659279808524976004872421382255670910633119979692059689680820959727969489, + 13950668739013333802529221454188102772764935019081479852094403697438884885176, + 9703845704528288130475698300068368924202959408694460208903346143576482802458, + 12064310080154762977097567536495874701200266107682637369509532768346427148165, + 16970760937630487134309762150133050221647250855182482010338640862111040175223, + 9790997389841527686594908620011261506072956332346095631818178387333642218087, + 16314772317774781682315680698375079500119933343877658265473913556101283387175, + 82044870826814863425230825851780076663078706675282523830353041968943811739, + 21696416499108261787701615667919260888528264686979598953977501999747075085778, + 327771579314982889069767086599893095509690747425186236545716715062234528958, + 4606746338794869835346679399457321301521448510419912225455957310754258695442, + 64499140292086295251085369317820027058256893294990556166497635237544139149, + 10455028514626281809317431738697215395754892241565963900707779591201786416553, + 10421411526406559029881814534127830959833724368842872558146891658647152404488, + 18848084335930758908929996602136129516563864917028006334090900573158639401697, + 13844582069112758573505569452838731733665881813247931940917033313637916625267, + 13488838454403536473492810836925746129625931018303120152441617863324950564617, + 15742141787658576773362201234656079648895020623294182888893044264221895077688, + 6756884846734501741323584200608866954194124526254904154220230538416015199997, + 7860026400080412708388991924996537435137213401947704476935669541906823414404, + 7871040688194276447149361970364037034145427598711982334898258974993423182255, + 20758972836260983284101736686981180669442461217558708348216227791678564394086, + 21723241881201839361054939276225528403036494340235482225557493179929400043949, + 19428469330241922173653014973246050805326196062205770999171646238586440011910, + 7969200143746252148180468265998213908636952110398450526104077406933642389443, + 10950417916542216146808986264475443189195561844878185034086477052349738113024, + 18149233917533571579549129116652755182249709970669448788972210488823719849654, + 3729796741814967444466779622727009306670204996071028061336690366291718751463, + 5172504399789702452458550583224415301790558941194337190035441508103183388987, + 6686473297578275808822003704722284278892335730899287687997898239052863590235, + 19426913098142877404613120616123695099909113097119499573837343516470853338513, + 5120337081764243150760446206763109494847464512045895114970710519826059751800, + 5055737465570446530938379301905385631528718027725177854815404507095601126720, + 14235578612970484492268974539959119923625505766550088220840324058885914976980, + 653592517890187950103239281291172267359747551606210609563961204572842639923, + 5507360526092411682502736946959369987101940689834541471605074817375175870579, + 7864202866011437199771472205361912625244234597659755013419363091895334445453, + 21294659996736305811805196472076519801392453844037698272479731199885739891648, + 13767183507040326119772335839274719411331242166231012705169069242737428254651, + 810181532076738148308457416289197585577119693706380535394811298325092337781, + 14232321930654703053193240133923161848171310212544136614525040874814292190478, + 16796904728299128263054838299534612533844352058851230375569421467352578781209, + 16256310366973209550759123431979563367001604350120872788217761535379268327259, + 19791658638819031543640174069980007021961272701723090073894685478509001321817, + 7046232469803978873754056165670086532908888046886780200907660308846356865119, + 16001732848952745747636754668380555263330934909183814105655567108556497219752, + 9737276123084413897604802930591512772593843242069849260396983774140735981896, + 11410895086919039954381533622971292904413121053792570364694836768885182251535, + 19098362474249267294548762387533474746422711206129028436248281690105483603471, + 11013788190750472643548844759298623898218957233582881400726340624764440203586, + 2206958256327295151076063922661677909471794458896944583339625762978736821035, + 7171889270225471948987523104033632910444398328090760036609063776968837717795, + 2510237900514902891152324520472140114359583819338640775472608119384714834368, + 8825275525296082671615660088137472022727508654813239986303576303490504107418, + 1481125575303576470988538039195271612778457110700618040436600537924912146613, + 16268684562967416784133317570130804847322980788316762518215429249893668424280, + 4681491452239189664806745521067158092729838954919425311759965958272644506354, + 3131438137839074317765338377823608627360421824842227925080193892542578675835, + 7930402370812046914611776451748034256998580373012248216998696754202474945793, + 8973151117361309058790078507956716669068786070949641445408234962176963060145, + 10223139291409280771165469989652431067575076252562753663259473331031932716923, + 2232089286698717316374057160056566551249777684520809735680538268209217819725, + 16930089744400890347392540468934821520000065594669279286854302439710657571308, + 21739597952486540111798430281275997558482064077591840966152905690279247146674, + 7508315029150148468008716674010060103310093296969466203204862163743615534994, + 11418894863682894988747041469969889669847284797234703818032750410328384432224, + 10895338268862022698088163806301557188640023613155321294365781481663489837917, + 18644184384117747990653304688839904082421784959872380449968500304556054962449, + 7414443845282852488299349772251184564170443662081877445177167932875038836497, + 5391299369598751507276083947272874512197023231529277107201098701900193273851, + 10329906873896253554985208009869159014028187242848161393978194008068001342262, + 4711719500416619550464783480084256452493890461073147512131129596065578741786, + 11943219201565014805519989716407790139241726526989183705078747065985453201504, + 4298705349772984837150885571712355513879480272326239023123910904259614053334, + 9999044003322463509208400801275356671266978396985433172455084837770460579627, + 4908416131442887573991189028182614782884545304889259793974797565686968097291, + 11963412684806827200577486696316210731159599844307091475104710684559519773777, + 20129916000261129180023520480843084814481184380399868943565043864970719708502, + 12884788430473747619080473633364244616344003003135883061507342348586143092592, + 20286808211545908191036106582330883564479538831989852602050135926112143921015, + 16282045180030846845043407450751207026423331632332114205316676731302016331498, + 4332932669439410887701725251009073017227450696965904037736403407953448682093, + 11105712698773407689561953778861118250080830258196150686012791790342360778288, + 21853934471586954540926699232107176721894655187276984175226220218852955976831, + 9807888223112768841912392164376763820266226276821186661925633831143729724792, + 13411808896854134882869416756427789378942943805153730705795307450368858622668, + 17906847067500673080192335286161014930416613104209700445088168479205894040011, + 14554387648466176616800733804942239711702169161888492380425023505790070369632, + 4264116751358967409634966292436919795665643055548061693088119780787376143967, + 2401104597023440271473786738539405349187326308074330930748109868990675625380, + 12251645483867233248963286274239998200789646392205783056343767189806123148785, + 15331181254680049984374210433775713530849624954688899814297733641575188164316, + 13108834590369183125338853868477110922788848506677889928217413952560148766472, + 6843160824078397950058285123048455551935389277899379615286104657075620692224, + 10151103286206275742153883485231683504642432930275602063393479013696349676320, + 7074320081443088514060123546121507442501369977071685257650287261047855962224, + 11413928794424774638606755585641504971720734248726394295158115188173278890938, + 7312756097842145322667451519888915975561412209738441762091369106604423801080, + 7181677521425162567568557182629489303281861794357882492140051324529826589361, + 15123155547166304758320442783720138372005699143801247333941013553002921430306, + 13409242754315411433193860530743374419854094495153957441316635981078068351329, + ...[0; 302] ], [ - 21445376105821232747280055223032050399373725161014449207033808524504027971613, - 49684738714301073369749035791061182456037935161360748355432247732088942674, - 9826409059947591908303145327284336313371973037536805760095514429930589897515, - 8494798325496773219358794086647759478982958403252584257436898618394561204124, - 21251937175072447337747316555423152807036003235223125066270735279039060889959 + 11633431549750490989983886834189948010834808234699737327785600195936805266405, + 17353750182810071758476407404624088842693631054828301270920107619055744005334, + 11575173631114898451293296430061690731976535592475236587664058405912382527658, + 9724643380371653925020965751082872123058642683375812487991079305063678725624, + 20936725237749945635418633443468987188819556232926135747685274666391889856770, + 6427758822462294912934022562310355233516927282963039741999349770315205779230, + 16782979953202249973699352594809882974187694538612412531558950864304931387798, + 8979171037234948998646722737761679613767384188475887657669871981433930833742, + 5428827536651017352121626533783677797977876323745420084354839999137145767736, + 507241738797493565802569310165979445570507129759637903167193063764556368390, + 6711578168107599474498163409443059675558516582274824463959700553865920673097, + 2197359304646916921018958991647650011119043556688567376178243393652789311643, + 4634703622846121403803831560584049007806112989824652272428991253572845447400, + 17008376818199175111793852447685303011746023680921106348278379453039148937791, + 18430784755956196942937899353653692286521408688385681805132578732731487278753, + 4573768376486344895797915946239137669624900197544620153250805961657870918727, + 5624865188680173294191042415227598609140934495743721047183803859030618890703, + 8228252753786907198149068514193371173033070694924002912950645971088002709521, + 17586714789554691446538331362711502394998837215506284064347036653995353304693, + 12985198716830497423350597750558817467658937953000235442251074063454897365701, + 13480076116139680784838493959937969792577589073830107110893279354229821035984, + 480609231761423388761863647137314056373740727639536352979673303078459561332, + 19503345496799249258956440299354839375920540225688429628121751361906635419276, + 16837818502122887883669221005435922946567532037624537243846974433811447595173, + 5492108497278641078569490709794391352213168666744080628008171695469579703581, + 11365311159988448419785032079155356000691294261495515880484003277443744617083, + 13876891705632851072613751905778242936713392247975808888614530203269491723653, + 10660388389107698747692475159023710744797290186015856503629656779989214850043, + 18876318870401623474401728758498150977988613254023317877612912724282285739292, + 15543349138237018307536452195922365893694804703361435879256942490123776892424, + 2839988449157209999638903652853828318645773519300826410959678570041742458201, + 7566039810305694135184226097163626060317478635973510706368412858136696413063, + 6344830340705033582410486810600848473125256338903726340728639711688240744220, + 12475357769019880256619207099578191648078162511547701737481203260317463892731, + 13337401254840718303633782478677852514218549070508887338718446132574012311307, + 21161869193849404954234950798647336336709035097706159414187214758702055364571, + 20671052961616073313397254362345395594858011165315285344464242404604146448678, + 2772189387845778213446441819361180378678387127454165972767013098872140927416, + 3339032002224218054945450150550795352855387702520990006196627537441898997147, + 14919705931281848425960108279746818433850049439186607267862213649460469542157, + 17056699976793486403099510941807022658662936611123286147276760381688934087770, + 16144580075268719403964467603213740327573316872987042261854346306108421013323, + 15582343953927413680541644067712456296539774919658221087452235772880573393376, + 17528510080741946423534916423363640132610906812668323263058626230135522155749, + 3190600034239022251529646836642735752388641846393941612827022280601486805721, + 8463814172152682468446984305780323150741498069701538916468821815030498611418, + 16533435971270903741871235576178437313873873358463959658178441562520661055273, + 11845696835505436397913764735273748291716405946246049903478361223369666046634, + 18391057370973634202531308463652130631065370546571735004701144829951670507215, + 262537877325812689820791215463881982531707709719292538608229687240243203710, + 2187234489894387585309965540987639130975753519805550941279098789852422770021, + 19189656350920455659006418422409390013967064310525314160026356916172976152967, + 15839474183930359560478122372067744245080413846070743460407578046890458719219, + 1805019124769763805045852541831585930225376844141668951787801647576910524592, + 323592203814803486950280155834638828455175703393817797003361354810251742052, + 9780393509796825017346015868945480913627956475147371732521398519483580624282, + 14009429785059642386335012561867511048847749030947687313594053997432177705759, + 13749550162460745037234826077137388777330401847577727796245150843898019635981, + 19497187499283431845443758879472819384797584633472792651343926414232528405311, + 3708428802547661961864524194762556064568867603968214870300574294082023305587, + 1339414413482882567499652761996854155383863472782829777976929310155400981782, + 6396261245879814100794661157306877072718690153118140891315137894471052482309, + 2069661495404347929962833138824526893650803079024564477269192079629046031674, + 15793521554502133342917616035884588152451122589545915605459159078589855944361, + 17053424498357819626596285492499512504457128907932827007302385782133229252374, + 13658536470391360399708067455536748955260723760813498481671323619545320978896, + 21546095668130239633971575351786704948662094117932406102037724221634677838565, + 21411726238386979516934941789127061362496195649331822900487557574597304399109, + 1944776378988765673004063363506638781964264107780425928778257145151172817981, + 15590719714223718537172639598316570285163081746016049278954513732528516468773, + 1351266421179051765004709939353170430290500926943038391678843253157009556309, + 6772476224477167317130064764757502335545080109882028900432703947986275397548, + 10670120969725161535937685539136065944959698664551200616467222887025111751992, + 4731853626374224678749618809759140702342195350742653173378450474772131006181, + 14473527495914528513885847341981310373531349450901830749157165104135412062812, + 16937191362061486658876740597821783333355021670608822932942683228741190786143, + 5656559696428674390125424316117443507583679061659043998559560535270557939546, + 8897648276515725841133578021896617755369443750194849587616503841335248902806, + 14938684446722672719637788054570691068799510611164812175626676768545923371470, + 15284149043690546115252102390417391226617211133644099356880071475803043461465, + 2623479025068612775740107497276979457946709347831661908218182874823658838107, + 6809791961761836061129379546794905411734858375517368211894790874813684813988, + 2417620338751920563196799065781703780495622795713803712576790485412779971775, + 4445143310792944321746901285176579692343442786777464604312772017806735512661, + 1429019233589939118995503267516676481141938536269008901607126781291273208629, + 19874283200702583165110559932895904979843482162236139561356679724680604144459, + 13426632171723830006915194799390005513190035492503509233177687891041405113055, + 10582332261829184460912611488470654685922576576939233092337240630493625631748, + 21233753931561918964692715735079738969202507286592442257083521969358109931739, + 15570526832729960536088203016939646235070527502823725736220985057263010426410, + 9379993197409194016084018867205217180276068758980710078281820842068357746159, + 20771047769547788232530761122022227554484215799917531852224053856574439035591, + 20468066117407230615347036860121267564735050776924839007390915936603720868039, + 5488458379783632930817704196671117722181776789793038046303454621235628350505, + 1394272944960494549436156060041871735938329188644910029274839018389507786995, + 5147716541319265558364686380685869814344975511061045836883803841066664401308, + 14583556014436264794011679557180458872925270147116325433110111823036572987256, + 11881598145635709076820802010238799308467020773223027240974808290357539410246, + 1566675577370566803714158020143436746360531503329117352692311127363508063658, + 212097210828847555076368799807292486212366234848453077606919035866276438405, + 7447795983723838393344606913699113402588250391491430720006009618589586043349, + 7626475329478847982857743246276194948757851985510858890691733676098590062312, + 148936322117705719734052984176402258788283488576388928671173547788498414614, + 15456385653678559339152734484033356164266089951521103188900320352052358038156, + 18207029603568083031075933940507782729612798852390383193518574746240484434885, + 2783356767974552799246444090988849933848968900471538294757665724820698962027, + 2721136724873145834448711197875719736776242904173494370334510875996324906822, + 2101139679159828164567502977338446902934095964116292264803779234163802308621, + 8995221857405946029753863203034191016106353727035116779995228902499254557482, + 502050382895618998241481591846956281507455925731652006822624065608151015665, + 4998642074447347292230083981705092465562944918178587362047610976950173759150, + 9349925422548495396957991080641322437286312278286826683803695584372829655908, + 11780347248050333407713097022607360765169543706092266937432199545936788840710, + 17875657248128792902343900636176628524337469245418171053476833541334867949063, + 10366707960411170224546487410133378396211437543372531210718212258701730218585, + 16918708725327525329474486073529093971911689155838787615544405646587858805834, + 18845394288827839099791436411179859406694814287249240544635770075956540806104, + 9838806160073701591447223014625214979004281138811495046618998465898136914308, + 10285680425916086863571101560978592912547567902925573205991454216988033815759, + 1292119286233210185026381033809498665433650491423040630240164455269575958565, + 2665524343601461489082054230426835550060387413710679950970616347092017688857, + 13502286133892103192305476866434484921895765252706158317341618311553476426306, + 686854655578191041672292972738875170071982317195092845673566320025160026512, + 9315942923163981372372434957632152754092082859001311184186702151150554806508, + 17166793131238158480636170455452575971861309825745828685724097210995239015581, + 4443784618760852757287735236046535266034706880634443644576653970979377878608, + 21470445782021672615018345703580059646973568891521510437236903770708690160080, + 6932852445473908850835611723958058203645654625170962537129706393570586565567, + 17078326120157725640173982185667969009350208542843294226397809921509565607842, + 19251873001736801921864956728611772738233338338726553113352118847732921831266, + 13062907978694932362695258750558734366820802962383346229947907261606619788585, + 16576609187793673559170206379939616900133457644695219057683704871664434872406, + 17140499059660867342372156843620845644831519603574612796639429147195776838516, + 16226688173010504218547945848523900236290532501559570164276462499487632388445, + 2806068123803905806401128967330263340459046260107112845068533446899070326517, + 17788735370835052317224182711467216134690146479710634688273650370951230404901, + 9840665370904113434661468973557421114403401847108482949465899631150766783733, + 17357287363046228581837055771327121704742940914150998420465281177406182088510, + 8956082469997974864521346025916496675956939495318858500685756691488425559998, + 10583741436561099911914917245130852199607666337956354910388730829023746895549, + 15241902639811607164983030447109332729761435946009172128089506810551693978973, + 10889882303914055687481932975789161945462141459528413507160087442461090813788, + 19789561133254944544821898921133697408237804586549835559829396563401674817160, + 20741336668287037026472434608739333171202674306575625457456116338034432647230, + 17864073449995977742930566850933082711031717858550870842712972350665650521079, + 6017691253505466300212182439349954426085752315661098358839308909771637792741, + 5209125836207196173669497054522582922896061838702136844305036341250990710540, + 8138726312837322624537330169363664364899441867118983214176695868443641051381, + 15491983986041746833254372934846748393213690608865689646440909282144232382678, + 5054332867608171303802774230688792431028169804536607979111644888500809938980, + 15427030776591294577308915282298854681562344215287630895931797573417982096417, + 21754057982677295571284116502193272661309010996970316384923307174180521790164, + 16265286590463120486705206231835953324076688991892805307349612983237844034032, + 17679791107777049796013011282788633179411040182820636236163074053597517790779, + 4281652562868629887097957174897458165728741859103571825874408386197225591996, + 9168010397863299719604788533602757515513214141450093775967322808686129400625, + 17584182367226175071087689123358883902969885218985589531538416263709138156515, + 15671512310414658663135385639435845966109237059155734764323312289873534719186, + 10536294659491685326297777845632759824567028904726211134518740400643540109527, + 13431319759608247201135260841651365578663315527795431484765940626659812285319, + 9584697124715190200241839387725546204368618031045071660911490086723434692561, + 5180327104839158483066851400960171505063442195966219343315555549982472660055, + 18888217223053385111625483360538133292128748730565502371803782424772027937822, + 19535732913737027522540340630296365525208404217634392013266346283017745945894, + 8577759627886344995887423695190093296190181539234301534326157005220006624466, + 16793670928407147476673650839110019799844249677846432113010280456483595763987, + 13926032620965299897272071104154310460519723329016284975305942957859374938463, + 4794697578055472890255676575927616606591024075768967985031137397587590174501, + 3529566190782060578446859853852791941913086545101307988176595267965876143250, + 3975008029239568933166738482470827494289192118694622729549964538823092192163, + 17739094873244464728483944474780943281491793683051033330476367597242349886622, + 7367136451127531266518046223598095299278392589059366687082785080179161005418, + 11175297939460631138047404082172242706491354303440776362693987984031241399771, + 21687543815463985355165197827968086406938428974327951792877419032069230058777, + 21156136641989461785420005321350884477682466566148802533375726181416623358719, + 17347558768803521970212188258074365309929638984714303299899732035040892048478, + 16293716234695956076322008955071091921491953458541407305955104663269677475740, + 4206144021605871396668976569508168522675546062304959729829228403361714668567, + 19988050626299122864942213847548542155670073758974734015174045163059179151544, + 747972634423324369570795147739377097591383105262743308036321386836856106229, + 4612470951309047869982067912468200581649949743307592869671537990797895413707, + 9630852913694079049153027193127278569487291430069466630362958024525616303220, + 17941539917430916523930519432495442476511211427972760202450248798031711471474, + 20332911350443969653703295317915788278109458962706923653715140186132935894113, + 21764801803055897327474057344100833670291402543384934706514147201527191846513, + 18792043166429470991157980448329308661526906138700725174612608941551872082876, + 12308177224490762720061048892842527800271687977085172836705858261595655154325, + 6234555076867437297776538521925679658360922070165740193866337972293380196151, + 4651047048822067434403056477377459986292934655827821636179452835839127581305, + 4762047093602693619418269784972874862577325737690375448572644958129932507374, + 12373514879531674477721132062882065826558811149582829246378921774344318418269, + 452512704634345955634014968317367844987135264395068376894497483188243356523, + 21642936370936057063268550589361090955573362743817395689260298777690935495218, + 16170209200627740434842090607802586195654207376087117044989637541681675086276, + 11682826760471401430136435257946377996085824742031456481961511737883954750045, + 20628055165039718158878805520495324869838279647796500565701893698896698211929, + 16438375313036818694140277721632185529697783132872683043559674569424388375143, + 4855690425141732729622202649174026736476144238882856677953515240716341676853, + 11680269552161854836013784579325442981497075865007420427279871128110023581360, + 7052688838948398479718163301866620773458411881591190572311273079833122884040, + 10339199500986679207942447430230758709198802637648680544816596214595887890122, + 16310974164366557619327768780809157500356605306298690718711623172209302167675, + 4572051236178600578566286373491186377601851723137133424312445102215267283375, + 20933392620931420860078756859763708025350478446661033451436796955762857910093, + 10145870387395991071594748880090507240612313913083518483680901820696866812598, + 11173854866888110108878560284050142518686158431744851782991510385755602063727, + 3895357290105797542988795070918100785105415165483657264407967118738833241858, + 16358886674154007883356717944805100413481233709808000948036974385803613296849, + 10544067501284177518983466437755150442726536257903869254459488412549270232123, + 10495171258604974589451578238018388630585794890815982293891430761424812600427, + 13820724103604550843562070971473423552484851063169471886037640613650155173554, + 2334954333435579600152488915208745055087482119087065911968347050969338669409, + 15100284614446277058846085121308897497066957549089629374506920751044105723791, + 8493821960754696376711287628276980042183127459347650448500304251148421115590, + 18612435536889941393944858783110719304584209891406420832295898519317994950798, + 362101794940079733974215941991047456600874474038781578925062694203564740952, + 11020033081956343850903875701444955317664141075326494650405276926536449284939, + 9396289482656518627529185765935649373549564165735162258912975312413185691167, + 6879055176150676925438486069371149089824290576271090206945130252868108043422, + 12466610601804566637227883322591924115458766539177061670432424956205788935144, + 6570302110526154075173287644133038486970998888099669190857256824048085590052, + 20997862990590350605775941983360263378441519274215787225587679916056749626824, + 2642485040919927233352421501444361753154137311893617974318977215281720542724, + 18832940311494549247524002614969382413324906834787422940144532352384742506504, + 18751288968473015103659806087408412890105261892140397690496125593160830694164, + 13938622158186434739533995447553824444480420613323252752005511269934155122652, + 12878982657080117316101160964182202074759312554860119090514406868768962707099, + 13757859113119127982418426758782225628393556023865807897214601826218702003247, + 11817871682869491875135867072669251115204978941736982465520516648114811792373, + 11336448548896065624515261709306933490181794458266726453198857687608284871020, + 194970717714150352477887371297168267861902418496792228400198694925721020795, + 4999282817977533227652305360183045040853565298259070645110453061034932285549, + 17094174197873140035316532568922652294881600587639905417701074492648767414173, + 8484251464872873032022789624790167173458682056313339863651348894878144808746, + 10260366716129057466862964875306868898686918428814373470382979997177852668590, + 549263552864476084904464374701167884060947403076520259964592729731619317724, + 10052714818439832487575851829190658679562445501271745818931448693381812170889, + 1735373362835209096342827192021124337509188507323448903608623506589963950966, + 7998373949540733111485892137806629484517602009122941425332571732658301689428, + 9035170288660659483243066011612158174896974797912618405030929911180945246244, + 6458619567307414386633203375143968061892762498463026121155477954682976784731, + 12314261817227551876673777186352972884847144237148169773300066404053441924532, + 19869454329688183813243851218196625862680921049019496233616575272637276975230, + 20326917073492686652690019138603910654692396590122884746951129061818467704300, + 20403270805536666081472738304916561119325397964511536801752236086414818653063, + 2865941730880218719188224311916978807415673142487507504983320505748719154068, + 20614246027521726470902405957496110178017768563127335842405314212897493119848, + 12060194341463088508348622863463208827312128863463014006529428845777217660299, + 1128906798719793375274166820235650701301189774851381709919492584451845983197, + 19670876372911656158743764425809421400123168087389888660308456184201759209723, + 5647230694522866559497222129254930524469944430191328619422533907417776118543, + 318629082509194371490189248876734616088516535434806492900653650176451776632, + 13685970881538585172319228162662520285656571966985351768743970447782846353365, + 8283840607829148567836919316142994745766280854211662326632930274668867638198, + 8968895518159422029900464138741638511289476298837958524156654785428413265371, + 10061801991000917366002570579819627134666386452411986168205986791283562415829, + ...[0; 241] ], [ - 5539100337780919206842837176908516952801756637410959104376645017856664270896, - 6297628909516159190915174165284309160976659474973668336571577778869958189934, - 12792263637464508665199868777503118105486490400267592501708855807938962470650, - 17254685306085558791725544672172906900581495686070720065168939143671412445514, - 3590396502942934679818900672232030233017710909687947858184099000783280809247 + 6652655389322448471317061533546982911992554640679550674058582942754771150993, + 2411464732857349694082092299330329691469354396507353145272547491824343787723, + 21491443688002139478732659842894153142870918973450440713149176834049574486740, + 20196926676989483530222124573030747187074792043523478381149800153065505592963, + 12986278951352369831003505493892366673723882190521699331613883287145355738793, + 21126146258242782643168619000295062005037298340836817770565977031890883232034, + 15509665795506578582538177431401381655815033647735781734613703976071034655246, + 6989769181472743404364681671283889685042701491627165526899522083327752110839, + 7062179885254277466334896166987547257487047183881628199983668518000910197987, + 13842521112365108087725039904948872289730786568469683976372377853164252494752, + 3830559505943186272618534143266118508463381443414165428900505002474439179836, + 17704863473432653834041116667846189591617394753001613253930974854399793083900, + 875580502229441633079974792778818749112423694973231971690365132230865385439, + 1971134273535892826573832061354985059300866001765691176219451252512658771248, + 4865738840363990164915013008693722144676933915103280504727326977328013515878, + 1148603338028060679975883868174895825055359423662532941509525326937127571764, + 17506086433923270253695698017062834613463718526046463655503742220257039588796, + 21580033018107258179208198773211859664893072138803756118939260252922297665067, + 15411900706973212043830142913959920716501447427702082030760032355626616412240, + 12219699506725448409610279620972339448030565224304464695714944121760832152291, + 4525719544192047521328360848269156485222470829314314216955024799558286708479, + 19667371373588322336224317159113441765198420040800065314868656839300028747331, + 18916925604689704279265158984702141998345424765142129953154245912230835240445, + 12789343981741773931665143789673052782408749041041266509485929045869073416222, + 3094428508959717445577232225505810354980663487713729230015754183012845687401, + 18544590634480965569098056786078005630500574069468005220462377474861119476492, + 20990087440247450018723844204951613913840993427110495085701200965767234569705, + 17552251989761134508416634118845221324472178264364440017634233349418103869223, + 21000797802575507763447855752602183842956182733750968489641741136166640639409, + 19292751508591545849778577901067988044973302547209758604667395356943370737868, + 18314088316445539319869442180584299715533304874169767778761887632882728399870, + 15003745150856597539000559910957155642193629735521291045949652201905498569732, + 7839443900003691950104175747634267110464104444913379977500178134209666299140, + 13568305490393393394812598233983935295266242465548739772708079888867621061127, + 6453005227995051361096639028742707098785560656441339640433794156400437698140, + 1420171596348195609536167209221442141824294918625468780931400849866478645240, + 8347329128252205996443084339884155586061343024498283583400215109265013719709, + 7893774494551056447960817286805128884970061671041428326788899872964096959040, + 8970476243368194065341537088653900235777512204874037182428362347342487241690, + 239049405935404678508864874854718951364753739466303321590415544572014148257, + 15772878921699764223771017074289335629553777447709755479885293350677783703695, + 5416082112919155131434995906647355834510201879607888732259087164602171650389, + 4384524908062410354304345761652962203632712291085564157560146286207296352050, + 4210984612917608245844011498198864216639269565627982123611519493203177283139, + 18816442907032290878644773027005263628136050677095986565400687355912498966559, + 21443510232279945782338486087712914668515437675585863788610958361560172084515, + 3234314779308300525339049581669531363375743827111579883853941968586490182859, + 11029499234949696730080035941750777601416171837281021031653841244636590396063, + 11145210633226924132308292113124660576759662647204939721872338908644906571564, + 4583160563963432761409369246361117506465307518522062239686649163525543782173, + 9813992026757562966842771727657080117609486122615087352428596024939855084450, + 10084171857039480706430282187972782725948479260179367780776125786119489581409, + 3874212709197875589640151274548083098712939093643165182881681226579903752816, + 21595542491397091124739711708612983479307589335640792812157875295064235960610, + 2068530815441314105493629066002923150651375034543842424822712297257260726954, + 2673459852071215292298131389250564595426361004231758522146794940265552265806, + 8591046256746588406353455230465605224309754008961178558834659065898923355164, + 1020055192431352394776887540248098706183934464205704158014904833376067287118, + 11085709480582865378042656141271006552092494690130782253913953070642865919312, + 5673844083530503489429922596812992664928167369104420134641855283771127716005, + 10492199162275168254265892158402955076490959375050993042712629236807564461542, + 2280843393156259739329331366624245275580688891778782679394848304764573859886, + 6807797027131305026345508953353882265754363485246407959111359919046340709440, + 12692191384043938397944633973317584101723715998700063415107128429315536223446, + 19818676957110967644349139912613239435706480354664804036688552936554140369382, + 18055602608192644695569077694296748842203151828348990995792087204755925787339, + 20934555391215769430553078793246717148484784880715746179415906355043590089450, + 11420705181439111353998210442417752592951340005396931802449360401461783159557, + 19878854521263746227125001670931867821366047088989510542865511663910116386085, + 8568201846715449867087132677683368912214864824182424933182820310911278496552, + 19198701614488576617610339232794062430644024620523684127268879880793305460015, + 15262122764244854433806270478871594904740306012582364033343126589996733802868, + 6412758421155818207287638337822550233376667015263373809976157264137577776202, + 17371585001641430978766734501830788427263945848682170096055857509304472649262, + 20262970042379497707724791203314262108784948621691331141565359315001027736581, + 3859750447119748295302212198327542106766447958113540005985799287718502362717, + 1172269945800307665458943534144481495673510885455899148864236015097947176746, + 8164247467959680477306326470118519335673181279975551434197731340070491876250, + 4513977811114181395323888111232002391599397736872779927267726121435887238972, + 1075250595927474080680862736233039825365918646878264905022213616210377518447, + 18658420120424372681792175914064174056413842231969276203770574969914576681364, + 17769673440848360838244654765103041739044212539359630263894092078288342647801, + 4319086204044362848967484441065231939136453667264715596505827197873119273506, + 11221173270629292820060668122527062274557317856738971635698169204652845111606, + 8635411372759272135249379415383299350267629947167809163276219879514948820576, + 926977621651476360285369760355547766944001783780761167546467658394097283069, + 17702143780592866375901805387463459229828093905183622296234691441436877570082, + 629612289140842594504574984021125242351317893847688437087866691775821981724, + 19990548577495092294245865870717186004301934545721835081514347926537975465539, + 7124830628609719908679298707909792306162298058570958688501370177898647946696, + 14620227791860703231425817538142948793892390269806790476396226159679984968174, + 18495581997440241868332244230687799183899751339442721677540757155760745277888, + 16922065056093401385376103551657968760602009001905886435813054626317776258714, + 9969610601962874779035054685661667941954971427956866645694064022029705170229, + 15281641269114187762159685323068136816556739502211864119670902056596295644116, + 12114994625438879103001132949163961965524612903017200394727056658298824651596, + 4840986177718281128440833017205097196672382395936939379498412745183060615212, + 12847307562796769659308999092658905656250954898192781948610713494470441775991, + 20290096217351155282642224215178246911041509999959311313223857240001143893317, + 16151664509646153154405691138084115125600386733136285504828908979176781265710, + 13848845391482751436287906247470303487958950799995701248612703022979890932133, + 6335716166231441585596963683321661194889815181545222079376536449814718259931, + 1824302750039354704619545544386637317858342555634601563660279997221547953768, + 11327469654081586239268713126961534952233559223228327222485848924908493444712, + 10077703415170135154603829433031861799853903739210136452726077323833067256620, + 16368073884579385814331927334821006319227867093692644942500207970751483237405, + 10621580796499573269115131164341885791299038227955222944695715163010783205295, + 2099241376651019397894434242565225315652133572870234550073686122343103853816, + 17104632243449417396641550271977294699471083572885397875525767745512335891599, + 1935453754847256492223646005402770357836971113012418013930273797463411526183, + 7492761611332930896292052363224494314920390056637668407353957465667515477934, + 16836705924460095689555600825174696605443212968244843485187771119291716736958, + 16995495500678141665340056658079449793587669420913589967848082091551329904176, + 16097379973857697753436437302681608056543122759719328497348770844548177814262, + 17476569537128329379528694049566216604638194592812108658767104922628767500420, + 17997217989870184804787026924935938133194070033518938653831611194683423549591, + 17573343771046232580761295935281170028624495346579002725814597714902588657750, + 2450087639204541254902859018960918562514681200270997307467560465282168310665, + 17288084325555056222618040923753050382954155896826087372317882602328092535440, + 21837047676579063581498107773514419735425738753079336764356909012851439336687, + 370061273472837873736743292149368449614309676635341873070086681342317566380, + 420725183996224279379885018872359102189091670793820517618337092091910692771, + 4966571645678139143731798992823327185758562224229132271884647901363447388530, + 5039558223429273757296118284876763395391635773837549121798873235133698166026, + 14663152729953724779401067486012084029581847325524052152795817923033297673686, + 7201040456590575809960214033959496417566605177095808543357813677845263237276, + 16872945504528960415453618286121813996587432836152082188694652370255998768595, + 4914824783780909279212078186433590922437371437384817332713271291839616026466, + 17503018483514413315464207189113334433424965178631599286655188843769810245465, + 4087750571011463387872022799241315348852213278729592692674275176152296405923, + 4006961923780091252337105595934918049936238157468198971234322013673884171131, + 4481908842184366902145805444001507554481032302978790080019710161108326487967, + 13532316826436461968093937893872910736305115143550039673102602344678825540956, + 11602986656925867325907196773754426955346837006705269228226729102186031417465, + 15306992574062791537454541745213815567999895856471097922112648012979731636068, + 4497571735611504561173050536899411999551839050319538712220770383407135602945, + 2571242673174714867278075260451133687893879636121064640779554188161591611843, + 7070272070524747733177730083966686149849667613589868731851816020060781720851, + 1308310289745495626002351437755820460104812708071634598163946330870933261232, + 9483468192990391193401121929514821570714432121414330663623018046165053411090, + 7317568349845215930675847155716598288688799068821709820024570206796617676748, + 1918505733423704616434273602054555051755671749253598966287072464475922854850, + 15158168161084905689406532256983805923258003804476527617207287404280855731962, + 6855540174355511438343304861678411868002455139032857270673849263857877330771, + 5989863238360846166935911112885654223487221280254816980802479355446167746774, + 20283337058688740322296928691341300752003492063748410749625272920572074851396, + 18957132189629332408653055312790838576277703952267542471751593810468444454136, + 15764518568966520670995753676429154315765754748131847346608706222194564055358, + 7192524197002826721654253762628934164676539329903087107420445743247046038858, + 142950766663597487919643890566358241353679421113406309294925836697585309311, + 15012262168187689680572958978610204856600235635916074406168861726626292993057, + 20795666834671497603181209610179324236645779324677512349797033323222380300794, + 12650341271833683789775531792948185319868795529390391267833516836256688318306, + 5597700232877580665749288204589530549415282468176625525368428476461504532052, + 20949303924691159143653175365242293984396858344688574262804199947001630916385, + 10746523145835332938672833282581864816136388045771578294905302886974358762209, + 4998982766221590779170630035756820066555357949247521575936385387288356143784, + 6936999580131731861735955554005106460473097800566952971315565150681540640020, + 6670695360676548472482680016233507548657051302712214051977034166870814430578, + 12210816592786563975173850937247594401582085430897698766795696447223454826466, + 14933901149105284237676334791785996160108290333321693498322435129559137152007, + 3848529433916624869590379003597911090976938589461403388133685310398004369431, + 12778805225074604003024964969486878839359935515509480774809299341511161183802, + 3288267180428684202786697419666969564766921974531343432588030535602163038467, + 1272672432174256751826350693883913844502039730140570583479554071765667798207, + 21130828804874452930669244946376257892693846272313548250936991077452679117587, + 21254559353072473881932828401787134230282801383134765683324465204971002861493, + 4116075860631781527931204624078712926526805345818156200756399332393348685924, + 17435888597009729827411190999389277840088354756277916760187756022854497211746, + 15837398163415665169712832984380121382150588321621493928953938599666110830812, + 17988638446757562417082379159769772097890681265659458369075768452342579854303, + 8144561030363576879343874888624208577604401139613622673042754207987577727758, + 20020299925602421262203305284307419339160247406220693128040712457114283033661, + 2945951415037890626891130390523013930737768652394758977777336357159436605764, + 1505954324723537402640844232704189835623922400329086438898375859826553573763, + 11851584491756305117491374581845512067704002072833714119284164514457248861803, + 14471204965036278214508938537949717553799007630471016532866101610339050785912, + 7163557293233604902868673807221391042191134560333950452577270522828534690707, + 17291625782465108601367695465389799786592304061550212130987221355832952230827, + 10240907112109243116543462081552827576656826251172050843989873656917271396422, + 20702261919346727858635106264046787321170414155594199951578791234276181642650, + 16678253307828004252292273162411388452019952018258857370242272543091326285541, + 19810917631941180098047817620026253706643400683524412974923209268916769874447, + 3357220165225360610202375608872621445880880830154732998557832689480921421791, + 4392285438534542495332422274902727975330102148971785438164412161504066619105, + 14642025133729666610167675086855441462580619607677226879159952689184960379911, + 18142623439987890999821892559271093087005885278955082040377769578204898750505, + 11769399023330099592616157336702104329646487200891911089287290893650532639221, + 7261353756299584174448625214367175510387913706095214313669922259027644778060, + 10406994568199070863112470594593301582798997458844791396920771226539013327304, + 7475277967562870216712397220016587384793504784585573136176313471517144184018, + 9598064630327104406929367986473441777975480987434868213697837347643980267620, + 21137410002545951849752865514437404724653771608225272412595423069852350320648, + 12345612867231779996383303763804719815752861524077922121654106906093103051400, + 16461750199070055335468534730937701659470268635084522644824623393184528879703, + 7829250842543018165409887731515254191943527926556191989558018633300783421935, + 19801151644322693878208767560968285812646931156576102755771403150148125880648, + 808770634664491371274943928223981161442027957963181999892266696287962813461, + 2298122748772261447929855283951027113218922003687701626762072351622993276571, + 17407798064458858450209051887305178872029674498718760624162479511390762310526, + 18585562277464562541666582720366573863334618817908062612923861658144918595030, + 733976598693219656339731904831283238690050114241501938501377743874139460889, + 11316063986696838098122262534148335669847478050407756877728672233736962269417, + 17614529714381496379478130066245111825610297227468263851608027100133421612826, + 12110694197729365219340374599835523099651939156213930558791147158357810646901, + 4337343008663255658976574468931581484970687989356019720784093082313510905405, + 1379188959674402095268172673987199124815512095460112504778179157481327937561, + 3116148242507754420428768481157196067508084836097458698846114802493377512591, + 13306507137873332434793374848948087993544118494881134631519748904811343155566, + 18496878480807017010077624766326681523549495609998881196570603040242554712562, + 3940126764022508707486095199473913866137718790062498893812401335738707507732, + 10030078765792498033316282784150304209584388923549357286679864120250994473810, + 18519871685760382462428068450331593474924737719734568498029727699878543899254, + 12599428893576891013523136950822667754415283296587096197120138265392279834128, + 16038578953099895530943034305356008247313649524436132877362941968861459073483, + 14319233878082524834510736727226054073026413911339853399113450188859080424272, + 13710161613540579690732775978855380876556751245265568031703536595040993113748, + 14958726446649273856607176275240008023824615720456760403465034344703779274727, + 20935428111942360630758629263346308597806819928838924586682307174931367773605, + 5826394436548487315966647466017047216786257295199620110266250301500717796281, + 31401797997389676486806123612280306684597605608110075525648021056710776011, + 10784171495708237485952707518956314344821522727746927291389338644844400581452, + 11604345371765580191117799693565193618158448665352599382713281103552305960442, + 1378145039624937931836538950217364481423707761527018494355648047365613434790, + 10284294167221806561993937798090888689421933711157676807977401896199778472860, + 8233695574758520342808807499924062869636681352769371531557726871630696672029, + 6570581391072134029876349038190171593169496519436674767949949730275868319732, + 4026501263908027819614805027945064360196399012004574117767831931274788631138, + 21091098569404004244061462065218203986433580687172854429523306262593782053656, + 20711772916118045406356429185975897495222240215931761100801599257137350834799, + 3165519312799351250309462589160165591299333587158531489859211268084164422251, + 16470663723473939739601217501478624726068461799539012562455639586886033078064, + 15672299304945968727435591100602007503785845873606917887638890765525875123857, + 21393538327627889838198844493522533627143658125568123117776524944297103649079, + 7688819203734248199049004650451546300187194458173935784579101984183800649342, + 6609663518412297884695057080546416278366560290439222127471462938252865438638, + 3476303650597281786976907813110835564442121684386467570637538230409080744769, + 20633582549754495054832414039299188930065286005370053173386561254823483851717, + 18067076834611402459142612082327591538480657933568191619109271502102126814407, + 157209609820117793892254328219308970217366919934739036156851508233236414461, + 1848396116513925340973398423998379465460554039715233953825786874352442451413, + 188642786730195655565401615804782553245486295156304142809552609651873793325, + 540089254487190924787439362270708251103955915909358626209177199653451469720, + 12796274768956950589847157187031845061404119522843128177103898080653493269942, + 1785666356337148874573621868025910291826158842346617719666738769156993598966, + 20649919247042517528354490854561347316237285929352042389729444382153378749538, + 9568390566108569727471722677925269460696523515877621230569682954652430518787, + 8590683334740232786825518158771304803451657249486419816607179533515442407283, + 9321198393538172042803957409292145345834077448228642847843261373640165958582, + 3651905214805616378360839954289447530035139753215923648216350128870943481828, + 1324345422558073117779462079218851558068746895262914344818945294328678893083, + 6666363895154434021620869731925915051086919707989020578203743660669796175288, + 9850757893972463103359995012900314323213006625927501272997539940766979170137, + 10214293226445704940138790188111862069675188797488928722469679760666574484266, + 16862124085118494177559484642483513597285992646267864845521573612482278871023, + 9172340118369291059693735314505606817316211450324955429310200429408035954801, + 1968992755714619414656181112336357119271845800144345284299978250769356388249, + 17192498940296212027365280042755701662136570107224000496521552617655679821443, + 10063385968535643122430064779260670089120686456635080613693015398478175344193, + 20101961459945738562625328882763768836449780661345042148985756598106706734632, + 12704305975772252539534386080950631076046431529894091327218544197389260775334, + 3008242816727585639441748210631464697850194693570485141354082562181236010097, + 7797705698071555811456747812384107102104184812467361013142453143842134807658, + 19323240331433203844038522035479659453946066968727795017745942269828428751105, + 1698137797127320576751729191866734754105401103859852376273763815257758421427, + 17656850887825900397821271738817912328294075224643535784810269137125067875996, + 20755447986835730799031196367323817361150623932048563112034040627213597261325, + 6221130271964372280138992636208062417325313096379273438539556580491430711297, + 11042709376363248213366896208587241517252100440844476816212498352999929578287, + 987361321094619571176752720390429919723900732295551211263814448408232028205, + 15077982986114392945859048373768437818569856001604485167476360943078774679228, + 6278894644165961404521866714059972066255652200107181684047812674333675794053, + 2649747800006903047073625320829560088088800522557851927539477888486006072675, + 2636278052351769676017824297717609512488651850924228608531372135635042762078, + 816232991472315395984098922575496846552245086608787214581606973359616326446, + 14372687274434205592004117128588852491871014819273428668840779210928924573820, + 7351401720390274950322621121981079413650308506660552567079785209176949174210, + 10275293929161727274572318228903710245677747557851999483919909420098936352013, + 14869686444606195206734119702227763209172799407142930791211203702643805341518, + 937617196362766626935279232045712623531859540210120280128165029613358941709, + 21331527351771920568751070369057714014285398281585036009305608379072813379081, + 4305436470381074948146072259605215282335211631970525440530773004228212378618, + 5894273721571292784412707230481346442881109207745969297947253583203466014760, + 6512250441044591603946512492071171861967500633638753443182294740883123881284, + 20863871952569294813936866452848141274047362082838805921071316386912981651979, + 18788566662709810970880679984141390717017951403407913908833463086244783373013, + 7784927597396249543149135503684024377171301321636804832597181795981969626201, + 13818519831569592521516488188127966399245767953522268350556654747680372036664, + 10515208647860053151690062640705322684876580250632027862984821874343071549235, + 797604926079325807488629085866693514275115789253871397971708541758696512985, + 8741784289526985522570446847275649913333939699807282742190607491216732972386, + 20966712704043418981047968701828936463778140093909973286855779694780086635828, + 11359697297415630167449040380538108774924967116147664240213257348125754475868, + 8070907838094569287067982462230761680706116783989613960066342967469297961118, + 1868550288036217638713133945402464194193242298015503906068429633793800456561, + 198709459347510170000840600179608479136663571567208109852828485236018304733, + 1601154135701845545733926027872374554514541574822026314034696802419388627041, + 4363994778006302991481199477873248350039564117453810275561422974475581105893, + 773054378219982710451611471050404495804413666789496412742983455527754059148, + 5209426340109575519362014651321132459061755868557415513439993327176584352934, + 16124961412020675839394907565568143713078242978522632778625312854364651991011, + 20812496670075231301471694692369245988519082317145989298573032859079075730004, + 3312489967581906638742585802390894285073229440039144559060030129184388053832, + 2967475373447822846542676378804990140732835322255774209561143670843223463335, + 19744585401442299381952694102570931935735276268739851233412754166721728873141, + 20026293345566344685499234599699178313754630774489046573312844763673073616936, + 2611303659034102517884318354550433047021831422518437228002960700934925644951, + 6230291832603218406134986471162106408091661326026848531605999413028246206577, + 9126162046556730019959291776456914453189657463686708035601186672661595109020, + 18827736146609035067773173111376739253733288103277133456626928961785293662143, + 2328703958261360872869074208611873245571971231035163763965210852182760438390, + 13796410059666172174899788866809560044715551934510722965495280798363043241416, + 1593663256684781552813616365605526150610454082601584196604084376715746899324, + 1565874145189898288764434737762721576951043839540107044892767693968417810945, + 8709849304563896945461696717753976956465219721409993781555147204068634555572, + 2994256803561260177499267243802460581941891553208150783951937342406846377191, + 10452746656507347152042187616753027475507881362159944564077673851918869542550, + 20130580998875572619695450234900655050996104101008767761546912649074040426200, + 18926933358104691474037431437316089682088433006245222723356764715400831411716, + 3783551594057498940671877156409957274854990650480535806320220142873170375307, + 7919031943604095374667473717154511882451510130166237539514111182596247372692, + 14518552587329209714850286012780632801030157943402419401997576700600952906519, + 4770764028263701271241862755569969531641408032906982530346384375773459918490, + 10866502826034731763529371496585294375373238783964914673031891984092997621879, + 4234148117462322266937279401468367908013627589417699250592523530383852950379, + 10747942066055887965185603234524367638106812660210378090215017248140719240336, + 2587411532912868255102795810490361867789634574022411742057853375399270197531, + 17350061113113681344498080520518808976916692173267298878258722510332360424059, + 16490282364669098969805528215926442920328903121380947471680517193373377657129, + 9274691782659584680377375192682066090127280485689527337429804211265749864190, + 7630965482352419767782717986075793694403609453648729580916814032587325374653, + 9483872310024003776681196467845329825094379763716541754956796450187787638623, + 12182966986735661215639970080491757244218854808156498220088212871061979325833, + 1853790963611367149183440339188924598268644281518961106776656221408171642714, + 17425077915972423995335545370701802959607559878032910147159424242864219303096, + 14571075346526399549826264845894977639678567831720652860528738036970272895919, + 5627701855249158721927849603102149698163511782011562166637339712383551336091, + 3620805686755372260289125555061886982808014642356719556961142525373021656729, + 11556995641752009899073583627136467840237831247117281278719511600076965602980, + 18960242154096055221658318882298412299294886669455506299567210308762501113202, + ...[0; 157] ], [ - 19055249881366445073616526879263250763682650596233071589085239500077496415637, - 7367697936402141224946246030743627391716576575953707640061577218995381577033, - 1322791522030759131093883057746095061798181102708855007233180025036972924046, - 20456741074925985565499300081580917471340328842103779922028754640077047587707, - 9059147312071680695674575245237100802111605600478121517359780850134328696420 - ] - ] - -// t = 6 (5 inputs) -def poseidon_m_5() -> field[6][6]: - return [ - [ - 8266021233794274332054729525918686051968756165685671155584565440479247355160, - 7947823415909040438587565055355894256799314737783432792935458921778371169026, - 16508811191852041977017821887204137955816331040385276110261643892701458724933, - 1804800467126006102677564831888710635194614232739335985819349312754063580223, - 11189892034806587650995829160516587240879881493093022855087765921356611070470, - 20567450145123179140729389574352706949280207113956641415022972885523439610844 - ], - [ - 4666756311257455192796774305229624459258864488677689058174087310651786875914, - 11389253665835451896363091846189307652796786468610595637047377864063404843117, - 18793736599347263150867965517898541872137378991464725717839931503944801692688, - 4206344588923325482680116848820594823631536459347642329098796888497153867720, - 1739462481670645248707834504605096139894257554120906850613041004917967456145, - 18514227342636266640333254638454588508118462110178719555586534011641424431745 + 9174141306060971809979631725764298697615039980311809306145004207410652431953, + 4847693924685156250211477469465516228032151306221739650606132660616428517315, + 19669833054057639609249840291533340493211768292967819468538893000195036768991, + 19800508893433268850924828171290876015556093796000695603651522426066333836892, + 8244699449852279148780456022144420353408196866113049322676048275081354214716, + 1563672068712965454176533719400672258364596155638916268717470967009721945171, + 12723223712027468580318230235559705540011996847167975439677647504573149248849, + 19944398841194165937952509356635863229327574447452745793253427406349161295763, + 21218058308392585368594275702746106483411305671883946244077923955757637296177, + 18442884961885927579732373746933397748806426938144021013884176466434407012116, + 11138408360119814115926439449668526422561003790198269766757675305576549475808, + 12724564576884231109847024566806896391934587839830522481308995309797961575379, + 4897733190252075532660075013731462724561461746919488679609618967302541674417, + 4797748331306263412471031924618974997396620231469532262170060449304337691527, + 8626839560132907403537141283531395025838110825355541158539075100658769738351, + 6096293906324574249636975851522292408228519044739444932687579741964974917617, + 2351617695830568421216396081605990689071283678701192113347036659596049514149, + 3045682390398203085155257535118136303069379656645406266260961816947178911890, + 6935829264874515341379952008241845470659188886156484974987865751370715745075, + 19847439266968955911971997829840067368072860877451092633069920565944933744280, + 12795097343831149148337906863235678514689648096503928066579129201713661539889, + 10424580232112390318877053133877999442988769389050776486274146627765228950235, + 11651452649618223740363812212607761589812354035139843126315028745587570714609, + 21307929358023177131550002602820591970791247513576735567457471459920519084552, + 2579908580162153663820021562014873149811195641589016321720930006635393981680, + 8198198178555784054784079137247244121807775986273563786249987394640289859893, + 17176088986876377315956611075288620878117708836881362200541916957398026761276, + 671389874397910339333118510595007038137908096657753354622355890021074216004, + 19161949137729278558310070194809106779119877882343914445178348849980058405327, + 10827554013954037091657804154642286174226562252063767377995268439458401752538, + 11693672899474469123468133710607776304784343543318650064064636202512816205843, + 7026547767612627656560992117440221331093280829523426249915938274837157551621, + 14422968137896343032446633683271253661000603582016449215470992885331170459671, + 7685352543184863430081115767111935982586458632527708735083385591291346555502, + 14089009391529192464370954954330128327830078875414722902347666490457756695535, + 8424161061743752192085022963953944100289245618074575727145394775891645849043, + 9809236779073852557054640507912802523501426410996355424610807253990040160483, + 14100245203768962710288059230665566265892855964739454261791429988929622355986, + 7775683622333704945225255741567928967674629526812606133980425422182282014012, + 8739247215686497264451630351996892836638898510934389758205488381695687859658, + 9431876969679115468275053745264413939426444105271849398322497961102606290132, + 257914055321743732506701382989022126153391940932933566664491918941925247878, + 21801414068435960590201256257290267142214176965736081788536576642934903066059, + 9465495933537134443327560834432669768951376466867005153580146079082722525723, + 7862366214258716333873810314803222267215825847232397599183717032713290878315, + 10701164906390193792620967030790214270231326273599373762943959252633779929633, + 11951628827727068395937910010248864431667047516686609553745879936868276916066, + 14268744039571470490378560085356767818183790841094115879980723591887874138419, + 14468215915818797151199796266933432577607248341385185700017147731054148927023, + 1523824033338639123415809477892820349580561577160869448927791050266158538520, + 13559991428776910947424645696251487328999214391124402586267086012691140984198, + 18151203063828433535061866995346135260543721730169485344610433976436663085882, + 13436242600153492361692256644258899977135098134175123174795293078081801647137, + 9384556671429507406657070680351030238568956203341356106463890924933167416522, + 20321079285577981781556986944841048777999006905303986053275199507771332527205, + 13510502130738135726695195328780836716597947131948116750163533622597187969844, + 20903049289119144354363108865308751668897757360882852151457514926552553533040, + 5611953645512225417723205546533389174830971368309601830751921473015551069534, + 8816886019615642422040038431962872654062471314244185285424018745071289038220, + 16751828354835345790163611999302863949792305206769993810746019449909446216365, + 10421654749141018171116296259626916395875529220250947127973888230084671091757, + 6065225315766552671037285757918350882361743810888619479819895087632281975681, + 5737755346739850738724717271213687543479332312420206954339242459110768587128, + 14770522272891919220644639305274656491731294860310497013287297810648680944682, + 2777394791070450473479179489594969793054480209411136328689318984981401732197, + 10039559932930709555975364107098145624058027439566384376771787183526929807647, + 20757756003754261934858081777796652436155530474748550156383127600004580439167, + 13253166894715452480712170898662712132411702335275401581167208877688374856806, + 2037004052447343668129085129987646907388123739343356363273464870501805506884, + 21829471491172175426560705585746893969222010633542962882847909490991398830669, + 5130395545419191392223692116621486075405299333195732914002649716762739787586, + 20333821730990393095934147177227294218344864602777744425090741435432040213391, + 13629653802252084129446975515814037702423511189484562534040643669977716900228, + 18489091892360842692678715136565494502607711254719045543684163289077857041829, + 21380328601365035012832876315565064374684993115210423862017233170195286906080, + 2280052193465635727584791148501382679094142036232980037838088033232747821762, + 21415541711468815972744677841317235994302058341802530962394281077076174148777, + 17146992672828650459975820445250769505470616910596779130798889014378635881076, + 21676475584514120109058208398560066698690773910598518925936412952356431597439, + 18337052978997482578725645166749278142628133291693686105612531426715865276143, + 14864089429815580405957698645045711801464462794754089671996837547347950054532, + 10834607317840698149140890207826430113987295440254355899459691878793978994131, + 1157143498448645320415276909137008396665083714591338741616893578930275511205, + 5027542104048754930085470328670427788489455916338375169351586496298129661248, + 1922685817237874482932428650501872692326329693528175054457715565489676406535, + 3071473720617798005831658342971536643616129392641449174655528578463370685788, + 21091078808046042460442535848913779439792606439995062001271357804782672390627, + 19773167374024045118471391738750949555178717045037157435777574972149053404157, + 6418695831178793575992210834992785624340084513619644969535805236049937971859, + 6317875495482489567338519005308431806047606843913867465201005132273298011425, + 18001249545956637376455848019549801116909661454019565655561439372098476761813, + 15530167556609139699164228289904946047951254183080358784988008899829027775935, + 8702757129830652230304011519426558036441096750485189115358314568895250616455, + 6369986882953061252605652398893489899416599935424066958291402945530517772170, + 6842894437627604179732847187262933342846269043996061072487488027804029200046, + 20951621154051947571647917571547811655800779287153833018533872651413529893817, + 1219277535080749134805291725937516331501172121638812333911793209536894469364, + 11704605822590166851511022757496386950530399074796545751042566537118336773236, + 5983427701962592508775640503988144495847156070437130549832329402380170245893, + 20169091361583397776908351163571343158517532527313940288212943504015977979442, + 3347733015762117176159731683196584632702931062411889821726902331981723958255, + 16217509027282489850987935065936382820558307489954122630844029918951230268972, + 10781269196927764524006466217779648732772805761839205677745819812868343369087, + 10568911823766972365218731330080733630028238366288098114239172953421915095075, + 5568774544682750792074131352530555554984876659733959079036284517928264996437, + 17854353469028651373397049175548228061144941710027186166132671198740388767529, + 6573034112757039329551886086829829282007989555105157401271097204633906940776, + 14069627287078359391137554212536883450595451640858724555679971658981340584258, + 21119713641590541511025673864154852875977162278614553796484277752677323191505, + 12802116677235410441672624559825044917295689876859311183079161588690810005363, + 16037054471696658545113065872215787085337497333273419984439267709950724531124, + 11698654309680908244303850432833183602706804558317993513795996394673734185716, + 15147889780127043019188099948246961619198549928908180192590946633702778981583, + 3657342516407201801006680507925024451922115018712017224805778401726428603983, + 19776786467141868744713630352693556348834540992018636838044610844396164981103, + 7980994848490005281733955776875257044050741738176865989521982608944874160873, + 12415191330803073018395217955802011585094769098717180100014182475381600382452, + 9300986814650530426668152137665814177758578011365736727321578452726378799933, + 4412208980274764197258090802604347599791567698589180187154608728755887977460, + 2582317668924231956058541757507620542434237159213236485179804217989764223164, + 19860814395849792324574773787600734118308975251437485131415273418632757301303, + 2765909129639570206766170018363951893338720647679193401532780051354569922989, + 5402210382809272147099442645489124829067576777592680891367494969197685281513, + 21011104174655621871977821285307554463403659856745964274018020456838460357574, + 7018364707286303918877589672878574811337524823085078243421192184715151775983, + 136380103284908296988715215087018020601815024625535396780012012453684253071, + 15953315437474610448052466140270091879233956524793052736202793153707558909889, + 5912305909658884889781037379491781973092020933879206417274479331390062715252, + 21575635295587180789566592951559325743281772394055590203112195979769645712827, + 1541325805478255472079288730846072146731241030100908414806224735345400173350, + 17207219201921814683730773200330679841907450967511507012179337438654141678023, + 18266907794578843029196926509122804272900478710738403531664855427655744759655, + 1204224895193276222782842236712348692319665277014183965830735736728887994581, + 4023246588034712778784328407820569751989619386134504404739514704773521558127, + 9064437981037864995763386367268294611921404895425171966596873454090899491243, + 18733802217274421976148972926716884457128521840010001893311936746027998476583, + 684088380644531080099595788833220377905013807951051638705160997709156627273, + 11994830816367980341637110785269531718699655485484715851375754143223090344544, + 1831724566362300629700078416489434571462666430381219293205871349415506993475, + 476710745682537342427691635955087951551678644045621275039835625280220347951, + 3586272766499559446129476613035465343616602918105042144185864609818186807939, + 21220348736799044560439132291243370111879983677197111626309132298278891334631, + 13683795063599185801186093771702503913590598475095473714851383723199050309401, + 16118007386401646906425171859166434660243697555307927508268622819509657450614, + 20930641024767526790605168032291665313905337763598128831404465184891980632233, + 8098646212401100552303711812039666794078834386731698810205195111722330322418, + 11585783577173465460243373201831086724911159484415020913089605532852648999143, + 6939053275662244505087635417541857793206828446247848992283188764105131966721, + 12798043540382494855660472922674138947867597503468216532170157050160462426199, + 20713389801600667412553956346192236970217099413304167366340548074880917096741, + 8708207547232102069057776099666995672015399188924281674772351753887161579745, + 16016293152251662056020528248861487281148011452459422778601663166015837379163, + 14324897997637439510797191208789711173129460994362368408063402682894248793270, + 5652996184880208428967511742390474289004021508049280419259474250332590598159, + 9877106633097964013050071703002221796318046172981334418310092241450453368579, + 5385816971548914185604875069230499528103133871233951354186676373318036241822, + 8683091293306949708478955451280670950858818602696102489349595054818146782362, + 16854975838650963077652189417311897888852709425835763860743171659164792100482, + 2485160816649177905834265823672532710299580013309324666453183278408904845122, + 13571692148185502188613896013359942531817915076247598483272449919094247957149, + 11899399615412173136098732970606292047945698835588882297719609812145308198009, + 16827672312681684936590464376780346837611857292837989006980972390576065571472, + 15588237822592586948064701827497915157359094833395277985658706133691498343174, + 18356642512438827417103800170157877145465512961188328254773957819312191285168, + 21642368145757804795143182901389223409544979732781450480847315495418822041608, + 13104082060493963869934085622104709047787444250961437496674916673804812287386, + 1561532086277971111804773016487251313460788916643968126116038406859074212104, + 2718320602791009266532615731130512762296058687816604986701989820504700684864, + 6182683520717583142027400659687593712743548729948584058329789905227082638908, + 5757242145794370726637363237313640925174531077560764545993554185332488520899, + 13688467192244237790806289073845563960119021610896694359815485764764608925981, + 12528461541936459922472167643986446262977222390263675720335825628163511159437, + 4897268894447399415795897967133432014527122426051771866816059363418177665482, + 764332419588242767884018802335623760055144509861323437945071732931233600264, + 11755468878196093893190753985692714003062307843033761257593209352165323938879, + 6006022813561851182403581780143813226749481175437001910923100661321563995672, + 13901542382190510449243772206670622017835690746895066410475076631498053123535, + 17648853891656481911225897080296737974064729032668806126284849597245044343224, + 15106333841965710929952896897521673254279668876709612770907537801609875568099, + 20899315415025260484895459315726322363345188136910564549344894025053466430346, + 1409310408943258102775009950750654615881913956151269414096059752250092035807, + 3899088673345731523976816322438172722785832982334214339521575164464706226294, + 21406686765584824639201351330529610299177537976609066339927938099572420696135, + 9121591670793901722224770893633585291275002987585289305307167711146944200595, + 10711764678410479049841945177317023555168593838022414378232020467195337241279, + 6599257303974597452501135281719536074294806740553273627128065549267140155175, + 2142616913275380526921597026822750992917222975992774063376747381991404337593, + 16361086527663411948363284957489078505159658832010445114438602510508720771278, + 17122647864721668762640781848678028227021534122268561738445496382823789619088, + 21708018685042482318786273055293241752114005312590172460099480713746031274624, + 8303630654111760473056607545365338851734309857718959193970615705292826806179, + 3658686547507488906491014260011151850549759409901579684176172268581462329020, + 7720024124908065424512743488999250878143598904717873371853608249805302871508, + 8805244918657836956533473437651380347005779399042661429698187314657501156241, + 6303681354794120075893215838935586592706844702088252970663343726024171795351, + 21512507181643408509426104627003618425209526633080701556628608990726677651135, + 11835373417333287523801757951049679177935522717858158305516568595764125190183, + 13059698839045014411602727811400239840163533672024084777768305507840091151855, + 17635240655824524168378284083397931667938326555447077097306236826752492079430, + 3374412791113107178205006579112630099131939030015047870738873452427211677886, + 649711083340882271985565833699379436167716866997851102439037906608755280128, + 20002805138014565226408902156524463368767807620908543995020210484077706418135, + 11071355197960433041624284534649121637702414580710232237233568479006159191217, + 1105441595020980635809093220782460032826849883993030969714432603468135735502, + 9652765957610682812348919340146799318537766051849796416434577860126024594091, + 19248299650856496267902926731608572596705132576830681367365128976226233392929, + 15285802367070100569572399512275861017714681455564415244982064571963339715277, + 19970416835730683993734843405673457882587154729456022607061085470691843864556, + 1017865638757684714433500504002748241987153668285974836527484933462490771227, + 17284848056169793253916338792235498052654877955690514601079806604278964099314, + 11718277105372928962350331838305733149270432706448484259807630484543527733952, + 6670793378364949883511003949124179112275066568088468958915163969545409700112, + 17088789393958965094855662340742013087397643056458490270185660553870734946796, + 1930788514812600942005320214284180860980345276633471423966020111188605196111, + 8844343159753729614645407314580317697758296041737296276765583948670245312842, + 16657939543606018325703787748629433167511611178952563626096990460124133990109, + 15333343644239485619497914931918504163396626751908652058758135581206765801100, + 16533875915742793452819179569144271760125646811168930162441077117553849625884, + 19679534317472082858641184998487299940737032844519038845860980362664393659234, + 16385719932525604857740698205965045007053424961009717093945644387917936681719, + 14490521084213123170781774542655088188106794646066074998587858678154251198444, + 6386781978322405984893078797365492485297499058328348606653460996474947075858, + 17508047533433736707046937662428611868296556965172642086594091783148965906980, + 14904597000414815084666285064575232635645852687797347860862157463159487771060, + 14979972442969995336727018758631782107138089738395941038626891064816880204567, + 5299243186271864957800928637599294208954109271450189950375274196644046222516, + 16189884555052883188473617525411302750109401983487269295700675997730645714379, + 1645560170870292006287241616671417605853047420339675073261660626733726665673, + 17866745974872498136933906591373095763114066893081150553715211393380040095383, + 5744849574386643500716045532645657520001448510343827372577217716983339773799, + 14021966200238971589811034967347517039341058556783068950884921208853167419283, + 1201178089866013320759085637098781870734315826415474628546655403142858044361, + 5875644793836087035760988842421852197052681650818034527831700615895391179258, + 10875065950479466897559006840696567433921014267247530366235539292597441428702, + 2221662399199449388725697795500999209427453463134383582414172135385907744785, + 9758513532658579204941116584445291102215928928145103503086996542188799521709, + 20879593323317766577775570558015407573466986714590017262168011643343469361329, + 17225846522404915080676699509636264825833159640824918876741681229188434930856, + 15189442986691997434021855855358620506645387296294217783597931695143376252483, + 15973617135551858849206811241799666696907820418171736027820254766840973764431, + 11888113439449420418408437784450952639345990804839507528208325036625374967083, + 12365920814385241227394825974928370916184942218042429533600397623369545597697, + 11966175169612449906889690852332416255478894176917636726028104087408060623141, + 11163554022908212145274813635928762748847331295589087669583554722521180712379, + 15273476004030808005186443499782264987539818978741159793745891769358221570633, + 2013969196885866182480519514425192091338553670034650196068995589691938248955, + 5008975446746271526106846692137145404766553748264648461545948417006052208130, + 3926749194225734582453671614337621250954608160208554883789519551411469033731, + 1635544156808471185144068767649088695307748439189898784051754434524720057896, + 17144944482517962143604430553750908864860079758005337246916094084534304051981, + 13823503533305241872793740090687668844401004819859520464168798913603662683770, + 16335911272023134851779534303717879370955813837529588982953758998930285394340, + 14467284210444150699969889681308566002886261365990840091849371665183151060295, + 10578205764525658336257882813734672799527733392763965031628376897794294290414, + 18771425328697137255453620743509164311086906349726510394566012237817674245865, + 21804626093983212038528370352039806004465345685985435415809095637323683466452, + 12056805308954301132385034564357716323176447186932453788072119595595483786736, + 14307195735327805282612857510308008767450554777122724855715789120735513378827, + 6848201070063637295416045855906784325422580350462489495889308309540335269587, + 631364713487758647973016689203003205602593076699875191323345338325349259049, + 16214655556434201961140525501007839859074077768660052713461045928979956365067, + 20940788212183642266181811368870506130164462254923655617893660245551698033523, + 8257440848494309435270838240795567828478627302119374684511017376568090372435, + 13701089242130867705897643891164147923878521147124165292045879194108024940909, + 6895272953337895406509859406973110417619874994579965619097329249292199573333, + 530437169778092455975584310016745919549274205817234464915791595041990209639, + 9008612822403008353420189298381046023002474279157557733428254452507266389025, + 14863423501786052071018008300345884780479084379412157784789951872243409629758, + 20091026239041315645045502002997446404106877721183777765607724358538559881231, + 11103877261161399045807234470901399725912406134008627937945079980590775715243, + 21529163495181909351665093277427712610965764606448489357319207727176092439794, + 19540446772694448035410067193880900774391072899517686330271100773183944540294, + 17549510450820803306426739851959754252204444648959723652883552677325100583689, + 12252518814610348662318155253547558779974557529822012236107550517806390105567, + 8058115132085119666951861652409945532276905989404523986413207631657437321956, + 15916100116790431839835734530362130437167135501074855072245598938219364570910, + 14256533476494466694764843270015662315303617568641801280831873052211753536970, + 17865471381417606502707639037418669122823481329049436020149405646709537112534, + 14015711483636570179335132940981982618090553643653746531174110949872682031017, + 6075776171664976866533080327142904134938121198707020111533599997509054627652, + 6357981809351565370498807027309828058036389418343890944791766504532174516243, + 15145296985037303761634018005118672316118004891352906450983918852209191841446, + 2473672396516437070485250176897956191104549656554290725379242542480862701754, + 11059085933391482002269653121188853142706883316754376424538662772943167665341, + 14804069155713123448375113552227724310276294677318593116834685772120057819258, + 10146378656966122923223443263705119557842694560695035707977826044606938090895, + 21828309590915152213768434346306434851424116996828875020020066586363340244814, + 15568879616082229996551157805731419126872501425454775741945679993142071548779, + 17504079509060638501918729619244098692140123800571022969294759717277257664716, + 2998311560047298465700351970612785742605093777116697796464434026101441410385, + 20229972737818088327107446854254558628041027965197447598027135778783710740259, + 14884874200763033520375899992902136897590350894844904733314191389520252900641, + 9619409751736964504139815024141276029474791187139050183491749032619248817404, + 11534029087676783672833531415041588991838838078174102967049055562568798961925, + 17106297093375816944137015955705541133308466659538554159312635106186252148471, + 21676736161168806529097919794022110433487869702564846859065695507460463414524, + 12596447704589377083704857810305080195761099125652005594925931498073219198049, + 310943124066162607352831846280730445558498286205117614171844835745706684432, + 16013029710570597613246104892930389004941711962070683476555063566372534206859, + 14282564976066063966062366540992448474634085812789771416509095817495183298269, + 20757241092771652500911491636894210910134068426068355089789205706892703219255, + 17084251309147907751212619949757520468224028014308500329099194408342072624132, + 14680350698112448759886861002622963534698534998651150537754386791270019720748, + 17739512731440543100681958009173086667000199263945053345384367808940651002571, + 8967486063900234709994801661246451094429250620940593387993430620369318619734, + 3906067814916986286272005884942051451306945488494283077675304366798199289520, + 2517004675157816404807349457307096161030587393097616279110332574293494030636, + 9995302877359286298434340810356550712107485295049220989690824504445305103587, + 12849909876017357260683411536833847986127911582040960825577300322066595609115, + 18074515800779889507358182860997188274134395074469953155084226981497567860114, + 6692811728183968363967959295970424292426462800383828091752006855360167264617, + 17859827663908740084792157440799065184931609649811664442236242315795442091367, + 12243409340804252499520308602187370739653046835019551522661290645230850934962, + 3009118420068966587115224335717185828292538080040896739662684632413054772046, + 15856202298588272962175258696610233941787471472716811521132004805327415486141, + 7549804594729480554341356998842376772514802673462970334329441043324983960866, + 6390806437030742378988258255983502109201709511321162596105974797942236431761, + 17370236522182003753669946647208335160124999930136364231371998757664000198520, + 2261672244214630177095236704932243497157963117166120717011661647779055001646, + 17325026196605130064689259977831126468940872193987407658419640959345091161632, + 3631641025220845885502691330008982895233731506600778684638817282531001457735, + 8656561399441987116927438675277763317789561532507396244334062468892541066084, + 4069166732330197412844703565599514109399373916243310212229125901351402003915, + 19808198732373520522982274785888742523226720967259539531129335924093928174880, + 8555796834031869022510134190573521699378201702450788201649007358450530423866, + 17759660636058865290579521740750449606781204755231964378855563896473545202303, + 1335826395218609619260020055566056869243760115287254209950063597653055872566, + 21596200365241795669701682696176077888309278223833581800772036945674858315765, + 12619752319673193899296833725747186284394167228468888029626464753793997178599, + 17420588547980145067421969830249755561311178399975476925894947008643385243007, + 10337481272389772505654575850886249605422739785111225132545740838911222864209, + 17928431631046752749930349099366498612885288622404560316665023363985966878427, + 3075798659324203306711977985120251896073145961913793478792728028765206521425, + 4639500613932181914847461422373341918892878975546430906324216810326467690534, + 15396322795715441250300995201889120935591602515487993982711884319616897970533, + 6391276937505284102735701938724106665734769352007891548547667448647832351929, + 6811373320779057384916660178551330838095673247430496448933336925226142036083, + 6590973140323934807800215988687710942074412987201753370126190631819398102173, + 19364648614154949386936259588484266535262135334799266379433252509193375956715, + 4702754284612371917466042550086249683933140314858807272591351280832918881874, + 1081036249074169248236179367049085684430282426446509768147097371368406374049, + 18548093223441988703029589168425055383154624592689171393242936199350770119589, + 11098999608073377668352846814752381891400020647878345005629685447730764310163, + 16001262992680194260590639872321865154716987495605624862471107193457192704714, + 21696229443869118415905915570780926763029898831113534481730746953640692230062, + 11716215712634983607563947056324900205144202447594949676250978337464771243867, + 1778908113733035314726603632369389424542091991692308812147944884836647395775, + 4019081204388123040098634987844274011285321286777408246805308194144238418480, + 3473266952388383063447927231564219811787341139731701190625605897592140631276, + 10457881304788072618845101933412333126160339089704353596608910674508961127232, + 14926101732700077295531234099443522459232814784151318061435025890154852791802, + 4036967072197259618286839959572768559469665646019907384624959071646231971399, + 12776716624632228928613396031717959431597335742467953143594165782617234803915, + 18894783424164609284436913400522166453255844750192864579927645453695213022195, + 6303809107919167113924303987533838414137996606980561570652539716097058487126, + 4729698693443803882717817492985796053343431875965792864932005291979914613160, + 1645790034267553926884568714540144778649055395816210525904813567839945991808, + 8138260225269705405100573121045873922755899939885385491610389913906979427176, + 680936760009829486282006800072001712155424246576949107399338687767760991887, + 17240357869291182045663678468827695873425113788704614245279840174870850373113, + 19100963939745621863641468371111320143895293700517367016077996431570157414340, + 16188989656090417148189510820963186890780289777598053654241741803194118100843, + 18027402882394597868782011288920739982398714370069420860949975937357531046151, + 17780529984916796963712255733293310230026423072958099290880849386941451922559, + 20004531511171838591303710792081846238092292916166965045929062171308088520097, + 13855731634251510230399834192704620793850325654395687428672253016405315169901, + 16872938837392115669581040432902657478544143723662502779821325505282093696739, + 2541555081244462826761076743762714962901590548271316707071685417008817634653, + 5136424039269088350807839181761422963254683236279333039713142751702136147963, + 19216238128964101420135465007632926445321991494181045543846024053552797518994, + 18868537488540023742258053821537824724371813776839672880900985865823137839953, + 18246710415801024039719497716350501105591286880983169809863166130543617917249, + 20608694004331631709610739723463009412162748201282986294016482926528443868949, + 11318113915971658853560322943565673154831611543653209084299774855226816037778, + 16240989418312335385576389959938922684406585560688799437547298624184839261343, + 16171299673760267132909753100946681733778389681324959987573199154235691694977, + 8036823955656422391918380552495301547890420665617977624790236120392727764522, + 20269862530534739231936251654244170650781428788816658397167110617927916774329, + 2368678892744667199202318323282128737449992006513656480477288092472671147090, + 4618078962163037429845764284139891171861860687111566735174912070413086829215, + 12695350627501306162901105159009497730633599768443844225981772758225613194238, + 16356283146491744069785034066388746989409816380917535719898337817088223419024, + 6407893217596287850421377738867081146106659458551198123106454022096864887316, + 18168868018352364136212098098453930600797374324006271488950341490483455519349, + 18352629174410142476418438008157117497168118524562206830585500251463010761689, + 4344169393287991961961456515301754172943022039566219343212376057129143739343, + 19424839806870716108478074501405697296961947409763509419111261767390677718987, + 5796037897847804302272999466834285170265203646465480652521088328457333766863, + 17402105801450379889120987010453669096275392789725153915905747267778100864362, + 15540989618743824352651126288511222263828123668208146479603617243655978402205, + 945810410725426921570254447269595873973858272778720657523509910503434094174, + 6962323734045776666289031609372270190654631739266635759799844631053633876675, + 11382945272742312954364642163371436855283161775445664525053938433459897196647, + 18940251871958826726849623572811640436342841713786099464305053400421580490631, + 13969540696178305383564753026163726563325318478290740131984853424331762285147, + 4841983966001277917879506889862519614692143906356361564304719688757862622407, + 8939049562492171082419559182596894186639203815268680721033389307282239000385, + 19265363396776097866041313346787101192508520582744521467413665478819721956884, + 337106861429123598189388456471513480497137213511877011021531147545809512194, + 251367482782327915297484770356856386307188967585026711663629212746150191478, + 19506616511267234489421548744907283107923549136620297132842391511025844759064, + 20633589633280372440758096707466273580151526293980868749421563697429194761212, + 18833062060138888612708634036427140134887774731041742144004707524569102994071, + 2927291160590267909596732410727396533948837350308818016906834558527125752899, + 7095572562193114209617459307511041110255341231707924363346373597653253806883, + 14274988113217913224290208839851596837329960221329537670822013510325939323091, + 9965830780560026128320556230399915681196410289456547935188741323403719404039, + 10333365845496980935202034863900757172839454015352626511769637076650624839070, + ...[0; 89] ], [ - 17887039315911403193186866703775654467672391491657957999455462537283842145802, - 2824959020572825365047639014537190268717891749361604043531643698340708119767, - 12521547103713919592301476538318318223836047611311454785951907894055964264287, - 8658146183671258251984364885894342376430874614261222570603159082682815800788, - 154390145585284450772861151318029820117470958184878116158462181541183085587, - 7593705166056392393963956710828665339496927193740869686529339432486182720653 - ], - [ - 5529559239163081088908568555890212324771345012509269613465629182165427812002, - 3729910453162885538930719732708124491456460687048972152311428493400220125686, - 11942815243552870715777415109008273807076911177089425348095503288499102855779, - 498938524453430895689241565973888863905147713935369405079343247530256066618, - 3976257517234324421403708035200810671331954932478384823208414346189926720724, - 723540703523219510043977323240437576248315561543814629392162302024056718473 - ], - [ - 13306548824219676333032339487546407241767961556934015003605485324283250885682, - 7970147269291664639740298762956131361316495463191268382513594527221399186752, - 20633313939958767604804835838065337107615699351647541991788258289962727735454, - 17162090859520817529294904484646695645841022315617926715432606252643123848792, - 9181379842957190051440498041153333325098774266789773971685141362947015398641, - 7051606617662816798224904133351061549832959857069896192072217769241273559278 - ], - [ - 16619522548478824222688310091434959542211899852679631815023615875678448806029, - 14965311177811968100298579672135357167599499478246106482433786066289128683961, - 9792733250919070275775594069208673385381167169182805600474820364274865306108, - 2069253833779081039049908513863485270550301879399727430830923273191877809560, - 15847298987712771667136245955631872888473964330474501593909263901393348546986, - 12244443532166430060291409356011430759892629145539185535677568234713942157668 + 15193892625865514930501893609026366493846449603945567488151250645948827690215, + 8655680243784803430516500496316192098841666200175185895457692057709359214457, + 11710807066713707084726423334946631888369490193496350458331067367713412617049, + 15442364818086019103203999366702499670382575019009657513015496640703659810202, + 1358747428976145481402682338881091555771254635226375581638965497131373838774, + 15658002471767984962034589730824699545808755102240624650914676102923421241582, + 6420480504329990097173256112095253518339231893829818344055438052479612135029, + 15457172495394305353698644252424643614748461590123908880271021612601244389162, + 5745943350537490600340174787616110056830333091917248931684290284533019091654, + 3877253492903478989342845512796806320713689655633086736499730391667425329322, + 11257677301507982757739320943403112189613848490812422490591766717141506751601, + 16906586852467953445509312290627525856126394969718997799028223470195783329296, + 15263589725854108297280528692120758129000336125328939290924952731952242586386, + 21735940039489460025710098364749096267519151075908323637361429746399161905338, + 20023056608360522105358681147781839024069418874082333862551226466128829664291, + 5677500725280079960679484373333947430817198394184436922575072427342643665917, + 3080516739494460477657748111767941482024045797587058388950619118994388252853, + 21486496065617100719537932626843898998311175055335457507845650282870586541596, + 5371049178920102602305531530023787518286335086323221270202212974241707302466, + 3074817222296007572297581554183445947239252698770067839721345984255386069425, + 19180807038569629573914331337874446591506172622522351734982093457681161813141, + 16937785199372956273358037645552299688842385008757508130180245705952406225194, + 1688218397616770248184651775433764527272029131542529408516364801909017591719, + 16315958669815317541884966612581197291281164499674338063931623110684590850347, + 6218230753007070123505625054833158632732536069700963073464625252554943737669, + 17774528060285257656595928889288330429565059134928074258373583886985960212139, + 16197131592052727313460949906369199026477758140133103701908949020106767192893, + 13418604038232148873269488320329340508522225417123160144993642839875173062296, + 7265658443160253752317166706266927598319661172006072732797351716897681315157, + 17200150079219747370109251547638276280610591698078334228421747259741754887, + 8627121890622175767416692555014275717515106888840919734160364408960047296494, + 14546964505431549758350267964924534495477687922558528647552728692912697049247, + 17132720822762740343718421124251772119916072270451579802112353604446214831761, + 234333065870376500756753915306346778417056884715946003873280290982247600083, + 18375643491701271245209094287106352436174133929245169725584150600992143374298, + 5158448692161567615645197008737390561357077078129599243188536485308363800282, + 614161645152783610732075198073600394068518413590650990586931263981193439341, + 12661793104597977909223565537293318966803153852970198322604479648383643541371, + 13041905650419760925682179803296711066088286278603171065755078690359168540579, + 15006023590144168506070897325649191051975999212058008674224953860265667513015, + 4983349941266961584317889823965291023669365981564144622292227613558024302012, + 482274340065333833495445682213681402212945945150526736364263233985449810602, + 3966893131006556898236790392613869798057510088913626163333804949895810673044, + 20923301526284527685000591080290190641416245135554916208054502046381491809443, + 20838692384005825835959734210506718428443540957544929066941550833051093000166, + 8282357714606447781782716442854085217089572080066047419459610560432999443766, + 5410651444876169088887579490283094453001167796545260026969919887357676973543, + 15276966646285075387317940436655285872037988805762800567413073418506412856419, + 15066911464727337689573664613158712498015597773345106524271610486257089622849, + 14583790985054968382519116885383608902981814292128186470697458065499359610203, + 12059090796146479535492139954279038037217093044815277624197659219529427760034, + 7273811886044732271171500579064359282424476926867187108258957006777685922641, + 1463086899665237074608503061872751147444637332808872866814340325832200880984, + 4403177494620214359779479537027014449448686844655371530169401219256448130398, + 10860968418848589590932601250051274256181778387706764281989724391784015147562, + 5268786978207139542368199165627108325282167169564314266747401266496556301775, + 10683355823176907476704511935094343405052640940909677712096702771871787224727, + 12998090263935761477316698114799901126086030852595294916463464609721875730852, + 21401280461419124637791689956622923839426783908187419462727763377498739154778, + 9827224472048063173905906705579289843819400982583185823840008976971109664519, + 6215804144039763858354471461864183189301201862376216122255322421321775987311, + 15461308489200344015891625455653488930440613755785081602434124530381300882814, + 19336334695450889400681207491394600659946256404722006637851709906131899294790, + 1712331165786355540802697725399423752392267480553199895882357858951999960061, + 18153038525983970702748717571053178456148003321236490384959117581005013333018, + 1080183517033034908031748897211289245459330899463186432840251241943892326023, + 8948022108193679628295152361559653763100984324221629445749311939820327674857, + 9553342289560502306921915013446606435600388298465288181461633559299564421155, + 12714965617376828547637017050548818007690047452402682720666099310241001848988, + 10945704657865102635748104464461970844653553427083981539165832149959193156197, + 17511714411688352203059545713591160825310809755917403629838415797949261359373, + 9253691969419856285051096287845246422848295397226841130282244592511676512433, + 12218945350859454581754463621617733341764245716874083264842931063272433793037, + 15268139709971695434346690496076067658968455677120655340969837725391575270485, + 7948825129295102283421620705853168119104356217418364837218892682579042520651, + 6887299291348589691868712194070626390224806410428583073294593431810559288717, + 3610235157455454109573625364057240708256027358184031380521552355839155549623, + 16532488069063334064099666525339953823111673083177894678898823509406678724969, + 19317517725107761280217103201908049748015068578935276576200982249386084367574, + 14980901224290526859762385599553818204548992110637275324411078408232697158492, + 7741797285700915051013289492475875831764653137095445146268474269974647962596, + 11964233864746181868467810392101989052496076326472717372132104394243614334823, + 12746657111181947224582102380049766839578185276220682311596480990298620200286, + 6408726946032901840418309506578019708113712492100046332894630652186614300568, + 20959261828945984489015610988397031913577918654575078054490013338416801523934, + 3173674599420546165852740604987014294355430358334465189504551707066179193914, + 16110281513253204315524614633789708146700074483476149119440509845258215816735, + 17135377580103690088853370572199271964414896742342749305424508776150797285064, + 1405769920008485935711505753346340073052795087429311991287498566024570212365, + 19088073362945853867763169651582894739272002359692597239222895238839593467749, + 19897231284455588615416169252449008151349728648961637517447194842672488184146, + 20476415629812014715153863754869742189693986277342067785614833846523246536739, + 11074321446706734150375041020583051611133090415774365192315805856051215270782, + 15231367549323128694183572409135806408519505225209496441892541205465727777072, + 10515952069292929457050921929301902464262874744159361114100398880194109971971, + 3216370118771824418364829250073852356774095079734089790620447714552849459645, + 1940445924652458480775282556203659335417827058983719042726494187979000691704, + 7899310668555694144370607061960060230071621529123669746309839400642332452086, + 3125410912833939638823760577011271607678545358020637189655641109813198731542, + 2980079409624774815878860133121670095839651294537928173829312563570356348730, + 3766498515736372882285796238406751547889526137955288498682767455795237989580, + 21751217522789414135074956130080241003845828660310903627224390345319859795839, + 4947229586642010378772262640583556676497656670779800090478805824039760706318, + 2168676839236948809859825591626629233985269801981092020040909992251312517552, + 21172906642114648036685108008020762271569381607092920279879047961076646303327, + 882675742500939602754673078407141697482716600335919344527751158504426951699, + 20942968937722199705624825492102184647835614761458159157410261242387423597787, + 21880640497503102067412608072166388563991106464538369680846671301780353850077, + 17593472026567804917122179982860735087124786197105685847979050530954084564297, + 4492875530722152383516030266828166766820778742874238188105265500984280376666, + 6799763500412433367637987497601148507907071065930142757525839585946238894092, + 7812331664758167657763399273963290017340604299019483750344476103319142702775, + 2222332747647756867926707541092465789402467819000336747029352557749400316077, + 20438798382149666667185974604464532451975024544676922060351031604444896151494, + 16155157103796724378615022758633778903205872772589663310774455593497441785913, + 20281325298063880945091623185126257485818350714264176365501683813650871716911, + 4922178080989486450454493110764936742315495846015561426329316977670113220071, + 19579063976700768282784922967523980346960151903154507737857728349662090787824, + 2458828873355000645851832396764221987760639423132968569631493912353159373462, + 21166618206785010755521994106737991950548963896649678270059527421944129497211, + 9131643699583013708059191290958290089892787165715294157378879201986981390031, + 1820371114511473946932363841206094088983972935646887524223011276305844153307, + 7264184404232663540867032945940974372967974872966180860960243405462016972362, + 11228656105550475045610757902396386402555430893045183008968975441800824215261, + 7151503559113638565935009743218857812859208253653498318591469659718664783964, + 16876040581364499037941813142092448836399042253618385783944016186340703846779, + 10334125383426918152464737478646460879481305348617711177774418125714273980769, + 18900559046103390399749767994653107625464807708680067464279674225251110804100, + 18685667289312169245526749652972366835289568864080726348092618145885982989561, + 19970582871354083670567197978171723431124602481748785146813441774826500485907, + 15873472427137024971035326229485784626398898771525077832924901475242073457867, + 9090803292122260583635467396769157643561973206888822931647063181944243467413, + 10156295009710074552070572489422360071526675259143523597882131082376797944708, + 18600630374968456966046654667577076758720435487386724419578803020365834014000, + 21292291483064245088298314957584631356250347533568992016547598449487977536460, + 2784266893057214755054197979675795184619614089277590464548240934105557638370, + 21206743389683892419024645604723431382001453245850423743581664552645211926469, + 7915761821775326316473924816837591351530533394717381318596295803119061411675, + 21881095237485064870468603451853549262304643738646051878343976465227744077912, + 2011784725603622472271597952122938645154942022107573948889667939904597454410, + 21059869383015715705096974077910228193608826877524913363323189378554601804559, + 13660545486380051482020817701263881806531607595506890631732662177505270213284, + 10831091042775967380899180760062457635694790868286967266013231823406639854653, + 149288128407476550494800886735600251983375852319258454101603889073198917321, + 4032475033542195421623899365282946172767274020529645277615759958662043553317, + 17860535012887415629230166789742533149365132198763199254812432302158542514395, + 611194463774512114860065022851497908950074400927073001695280142990812150583, + 5518364261187313845085346561539515049557757056751872639492957432879259341390, + 783263978868449790737487156609432867806742277074765259237378374864740012575, + 19059339826992310300213673274315612374137067865428300882729551175173242291657, + 3179709304184015397125565132235783368222831063701934511986753856772139349894, + 10954198701843076039176000728742415722273043852061382139560487789741501275316, + 16411266672500930935370066093245284646483148609897099268661795671514664627451, + 14614816948231085620934132277599546641612327229810158468490195811014141518325, + 2458257206135880430320027516329707989817636936777744813891328347210486074414, + 13549483340434455515002570470395006683062583844603627042649952800864870013910, + 14465927800403373425828183741641078057513049263889255157342086762479739044711, + 4039391352709218793104596256671892882216573882631238721514928981154171136548, + 12750457082077152291009387792121930725761848879916565703854704756389714536037, + 20703941646953337308096638741387402857948436803334980867971163138332859477843, + 20148755487317949638981041809982361196106823990400472213765926589941031736503, + 19035096428824471222963574043396024781574056587456391309795571372815435282399, + 13597108420431213178364236660710194375344287228654817880431599113069659963625, + 16737817219786305757887002253067607822378794077688837656791543060369162185533, + 5164935079689729145670846016031605160169301936105766707946436049006171651941, + 21653381930704765824477248798502813954284378782353810890869232482999795586793, + 2062605478140760101860087118379474541965619844748678233207247884294051836812, + 6841505950265078437298089354417829781031272459823272323626556598403583002674, + 18723551101558427097952125661588457059960574026361073828482106612260297969553, + 7898804490983679270754258611113569895515918945891808074921872907759024464249, + 10882278698112390755842292529204069263813359338030917602809789513528936860051, + 19447560013395173052961224723195565400117958329259001072560983848146677205053, + 6251288025262210726686494480483550276704856797649458538460443509657307219922, + 13176666617050786358406074057104742181338809005466316548399895981897535342946, + 20703225796049910173111490454489910459787604528779911406172217267261190895618, + 20336720518722954780604743873837334696992422089627753769439653667292899832714, + 21420427865372074512365684526694872695798980614525900481233709853915806389425, + 2498895690812694987926199054702295457557454143930759961192198950277119149872, + 18753512301709603592612141197073246313430368834576850495154922324845448997662, + 13229612292359498096055458608547157785066962647476451239567069089111704445000, + 2690879919643532184588441383789963956137193400890598777054187145581183393168, + 14142396602342548413722428497204107502988046500369932366351553161157672540408, + 20448725195660080278132534867269279218381543910636641344871383714386318629041, + 2559459540570011016181396098001618067535109329950570139376049832813577592045, + 2209294835847631004298393339896770055851570184195462947318472391473531519454, + 14610669112573509857774678749257346364319969641690596877040685661582231189775, + 15281088465087253563674405311018738676067395725444151577815750152538449780965, + 8600553033773805414817363397077178137667131851961144771667772828459236208319, + 2748346039979601666392027583251905158817539034260921486084376270967628661657, + 6854960712378511006304629447898292218014632388505703802374806527561178043857, + 20207552563190343462280438839438087615024485494479390954719687107061991587248, + 10281541252271366635718295778088948309847900730867531177275273130071062184625, + 18855605847424121529776135453072696981767402526737712879984848146282568841809, + 4160214035780913418097601322951078913381556877408879904436917334405689553255, + 2122867135885631508183413043949777333811557914428796322029495785048111325437, + 18793959580906171893053069386015945646795465354959679615181136313144978078417, + 1043591673717355695648236328597936528752358227297053230241551190351813693314, + 15686469257015275311444450012704351019335987785561570672026138336552980987277, + 14048856209379833670666148034655599475317994357805584661156301746235313941815, + 1011563953969880478397969933799483261900428580241502003261587014788238280391, + 19240556623066672446907714818724971233422104071815927265423017590508305430997, + 2121904286573815063480388650799381683473766736407678915747169455786741101182, + 6724437969134367395210139771738563153857495313330774537559578422672993498270, + 20206855573383441961836932177838081339503382415601366823182724056749038447809, + 3659051978213562322887447057085386386485486575515693147713900345497451171308, + 21246119528547168535908718411570119652856799993958321864163737649108920924448, + 10446114322905404392321651684574668727564081327779662579984472408056125404335, + 10052242287865403393859620372179811039720807230902452334457123873762222543944, + 6373462744579965543231173757071025010089494620309953425653057223643612177083, + 11716070974813426833631730493593924834405915845847679294742728105127112594434, + 6451284530793440411577197006976867289209413848762574411101073727224316913966, + 20143217291446069633369261481904349401356557325260758866598205109039367201468, + 7741896897172494958877302103827661518814930985518070029789560123401964418102, + 7414486245715284930410091802521351113719159777210731898112598211035848096490, + 6480506916211642204624111742530825907262535747743645014149694168805302825019, + 18349725066341807634895742572304899830893334427067633858521634672944685466440, + 1838291082333887710851505844271184097051704051003105078056248035350245616867, + 19201915197596065583046168024521824662441686729039260890206806469763190071269, + 11253788423541320580105520117231178489492440242200599071301755928628199128159, + 6048832714406694444296771635481934823208451249770515560893368035838759154821, + 6398008918881249487422929614611145638894557821587972164243877575640548705346, + 7013037564266297435879776776659289982125632651326438965546874242685502904730, + 5942504790082366811245813670914617310604940200824079289270465669331434165301, + 14344789199380317440464969138686896230070901882253997360605407637865754361287, + 19920212380356573378521292048728904573841049083972983190424200459025557666792, + 8983390577894750782268266038315113359711163721228398686939390484499979421166, + 14953991148867572055684497824790735528852361750007063016470842397064705671772, + 5592033578501586280289038012647352732276003389059749788953239057845882297561, + 14076883072716069263619564306953450824526010844333044566762059693672378725675, + 11108270411921226463443318601950168860230077781212396032908932369105145901793, + 3681277588815101350213324449908372578846563884174807724121308021640034446476, + 7194753190480156904207319938161903897566477363779122267985209483435838216959, + 21241255448366937244332942306324590869759761073985963892514045368815880517382, + 6203071960722514588958553813186803009742459823360660333787981951206442471249, + 19041823565851118046937769551785013706136778514067168239416647071096062639366, + 4928136619692555022185087228378238193895894009623071873887735418398682287593, + 16266329364886004534411977872528706660422476743809029518681886596981922182359, + 8814684891729998059175829142248330760704444206534875755023421115211106199303, + 11072277000652722690981202459933101924925520292174200155471966778637063588914, + 15889576313969861857250394875354819627977602318110620311480656842740292435237, + 6934515229262494305594741689326968268143898236690173897991110238064230886755, + 16212991575388366798683594066983659236103186124339324856776288894513503543244, + 21100508914867482363389012032457112622475533432309937238082785660233880354422, + 10381104469089401657446748653199843213201270332853172509558263968565255702795, + 8849389605935865968361613766905708889092097013638425059146677490704442276611, + 4826404934194100291623537890117339503344940312401101713754206109744511979962, + 9981819567268652304810465083896863711149056310505889216307212434682251812603, + 16218484218588441290424553684558267080330286201433140852298971691458926313766, + 21317661296916247018967238829275056855142711494630067664736600708605437812892, + 19523923008662567951910986132173659591346561824926093935331274289896011695634, + 21439241836891927940168832009944210084078628922824257988298290967895179737163, + 3818036890597976956138669961319975835941979944306305168232209375279960168960, + 10212547715001519604442389033695156945619060410131175896383181616280631586732, + 956283172524544133830416114111944076629240232397666924807554743752464221045, + 8545109273807246425343308224167362024331960554428088718932211551700420545275, + 5647769597708100114837534314408246331518385631750569421373379085922684908872, + 21776221280695269311212391423788179027868152904973644113087833004348746215729, + 15989020831232836203074762591626149244364214836699154611339161287030952623233, + 9384665943619921791886218744024370375464874104981653298499433530463000935024, + 15469006121097295841026542766455781293432005131673839148320165243166330403027, + 16103671377537767724271717097892044266704736999841135349844319906338275108222, + 842367229428650719054831004741080336526228967970570607897528985803108607790, + 8752325400224955775788313769797750158375262384121380328719514077259567119347, + 4803861091350023344885030428100876947830986453029412601567992550504530969575, + 7917553047944370948250445233027936387189889293110390303835890604428798853681, + 16378323148632546424902611135263436821435778030958161546757828745002247975096, + 19873719885630097137106352132870659633926425645300622070145979694717581586592, + 20324790419158243246762098227260178678767896786893299456278167341205663612964, + 4358908354524026935988729716331497263147669784003421920394531784876541301801, + 14403952632095852077754539203207047943619815438482171213105824864831554185165, + 16410713482142323347391147127545553384558868490870150984280601225023662513809, + 7304216341846662695189617252648753140769311862815448449926830269690397729157, + 16792943782280077475956215580025612636120139194657275471595325031090407485768, + 18494329391227402645175320826355306995912366111176422593669423022411884295357, + 3277597348237827068690736756050060740435013727549848360800059544123155276133, + 9396765756719511114743964794180256605700037182617127755220919249774110852382, + 5637053961584389263881381098869862042993858662768294676971865632259649027245, + 1752142832257643043564515360000718468888861086573246457619082905919623770956, + 14504506574384680785750882507533398260948836347427103366421836731538357314790, + 18947994518078004413210940685748534988014581551965984303066903086446389273117, + 8931855168578615387850254663107425567403115805663142600825724478150698936342, + 10982092525200624040399870568387498905840578524691489797530932831401946309626, + 4738907023206802373255186532236849256768509848242049657234258536668430260775, + 10888145285628319545262252531874405309329869513560101920454793431198094714989, + 4767721624212785367044047554655794533816937807005608600525762243335180089923, + 4054394679973840378112083329204220302222586590732553688297938891619998137578, + 15390471663419625573793381445844013245022413344196724396864223784781333233143, + 690498740448849288977645176879593806019080276382495160049117613302192708860, + 3326968907274045758110436838010900592335267522219473049427145975873344598768, + 19461545874830130561487975864151403334363998126023624462211037468138940028328, + 2255249425919459031033123095731665691066980364231819200773725596456576056043, + 17139538647342063569964264947811360956712827863014723985947727876623459280539, + 262834317961189780923232082352297808796511874872711860311746704570027370416, + 17784213646586812350819691264737755884800773322574478474130308351003659945289, + 9206479615073686723914227166450906925650471865894639492301222855979337534393, + 5955379232184076713510750681781395826148323482009739159408415185190732125682, + 16345512244217240951729073298135981012471478596479891072149124888060645303490, + 20053701095030547796310908765544502773063879272854547881438596069907281565287, + 11519146559536679602608982593432194283609736022486509747046459824035493513614, + 10868663839942247532249591973192159672852196011910414460124452013501564199585, + 12668355291693420029179738224611760713369106517542315102687346083105601320689, + 4091011252347209563858280520339886760216002486858313383741839652119084430270, + 11416347683590132388448480763970462739172261435271326798646502987745949753371, + 4462763980178675172541782335457125059884067698347130082276003539434128058577, + 21728891122467658477520865529973242372850367356840114983386033432316519759391, + 9556106604731806817435679463077765288658189491612307664294729425381901530224, + 5086982973132652080709554654284904229374030594786774699435814748257879554118, + 2278505454992311041650060186856758463754878439802195559533882189615578260695, + 16123495070352975934848591912315341924608875638550779884194576881433498909405, + 13177225503435100563531015597038445430211235761527278782674200718068329833622, + 11626932451843299545922103072142674578946680165802341368625957942237790110177, + 8872973246419344365802198448930136062421718851114220299577394844231810068090, + 11920016786052130191738519934437207519332291620474831138559948859328822621221, + 2773753221970604083383541092979093729869734021029185810064937974430862835870, + 1194583082499114147792330367943150006952486615245506995832323057119894886077, + 15293312601348482070373672684782686300692505365845870624263228679370968807837, + 2292156760291800990693425534213440357167359161992251338587906324724034592198, + 20920049766730284147153707151387304988393631464951398563908410768221002588086, + 3587899345078220957148828249287269521408604837648269936718299413697642586126, + 5857527906708110948691023855516662527925762284342493618496858248142623857037, + 18312267494676788897591109008609888960798722042916784593521762607767538629817, + 18354455618287562133438807735729369657256664914390381320892039403006410339493, + 18594037435499535688023807489676900345345731643180370940972090155512943637000, + 6361231157299815359812386352981667048590510979947935475914610076041390336883, + 6503045850716008738909204934356093641022474278658078426701342798380459107813, + 15826908470360778431798326530563200301151807861414464213699967513881040969457, + 913167165738148713876672473302437265273760468892350716109373788573860454641, + 5163418960719047707254162004625467116036830361107107814320243058319914687515, + 1852750695670141634014249062360862036043602867770163972096325792863710036947, + 16164029969996795952250343426848596535809001568622155377829217918121790073916, + 42291476149937488089591434144089904529405222471677684973768504172369443350, + 1329340386229357940610579826659090359930768580941108555938139535621252899508, + 14087936453397725507000489457270864434699508074557952952329368237400407748133, + 11454917885298514922755456675259734718428103879515668717779418480236210705323, + 17749966508430836878443008025013283275306943216523661550528505419303121693213, + 16617298839486771009961431205770630163409905047728421465641369616889696635464, + 5622873871440608391107520706189063847917690892897751818294742462879871297589, + 13537715561706278379083684257583804567523085149672090320983273122424669242274, + 12609629910090871112615676094781247031353826207267723991911250780907380059468, + 11881347692420971451998583525696964339513193164613288356598017302547676912004, + 3620434358220496198439193226313617496907852030586214671337652678218740406153, + 16586456872124455799862826347901525401871594428044067424833235946565396779382, + 19602593015746956165116919928045364895525104709835703557292833702385934632182, + 2465427491077301663150648330772125184470808854603184374760649420983178107738, + 12521323976712195518272978277895155774288446093713549157148428964880747896725, + 361951232333654306694462853852464888974834703718677826403016226307188397185, + 20048343816024297162848487251896481827914904696805156112188099141327595641104, + 997638030405613623344188782838773314122493364653596616029491564227193697621, + 10932007654988104622042938184134556963651043067553327861790671211490960094259, + 47171599193060570819891696279547021610376047998583333086685382152080932821, + 14669115378939104862697280661831896914139331878760241858539421915983017116504, + 17868874372855679948405169936193924176514630305572838555185339642210810710203, + 10178296575837129106771098084407669500326673901243393867574658658064222502028, + 11497182727976130924559852428316615034304736115488257034951588831868596612725, + 18847036158089242140209840241495282890278502700082131513222116906134183113862, + 15514518995390761662346743876733004358408187550386554449789531199638765348953, + 11474102901522012346251529527050392650125347221410246734211005177721289856415, + 6612195415835443084676700243243174090072629504450965229103970796390091290688, + 11572474094368358234669561324969692616275099241307798860733942350364532366113, + 3855324911963410548772360326122995145790506408472649961229511965629894550308, + 8802640003128749594245736338745752744580147773009816234644244502373660889677, + 15676839305513015047736600040932186843826469281853634239081282896349443894145, + 11124722103091011602185413968164672678635980457394627450785290630813993266691, + 15087674670944618980358596427703842917302233637812357643695687556421910213028, + 457555060782651847600218200815104907046227486293278645126081160142069992497, + 5340353060455057701755599760342180989590806327490432497082435572367648024359, + 3289809733259936118731355294329652879189400852472418229718273887860572748363, + 1821386174933044868215348232606758690922944887434531299978498726875279584854, + 17399236630582894158137572250502674699298844870791766041927951699287421557453, + 16772722824042046255416248879357647708113647471330900665176012648038469814744, + 331374066696126093678097185404981758791664151917354547180452342655690460271, + 5482079579065945934120471179616600325379965440378196448353560421120276746028, + 11861638874356162254375133266687016527365630872709665703116365332534843803431, + 19751278476934230895840638614095718373810690662562196455711240141902305648888, + 21017623330912840225230534280017695045717261514215145256795880310933667407841, + 9692530233397639077769939390011937602190121885296235066426091743618448584134, + 7914031992737639503490179289412369887137436318696390718781298556229610513180, + 5046304088054212585035723354298412694927209198400753780585596829596665931980, + 12735457541003664856181534137486291132119134214862779086936585300598349629287, + 8144204472889944485922664106370529127382213990656088602566223875490414163362, + 5526161442679804982165840590640681348630369336752481706044759543203459722566, + 4665464612431440885211271075488840033628676516298384234452346107374012633528, + 8451965709652752887539585363308640999657377914501438391781526068371105983117, + 18990458193856163728406448194111866469438835810342179114684453609893347662421, + 14602960690767985987882800342208585041637986661619503513589079723840776294824, + 294650277854196485752526848096008214721988745350555311479128101695333774927, + 9930361494944692931597991649915857642608730961125454734483697613693272941776, + 17972565769620820679641368732920396905240248490243886868922250461473059009007, + 11842743032528966560856860268344505094861546674985872961254820091273444880060, + 2260251491209762630871337015316066081541066308706934094017641769176593121838, + 21336986809148977544823484666876006147697590184356254785752148187171367963063, + 15637234083283356311249527335446193685599985235080555266374006156231977517227, + 7637477891046186378249227336975234440873859617986704147458186423096226771577, + 10435340982947407847927678888878882924793449778165415690957335683641419176012, + 21071574044063633264442120715854514033847137356154103023224485568597330648075, + 20085745552872944745120547909310789275453780111307008151203836541147270866122, + 2369255222739182549768488367357061329939116877812397072967912842660453854658, + 3320710154094663715463854219978294133429318041799642537800174050047893035878, + 2437552820481788519744888712380245016748276158860265401041560980354471184914, + 6687580113987208531705167517979176727449238324356562435678492283111952291541, + 13835828959457330678345759960614663723017667326485961761361157914420441377430, + 1823843951353887792473925888956554516299304358703549730900495356152013614424, + 18229384804985230011714562427207966412342158903455811854157839446374012856695, + 4983049472282717134994110428470567601005310848076496400503178535459679438524, + 2047051967230753763135778305592853785901616983565528680886843131244871631064, + 17059505494771925862841990046823342770591010831955480339095397897088168520686, + 5845823714127413134610517798305104245114036685335948729450609519089263487144, + 19810252752845594230307894817800427820113926573704856490871938876757561680148, + 20741340243371419379519807725035036726040739024854919427690724405113594586449, + 17305746835229988220561638584011917989169628535378748397361130724475478785704, + 16273970657972145440112726408308019138099820274904080726219726815138597785735, + 4927605725478881247988642936459897069651251926499343645614635597380235002430, + 4076655226193629464789557616268492785057128805549395585385432329518368497686, + 18134767316186963456589895259454813585756254459227058992203617493951135964914, + 20798436806114056077588608064161229365173163847083955162560624566238528904361, + 8811900287453512972593412116532745098600991077158875340182906101108258578231, + 1611466530857794066271650650204918615746591649578992581483080164777650137733, + 19520757346022691586967284723955378385034675472244175822936613026597514818901, + 8258287931139503595713718829279050060190693609290797346704848518381891359704, + 13807143439443425137076128013998009581746894329904809421858222329599144124143, + 2034200548964915935625429760202284220693125881760822084201315022529206424506, + 20594375914400911567795140472107624446159181622166676420027082349633992663301, + 17773828019575037451999782968066986504577459910353828196403976545023426528432, + 10645884969014005687699860915213473815514464399964009808411811895545112650817, + 3135829883501342672772973577699379927756997243617424917654928164800203666496, + 21807676600134151299257078976418813484444183016737321278512745883771478511369, + 14168063038909284721702678019083222059818438340503980617872573468231611140141, + 19022539506931505257153342575586362988716958060936788031721967221986624233067, + 919797128086310623571009200546035983274688764270933413427846490906074137487, + 10651353481391913627770814216074873532920753703051075188645774021198634943682, + 21601553598752750925049978818528421110707879819831249175157596816870100048288, + 9544964974935674319204796617933096476421551193682156030394816088243121582636, + 17113833205578964054057051521784698139661258340576694677296240312431808476286, + 9889647672195559279745677506312894570402108521106900082889976819798270827735, + 16028191999932520938901585234936954312994452706490572504997534210876573833649, + 19224701772787524647172128751148104366752057774529591812815327738829591289117, + 8065294760892477625290114823800398061529770004833832691347498933238361039736, + 8385011404987806129246014860479833290406969218526611328586242951296814426438, + 17626526623257098006524211054563886193098683828265081734658432468695686509315, + 9760584950604786147191288118087660976225563461953070125437519145090832114537, + 3282956645059793949082172795607530130101621492305193365378997603911833418463, + 3788543541342252822847978185963388795825378340921321139695221828685330606335, + 5728277403393912877393143174229934529937061751983246730506397742038949251701, + 20532577038632159357383817240596922896191478140446876998140515404169184846609, + 6138500779693128517529525961343097735306947649093633133232282430353593175172, + 16387038830089541476468870208162294639575042754761542956218362331966004300870, + 10184264376398708852688445921404363179240954227345322711923845040842165453208, + 12576299651793170522912156101640799825541149618303513174146382191633847258859, + 1340015400080181141720946234858756484323564628916867888877667239334982793481, + 733959369856163480135680991009606990817015555938726628110611986599242143578, + 11467033813562140192244869512537566463715027496952375979909160849747976831918, + 4619667645046391146577435774790188488541561222783010406420406869960248783331, + 58552761198135931030902257754896948615688045302818928845814661296914920622, + 1199849881730507352706524556330002080538296688430736582840314007371442152147, + 7124502590511184113044595527748024819132713282667933641439666531514739645089, + 8623660134669459112474551498616256867375253975034970808437732784494772311361, + 12655669439191191182341423414424342421477486764113555800095493091893820045534, + 18432703875775002490514477493898870315422995231506677048275960580528644904682, + 15467220287938881354678249472400749704814316816035426814619089032223454845193, + 2851120240492392321044027263769720216640877441121430445737594074121655318176, + 20519914249934881206828098454303256358482675671718589102535780334267934987941, + 17275124961392392047135728713829752470490098022504524438869454049765356211723, + 3323710067527231515807603961736782048796606296990840839366613937968342331886, + 4468708240622802562056471128793253296493002925988003094771284205007772045098, + 9006494818135081033869830730030943407240565201693254355620348420258773924028, + 2624130417875598753127999576825019766166727976335690685433712946223008520912, + 164131399455376615654870570697119442360078693174350746600132391198500093412, + 14931668887432843139264972187415200544679230597820424081936926034478502874299, + 1638753880783574431267395352024193675000113296497173968722590753809640941864, + 15505380865926802396097545843811910443367233632805651511272732002583232431557, + 17973744614207669251901495093091561913998272050499760575282030108740677066624, + 6137688223696761009295745609563284204827706564566466060484103844265403078408, + 14774243062532823236792831566222119634320864630838624098798648826842418775856, + 15864970393171078370207775103899428499600152663946379517190945807315353544891, + 19010063123357565300336230971672519561204810737546730911549311353159512986740, + 12607162829921425080830052984475623157169603642577010527391007035133383807243, + 17803108634879437217723652777640120469990779759700458421844361066182881628345, + 10065874953507223318296028499872542865030107611981933577973812883589535269142, + 3276471432535144390388324850641020151392959100393035635141206272558418581928, + 7532054601401798035926415744768772852833516520318445183340725930886329458991, + 18893822928119227829016544343228228897166113682019317256005502643243867377334, + 15940597493253236451533839310728876441657428995464658827726295547815292644378, + 4268009387843764409267791203070919313017052533005657826253994943184768120896, + 21611251949238422413354051947529388972078300717392131751061464498329326474580, + 12516447001729804412674006874184731098280474050775388553768469608793631490618, + 49838549447142926741568525697026885045023997277705726329780325103507790978, + 19763902910323896567698991616245963026306943100978479625077573937114135803058, + 12029297973430627253212633299020402005457460023136429653800185001711727387314, + 17676997725594777991384952086633589048516371093397126876621255518370680168503, + 10567543371894667303450346380722020266352683222046730266924342174164712049360, + 14583364850544999818712646438016435003942847076919084667364987497592599663937, + 17348091487238815837308569582101875357715798351834275089190053280855958465528, + 8743083090296259283603789316855921930102444739264013461469099560398359267240, + 15114064505647935792598848256320570567717917317803629185764147361301698519005, + 18332675991829764561879941291908436508530604635608341316693114747813051532006, + 1757567731797951053080580099911774643896363235228742197150882457231133285549, + 6526388717947413328592956348507481629843816325885832861915399601868279124246 ] ] -// t = 7 (6 inputs) -def poseidon_m_6() -> field[7][7]: +def poseidon_m() -> field[6][7][7]: return [ [ - 19332164824128329382868318451458022991369413618825711961282217322674570624669, - 12346323761995603285640868741615937712088302657627126374070962894016296466118, - 3913895681115272361294397190916803190924061797587910478563401817340941991811, - 7048322889096718105055545382948709082135086733564574465991576956878202831861, - 10375086910057323893637057154182902576957472442368661576421122036461645295833, - 12765622911241487148932810040772504127756393086809438933166282251044289864727, - 266900212758702307861826326591090138389415348463003233900705815890364224151 - ], - [ - 14435131616556129905356866638030823183270286404767286105643513738132789033353, - 5780976801287540146775934937953368730928109502001687434229528186520268917700, - 1618320442446662026869390273942730786145909339107736579759397243640902802126, - 3818399583522206096165108192531271582827953520684743806492664825009577810261, - 11764506724346386316602508039052965575734225646587104133777798242528580374987, - 2414215974836165993714858157462355581258152126063378817495129367240311967136, - 17609437036230923129211608175600293197801044251801590649435913902851695334081 + [ + 2910766817845651019878574839501801340070030115151021261302834310722729507541, + 19727366863391167538122140361473584127147630672623100827934084310230022599144, + 0, 0, 0, 0, 0 + ], + [ + 5776684794125549462448597414050232243778680302179439492664047328281728356345, + 8348174920934122550483593999453880006756108121341067172388445916328941978568, + 0, 0, 0, 0, 0 + ], + ...[[0; 7]; 5] ], [ - 363438080029711424794236047863047716381155074181485245036621530063262917196, - 535766679023716739184211613469394818313893958493710642899297971974381051070, - 5305068908469731303772738758164870877638068032868328180355958394150421214337, - 10807632568240507366657354568432178961148417327580695024415275247652313539292, - 15964415873358391713354948903242729080763777490509563223190335273158191600135, - 20700362719972015883260687302741075186857660623182772413609788566925949033885, - 10135127975676256977820296631533839366076919827597067890970660746228807376456 + [ + 7511745149465107256748700652201246547602992235352608707588321460060273774987, + 10370080108974718697676803824769673834027675643658433702224577712625900127200, + 19705173408229649878903981084052839426532978878058043055305024233888854471533, + 0, 0, 0, 0 + ], + [ + 18732019378264290557468133440468564866454307626475683536618613112504878618481, + 20870176810702568768751421378473869562658540583882454726129544628203806653987, + 7266061498423634438633389053804536045105766754026813321943009179476902321146, + 0, 0, 0, 0 + ], + [ + 9131299761947733513298312097611845208338517739621853568979632113419485819303, + 10595341252162738537912664445405114076324478519622938027420701542910180337937, + 11597556804922396090267472882856054602429588299176362916247939723151043581408, + 0, 0, 0, 0 + ], + ...[[0; 7]; 4] ], [ - 4251490167543116819728642817282216847143714366441358372252125244838181656331, - 7745587495915033527847242564710473705100826890903278244320948416581724663023, - 11741113129223221800185946819924457344647035336264986754437921049066977440806, - 11630296782890656599545188109639399768829653360050213193782325240600583381364, - 16861140446185941149398487176581839232380972247302922484807333229513905651035, - 365879246117123675211400356410703684399715291171114630107795112994207447819, - 21725607857580053522363567649763546934441685061337033780528788383243719579033 + [ + 16023668707004248971294664614290028914393192768609916554276071736843535714477, + 17849615858846139011678879517964683507928512741474025695659909954675835121177, + 1013663139540921998616312712475594638459213772728467613870351821911056489570, + 13211800058103802189838759488224684841774731021206389709687693993627918500545, + 0, 0, 0 + ], + [ + 19204974983793400699898444372535256207646557857575315905278218870961389967884, + 3722304780857845144568029505892077496425786544014166938942516810831732569870, + 11920634922168932145084219049241528148129057802067880076377897257847125830511, + 6085682566123812000257211683010755099394491689511511633947011263229442977967, + 0, 0, 0 + ], + [ + 14672613178263529785795301930884172260797190868602674472542654261498546023746, + 20850178060552184587113773087797340350525370429749200838012809627359404457643, + 7082289538076771741936674361200789891432311337766695368327626572220036527624, + 1787876543469562003404632310460227730887431311758627706450615128255538398187, + 0, 0, 0 + ], + [ + 21407770160218607278833379114951608489910182969042472165261557405353704846967, + 16058955581309173858487265533260133430557379878452348481750737813742488209262, + 593311177550138061601452020934455734040559402531605836278498327468203888086, + 341662423637860635938968460722645910313598807845686354625820505885069260074, + 0, 0, 0 + ], + ...[[0; 7]; 3] ], [ - 9222866548596464928765000608129177609426964853736257576074550520759533736918, - 10261578281201197531384003420612639018011405529775212563256392340336951230146, - 15644037447921591571869862919382888810859308861783088910843592577202362807673, - 12752004188139535619565478547449108772137477456363099481095747591698702436636, - 4205805109630387448825516813913983509046636797101589615147198457314360427718, - 21047095155106717901091873146599497621258071512562421967648909471775919992713, - 15624165295872926124160584750951090817255240214488120310950503163805737026315 + [ + 16789463359527776692258765063233607350971630674230623383979223533600140787105, + 17179611066821656668705197789232102741366879862607190942874777813024566441829, + 18653277315487164762584377009009109585010878033606596417396490909822722930739, + 7373070639853668650581790286343199505413793790160702463077019294817051722180, + 4823864393442908763804841692709014014130031798360007432734996408628916373879, + 0, 0 + ], + [ + 19196309854577132760746782449135315310664418272926255500908899397538686486585, + 18123132816088485879885148351452823314623055244145916622592591084094232513914, + 18436594886553181913092702411547018228276047601279727265790147051821171174455, + 15167500404313194506503404655898040457721633218143681920692711693000769735187, + 9437986152015460505719924283993842205604222075968464846270136901243896809793, + 0, 0 + ], + [ + 21445376105821232747280055223032050399373725161014449207033808524504027971613, + 49684738714301073369749035791061182456037935161360748355432247732088942674, + 9826409059947591908303145327284336313371973037536805760095514429930589897515, + 8494798325496773219358794086647759478982958403252584257436898618394561204124, + 21251937175072447337747316555423152807036003235223125066270735279039060889959, + 0, 0 + ], + [ + 5539100337780919206842837176908516952801756637410959104376645017856664270896, + 6297628909516159190915174165284309160976659474973668336571577778869958189934, + 12792263637464508665199868777503118105486490400267592501708855807938962470650, + 17254685306085558791725544672172906900581495686070720065168939143671412445514, + 3590396502942934679818900672232030233017710909687947858184099000783280809247, + 0, 0 + ], + [ + 19055249881366445073616526879263250763682650596233071589085239500077496415637, + 7367697936402141224946246030743627391716576575953707640061577218995381577033, + 1322791522030759131093883057746095061798181102708855007233180025036972924046, + 20456741074925985565499300081580917471340328842103779922028754640077047587707, + 9059147312071680695674575245237100802111605600478121517359780850134328696420, + 0, 0 + ], + ...[[0; 7]; 2] ], [ - 15064589937731741958666763896598138037875460434244947486199623542160035749721, - 1801577872277160959016940766173040841160105238799805406938450020949902989173, - 2896766420608048344829901127120623317655260981420052771341833288256800199953, - 12828791469509204618898135640019714232831708508424682785876476343251730674999, - 21363471986981372923191391880511344708743312828234098289107697080824665183315, - 21372706354350795416381912271616633829725494570576895047490974943034914894898, - 16006531510217730955981102005088687858079561573088629102219485906666961331083 + [ + 8266021233794274332054729525918686051968756165685671155584565440479247355160, + 7947823415909040438587565055355894256799314737783432792935458921778371169026, + 16508811191852041977017821887204137955816331040385276110261643892701458724933, + 1804800467126006102677564831888710635194614232739335985819349312754063580223, + 11189892034806587650995829160516587240879881493093022855087765921356611070470, + 20567450145123179140729389574352706949280207113956641415022972885523439610844, + 0 + ], + [ + 4666756311257455192796774305229624459258864488677689058174087310651786875914, + 11389253665835451896363091846189307652796786468610595637047377864063404843117, + 18793736599347263150867965517898541872137378991464725717839931503944801692688, + 4206344588923325482680116848820594823631536459347642329098796888497153867720, + 1739462481670645248707834504605096139894257554120906850613041004917967456145, + 18514227342636266640333254638454588508118462110178719555586534011641424431745, + 0 + ], + [ + 17887039315911403193186866703775654467672391491657957999455462537283842145802, + 2824959020572825365047639014537190268717891749361604043531643698340708119767, + 12521547103713919592301476538318318223836047611311454785951907894055964264287, + 8658146183671258251984364885894342376430874614261222570603159082682815800788, + 154390145585284450772861151318029820117470958184878116158462181541183085587, + 7593705166056392393963956710828665339496927193740869686529339432486182720653, + 0 + ], + [ + 5529559239163081088908568555890212324771345012509269613465629182165427812002, + 3729910453162885538930719732708124491456460687048972152311428493400220125686, + 11942815243552870715777415109008273807076911177089425348095503288499102855779, + 498938524453430895689241565973888863905147713935369405079343247530256066618, + 3976257517234324421403708035200810671331954932478384823208414346189926720724, + 723540703523219510043977323240437576248315561543814629392162302024056718473, + 0 + ], + [ + 13306548824219676333032339487546407241767961556934015003605485324283250885682, + 7970147269291664639740298762956131361316495463191268382513594527221399186752, + 20633313939958767604804835838065337107615699351647541991788258289962727735454, + 17162090859520817529294904484646695645841022315617926715432606252643123848792, + 9181379842957190051440498041153333325098774266789773971685141362947015398641, + 7051606617662816798224904133351061549832959857069896192072217769241273559278, + 0 + ], + [ + 16619522548478824222688310091434959542211899852679631815023615875678448806029, + 14965311177811968100298579672135357167599499478246106482433786066289128683961, + 9792733250919070275775594069208673385381167169182805600474820364274865306108, + 2069253833779081039049908513863485270550301879399727430830923273191877809560, + 15847298987712771667136245955631872888473964330474501593909263901393348546986, + 12244443532166430060291409356011430759892629145539185535677568234713942157668, + 0 + ], + [0; 7] ], [ - 2389357602244845938251345005183369360523566673990464798041306722747500447645, - 15275955107196234672088664710679934029171843237458844492987233368659104714648, - 8038797517535218686870517662905230585331773059774130312418943649247287196930, - 17923922393436914864421862212181654800719733137689602673604754147078808030201, - 12890519745320143484176500044628647247549456778462652469313611980363507314914, - 8058516556024397257577081553178859094042894928866720408652077334516681924252, - 768425396034382182896247252731538808045254601036758108993106260984310129743 + [ + 19332164824128329382868318451458022991369413618825711961282217322674570624669, + 12346323761995603285640868741615937712088302657627126374070962894016296466118, + 3913895681115272361294397190916803190924061797587910478563401817340941991811, + 7048322889096718105055545382948709082135086733564574465991576956878202831861, + 10375086910057323893637057154182902576957472442368661576421122036461645295833, + 12765622911241487148932810040772504127756393086809438933166282251044289864727, + 266900212758702307861826326591090138389415348463003233900705815890364224151 + ], + [ + 14435131616556129905356866638030823183270286404767286105643513738132789033353, + 5780976801287540146775934937953368730928109502001687434229528186520268917700, + 1618320442446662026869390273942730786145909339107736579759397243640902802126, + 3818399583522206096165108192531271582827953520684743806492664825009577810261, + 11764506724346386316602508039052965575734225646587104133777798242528580374987, + 2414215974836165993714858157462355581258152126063378817495129367240311967136, + 17609437036230923129211608175600293197801044251801590649435913902851695334081 + ], + [ + 363438080029711424794236047863047716381155074181485245036621530063262917196, + 535766679023716739184211613469394818313893958493710642899297971974381051070, + 5305068908469731303772738758164870877638068032868328180355958394150421214337, + 10807632568240507366657354568432178961148417327580695024415275247652313539292, + 15964415873358391713354948903242729080763777490509563223190335273158191600135, + 20700362719972015883260687302741075186857660623182772413609788566925949033885, + 10135127975676256977820296631533839366076919827597067890970660746228807376456 + ], + [ + 4251490167543116819728642817282216847143714366441358372252125244838181656331, + 7745587495915033527847242564710473705100826890903278244320948416581724663023, + 11741113129223221800185946819924457344647035336264986754437921049066977440806, + 11630296782890656599545188109639399768829653360050213193782325240600583381364, + 16861140446185941149398487176581839232380972247302922484807333229513905651035, + 365879246117123675211400356410703684399715291171114630107795112994207447819, + 21725607857580053522363567649763546934441685061337033780528788383243719579033 + ], + [ + 9222866548596464928765000608129177609426964853736257576074550520759533736918, + 10261578281201197531384003420612639018011405529775212563256392340336951230146, + 15644037447921591571869862919382888810859308861783088910843592577202362807673, + 12752004188139535619565478547449108772137477456363099481095747591698702436636, + 4205805109630387448825516813913983509046636797101589615147198457314360427718, + 21047095155106717901091873146599497621258071512562421967648909471775919992713, + 15624165295872926124160584750951090817255240214488120310950503163805737026315 + ], + [ + 15064589937731741958666763896598138037875460434244947486199623542160035749721, + 1801577872277160959016940766173040841160105238799805406938450020949902989173, + 2896766420608048344829901127120623317655260981420052771341833288256800199953, + 12828791469509204618898135640019714232831708508424682785876476343251730674999, + 21363471986981372923191391880511344708743312828234098289107697080824665183315, + 21372706354350795416381912271616633829725494570576895047490974943034914894898, + 16006531510217730955981102005088687858079561573088629102219485906666961331083 + ], + [ + 2389357602244845938251345005183369360523566673990464798041306722747500447645, + 15275955107196234672088664710679934029171843237458844492987233368659104714648, + 8038797517535218686870517662905230585331773059774130312418943649247287196930, + 17923922393436914864421862212181654800719733137689602673604754147078808030201, + 12890519745320143484176500044628647247549456778462652469313611980363507314914, + 8058516556024397257577081553178859094042894928866720408652077334516681924252, + 768425396034382182896247252731538808045254601036758108993106260984310129743 + ] ] ] \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok b/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok index 454213ebd..bcb80b99d 100644 --- a/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok +++ b/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok @@ -1,6 +1,9 @@ // https://eprint.iacr.org/2019/458.pdf -def ark(field[N] state, field[C] c, u32 it) -> field[N]: +from "./constants.zok" import poseidon_c +from "./constants.zok" import poseidon_m + +def ark(field[N] state, field[497] c, u32 it) -> field[N]: for u32 i in 0..N do state[i] = state[i] + c[it + i] endfor @@ -13,7 +16,7 @@ def sbox(field[N] state, u32 f, u32 p, u32 r) -> field[N]: endfor return state -def mix(field[N] state, field[N][N] m) -> field[N]: +def mix(field[N] state, field[7][7] m) -> field[N]: field[N] out = [0; N] for u32 i in 0..N do field acc = 0 @@ -24,8 +27,8 @@ def mix(field[N] state, field[N][N] m) -> field[N]: endfor return out -def main(field[N] inputs, field[C] c, field[M][M] m) -> field: - assert(N > 0 && N <= 6) +def main(field[N] inputs) -> field: + assert(N > 0 && N <= 6) // max 6 inputs u32 t = N + 1 u32[8] rounds_p = [56, 57, 56, 60, 60, 63, 64, 63] @@ -33,6 +36,9 @@ def main(field[N] inputs, field[C] c, field[M][M] m) -> field: u32 f = 8 u32 p = rounds_p[(t - 2)] + field[497] c = poseidon_c()[t - 2] + field[7][7] m = poseidon_m()[t - 2] + field[t] state = [0; t] for u32 i in 1..t do state[i] = inputs[i - 1] diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok index e846e3796..615642541 100644 --- a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_1.zok @@ -1,7 +1,5 @@ -from "hashes/poseidon/constants" import poseidon_c_1 -from "hashes/poseidon/constants" import poseidon_m_1 import "hashes/poseidon/poseidon" as poseidon def main(field i) -> field: - field output = poseidon([i], poseidon_c_1(), poseidon_m_1()) + field output = poseidon([i]) return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok index 29e196fb5..5bfb32220 100644 --- a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_2.zok @@ -1,7 +1,5 @@ -from "hashes/poseidon/constants" import poseidon_c_2 -from "hashes/poseidon/constants" import poseidon_m_2 import "hashes/poseidon/poseidon" as poseidon def main(field[2] i) -> field: - field output = poseidon(i, poseidon_c_2(), poseidon_m_2()) + field output = poseidon(i) return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok index ddc2130c4..653b821be 100644 --- a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_3.zok @@ -1,7 +1,5 @@ -from "hashes/poseidon/constants" import poseidon_c_3 -from "hashes/poseidon/constants" import poseidon_m_3 import "hashes/poseidon/poseidon" as poseidon def main(field[3] i) -> field: - field output = poseidon(i, poseidon_c_3(), poseidon_m_3()) + field output = poseidon(i) return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok index eeef269c5..ae18de5a4 100644 --- a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_4.zok @@ -1,7 +1,5 @@ -from "hashes/poseidon/constants" import poseidon_c_4 -from "hashes/poseidon/constants" import poseidon_m_4 import "hashes/poseidon/poseidon" as poseidon def main(field[4] i) -> field: - field output = poseidon(i, poseidon_c_4(), poseidon_m_4()) + field output = poseidon(i) return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok index 586ad7690..dffb7b6b6 100644 --- a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_5.zok @@ -1,7 +1,5 @@ -from "hashes/poseidon/constants" import poseidon_c_5 -from "hashes/poseidon/constants" import poseidon_m_5 import "hashes/poseidon/poseidon" as poseidon def main(field[5] i) -> field: - field output = poseidon(i, poseidon_c_5(), poseidon_m_5()) + field output = poseidon(i) return output \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok index b9f101d94..a2459327e 100644 --- a/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok +++ b/zokrates_stdlib/tests/tests/hashes/poseidon/poseidon_6.zok @@ -1,7 +1,5 @@ -from "hashes/poseidon/constants" import poseidon_c_6 -from "hashes/poseidon/constants" import poseidon_m_6 import "hashes/poseidon/poseidon" as poseidon def main(field[6] i) -> field: - field output = poseidon(i, poseidon_c_6(), poseidon_m_6()) + field output = poseidon(i) return output \ No newline at end of file From 6f86979dbd39271bf88e7639ef956d8e016f1ff7 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 13 Apr 2021 17:03:35 +0200 Subject: [PATCH 18/95] add comments --- zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok b/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok index bcb80b99d..351a4bb45 100644 --- a/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok +++ b/zokrates_stdlib/stdlib/hashes/poseidon/poseidon.zok @@ -36,6 +36,12 @@ def main(field[N] inputs) -> field: u32 f = 8 u32 p = rounds_p[(t - 2)] + // Constants are padded with zeroes to the maximum value calculated by + // t * (f + p) = 497, where `t` (number of inputs + 1) is a max of 7. + // This is done to keep the function generic, as resulting array size depends on `t` + // and we do not want callers passing down constants. + // This should be revisited once compiler limitations are gone. + field[497] c = poseidon_c()[t - 2] field[7][7] m = poseidon_m()[t - 2] From 6faf3cb6890db04853c084d490462ec528217c0b Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 14 Apr 2021 17:23:30 +0200 Subject: [PATCH 19/95] update bit rotation logic in sha256 and blake2s, add bit rotation tests --- .../tests/tests/left_rotation.json | 46 ++++++ .../tests/tests/left_rotation.zok | 5 + .../tests/tests/left_rotation_bits.json | 46 ++++++ .../tests/tests/left_rotation_bits.zok | 9 ++ .../tests/tests/right_rotation.json | 46 ++++++ .../tests/tests/right_rotation.zok | 5 + .../tests/tests/right_rotation_bits.json | 46 ++++++ .../tests/tests/right_rotation_bits.zok | 9 ++ .../stdlib/hashes/blake2/blake2s_p.zok | 13 +- .../stdlib/hashes/sha256/shaRound.zok | 135 +++++++----------- 10 files changed, 266 insertions(+), 94 deletions(-) create mode 100644 zokrates_core_test/tests/tests/left_rotation.json create mode 100644 zokrates_core_test/tests/tests/left_rotation.zok create mode 100644 zokrates_core_test/tests/tests/left_rotation_bits.json create mode 100644 zokrates_core_test/tests/tests/left_rotation_bits.zok create mode 100644 zokrates_core_test/tests/tests/right_rotation.json create mode 100644 zokrates_core_test/tests/tests/right_rotation.zok create mode 100644 zokrates_core_test/tests/tests/right_rotation_bits.json create mode 100644 zokrates_core_test/tests/tests/right_rotation_bits.zok diff --git a/zokrates_core_test/tests/tests/left_rotation.json b/zokrates_core_test/tests/tests/left_rotation.json new file mode 100644 index 000000000..b1542d41d --- /dev/null +++ b/zokrates_core_test/tests/tests/left_rotation.json @@ -0,0 +1,46 @@ +{ + "entry_point": "./tests/tests/left_rotation.zok", + "max_constraint_count": 34, + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["4"] + } + } + }, + { + "input": { + "values": ["42"] + }, + "output": { + "Ok": { + "values": ["168"] + } + } + }, + { + "input": { + "values": ["2147483658"] + }, + "output": { + "Ok": { + "values": ["42"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/left_rotation.zok b/zokrates_core_test/tests/tests/left_rotation.zok new file mode 100644 index 000000000..1813acf3d --- /dev/null +++ b/zokrates_core_test/tests/tests/left_rotation.zok @@ -0,0 +1,5 @@ +def rotl32(u32 x) -> u32: + return ((x << N) | (x >> (32 - N))) + +def main(u32 i) -> u32: + return rotl32::<2>(i) \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/left_rotation_bits.json b/zokrates_core_test/tests/tests/left_rotation_bits.json new file mode 100644 index 000000000..386ee93ca --- /dev/null +++ b/zokrates_core_test/tests/tests/left_rotation_bits.json @@ -0,0 +1,46 @@ +{ + "entry_point": "./tests/tests/left_rotation_bits.zok", + "max_constraint_count": 34, + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["4"] + } + } + }, + { + "input": { + "values": ["42"] + }, + "output": { + "Ok": { + "values": ["168"] + } + } + }, + { + "input": { + "values": ["2147483658"] + }, + "output": { + "Ok": { + "values": ["42"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/left_rotation_bits.zok b/zokrates_core_test/tests/tests/left_rotation_bits.zok new file mode 100644 index 000000000..49de4de67 --- /dev/null +++ b/zokrates_core_test/tests/tests/left_rotation_bits.zok @@ -0,0 +1,9 @@ +import "EMBED/u32_to_bits" as to_bits +import "EMBED/u32_from_bits" as from_bits + +def rotl32(u32 e) -> u32: + bool[32] b = to_bits(e) + return from_bits([...b[N..], ...b[..N]]) + +def main(u32 i) -> u32: + return rotl32::<2>(i) \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/right_rotation.json b/zokrates_core_test/tests/tests/right_rotation.json new file mode 100644 index 000000000..9ca8d55c0 --- /dev/null +++ b/zokrates_core_test/tests/tests/right_rotation.json @@ -0,0 +1,46 @@ +{ + "entry_point": "./tests/tests/right_rotation.zok", + "max_constraint_count": 34, + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["1073741824"] + } + } + }, + { + "input": { + "values": ["42"] + }, + "output": { + "Ok": { + "values": ["2147483658"] + } + } + }, + { + "input": { + "values": ["2147483658"] + }, + "output": { + "Ok": { + "values": ["2684354562"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/right_rotation.zok b/zokrates_core_test/tests/tests/right_rotation.zok new file mode 100644 index 000000000..460c5262c --- /dev/null +++ b/zokrates_core_test/tests/tests/right_rotation.zok @@ -0,0 +1,5 @@ +def rotr32(u32 x) -> u32: + return (x >> N) ^ (x << (32 - N)) + +def main(u32 i) -> u32: + return rotr32::<2>(i) \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/right_rotation_bits.json b/zokrates_core_test/tests/tests/right_rotation_bits.json new file mode 100644 index 000000000..0141c4be4 --- /dev/null +++ b/zokrates_core_test/tests/tests/right_rotation_bits.json @@ -0,0 +1,46 @@ +{ + "entry_point": "./tests/tests/right_rotation_bits.zok", + "max_constraint_count": 34, + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["1073741824"] + } + } + }, + { + "input": { + "values": ["42"] + }, + "output": { + "Ok": { + "values": ["2147483658"] + } + } + }, + { + "input": { + "values": ["2147483658"] + }, + "output": { + "Ok": { + "values": ["2684354562"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/right_rotation_bits.zok b/zokrates_core_test/tests/tests/right_rotation_bits.zok new file mode 100644 index 000000000..d18bc0809 --- /dev/null +++ b/zokrates_core_test/tests/tests/right_rotation_bits.zok @@ -0,0 +1,9 @@ +import "EMBED/u32_to_bits" as to_bits +import "EMBED/u32_from_bits" as from_bits + +def rotr32(u32 e) -> u32: + bool[32] b = to_bits(e) + return from_bits([...b[32-N..], ...b[..32-N]]) + +def main(u32 i) -> u32: + return rotr32::<2>(i) \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok b/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok index 239f9fce0..22b40e3be 100644 --- a/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok +++ b/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok @@ -3,9 +3,8 @@ import "EMBED/u32_to_bits" as to_bits import "EMBED/u32_from_bits" as from_bits -def right_rotate(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[32 - N..], ...b[..32 - N]]) +def rotr32(u32 e) -> u32: + return (x >> N) ^ (x << (32 - N)) def blake2s_iv() -> (u32[8]): return [ @@ -29,13 +28,13 @@ def blake2s_sigma() -> (u32[10][16]): def mixing_g(u32[16] v, u32 a, u32 b, u32 c, u32 d, u32 x, u32 y) -> (u32[16]): v[a] = (v[a] + v[b] + x) - v[d] = right_rotate::<16>(v[d] ^ v[a]) + v[d] = rotr32::<16>(v[d] ^ v[a]) v[c] = (v[c] + v[d]) - v[b] = right_rotate::<12>(v[b] ^ v[c]) + v[b] = rotr32::<12>(v[b] ^ v[c]) v[a] = (v[a] + v[b] + y) - v[d] = right_rotate::<8>(v[d] ^ v[a]) + v[d] = rotr32::<8>(v[d] ^ v[a]) v[c] = (v[c] + v[d]) - v[b] = right_rotate::<7>(v[b] ^ v[c]) + v[b] = rotr32::<7>(v[b] ^ v[c]) return v def blake2s_compression(u32[8] h, u32[16] m, u32[2] t, bool last) -> (u32[8]): diff --git a/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok b/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok index b1248f6de..a534b22f0 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok +++ b/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok @@ -1,68 +1,29 @@ -import "EMBED/u32_to_bits" as to_bits -import "EMBED/u32_from_bits" as from_bits import "./IVconstants.zok" -def right_rotate_2(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[30..], ...b[..30]]) - -def right_rotate_6(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[26..], ...b[..26]]) - -def right_rotate_7(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[25..], ...b[..25]]) - -def right_rotate_11(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[21..], ...b[..21]]) - -def right_rotate_13(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[19..], ...b[..19]]) - -def right_rotate_17(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[15..], ...b[..15]]) - -def right_rotate_18(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[14..], ...b[..14]]) - -def right_rotate_19(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[13..], ...b[..13]]) - -def right_rotate_22(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[10..], ...b[..10]]) - -def right_rotate_25(u32 e) -> u32: - bool[32] b = to_bits(e) - return from_bits([...b[7..], ...b[..7]]) +def rotr32(u32 e) -> u32: + return (x >> N) ^ (x << (32 - N)) def extend(u32[64] w, u32 i) -> u32: - u32 s0 = right_rotate_7(w[i-15]) ^ right_rotate_18(w[i-15]) ^ (w[i-15] >> 3) - u32 s1 = right_rotate_17(w[i-2]) ^ right_rotate_19(w[i-2]) ^ (w[i-2] >> 10) + u32 s0 = rotr32::<7>(w[i-15]) ^ rotr32::<18>(w[i-15]) ^ (w[i-15] >> 3) + u32 s1 = rotr32::<17>(w[i-2]) ^ rotr32::<19>(w[i-2]) ^ (w[i-2] >> 10) return w[i-16] + s0 + w[i-7] + s1 def temp1(u32 e, u32 f, u32 g, u32 h, u32 k, u32 w) -> u32: - // ch := (e and f) xor ((not e) and g) - u32 ch = (e & f) ^ ((!e) & g) + // ch := (e and f) xor ((not e) and g) + u32 ch = (e & f) ^ ((!e) & g) - // S1 := (e rightrotate 6) xor (e rightrotate 11) xor (e rightrotate 25) - u32 S1 = right_rotate_6(e) ^ right_rotate_11(e) ^ right_rotate_25(e) - - // temp1 := h + S1 + ch + k + w - return h + S1 + ch + k + w + // S1 := (e rightrotate 6) xor (e rightrotate 11) xor (e rightrotate 25) + u32 S1 = rotr32::<6>(e) ^ rotr32::<11>(e) ^ rotr32::<25>(e) + + // temp1 := h + S1 + ch + k + w + return h + S1 + ch + k + w def temp2(u32 a, u32 b, u32 c) -> u32: - // maj := (a and b) xor (a and c) xor (b and c) + // maj := (a and b) xor (a and c) xor (b and c) u32 maj = (a & b) ^ (a & c) ^ (b & c) - // S0 := (a rightrotate 2) xor (a rightrotate 13) xor (a rightrotate 22) - u32 S0 = right_rotate_2(a) ^ right_rotate_13(a) ^ right_rotate_22(a) + // S0 := (a rightrotate 2) xor (a rightrotate 13) xor (a rightrotate 22) + u32 S0 = rotr32::<2>(a) ^ rotr32::<13>(a) ^ rotr32::<22>(a) // temp2 := S0 + maj return S0 + maj @@ -71,37 +32,37 @@ def temp2(u32 a, u32 b, u32 c) -> u32: // this is used by other components however many times needed def main(u32[16] input, u32[8] current) -> u32[8]: - u32 h0 = current[0] - u32 h1 = current[1] - u32 h2 = current[2] - u32 h3 = current[3] - u32 h4 = current[4] - u32 h5 = current[5] - u32 h6 = current[6] - u32 h7 = current[7] + u32 h0 = current[0] + u32 h1 = current[1] + u32 h2 = current[2] + u32 h3 = current[3] + u32 h4 = current[4] + u32 h5 = current[5] + u32 h6 = current[6] + u32 h7 = current[7] - u32[64] k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2] + u32[64] k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2] - u32[64] w = [...input, ...[0x00000000; 48]] + u32[64] w = [...input, ...[0x00000000; 48]] - for u32 i in 16..64 do + for u32 i in 16..64 do w[i] = extend(w, i) - endfor + endfor - u32 a = h0 - u32 b = h1 - u32 c = h2 - u32 d = h3 - u32 e = h4 - u32 f = h5 - u32 g = h6 - u32 h = h7 + u32 a = h0 + u32 b = h1 + u32 c = h2 + u32 d = h3 + u32 e = h4 + u32 f = h5 + u32 g = h6 + u32 h = h7 - for u32 i in 0..64 do + for u32 i in 0..64 do - u32 t1 = temp1(e, f, g, h, k[i], w[i]) + u32 t1 = temp1(e, f, g, h, k[i], w[i]) - u32 t2 = temp2(a, b, c) + u32 t2 = temp2(a, b, c) h = g g = f @@ -112,16 +73,16 @@ def main(u32[16] input, u32[8] current) -> u32[8]: b = a a = t1 + t2 - endfor + endfor - h0 = h0 + a - h1 = h1 + b - h2 = h2 + c - h3 = h3 + d - h4 = h4 + e - h5 = h5 + f - h6 = h6 + g - h7 = h7 + h + h0 = h0 + a + h1 = h1 + b + h2 = h2 + c + h3 = h3 + d + h4 = h4 + e + h5 = h5 + f + h6 = h6 + g + h7 = h7 + h - return [h0, h1, h2, h3, h4, h5, h6, h7] - + return [h0, h1, h2, h3, h4, h5, h6, h7] + From c8b9436ee1eabfd2ae0bfbd49f9c1baf4c8b669e Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 14 Apr 2021 17:40:45 +0200 Subject: [PATCH 20/95] fix typo --- zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok | 2 +- zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok b/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok index 22b40e3be..0cde1f2c7 100644 --- a/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok +++ b/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok @@ -3,7 +3,7 @@ import "EMBED/u32_to_bits" as to_bits import "EMBED/u32_from_bits" as from_bits -def rotr32(u32 e) -> u32: +def rotr32(u32 x) -> u32: return (x >> N) ^ (x << (32 - N)) def blake2s_iv() -> (u32[8]): diff --git a/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok b/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok index a534b22f0..cbeb35fbf 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok +++ b/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok @@ -1,6 +1,6 @@ import "./IVconstants.zok" -def rotr32(u32 e) -> u32: +def rotr32(u32 x) -> u32: return (x >> N) ^ (x << (32 - N)) def extend(u32[64] w, u32 i) -> u32: From ec50be4d28de3d1b014415c0c2acbf225cc0b0ec Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 14 Apr 2021 20:03:14 +0200 Subject: [PATCH 21/95] fix typos --- changelogs/unreleased/809-dark64 | 2 +- zokrates_book/src/language/imports.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/unreleased/809-dark64 b/changelogs/unreleased/809-dark64 index 3481fc4b6..07749eb32 100644 --- a/changelogs/unreleased/809-dark64 +++ b/changelogs/unreleased/809-dark64 @@ -1 +1 @@ -Add ability to import multiple symbols in a single import statement \ No newline at end of file +Add the ability to import multiple symbols in a single import statement \ No newline at end of file diff --git a/zokrates_book/src/language/imports.md b/zokrates_book/src/language/imports.md index f8592c0ef..fef1083de 100644 --- a/zokrates_book/src/language/imports.md +++ b/zokrates_book/src/language/imports.md @@ -13,7 +13,7 @@ from "./path/to/my/module" import MySymbol // `MySymbol` is now in scope. ``` -To import multiple modules with a single import statement, separate the module names with commas: +To import multiple symbols with a single import statement, separate the symbols names with commas: ```zokrates from "./path/to/my/module" import MySymbol, MyOtherSymbol From c80d2faf774bee9542fb86ce629c410d83aba852 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 14 Apr 2021 20:07:05 +0200 Subject: [PATCH 22/95] replace XOR with OR --- zokrates_core_test/tests/tests/right_rotation.zok | 2 +- zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok | 2 +- zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zokrates_core_test/tests/tests/right_rotation.zok b/zokrates_core_test/tests/tests/right_rotation.zok index 460c5262c..900488790 100644 --- a/zokrates_core_test/tests/tests/right_rotation.zok +++ b/zokrates_core_test/tests/tests/right_rotation.zok @@ -1,5 +1,5 @@ def rotr32(u32 x) -> u32: - return (x >> N) ^ (x << (32 - N)) + return (x >> N) | (x << (32 - N)) def main(u32 i) -> u32: return rotr32::<2>(i) \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok b/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok index 0cde1f2c7..acb5dc811 100644 --- a/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok +++ b/zokrates_stdlib/stdlib/hashes/blake2/blake2s_p.zok @@ -4,7 +4,7 @@ import "EMBED/u32_to_bits" as to_bits import "EMBED/u32_from_bits" as from_bits def rotr32(u32 x) -> u32: - return (x >> N) ^ (x << (32 - N)) + return (x >> N) | (x << (32 - N)) def blake2s_iv() -> (u32[8]): return [ diff --git a/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok b/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok index cbeb35fbf..c06080d4c 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok +++ b/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok @@ -1,7 +1,7 @@ import "./IVconstants.zok" def rotr32(u32 x) -> u32: - return (x >> N) ^ (x << (32 - N)) + return (x >> N) | (x << (32 - N)) def extend(u32[64] w, u32 i) -> u32: u32 s0 = rotr32::<7>(w[i-15]) ^ rotr32::<18>(w[i-15]) ^ (w[i-15] >> 3) From c8322bf0db8012eaad5048ac06164922072bdd8b Mon Sep 17 00:00:00 2001 From: schaeff Date: Thu, 15 Apr 2021 15:58:10 +0200 Subject: [PATCH 23/95] wip --- lt.zok | 47 ++++++++++ manual.zok | 8 ++ zokrates_core/src/compile.rs | 2 + zokrates_core/src/flatten/mod.rs | 33 ++++--- zokrates_core_test/tests/tests/le.json | 86 +++++++++++++++++++ zokrates_core_test/tests/tests/le.zok | 2 + zokrates_core_test/tests/tests/native_le.json | 86 +++++++++++++++++++ zokrates_core_test/tests/tests/native_le.zok | 41 +++++++++ 8 files changed, 291 insertions(+), 14 deletions(-) create mode 100644 lt.zok create mode 100644 manual.zok create mode 100644 zokrates_core_test/tests/tests/le.json create mode 100644 zokrates_core_test/tests/tests/le.zok create mode 100644 zokrates_core_test/tests/tests/native_le.json create mode 100644 zokrates_core_test/tests/tests/native_le.zok diff --git a/lt.zok b/lt.zok new file mode 100644 index 000000000..2d657c091 --- /dev/null +++ b/lt.zok @@ -0,0 +1,47 @@ +from "utils/pack/bool/unpack.zok" import main as unpack +from "utils/casts/u32_to_bits" import main as u32_to_bits + +// this comparison works for any N smaller than the field size, which is the case in practice +def lt(bool[N] a_bits, bool[N] c_bits) -> bool: + + bool[N] is_not_smaller_run = [false; N] + bool[N] size_unknown = [false; N] + + u32 verified_conditions = 0 // `and(conditions) == (sum(conditions) == len(conditions))`, here we initialize `sum(conditions)` + + size_unknown[0] = true + + for u32 i in 0..N - 1 do + is_not_smaller_run[i] = if c_bits[i] then a_bits[i] else is_not_smaller_run[i] fi + size_unknown[i + 1] = if c_bits[i] then size_unknown[i] && is_not_smaller_run[i] else size_unknown[i] fi + verified_conditions = verified_conditions + if c_bits[i] then 1 else if (!size_unknown[i] || !a_bits[i]) then 1 else 0 fi fi + endfor + + u32 i = N - 1 + is_not_smaller_run[i] = if c_bits[i] then a_bits[i] else is_not_smaller_run[i] fi + verified_conditions = verified_conditions + if c_bits[i] then 1 else if (!size_unknown[i] || !a_bits[i]) then 1 else 0 fi fi + + return verified_conditions == N // this checks that all conditions were verified + +// this instanciates comparison starting from field elements +def lt(field a, field c) -> bool: + bool[N] a_bits = unpack(a) + bool[N] c_bits = unpack(c) + + return lt(a_bits, c_bits) + +// this instanciates comparison starting from u32 +def lt(u32 a, u32 c) -> bool: + bool[32] a_bits = u32_to_bits(a) + bool[32] c_bits = u32_to_bits(c) + + return lt(a_bits, c_bits) + +def main(field a) -> bool: + + u32 N = 254 + field c = 42 + + //u32 d = 42 + + return lt::(a, c) \ No newline at end of file diff --git a/manual.zok b/manual.zok new file mode 100644 index 000000000..cb8396d0e --- /dev/null +++ b/manual.zok @@ -0,0 +1,8 @@ +def main(field a) -> bool: + + //u32 N = 254 + field c = 42 + + //u32 d = 42 + + return a < c \ No newline at end of file diff --git a/zokrates_core/src/compile.rs b/zokrates_core/src/compile.rs index af5a91848..812ba473e 100644 --- a/zokrates_core/src/compile.rs +++ b/zokrates_core/src/compile.rs @@ -167,6 +167,8 @@ pub fn compile>( let (typed_ast, abi) = check_with_arena(source, location, resolver, &arena)?; + println!("{}", typed_ast); + // flatten input program let program_flattened = Flattener::flatten(typed_ast, config); diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 9ee78218a..c29780dfe 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -411,6 +411,20 @@ impl<'ast, T: Field> Flattener<'ast, T> { } } + fn constant_lt_check( + &mut self, + statements_flattened: &mut FlatStatements, + e: FlatExpression, + c: T, + ) -> FlatExpression { + if c == T::zero() { + // this is the case c == 0, we return 0, aka false + return T::zero().into(); + } + + self.constant_le_check(statements_flattened, e, c - T::one()) + } + /// Compute a range check against a constant /// /// # Arguments @@ -420,23 +434,13 @@ impl<'ast, T: Field> Flattener<'ast, T> { /// * `c` - the constant upper bound of the range /// /// # Returns - /// * a `FlatExpression` which evaluates to `1` if `0 <= e < c`, and to `0` otherwise - fn constant_range_check( + /// * a `FlatExpression` which evaluates to `1` if `0 <= e <= c`, and to `0` otherwise + fn constant_le_check( &mut self, statements_flattened: &mut FlatStatements, e: FlatExpression, c: T, ) -> FlatExpression { - // we make use of constant `<=` checks in this function, therefore we rely on the fact that: - // `a < c <=> (a <= c - 1 if c !=0, false if c == 0)` - - if c == T::zero() { - // this is the case c == 0, we return 0, aka false - return T::zero().into(); - } - - let c = c - T::one(); - let bit_width = T::get_required_bits(); // decompose e to bits let e_id = self.define(e, statements_flattened); @@ -534,10 +538,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { match (lhs_flattened, rhs_flattened) { (x, FlatExpression::Number(constant)) => { - self.constant_range_check(statements_flattened, x, constant) + println!("yo"); + self.constant_lt_check(statements_flattened, x, constant) } // (c < x <= p - 1) <=> (0 <= p - 1 - x < p - 1 - c) - (FlatExpression::Number(constant), x) => self.constant_range_check( + (FlatExpression::Number(constant), x) => self.constant_lt_check( statements_flattened, FlatExpression::Sub(box T::max_value().into(), box x), T::max_value() - constant, diff --git a/zokrates_core_test/tests/tests/le.json b/zokrates_core_test/tests/tests/le.json new file mode 100644 index 000000000..8a5092a9a --- /dev/null +++ b/zokrates_core_test/tests/tests/le.json @@ -0,0 +1,86 @@ +{ + "entry_point": "./tests/tests/le.zok", + "curves": ["Bn128"], + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["2"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["41"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["42"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["43"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["44"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["100"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/le.zok b/zokrates_core_test/tests/tests/le.zok new file mode 100644 index 000000000..fad82ef8b --- /dev/null +++ b/zokrates_core_test/tests/tests/le.zok @@ -0,0 +1,2 @@ +def main(field e) -> bool: + return e <= 42 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/native_le.json b/zokrates_core_test/tests/tests/native_le.json new file mode 100644 index 000000000..6d79147be --- /dev/null +++ b/zokrates_core_test/tests/tests/native_le.json @@ -0,0 +1,86 @@ +{ + "entry_point": "./tests/tests/native_le.zok", + "curves": ["Bn128"], + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["1"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["2"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["41"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["42"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["43"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["44"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["100"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/native_le.zok b/zokrates_core_test/tests/tests/native_le.zok new file mode 100644 index 000000000..abf72e352 --- /dev/null +++ b/zokrates_core_test/tests/tests/native_le.zok @@ -0,0 +1,41 @@ +from "utils/pack/bool/unpack.zok" import main as unpack +from "utils/casts/u32_to_bits" import main as u32_to_bits + +// this comparison works for any N smaller than the field size, which is the case in practice +def le(bool[N] a_bits, bool[N] c_bits) -> bool: + + bool size_unknown = false + + u32 verified_conditions = 0 // `and(conditions) == (sum(conditions) == len(conditions))`, here we initialize `sum(conditions)` + + size_unknown = true + + for u32 i in 0..N do + verified_conditions = verified_conditions + if c_bits[i] || (!size_unknown || !a_bits[i]) then 1 else 0 fi + size_unknown = if c_bits[i] then size_unknown && a_bits[i] else size_unknown fi // this is actually not required in the last round + endfor + + return verified_conditions == N // this checks that all conditions were verified + +// this instanciates comparison starting from field elements +def le(field a, field c) -> bool: + bool[N] a_bits = unpack(a) + bool[N] c_bits = unpack(c) + + return le(a_bits, c_bits) + +// this instanciates comparison starting from u32 +def le(u32 a, u32 c) -> bool: + bool[32] a_bits = u32_to_bits(a) + bool[32] c_bits = u32_to_bits(c) + + return le(a_bits, c_bits) + +def main(field a, field c) -> bool: + + u32 N = 254 + //field c = 42 + + //u32 d = 42 + + return le::(a, c) \ No newline at end of file From a3b22737d888fe5f3e25d40d65cc43c710aeac50 Mon Sep 17 00:00:00 2001 From: schaeff Date: Thu, 15 Apr 2021 16:43:11 +0200 Subject: [PATCH 24/95] consider input count and generics count in semantic checker, add tests --- .../compile_errors/too_many_arguments.zok | 5 ++++ .../compile_errors/too_many_generics.zok | 5 ++++ zokrates_core/src/semantics.rs | 24 +++++++++++++++++-- zokrates_core/src/typed_absy/types.rs | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 zokrates_cli/examples/compile_errors/too_many_arguments.zok create mode 100644 zokrates_cli/examples/compile_errors/too_many_generics.zok diff --git a/zokrates_cli/examples/compile_errors/too_many_arguments.zok b/zokrates_cli/examples/compile_errors/too_many_arguments.zok new file mode 100644 index 000000000..3efabfdbf --- /dev/null +++ b/zokrates_cli/examples/compile_errors/too_many_arguments.zok @@ -0,0 +1,5 @@ +def foo() -> field: + return 1 + +def main() -> field: + return foo(42) \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/too_many_generics.zok b/zokrates_cli/examples/compile_errors/too_many_generics.zok new file mode 100644 index 000000000..f34a17f5a --- /dev/null +++ b/zokrates_cli/examples/compile_errors/too_many_generics.zok @@ -0,0 +1,5 @@ +def foo() -> field: + return 1 + +def main() -> field: + return foo::<42>() \ No newline at end of file diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 3bd4f160d..bfa4a5c64 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -134,6 +134,7 @@ impl fmt::Display for ErrorInner { #[derive(Debug)] struct FunctionQuery<'ast, T> { id: Identifier<'ast>, + generics_count: Option, inputs: Vec>, /// Output types are optional as we try to infer them outputs: Vec>>, @@ -141,6 +142,20 @@ struct FunctionQuery<'ast, T> { impl<'ast, T: fmt::Display> fmt::Display for FunctionQuery<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self.generics_count { + Some(count) => { + write!( + f, + "<{}>", + (0..count) + .map(|_| String::from("_")) + .collect::>() + .join(", ") + )?; + } + None => {} + } + write!(f, "(")?; for (i, t) in self.inputs.iter().enumerate() { write!(f, "{}", t)?; @@ -181,11 +196,13 @@ impl<'ast, T: Field> FunctionQuery<'ast, T> { /// Create a new query. fn new( id: Identifier<'ast>, + generics: &Option>>>, inputs: &[Type<'ast, T>], outputs: &[Option>], ) -> Self { FunctionQuery { id, + generics_count: generics.as_ref().map(|g| g.len()), inputs: inputs.to_owned(), outputs: outputs.to_owned(), } @@ -194,6 +211,8 @@ impl<'ast, T: Field> FunctionQuery<'ast, T> { /// match a `FunctionKey` against this `FunctionQuery` fn match_func(&self, func: &DeclarationFunctionKey<'ast>) -> bool { self.id == func.id + && self.generics_count.map(|count| count == func.signature.generics.len()).unwrap_or(true) // we do not look at the values here, this will be checked when inlining anyway + && self.inputs.len() == func.signature.inputs.len() && self .inputs .iter() @@ -1340,7 +1359,7 @@ impl<'ast, T: Field> Checker<'ast, T> { let arguments_types: Vec<_> = arguments_checked.iter().map(|a| a.get_type()).collect(); - let query = FunctionQuery::new(&fun_id, &arguments_types, &assignee_types); + let query = FunctionQuery::new(&fun_id, &generics_checked, &arguments_types, &assignee_types); let functions = self.find_functions(&query); @@ -1883,7 +1902,8 @@ impl<'ast, T: Field> Checker<'ast, T> { // outside of multidef, function calls must have a single return value // we use type inference to determine the type of the return, so we don't specify it - let query = FunctionQuery::new(&fun_id, &arguments_types, &[None]); + let query = + FunctionQuery::new(&fun_id, &generics_checked, &arguments_types, &[None]); let functions = self.find_functions(&query); diff --git a/zokrates_core/src/typed_absy/types.rs b/zokrates_core/src/typed_absy/types.rs index 6622bddde..ac12cd594 100644 --- a/zokrates_core/src/typed_absy/types.rs +++ b/zokrates_core/src/typed_absy/types.rs @@ -993,6 +993,8 @@ pub mod signature { // we keep track of the value of constants in a map, as a given constant can only have one value let mut constants = ConcreteGenericsAssignment::default(); + assert_eq!(self.inputs.len(), signature.inputs.len()); + assert_eq!(self.outputs.len(), signature.outputs.len()); assert_eq!(self.generics.len(), values.len()); let decl_generics = self.generics.iter().map(|g| match g.clone().unwrap() { From 289a1b36c28cb1ba6098badca8ff41f3d2593e71 Mon Sep 17 00:00:00 2001 From: schaeff Date: Thu, 15 Apr 2021 17:01:50 +0200 Subject: [PATCH 25/95] remove custom hashes --- zokrates_core/src/typed_absy/types.rs | 63 +-------------------------- 1 file changed, 2 insertions(+), 61 deletions(-) diff --git a/zokrates_core/src/typed_absy/types.rs b/zokrates_core/src/typed_absy/types.rs index 6622bddde..9c905fc8d 100644 --- a/zokrates_core/src/typed_absy/types.rs +++ b/zokrates_core/src/typed_absy/types.rs @@ -11,42 +11,12 @@ pub type GenericIdentifier<'ast> = &'ast str; #[derive(Debug)] pub struct SpecializationError; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Constant<'ast> { Generic(GenericIdentifier<'ast>), Concrete(u32), } -// At this stage we want all constants to be equal -impl<'ast> PartialEq for Constant<'ast> { - fn eq(&self, _: &Self) -> bool { - true - } -} - -impl<'ast> PartialOrd for Constant<'ast> { - fn partial_cmp(&self, _: &Self) -> std::option::Option { - Some(std::cmp::Ordering::Equal) - } -} - -impl<'ast> Ord for Constant<'ast> { - fn cmp(&self, _: &Self) -> std::cmp::Ordering { - std::cmp::Ordering::Equal - } -} - -impl<'ast> Eq for Constant<'ast> {} - -impl<'ast> Hash for Constant<'ast> { - fn hash(&self, _: &mut H) - where - H: Hasher, - { - // we do not hash anything, as we want all constant to hash to the same thing - } -} - impl<'ast> From for Constant<'ast> { fn from(e: u32) -> Self { Constant::Concrete(e) @@ -849,42 +819,13 @@ pub mod signature { use super::*; use std::fmt; - #[derive(Clone, Serialize, Deserialize, Eq)] + #[derive(Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct GSignature { pub generics: Vec>, pub inputs: Vec>, pub outputs: Vec>, } - impl PartialOrd for GSignature { - fn partial_cmp(&self, other: &Self) -> std::option::Option { - match self.inputs.partial_cmp(&other.inputs) { - Some(std::cmp::Ordering::Equal) => self.outputs.partial_cmp(&other.outputs), - r => r, - } - } - } - - impl Ord for GSignature { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.partial_cmp(&other).unwrap() - } - } - - impl Hash for GSignature { - fn hash(&self, state: &mut H) { - self.inputs.hash(state); - self.outputs.hash(state); - } - } - - impl PartialEq for GSignature { - fn eq(&self, other: &GSignature) -> bool { - // we ignore generics as we want a generic function to conflict with its specialized (generics free) version - self.inputs == other.inputs && self.outputs == other.outputs - } - } - impl Default for GSignature { fn default() -> Self { GSignature { From f96dbd6254a7a74419dc0abf960299fb6c87bea3 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 15 Apr 2021 18:13:27 +0200 Subject: [PATCH 26/95] renaming --- zokrates_core/src/absy/from_ast.rs | 10 +++++----- zokrates_core/src/absy/mod.rs | 2 +- zokrates_core/src/imports.rs | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 7b29db1b3..1ba9b9586 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -19,23 +19,23 @@ impl<'ast> From> for absy::Module<'ast> { .imports( prog.imports .into_iter() - .map(absy::ImportKind::from) + .map(absy::ImportDirective::from) .flatten(), ) } } -impl<'ast> From> for absy::ImportKind<'ast> { - fn from(import: pest::ImportDirective<'ast>) -> absy::ImportKind<'ast> { +impl<'ast> From> for absy::ImportDirective<'ast> { + fn from(import: pest::ImportDirective<'ast>) -> absy::ImportDirective<'ast> { use crate::absy::NodeValue; match import { - pest::ImportDirective::Main(import) => absy::ImportKind::Single( + pest::ImportDirective::Main(import) => absy::ImportDirective::Main( imports::Import::new(None, std::path::Path::new(import.source.span.as_str())) .alias(import.alias.map(|a| a.span.as_str())) .span(import.span), ), - pest::ImportDirective::From(import) => absy::ImportKind::Multiple( + pest::ImportDirective::From(import) => absy::ImportDirective::From( import .symbols .iter() diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index 82c009e29..798bb93bb 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -18,7 +18,7 @@ pub use crate::absy::variable::{Variable, VariableNode}; use crate::embed::FlatEmbed; use std::path::{Path, PathBuf}; -use crate::imports::ImportKind; +use crate::imports::ImportDirective; use crate::imports::ImportNode; use std::fmt; diff --git a/zokrates_core/src/imports.rs b/zokrates_core/src/imports.rs index 38a03ad77..44ed8c79c 100644 --- a/zokrates_core/src/imports.rs +++ b/zokrates_core/src/imports.rs @@ -57,19 +57,19 @@ impl From for Error { } #[derive(PartialEq, Clone)] -pub enum ImportKind<'ast> { - Single(ImportNode<'ast>), - Multiple(Vec>), +pub enum ImportDirective<'ast> { + Main(ImportNode<'ast>), + From(Vec>), } -impl<'ast> IntoIterator for ImportKind<'ast> { +impl<'ast> IntoIterator for ImportDirective<'ast> { type Item = ImportNode<'ast>; type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { let vec = match self { - ImportKind::Single(v) => vec![v], - ImportKind::Multiple(v) => v, + ImportDirective::Main(v) => vec![v], + ImportDirective::From(v) => v, }; vec.into_iter() } From f2faa0a7819613096efe33fcbb38cdb4c3b2c914 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 15 Apr 2021 19:15:06 +0200 Subject: [PATCH 27/95] error out on failed assertion --- zokrates_cli/examples/compile_errors/assertion.zok | 3 +++ .../examples/compile_errors/generics/assertion.zok | 7 +++++++ .../{assert.zok => keyword_as_identifier.zok} | 0 zokrates_core/src/static_analysis/propagation.rs | 10 ++++++++++ 4 files changed, 20 insertions(+) create mode 100644 zokrates_cli/examples/compile_errors/assertion.zok create mode 100644 zokrates_cli/examples/compile_errors/generics/assertion.zok rename zokrates_cli/examples/compile_errors/{assert.zok => keyword_as_identifier.zok} (100%) diff --git a/zokrates_cli/examples/compile_errors/assertion.zok b/zokrates_cli/examples/compile_errors/assertion.zok new file mode 100644 index 000000000..046e62f50 --- /dev/null +++ b/zokrates_cli/examples/compile_errors/assertion.zok @@ -0,0 +1,3 @@ +def main(): + assert(1f == 2f) + return \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/generics/assertion.zok b/zokrates_cli/examples/compile_errors/generics/assertion.zok new file mode 100644 index 000000000..e235a6510 --- /dev/null +++ b/zokrates_cli/examples/compile_errors/generics/assertion.zok @@ -0,0 +1,7 @@ +def foo(field[N] inputs) -> bool: + assert(N <= 5) + return true + +def main(): + bool b = foo([1, 2, 3, 4, 5, 6]) + return diff --git a/zokrates_cli/examples/compile_errors/assert.zok b/zokrates_cli/examples/compile_errors/keyword_as_identifier.zok similarity index 100% rename from zokrates_cli/examples/compile_errors/assert.zok rename to zokrates_cli/examples/compile_errors/keyword_as_identifier.zok diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index fb32bdd7c..b85e36717 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -657,6 +657,16 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Ok(statements) } + TypedStatement::Assertion(ref e) => { + let expr = self.fold_boolean_expression(e.clone())?; + match expr { + BooleanExpression::Value(v) if !v => Err(Error::Type(format!( + "Assertion failed on expression `{}`", + e + ))), + _ => Ok(vec![TypedStatement::Assertion(expr)]), + } + } s @ TypedStatement::PushCallLog(..) => Ok(vec![s]), s @ TypedStatement::PopCallLog => Ok(vec![s]), s => fold_statement(self, s), From 0ac66da9ae9b2d0a2ecba1424d35820821c5f827 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 15 Apr 2021 19:24:27 +0200 Subject: [PATCH 28/95] add changelog --- changelogs/unreleased/823-dark64 | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 changelogs/unreleased/823-dark64 diff --git a/changelogs/unreleased/823-dark64 b/changelogs/unreleased/823-dark64 new file mode 100644 index 000000000..e69de29bb From abcf2f050ee8b0bc3e1cf4488f430646f8012b72 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 15 Apr 2021 19:40:10 +0200 Subject: [PATCH 29/95] update assert example --- zokrates_cli/examples/book/assert.zok | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_cli/examples/book/assert.zok b/zokrates_cli/examples/book/assert.zok index 75db27631..5d731a3eb 100644 --- a/zokrates_cli/examples/book/assert.zok +++ b/zokrates_cli/examples/book/assert.zok @@ -1,3 +1,3 @@ def main() -> (): - assert(1f == 2f) + assert(2f == 2f) return \ No newline at end of file From a94cb9f9deca59ddfa91bc52ca2a8294fffa6e7f Mon Sep 17 00:00:00 2001 From: dark64 Date: Fri, 16 Apr 2021 15:19:05 +0200 Subject: [PATCH 30/95] update assert example --- zokrates_cli/examples/book/assert.zok | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_cli/examples/book/assert.zok b/zokrates_cli/examples/book/assert.zok index 5d731a3eb..ccef80099 100644 --- a/zokrates_cli/examples/book/assert.zok +++ b/zokrates_cli/examples/book/assert.zok @@ -1,3 +1,3 @@ def main() -> (): - assert(2f == 2f) + assert(1f + 1f == 2f) return \ No newline at end of file From dafef03b1f5e7455e62923ffab2def6334441c63 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 8 Apr 2021 11:29:21 +0200 Subject: [PATCH 31/95] fix imports, more tests --- .../examples/book/constant_definition.zok | 5 + .../compile_errors/constant_assignment.zok | 5 + zokrates_cli/examples/imports/bar.zok | 8 +- zokrates_cli/examples/imports/baz.zok | 7 +- zokrates_cli/examples/imports/foo.zok | 11 +- zokrates_cli/examples/imports/import.zok | 11 - .../examples/imports/import_constants.zok | 6 + .../examples/imports/import_functions.zok | 6 + .../examples/imports/import_structs.zok | 8 + .../examples/imports/import_with_alias.zok | 8 +- zokrates_core/src/semantics.rs | 45 +- .../src/static_analysis/constant_inliner.rs | 440 +++++++++++++----- zokrates_core/src/typed_absy/folder.rs | 26 +- zokrates_core/src/typed_absy/mod.rs | 21 +- .../tests/tests/constants/array.json | 16 + .../tests/tests/constants/array.zok | 4 + .../tests/tests/constants/bool.json | 16 + .../tests/tests/constants/bool.zok | 4 + .../tests/tests/constants/field.json | 16 + .../tests/tests/constants/field.zok | 4 + .../tests/tests/constants/nested.json | 16 + .../tests/tests/constants/nested.zok | 6 + .../tests/tests/constants/struct.json | 16 + .../tests/tests/constants/struct.zok | 9 + .../tests/tests/constants/uint.json | 16 + .../tests/tests/constants/uint.zok | 4 + 26 files changed, 589 insertions(+), 145 deletions(-) create mode 100644 zokrates_cli/examples/book/constant_definition.zok create mode 100644 zokrates_cli/examples/compile_errors/constant_assignment.zok delete mode 100644 zokrates_cli/examples/imports/import.zok create mode 100644 zokrates_cli/examples/imports/import_constants.zok create mode 100644 zokrates_cli/examples/imports/import_functions.zok create mode 100644 zokrates_cli/examples/imports/import_structs.zok create mode 100644 zokrates_core_test/tests/tests/constants/array.json create mode 100644 zokrates_core_test/tests/tests/constants/array.zok create mode 100644 zokrates_core_test/tests/tests/constants/bool.json create mode 100644 zokrates_core_test/tests/tests/constants/bool.zok create mode 100644 zokrates_core_test/tests/tests/constants/field.json create mode 100644 zokrates_core_test/tests/tests/constants/field.zok create mode 100644 zokrates_core_test/tests/tests/constants/nested.json create mode 100644 zokrates_core_test/tests/tests/constants/nested.zok create mode 100644 zokrates_core_test/tests/tests/constants/struct.json create mode 100644 zokrates_core_test/tests/tests/constants/struct.zok create mode 100644 zokrates_core_test/tests/tests/constants/uint.json create mode 100644 zokrates_core_test/tests/tests/constants/uint.zok diff --git a/zokrates_cli/examples/book/constant_definition.zok b/zokrates_cli/examples/book/constant_definition.zok new file mode 100644 index 000000000..b6850f899 --- /dev/null +++ b/zokrates_cli/examples/book/constant_definition.zok @@ -0,0 +1,5 @@ +const field ONE = 1 +const field TWO = ONE + ONE + +def main() -> field: + return TWO \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/constant_assignment.zok b/zokrates_cli/examples/compile_errors/constant_assignment.zok new file mode 100644 index 000000000..e04da9f6a --- /dev/null +++ b/zokrates_cli/examples/compile_errors/constant_assignment.zok @@ -0,0 +1,5 @@ +const field a = 1 + +def main() -> field: + a = 2 // not allowed + return a \ No newline at end of file diff --git a/zokrates_cli/examples/imports/bar.zok b/zokrates_cli/examples/imports/bar.zok index c7d3af120..34eb1c5ad 100644 --- a/zokrates_cli/examples/imports/bar.zok +++ b/zokrates_cli/examples/imports/bar.zok @@ -1,5 +1,7 @@ -struct Bar { -} +struct Bar {} + +const field ONE = 1 +const field BAR = 21 * ONE def main() -> field: - return 21 \ No newline at end of file + return BAR \ No newline at end of file diff --git a/zokrates_cli/examples/imports/baz.zok b/zokrates_cli/examples/imports/baz.zok index 9fd704a38..84cc641d8 100644 --- a/zokrates_cli/examples/imports/baz.zok +++ b/zokrates_cli/examples/imports/baz.zok @@ -1,5 +1,6 @@ -struct Baz { -} +struct Baz {} + +const field BAZ = 123 def main() -> field: - return 123 \ No newline at end of file + return BAZ \ No newline at end of file diff --git a/zokrates_cli/examples/imports/foo.zok b/zokrates_cli/examples/imports/foo.zok index 43018b208..8dddfd8b6 100644 --- a/zokrates_cli/examples/imports/foo.zok +++ b/zokrates_cli/examples/imports/foo.zok @@ -1,9 +1,10 @@ from "./baz" import Baz - -import "./baz" from "./baz" import main as my_function +import "./baz" + +const field FOO = 144 def main() -> field: - field a = my_function() - Baz b = Baz {} - return baz() \ No newline at end of file + Baz b = Baz {} + assert(baz() == my_function()) + return FOO \ No newline at end of file diff --git a/zokrates_cli/examples/imports/import.zok b/zokrates_cli/examples/imports/import.zok deleted file mode 100644 index bc4e76696..000000000 --- a/zokrates_cli/examples/imports/import.zok +++ /dev/null @@ -1,11 +0,0 @@ -from "./bar" import Bar as MyBar -from "./bar" import Bar - -import "./foo" -import "./bar" - -def main() -> field: - MyBar my_bar = MyBar {} - Bar bar = Bar {} - assert(my_bar == bar) - return foo() + bar() \ No newline at end of file diff --git a/zokrates_cli/examples/imports/import_constants.zok b/zokrates_cli/examples/imports/import_constants.zok new file mode 100644 index 000000000..2abaaea52 --- /dev/null +++ b/zokrates_cli/examples/imports/import_constants.zok @@ -0,0 +1,6 @@ +from "./foo" import FOO +from "./bar" import BAR +from "./baz" import BAZ + +def main() -> bool: + return FOO == BAR + BAZ \ No newline at end of file diff --git a/zokrates_cli/examples/imports/import_functions.zok b/zokrates_cli/examples/imports/import_functions.zok new file mode 100644 index 000000000..32628eb9d --- /dev/null +++ b/zokrates_cli/examples/imports/import_functions.zok @@ -0,0 +1,6 @@ +import "./foo" +import "./bar" +import "./baz" + +def main() -> bool: + return foo() == bar() + baz() \ No newline at end of file diff --git a/zokrates_cli/examples/imports/import_structs.zok b/zokrates_cli/examples/imports/import_structs.zok new file mode 100644 index 000000000..61c94b02d --- /dev/null +++ b/zokrates_cli/examples/imports/import_structs.zok @@ -0,0 +1,8 @@ +from "./bar" import Bar as MyBar +from "./bar" import Bar + +def main(): + MyBar my_bar = MyBar {} + Bar bar = Bar {} + assert(my_bar == bar) + return \ No newline at end of file diff --git a/zokrates_cli/examples/imports/import_with_alias.zok b/zokrates_cli/examples/imports/import_with_alias.zok index e9bb21942..77cdd2631 100644 --- a/zokrates_cli/examples/imports/import_with_alias.zok +++ b/zokrates_cli/examples/imports/import_with_alias.zok @@ -1,4 +1,8 @@ -import "./foo" as d +from "./bar" import main as bar +from "./baz" import main as baz +import "./foo" as f def main() -> field: - return d() \ No newline at end of file + field foo = f() + assert(foo == bar() + baz()) + return foo \ No newline at end of file diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index d7abd022c..c1ec82280 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -407,7 +407,7 @@ impl<'ast, T: Field> Checker<'ast, T> { module_id: &ModuleId, state: &mut State<'ast, T>, functions: &mut HashMap, TypedFunctionSymbol<'ast, T>>, - constants: &mut HashMap, TypedConstant<'ast, T>>, + constants: &mut HashMap, TypedConstantSymbol<'ast, T>>, symbol_unifier: &mut SymbolUnifier<'ast>, ) -> Result<(), Vec> { let mut errors: Vec = vec![]; @@ -470,8 +470,7 @@ impl<'ast, T: Field> Checker<'ast, T> { ), true => {} }; - constants - .insert(identifier::Identifier::from(declaration.id), c.clone()); + constants.insert(declaration.id, TypedConstantSymbol::Here(c.clone())); self.insert_into_scope(Variable::with_id_and_type(c.id, c.ty), true); } Err(e) => { @@ -549,8 +548,21 @@ impl<'ast, T: Field> Checker<'ast, T> { .get(import.symbol_id) .cloned(); - match (function_candidates.len(), type_candidate) { - (0, Some(t)) => { + // find constant definition candidate + let const_candidate = state + .typed_modules + .get(&import.module_id) + .unwrap() + .constants + .as_ref() + .and_then(|tc| tc.get(import.symbol_id)) + .and_then(|sym| match sym { + TypedConstantSymbol::Here(tc) => Some(tc), + _ => None, + }); + + match (function_candidates.len(), type_candidate, const_candidate) { + (0, Some(t), None) => { // rename the type to the declared symbol let t = match t { @@ -585,7 +597,26 @@ impl<'ast, T: Field> Checker<'ast, T> { .or_default() .insert(declaration.id.to_string(), t); } - (0, None) => { + (0, None, Some(c)) => { + match symbol_unifier.insert_symbol(declaration.id, SymbolType::Constant) { + false => { + errors.push(Error { + module_id: module_id.to_path_buf(), + inner: ErrorInner { + pos: Some(pos), + message: format!( + "{} conflicts with another symbol", + declaration.id, + ), + }}); + } + true => { + constants.insert(declaration.id, TypedConstantSymbol::There(import.module_id, declaration.id)); + self.insert_into_scope(Variable::with_id_and_type(c.id.clone(), c.ty.clone()), true); + } + }; + } + (0, None, None) => { errors.push(ErrorInner { pos: Some(pos), message: format!( @@ -594,7 +625,7 @@ impl<'ast, T: Field> Checker<'ast, T> { ), }.in_file(module_id)); } - (_, Some(_)) => unreachable!("collision in module we're importing from should have been caught when checking it"), + (_, Some(_), Some(_)) => unreachable!("collision in module we're importing from should have been caught when checking it"), _ => { for candidate in function_candidates { diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index 645dbc5e5..9c04dcaa5 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -1,36 +1,92 @@ -use crate::typed_absy::folder::{ - fold_array_expression, fold_array_expression_inner, fold_boolean_expression, - fold_field_expression, fold_module, fold_struct_expression, fold_struct_expression_inner, - fold_uint_expression, fold_uint_expression_inner, Folder, -}; -use crate::typed_absy::{ - ArrayExpression, ArrayExpressionInner, ArrayType, BooleanExpression, FieldElementExpression, - StructExpression, StructExpressionInner, StructType, TypedConstants, TypedModule, TypedProgram, - UBitwidth, UExpression, UExpressionInner, -}; -use std::collections::HashMap; +use crate::typed_absy::folder::*; +use crate::typed_absy::*; use std::convert::TryInto; use zokrates_field::Field; pub struct ConstantInliner<'ast, T: Field> { - constants: TypedConstants<'ast, T>, + modules: TypedModules<'ast, T>, + location: OwnedTypedModuleId, } impl<'ast, T: Field> ConstantInliner<'ast, T> { + fn with_modules_and_location( + modules: TypedModules<'ast, T>, + location: OwnedTypedModuleId, + ) -> Self { + ConstantInliner { modules, location } + } + pub fn inline(p: TypedProgram<'ast, T>) -> TypedProgram<'ast, T> { - let mut inliner = ConstantInliner { - constants: HashMap::new(), - }; + // initialize an inliner over all modules, starting from the main module + let mut inliner = + ConstantInliner::with_modules_and_location(p.modules.clone(), p.main.clone()); + inliner.fold_program(p) } + + pub fn module(&self) -> &TypedModule<'ast, T> { + self.modules.get(&self.location).unwrap() + } + + pub fn change_location(&mut self, location: OwnedTypedModuleId) -> OwnedTypedModuleId { + let prev = self.location.clone(); + self.location = location; + prev + } + + pub fn get_constant(&mut self, id: &Identifier) -> Option> { + self.modules + .get(&self.location) + .unwrap() + .constants + .as_ref() + .and_then(|c| c.get(id.clone().try_into().unwrap())) + .cloned() + .and_then(|tc| { + let symbol = self.fold_constant_symbol(tc); + match symbol { + TypedConstantSymbol::Here(tc) => Some(tc), + _ => None, + } + }) + } } impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { - fn fold_module(&mut self, p: TypedModule<'ast, T>) -> TypedModule<'ast, T> { - self.constants = p.constants.clone().unwrap_or_default(); - TypedModule { - functions: fold_module(self, p).functions, - constants: None, + fn fold_program(&mut self, p: TypedProgram<'ast, T>) -> TypedProgram<'ast, T> { + TypedProgram { + modules: p + .modules + .into_iter() + .map(|(module_id, module)| { + self.change_location(module_id.clone()); + (module_id, self.fold_module(module)) + }) + .collect(), + main: p.main, + } + } + + fn fold_constant_symbol( + &mut self, + p: TypedConstantSymbol<'ast, T>, + ) -> TypedConstantSymbol<'ast, T> { + match p { + TypedConstantSymbol::There(module_id, id) => { + let location = self.change_location(module_id); + let symbol = self + .module() + .constants + .as_ref() + .and_then(|c| c.get(id)) + .unwrap() + .to_owned(); + + let symbol = self.fold_constant_symbol(symbol); + let _ = self.change_location(location); + symbol + } + _ => fold_constant_symbol(self, p), } } @@ -39,7 +95,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { e: FieldElementExpression<'ast, T>, ) -> FieldElementExpression<'ast, T> { match e { - FieldElementExpression::Identifier(ref id) => match self.constants.get(id).cloned() { + FieldElementExpression::Identifier(ref id) => match self.get_constant(id) { Some(c) => fold_field_expression(self, c.expression.try_into().unwrap()), None => fold_field_expression(self, e), }, @@ -52,7 +108,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { e: BooleanExpression<'ast, T>, ) -> BooleanExpression<'ast, T> { match e { - BooleanExpression::Identifier(ref id) => match self.constants.get(id).cloned() { + BooleanExpression::Identifier(ref id) => match self.get_constant(id) { Some(c) => fold_boolean_expression(self, c.expression.try_into().unwrap()), None => fold_boolean_expression(self, e), }, @@ -66,14 +122,12 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { e: UExpressionInner<'ast, T>, ) -> UExpressionInner<'ast, T> { match e { - UExpressionInner::Identifier(ref id) => match self.constants.get(id).cloned() { + UExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - let expr: UExpression<'ast, T> = c.expression.try_into().unwrap(); - fold_uint_expression(self, expr).into_inner() + fold_uint_expression(self, c.expression.try_into().unwrap()).into_inner() } None => fold_uint_expression_inner(self, size, e), }, - // default e => fold_uint_expression_inner(self, size, e), } } @@ -84,14 +138,12 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { e: ArrayExpressionInner<'ast, T>, ) -> ArrayExpressionInner<'ast, T> { match e { - ArrayExpressionInner::Identifier(ref id) => match self.constants.get(id).cloned() { + ArrayExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - let expr: ArrayExpression<'ast, T> = c.expression.try_into().unwrap(); - fold_array_expression(self, expr).into_inner() + fold_array_expression(self, c.expression.try_into().unwrap()).into_inner() } None => fold_array_expression_inner(self, ty, e), }, - // default e => fold_array_expression_inner(self, ty, e), } } @@ -102,14 +154,12 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { e: StructExpressionInner<'ast, T>, ) -> StructExpressionInner<'ast, T> { match e { - StructExpressionInner::Identifier(ref id) => match self.constants.get(id).cloned() { + StructExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - let expr: StructExpression<'ast, T> = c.expression.try_into().unwrap(); - fold_struct_expression(self, expr).into_inner() + fold_struct_expression(self, c.expression.try_into().unwrap()).into_inner() } None => fold_struct_expression_inner(self, ty, e), }, - // default e => fold_struct_expression_inner(self, ty, e), } } @@ -132,28 +182,29 @@ mod tests { // def main() -> field: // return a - let const_id = Identifier::from("a"); + let const_id = "a"; let main: TypedFunction = TypedFunction { arguments: vec![], statements: vec![TypedStatement::Return(vec![ - FieldElementExpression::Identifier(const_id.clone()).into(), + FieldElementExpression::Identifier(Identifier::from(const_id)).into(), ])], signature: DeclarationSignature::new() .inputs(vec![]) .outputs(vec![DeclarationType::FieldElement]), }; - let mut constants = TypedConstants::::new(); - constants.insert( - const_id.clone(), - TypedConstant { - id: const_id.clone(), + let constants: TypedConstantSymbols<_> = vec![( + const_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_id), ty: GType::FieldElement, expression: (TypedExpression::FieldElement(FieldElementExpression::Number( Bn128Field::from(1), ))), - }, - ); + }), + )] + .into_iter() + .collect(); let program = TypedProgram { main: "main".into(), @@ -170,7 +221,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants: Some(constants.clone()), }, )] .into_iter() @@ -204,7 +255,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Some(constants), }, )] .into_iter() @@ -221,11 +272,11 @@ mod tests { // def main() -> bool: // return a - let const_id = Identifier::from("a"); + let const_id = "a"; let main: TypedFunction = TypedFunction { arguments: vec![], statements: vec![TypedStatement::Return(vec![BooleanExpression::Identifier( - const_id.clone(), + Identifier::from(const_id), ) .into()])], signature: DeclarationSignature::new() @@ -233,15 +284,16 @@ mod tests { .outputs(vec![DeclarationType::Boolean]), }; - let mut constants = TypedConstants::::new(); - constants.insert( - const_id.clone(), - TypedConstant { - id: const_id.clone(), + let constants: TypedConstantSymbols<_> = vec![( + const_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_id), ty: GType::Boolean, expression: (TypedExpression::Boolean(BooleanExpression::Value(true))), - }, - ); + }), + )] + .into_iter() + .collect(); let program = TypedProgram { main: "main".into(), @@ -258,7 +310,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants: Some(constants.clone()), }, )] .into_iter() @@ -292,7 +344,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Some(constants), }, )] .into_iter() @@ -309,11 +361,11 @@ mod tests { // def main() -> u32: // return a - let const_id = Identifier::from("a"); + let const_id = "a"; let main: TypedFunction = TypedFunction { arguments: vec![], statements: vec![TypedStatement::Return(vec![UExpressionInner::Identifier( - const_id.clone(), + Identifier::from(const_id), ) .annotate(UBitwidth::B32) .into()])], @@ -322,17 +374,18 @@ mod tests { .outputs(vec![DeclarationType::Uint(UBitwidth::B32)]), }; - let mut constants = TypedConstants::::new(); - constants.insert( - const_id.clone(), - TypedConstant { - id: const_id.clone(), + let constants: TypedConstantSymbols<_> = vec![( + const_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_id), ty: GType::Uint(UBitwidth::B32), expression: (UExpressionInner::Value(1u128) .annotate(UBitwidth::B32) .into()), - }, - ); + }), + )] + .into_iter() + .collect(); let program = TypedProgram { main: "main".into(), @@ -349,7 +402,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants: Some(constants.clone()), }, )] .into_iter() @@ -383,7 +436,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Some(constants), }, )] .into_iter() @@ -400,18 +453,18 @@ mod tests { // def main() -> field: // return a[0] + a[1] - let const_id = Identifier::from("a"); + let const_id = "a"; let main: TypedFunction = TypedFunction { arguments: vec![], statements: vec![TypedStatement::Return(vec![FieldElementExpression::Add( FieldElementExpression::Select( - box ArrayExpressionInner::Identifier(const_id.clone()) + box ArrayExpressionInner::Identifier(Identifier::from(const_id)) .annotate(GType::FieldElement, 2usize), box UExpressionInner::Value(0u128).annotate(UBitwidth::B32), ) .into(), FieldElementExpression::Select( - box ArrayExpressionInner::Identifier(const_id.clone()) + box ArrayExpressionInner::Identifier(Identifier::from(const_id)) .annotate(GType::FieldElement, 2usize), box UExpressionInner::Value(1u128).annotate(UBitwidth::B32), ) @@ -423,11 +476,10 @@ mod tests { .outputs(vec![DeclarationType::FieldElement]), }; - let mut constants = TypedConstants::::new(); - constants.insert( - const_id.clone(), - TypedConstant { - id: const_id.clone(), + let constants: TypedConstantSymbols<_> = vec![( + const_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_id), ty: GType::FieldElement, expression: TypedExpression::Array( ArrayExpressionInner::Value( @@ -439,8 +491,10 @@ mod tests { ) .annotate(GType::FieldElement, 2usize), ), - }, - ); + }), + )] + .into_iter() + .collect(); let program = TypedProgram { main: "main".into(), @@ -457,7 +511,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants: Some(constants.clone()), }, )] .into_iter() @@ -515,7 +569,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Some(constants), }, )] .into_iter() @@ -533,44 +587,19 @@ mod tests { // def main() -> field: // return b - let const_a_id = Identifier::from("a"); - let const_b_id = Identifier::from("b"); + let const_a_id = "a"; + let const_b_id = "b"; let main: TypedFunction = TypedFunction { arguments: vec![], statements: vec![TypedStatement::Return(vec![ - FieldElementExpression::Identifier(const_b_id.clone()).into(), + FieldElementExpression::Identifier(Identifier::from(const_b_id)).into(), ])], signature: DeclarationSignature::new() .inputs(vec![]) .outputs(vec![DeclarationType::FieldElement]), }; - let mut constants = TypedConstants::::new(); - constants.extend(vec![ - ( - const_a_id.clone(), - TypedConstant { - id: const_a_id.clone(), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement(FieldElementExpression::Number( - Bn128Field::from(1), - ))), - }, - ), - ( - const_b_id.clone(), - TypedConstant { - id: const_b_id.clone(), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement(FieldElementExpression::Add( - box FieldElementExpression::Identifier(const_a_id.clone()), - box FieldElementExpression::Number(Bn128Field::from(1)), - ))), - }, - ), - ]); - let program = TypedProgram { main: "main".into(), modules: vec![( @@ -586,7 +615,37 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants: Some( + vec![ + ( + const_a_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_a_id), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Number(Bn128Field::from(1)), + )), + }), + ), + ( + const_b_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_b_id), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Add( + box FieldElementExpression::Identifier( + Identifier::from(const_a_id), + ), + box FieldElementExpression::Number(Bn128Field::from(1)), + ), + )), + }), + ), + ] + .into_iter() + .collect(), + ), }, )] .into_iter() @@ -622,7 +681,35 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Some( + vec![ + ( + const_a_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_a_id), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Number(Bn128Field::from(1)), + )), + }), + ), + ( + const_b_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(const_b_id), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Add( + box FieldElementExpression::Number(Bn128Field::from(1)), + box FieldElementExpression::Number(Bn128Field::from(1)), + ), + )), + }), + ), + ] + .into_iter() + .collect(), + ), }, )] .into_iter() @@ -631,4 +718,139 @@ mod tests { assert_eq!(program, expected_program) } + + #[test] + fn inline_imported_constant() { + // --------------------- + // module `foo` + // -------------------- + // const field FOO = 42 + // + // def main(): + // return + // + // --------------------- + // module `main` + // --------------------- + // from "foo" import FOO + // + // def main() -> field: + // return FOO + + let foo_const_id = "FOO"; + let foo_module = TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main") + .signature(DeclarationSignature::new().inputs(vec![]).outputs(vec![])), + TypedFunctionSymbol::Here(TypedFunction { + arguments: vec![], + statements: vec![], + signature: DeclarationSignature::new().inputs(vec![]).outputs(vec![]), + }), + )] + .into_iter() + .collect(), + constants: Some( + vec![( + foo_const_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(foo_const_id), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Number(Bn128Field::from(42)), + )), + }), + )] + .into_iter() + .collect(), + ), + }; + + let main_module = TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![ + FieldElementExpression::Identifier(Identifier::from(foo_const_id)).into(), + ])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }), + )] + .into_iter() + .collect(), + constants: Some( + vec![( + foo_const_id, + TypedConstantSymbol::There(OwnedTypedModuleId::from("foo"), foo_const_id), + )] + .into_iter() + .collect(), + ), + }; + + let program = TypedProgram { + main: "main".into(), + modules: vec![ + ("main".into(), main_module), + ("foo".into(), foo_module.clone()), + ] + .into_iter() + .collect(), + }; + + let program = ConstantInliner::inline(program); + let expected_main_module = TypedModule { + functions: vec![( + DeclarationFunctionKey::with_location("main", "main").signature( + DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + ), + TypedFunctionSymbol::Here(TypedFunction { + arguments: vec![], + statements: vec![TypedStatement::Return(vec![ + FieldElementExpression::Number(Bn128Field::from(42)).into(), + ])], + signature: DeclarationSignature::new() + .inputs(vec![]) + .outputs(vec![DeclarationType::FieldElement]), + }), + )] + .into_iter() + .collect(), + constants: Some( + vec![( + foo_const_id, + TypedConstantSymbol::Here(TypedConstant { + id: Identifier::from(foo_const_id), + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Number(Bn128Field::from(42)), + )), + }), + )] + .into_iter() + .collect(), + ), + }; + + let expected_program: TypedProgram = TypedProgram { + main: "main".into(), + modules: vec![ + ("main".into(), expected_main_module), + ("foo".into(), foo_module), + ] + .into_iter() + .collect(), + }; + + assert_eq!(program, expected_program) + } } diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index 348450d78..f72bbf3b6 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -13,6 +13,13 @@ pub trait Folder<'ast, T: Field>: Sized { fold_module(self, p) } + fn fold_constant_symbol( + &mut self, + p: TypedConstantSymbol<'ast, T>, + ) -> TypedConstantSymbol<'ast, T> { + fold_constant_symbol(self, p) + } + fn fold_function_symbol( &mut self, s: TypedFunctionSymbol<'ast, T>, @@ -193,12 +200,16 @@ pub fn fold_module<'ast, T: Field, F: Folder<'ast, T>>( p: TypedModule<'ast, T>, ) -> TypedModule<'ast, T> { TypedModule { + constants: p.constants.map(|tc| { + tc.into_iter() + .map(|(key, tc)| (key, f.fold_constant_symbol(tc))) + .collect() + }), functions: p .functions .into_iter() .map(|(key, fun)| (key, f.fold_function_symbol(fun))) .collect(), - constants: p.constants, } } @@ -692,6 +703,19 @@ pub fn fold_struct_expression<'ast, T: Field, F: Folder<'ast, T>>( } } +pub fn fold_constant_symbol<'ast, T: Field, F: Folder<'ast, T>>( + f: &mut F, + p: TypedConstantSymbol<'ast, T>, +) -> TypedConstantSymbol<'ast, T> { + match p { + TypedConstantSymbol::Here(tc) => TypedConstantSymbol::Here(TypedConstant { + expression: f.fold_expression(tc.expression), + ..tc + }), + there => there, + } +} + pub fn fold_function_symbol<'ast, T: Field, F: Folder<'ast, T>>( f: &mut F, s: TypedFunctionSymbol<'ast, T>, diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 759421e67..373a2a1df 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -61,8 +61,17 @@ pub type TypedModules<'ast, T> = HashMap = HashMap, TypedFunctionSymbol<'ast, T>>; -/// A collection of `TypedConstant`s -pub type TypedConstants<'ast, T> = HashMap, TypedConstant<'ast, T>>; +pub type ConstantIdentifier<'ast> = &'ast str; + +#[derive(Clone, Debug, PartialEq)] +pub enum TypedConstantSymbol<'ast, T> { + Here(TypedConstant<'ast, T>), + There(OwnedTypedModuleId, ConstantIdentifier<'ast>), +} + +/// A collection of `TypedConstantSymbol`s +pub type TypedConstantSymbols<'ast, T> = + HashMap, TypedConstantSymbol<'ast, T>>; /// A typed program as a collection of modules, one of them being the main #[derive(PartialEq, Debug, Clone)] @@ -144,7 +153,7 @@ pub struct TypedModule<'ast, T> { /// Functions of the module pub functions: TypedFunctionSymbols<'ast, T>, /// Constants defined in module - pub constants: Option>, + pub constants: Option>, } #[derive(Clone, PartialEq)] @@ -320,7 +329,11 @@ pub struct TypedConstant<'ast, T> { impl<'ast, T: fmt::Debug> fmt::Debug for TypedConstant<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "TypedConstant({:?}, {:?}, ...)", self.id, self.ty) + write!( + f, + "TypedConstant({:?}, {:?}, {:?})", + self.id, self.ty, self.expression + ) } } diff --git a/zokrates_core_test/tests/tests/constants/array.json b/zokrates_core_test/tests/tests/constants/array.json new file mode 100644 index 000000000..7cbbb2bae --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/array.json @@ -0,0 +1,16 @@ +{ + "entry_point": "./tests/tests/constants/array.zok", + "max_constraint_count": 2, + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["1", "2"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/array.zok b/zokrates_core_test/tests/tests/constants/array.zok new file mode 100644 index 000000000..cce74dc75 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/array.zok @@ -0,0 +1,4 @@ +const field[2] ARRAY = [1, 2] + +def main() -> field[2]: + return ARRAY \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/constants/bool.json b/zokrates_core_test/tests/tests/constants/bool.json new file mode 100644 index 000000000..f11aea9a5 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/bool.json @@ -0,0 +1,16 @@ +{ + "entry_point": "./tests/tests/constants/bool.zok", + "max_constraint_count": 1, + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/bool.zok b/zokrates_core_test/tests/tests/constants/bool.zok new file mode 100644 index 000000000..00e0ae116 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/bool.zok @@ -0,0 +1,4 @@ +const bool BOOLEAN = true + +def main() -> bool: + return BOOLEAN \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/constants/field.json b/zokrates_core_test/tests/tests/constants/field.json new file mode 100644 index 000000000..2ec19a1fc --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/field.json @@ -0,0 +1,16 @@ +{ + "entry_point": "./tests/tests/constants/field.zok", + "max_constraint_count": 1, + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/field.zok b/zokrates_core_test/tests/tests/constants/field.zok new file mode 100644 index 000000000..4408b12e0 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/field.zok @@ -0,0 +1,4 @@ +const field ONE = 1 + +def main() -> field: + return ONE \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/constants/nested.json b/zokrates_core_test/tests/tests/constants/nested.json new file mode 100644 index 000000000..61cfd3092 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/nested.json @@ -0,0 +1,16 @@ +{ + "entry_point": "./tests/tests/constants/nested.zok", + "max_constraint_count": 1, + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["8"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/nested.zok b/zokrates_core_test/tests/tests/constants/nested.zok new file mode 100644 index 000000000..a7861aeba --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/nested.zok @@ -0,0 +1,6 @@ +const field A = 2 +const field B = 2 +const field[2] ARRAY = [A * 2, B * 2] + +def main() -> field: + return ARRAY[0] + ARRAY[1] \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/constants/struct.json b/zokrates_core_test/tests/tests/constants/struct.json new file mode 100644 index 000000000..4d77d484f --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/struct.json @@ -0,0 +1,16 @@ +{ + "entry_point": "./tests/tests/constants/struct.zok", + "max_constraint_count": 1, + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["4"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/struct.zok b/zokrates_core_test/tests/tests/constants/struct.zok new file mode 100644 index 000000000..92e705cad --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/struct.zok @@ -0,0 +1,9 @@ +struct Foo { + field a + field b +} + +const Foo FOO = Foo { a: 2, b: 2 } + +def main() -> field: + return FOO.a + FOO.b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/constants/uint.json b/zokrates_core_test/tests/tests/constants/uint.json new file mode 100644 index 000000000..a2fccab82 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/uint.json @@ -0,0 +1,16 @@ +{ + "entry_point": "./tests/tests/constants/uint.zok", + "max_constraint_count": 1, + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/uint.zok b/zokrates_core_test/tests/tests/constants/uint.zok new file mode 100644 index 000000000..914308ec0 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/uint.zok @@ -0,0 +1,4 @@ +const u32 ONE = 0x00000001 + +def main() -> u32: + return ONE \ No newline at end of file From a2719938322ac594a0d7ee5994974d6228e17138 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 19 Apr 2021 10:59:23 +0200 Subject: [PATCH 32/95] fix tests --- zokrates_cli/examples/left_side_call.zok | 2 +- zokrates_cli/examples/propagate_call.zok | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zokrates_cli/examples/left_side_call.zok b/zokrates_cli/examples/left_side_call.zok index 91670e7e7..d01ae6194 100644 --- a/zokrates_cli/examples/left_side_call.zok +++ b/zokrates_cli/examples/left_side_call.zok @@ -2,5 +2,5 @@ def foo() -> field: return 1 def main(): - assert(foo() + (1 + 44*3) == 1) + assert(foo() + (1 + 44*3) == 134) return diff --git a/zokrates_cli/examples/propagate_call.zok b/zokrates_cli/examples/propagate_call.zok index a7353e6d1..d2dba6f8c 100644 --- a/zokrates_cli/examples/propagate_call.zok +++ b/zokrates_cli/examples/propagate_call.zok @@ -1,5 +1,5 @@ def foo(field a, field b) -> (field, field): - assert(a == b + 2) + assert(a == b) return a, b def main() -> field: From 41a1b5f6615384c65250e5e4a382431c87a71b80 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 19 Apr 2021 11:32:11 +0200 Subject: [PATCH 33/95] use string instead of cloning --- zokrates_core/src/static_analysis/propagation.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index b85e36717..93998febf 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -657,12 +657,13 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Ok(statements) } - TypedStatement::Assertion(ref e) => { - let expr = self.fold_boolean_expression(e.clone())?; + TypedStatement::Assertion(e) => { + let e_str = e.to_string(); + let expr = self.fold_boolean_expression(e)?; match expr { BooleanExpression::Value(v) if !v => Err(Error::Type(format!( "Assertion failed on expression `{}`", - e + e_str ))), _ => Ok(vec![TypedStatement::Assertion(expr)]), } From 9875fee6dce7559add22bcd5a7c0f8978e30589f Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 19 Apr 2021 11:55:13 +0200 Subject: [PATCH 34/95] update changelog --- changelogs/unreleased/823-dark64 | 1 + 1 file changed, 1 insertion(+) diff --git a/changelogs/unreleased/823-dark64 b/changelogs/unreleased/823-dark64 index e69de29bb..ab39e6c68 100644 --- a/changelogs/unreleased/823-dark64 +++ b/changelogs/unreleased/823-dark64 @@ -0,0 +1 @@ +Detect assertion failures at compile time on constant expressions \ No newline at end of file From 708981144dda894c190dc8fcc0fa662d8756aaf3 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 19 Apr 2021 13:50:37 +0200 Subject: [PATCH 35/95] make tests panic if max constraint count is exceeded --- zokrates_core_test/tests/tests/memoize/dep.zok | 2 +- .../tests/tests/memoize/memoize.json | 2 +- zokrates_core_test/tests/tests/uint/if_else.json | 2 +- zokrates_core_test/tests/tests/uint/u8/gte.json | 2 +- zokrates_test/src/lib.rs | 14 +++++++++----- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/zokrates_core_test/tests/tests/memoize/dep.zok b/zokrates_core_test/tests/tests/memoize/dep.zok index 43439356b..a8c2d4db7 100644 --- a/zokrates_core_test/tests/tests/memoize/dep.zok +++ b/zokrates_core_test/tests/tests/memoize/dep.zok @@ -1,3 +1,3 @@ -def dep(field a) -> field: // this costs 2 constraits per call +def dep(field a) -> field: // this costs 2 constraints per call field res = a ** 4 return res \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/memoize/memoize.json b/zokrates_core_test/tests/tests/memoize/memoize.json index 03ad5490f..3cc57aaf4 100644 --- a/zokrates_core_test/tests/tests/memoize/memoize.json +++ b/zokrates_core_test/tests/tests/memoize/memoize.json @@ -1,6 +1,6 @@ { "entry_point": "./tests/tests/memoize/memoize.zok", - "max_constraint_count": 14, + "max_constraint_count": 32, "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/uint/if_else.json b/zokrates_core_test/tests/tests/uint/if_else.json index d4e7af04d..a594acba2 100644 --- a/zokrates_core_test/tests/tests/uint/if_else.json +++ b/zokrates_core_test/tests/tests/uint/if_else.json @@ -1,6 +1,6 @@ { "entry_point": "./tests/tests/uint/if_else.zok", - "max_constraint_count": 28, + "max_constraint_count": 31, "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/uint/u8/gte.json b/zokrates_core_test/tests/tests/uint/u8/gte.json index 1b3d35b87..4ff491a74 100644 --- a/zokrates_core_test/tests/tests/uint/u8/gte.json +++ b/zokrates_core_test/tests/tests/uint/u8/gte.json @@ -1,6 +1,6 @@ { "entry_point": "./tests/tests/uint/u8/gte.zok", - "max_constraint_count": 681, + "max_constraint_count": 683, "tests": [ { "input": { diff --git a/zokrates_test/src/lib.rs b/zokrates_test/src/lib.rs index 7c48ebf47..04a57e9bc 100644 --- a/zokrates_test/src/lib.rs +++ b/zokrates_test/src/lib.rs @@ -137,11 +137,15 @@ fn compile_and_run(t: Tests) { if let Some(target_count) = t.max_constraint_count { let count = bin.constraint_count(); - println!( - "{} at {}% of max", - entry_point.display(), - (count as f32) / (target_count as f32) * 100_f32 - ); + if count > target_count { + panic!( + "{} exceeded max constraint count (actual={}, max={}, p={:.2}% of max)", + entry_point.display(), + count, + target_count, + (count as f32) / (target_count as f32) * 100_f32 + ); + } }; let interpreter = zokrates_core::ir::Interpreter::default(); From 42900ed3bdae0734510dfcb7471ab8e7d26c9186 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 19 Apr 2021 14:38:28 +0200 Subject: [PATCH 36/95] update book --- zokrates_book/src/SUMMARY.md | 5 +++-- zokrates_book/src/language/constants.md | 17 +++++++++++++++++ zokrates_book/src/language/imports.md | 5 ++++- .../examples/book/constant_definition.zok | 5 ++--- .../examples/book/constant_reference.zok | 5 +++++ 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 zokrates_book/src/language/constants.md create mode 100644 zokrates_cli/examples/book/constant_reference.zok diff --git a/zokrates_book/src/SUMMARY.md b/zokrates_book/src/SUMMARY.md index 6ccefb31e..7755bbf70 100644 --- a/zokrates_book/src/SUMMARY.md +++ b/zokrates_book/src/SUMMARY.md @@ -8,11 +8,12 @@ - [Variables](language/variables.md) - [Types](language/types.md) - [Operators](language/operators.md) - - [Functions](language/functions.md) - [Control flow](language/control_flow.md) + - [Constants](language/constants.md) + - [Functions](language/functions.md) + - [Generics](language/generics.md) - [Imports](language/imports.md) - [Comments](language/comments.md) - - [Generics](language/generics.md) - [Macros](language/macros.md) - [Toolbox](toolbox/index.md) diff --git a/zokrates_book/src/language/constants.md b/zokrates_book/src/language/constants.md new file mode 100644 index 000000000..8bad07217 --- /dev/null +++ b/zokrates_book/src/language/constants.md @@ -0,0 +1,17 @@ +## Constants + +Constants must be globally defined outside all other scopes by using a `const` keyword. Constants can be set only to a constant expression. + +```zokrates +{{#include ../../../zokrates_cli/examples/book/constant_definition.zok}} +``` + +The value of a constant can't be changed through reassignment, and it can't be redeclared. Constants are essentially inlined wherever they are used, meaning that they are copied directly into the relevant context when used. + +Constants must be explicitly typed. One can reference other constants inside the expression, as long as the referenced constant is defined before the constant. + +```zokrates +{{#include ../../../zokrates_cli/examples/book/constant_reference.zok}} +``` + +The naming convention for constants are similar to that of variables. All characters in a constant name are usually in uppercase. \ No newline at end of file diff --git a/zokrates_book/src/language/imports.md b/zokrates_book/src/language/imports.md index fef1083de..8d4d17de9 100644 --- a/zokrates_book/src/language/imports.md +++ b/zokrates_book/src/language/imports.md @@ -44,7 +44,7 @@ from "./path/to/my/module" import main as module Note that this legacy method is likely to become deprecated, so it is recommended to use the preferred way instead. ### Symbols -Two types of symbols can be imported +Three types of symbols can be imported #### Functions Functions are imported by name. If many functions have the same name but different signatures, all of them get imported, and which one to use in a particular call is inferred. @@ -52,6 +52,9 @@ Functions are imported by name. If many functions have the same name but differe #### User-defined types User-defined types declared with the `struct` keyword are imported by name. +#### Constants +Constants declared with the `const` keyword are imported by name. + ### Relative Imports You can import a resource in the same folder directly, like this: diff --git a/zokrates_cli/examples/book/constant_definition.zok b/zokrates_cli/examples/book/constant_definition.zok index b6850f899..016f231c9 100644 --- a/zokrates_cli/examples/book/constant_definition.zok +++ b/zokrates_cli/examples/book/constant_definition.zok @@ -1,5 +1,4 @@ -const field ONE = 1 -const field TWO = ONE + ONE +const field BN128_GROUP_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617 def main() -> field: - return TWO \ No newline at end of file + return BN128_GROUP_MODULUS \ No newline at end of file diff --git a/zokrates_cli/examples/book/constant_reference.zok b/zokrates_cli/examples/book/constant_reference.zok new file mode 100644 index 000000000..b6850f899 --- /dev/null +++ b/zokrates_cli/examples/book/constant_reference.zok @@ -0,0 +1,5 @@ +const field ONE = 1 +const field TWO = ONE + ONE + +def main() -> field: + return TWO \ No newline at end of file From b94b72080f91e47a4a085ced8ef76fdee5d50c84 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 19 Apr 2021 14:57:53 +0200 Subject: [PATCH 37/95] update example --- zokrates_cli/examples/book/constant_definition.zok | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zokrates_cli/examples/book/constant_definition.zok b/zokrates_cli/examples/book/constant_definition.zok index 016f231c9..10b31ec79 100644 --- a/zokrates_cli/examples/book/constant_definition.zok +++ b/zokrates_cli/examples/book/constant_definition.zok @@ -1,4 +1,4 @@ -const field BN128_GROUP_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617 +const field PRIME = 31 def main() -> field: - return BN128_GROUP_MODULUS \ No newline at end of file + return PRIME \ No newline at end of file From 3b5ad3d13e28c14d479c717ddaa321d009888ca6 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 19 Apr 2021 17:38:46 +0200 Subject: [PATCH 38/95] update textmate, add yaml version --- zokrates_core/src/semantics.rs | 2 - zokrates_parser/src/ace_mode/index.js | 2 +- zokrates_parser/src/textmate/package.json | 59 +- .../syntaxes/zokrates.tmLanguage.json | 1233 +++++++++-------- .../src/textmate/zokrates.tmLanguage.yaml | 349 +++++ 5 files changed, 1019 insertions(+), 626 deletions(-) create mode 100644 zokrates_parser/src/textmate/zokrates.tmLanguage.yaml diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 506029850..b76f6f1d9 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -784,7 +784,6 @@ impl<'ast, T: Field> Checker<'ast, T> { module_id: &ModuleId, types: &TypeMap<'ast>, ) -> Result, Vec> { - // assert!(self.scope.is_empty()); assert!(self.return_types.is_none()); self.enter_scope(); @@ -911,7 +910,6 @@ impl<'ast, T: Field> Checker<'ast, T> { } self.return_types = None; - // assert!(self.scope.is_empty()); Ok(TypedFunction { arguments: arguments_checked, diff --git a/zokrates_parser/src/ace_mode/index.js b/zokrates_parser/src/ace_mode/index.js index ec77a4fbe..537e0f76a 100644 --- a/zokrates_parser/src/ace_mode/index.js +++ b/zokrates_parser/src/ace_mode/index.js @@ -37,7 +37,7 @@ ace.define("ace/mode/zokrates_highlight_rules",["require","exports","module","ac var ZoKratesHighlightRules = function () { var keywords = ( - "assert|as|bool|byte|def|do|else|endfor|export|false|field|for|if|then|fi|import|from|in|private|public|return|struct|true|u8|u16|u32|u64" + "assert|as|bool|byte|const|def|do|else|endfor|export|false|field|for|if|then|fi|import|from|in|private|public|return|struct|true|u8|u16|u32|u64" ); var keywordMapper = this.createKeywordMapper({ diff --git a/zokrates_parser/src/textmate/package.json b/zokrates_parser/src/textmate/package.json index ebacd5de6..a72f04a05 100644 --- a/zokrates_parser/src/textmate/package.json +++ b/zokrates_parser/src/textmate/package.json @@ -1,27 +1,36 @@ { - "name": "zokrates", - "displayName": "zokrates", - "description": "Syntax highlighting for the ZoKrates language", - "publisher": "zokrates", - "repository": "https://github.com/ZoKrates/ZoKrates", - "version": "0.0.1", - "engines": { - "vscode": "^1.53.0" - }, - "categories": [ - "Programming Languages" + "name": "zokrates", + "displayName": "zokrates", + "description": "Syntax highlighting for the ZoKrates language", + "publisher": "zokrates", + "repository": "https://github.com/ZoKrates/ZoKrates", + "version": "0.0.1", + "engines": { + "vscode": "^1.53.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [ + { + "id": "zokrates", + "aliases": [ + "ZoKrates", + "zokrates" + ], + "extensions": [ + ".zok" + ], + "configuration": "./language-configuration.json" + } ], - "contributes": { - "languages": [{ - "id": "zokrates", - "aliases": ["ZoKrates", "zokrates"], - "extensions": [".zok"], - "configuration": "./language-configuration.json" - }], - "grammars": [{ - "language": "zokrates", - "scopeName": "source.zok", - "path": "./syntaxes/zokrates.tmLanguage.json" - }] - } -} \ No newline at end of file + "grammars": [ + { + "language": "zokrates", + "scopeName": "source.zok", + "path": "./syntaxes/zokrates.tmLanguage.json" + } + ] + } +} diff --git a/zokrates_parser/src/textmate/syntaxes/zokrates.tmLanguage.json b/zokrates_parser/src/textmate/syntaxes/zokrates.tmLanguage.json index 3730240c1..c55cadb37 100644 --- a/zokrates_parser/src/textmate/syntaxes/zokrates.tmLanguage.json +++ b/zokrates_parser/src/textmate/syntaxes/zokrates.tmLanguage.json @@ -1,600 +1,637 @@ { - "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", - "name": "ZoKrates", - "fileTypes": [ - "zok" - ], - "scopeName": "source.zok", - "patterns": [ - { - "comment": "attributes", - "name": "meta.attribute.zokrates", - "begin": "(#)(\\!?)(\\[)", - "beginCaptures": { - "1": { - "name": "punctuation.definition.attribute.zokrates" - }, - "2": { - "name": "keyword.operator.attribute.inner.zokrates" - }, - "3": { - "name": "punctuation.brackets.attribute.zokrates" - } - }, - "end": "\\]", - "endCaptures": { - "0": { - "name": "punctuation.brackets.attribute.zokrates" - } - }, - "patterns": [ - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#keywords" - }, - { - "include": "#lifetimes" - }, - { - "include": "#punctuation" - }, - { - "include": "#strings" - }, - { - "include": "#gtypes" - }, - { - "include": "#types" - } - ] - }, - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#constants" - }, - { - "include": "#functions" - }, - { - "include": "#types" - }, - { - "include": "#keywords" - }, - { - "include": "#punctuation" - }, - { - "include": "#strings" - }, - { - "include": "#variables" - } - ], - "repository": { - "comments": { - "patterns": [ - { - "comment": "line comments", - "name": "comment.line.double-slash.zokrates", - "match": "\\s*//.*" - } - ] - }, - "block-comments": { - "patterns": [ - { - "comment": "empty block comments", - "name": "comment.block.zokrates", - "match": "/\\*\\*/" - }, - { - "comment": "block comments", - "name": "comment.block.zokrates", - "begin": "/\\*(?!\\*)", - "end": "\\*/", - "patterns": [ - { - "include": "#block-comments" - } - ] - } - ] - }, - "constants": { - "patterns": [ - { - "comment": "ALL CAPS constants", - "name": "constant.other.caps.zokrates", - "match": "\\b[A-Z]{2}[A-Z0-9_]*\\b" - }, - { - "comment": "decimal integers and floats", - "name": "constant.numeric.decimal.zokrates", - "match": "\\b\\d[\\d_]*(u128|u16|u32|u64|u8|f)?\\b", - "captures": { - "5": { - "name": "entity.name.type.numeric.zokrates" - } - } - }, - { - "comment": "hexadecimal integers", - "name": "constant.numeric.hex.zokrates", - "match": "\\b0x[\\da-fA-F_]+\\b" - }, - { - "comment": "booleans", - "name": "constant.language.bool.zokrates", - "match": "\\b(true|false)\\b" - } - ] - }, - "imports": { - "patterns": [ - { - "comment": "explicit import statement", - "name": "meta.import.explicit.zokrates", - "match": "\\b(from)\\s+(\\\".*\\\")(import)\\s+([A-Za-z0-9_]+)\\s+((as)\\s+[A-Za-z0-9_]+)?\\b", - "patterns": [ - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#keywords" - }, - { - "include": "#punctuation" - }, - { - "include": "#types" - }, - { - "include": "#strings" - } - ] - }, - { - "comment": "main import statement", - "name": "meta.import.explicit.zokrates", - "match": "\\b(import)\\s+(\\\".*\\\")\\s+((as)\\s+[A-Za-z0-9_]+)?\\b", - "patterns": [ - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#keywords" - }, - { - "include": "#punctuation" - }, - { - "include": "#types" - }, - { - "include": "#strings" - } - ] - } - ] - }, - "functions": { - "patterns": [ - { - "comment": "function definition", - "name": "meta.function.definition.zokrates", - "begin": "\\b(def)\\s+([A-Za-z0-9_]+)((\\()|(<))", - "beginCaptures": { - "1": { - "name": "keyword.other.def.zokrates" - }, - "2": { - "name": "entity.name.function.zokrates" - }, - "4": { - "name": "punctuation.brackets.round.zokrates" - }, - "5": { - "name": "punctuation.brackets.angle.zokrates" - } - }, - "end": "\\:|;", - "endCaptures": { - "0": { - "name": "keyword.punctuation.colon.zokrates" - } - }, - "patterns": [ - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#keywords" - }, - { - "include": "#constants" - }, - { - "include": "#functions" - }, - { - "include": "#punctuation" - }, - { - "include": "#strings" - }, - { - "include": "#types" - }, - { - "include": "#variables" - } - ] - }, - { - "comment": "function/method calls, chaining", - "name": "meta.function.call.zokrates", - "begin": "([A-Za-z0-9_]+)(\\()", - "beginCaptures": { - "1": { - "name": "entity.name.function.zokrates" - }, - "2": { - "name": "punctuation.brackets.round.zokrates" - } - }, - "end": "\\)", - "endCaptures": { - "0": { - "name": "punctuation.brackets.round.zokrates" - } - }, - "patterns": [ - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#keywords" - }, - { - "include": "#constants" - }, - { - "include": "#functions" - }, - { - "include": "#punctuation" - }, - { - "include": "#strings" - }, - { - "include": "#types" - }, - { - "include": "#variables" - } - ] - }, - { - "comment": "function/method calls with turbofish", - "name": "meta.function.call.zokrates", - "begin": "([A-Za-z0-9_]+)(?=::<.*>\\()", - "beginCaptures": { - "1": { - "name": "entity.name.function.zokrates" - } - }, - "end": "\\)", - "endCaptures": { - "0": { - "name": "punctuation.brackets.round.zokrates" - } - }, - "patterns": [ - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#keywords" - }, - { - "include": "#constants" - }, - { - "include": "#functions" - }, - { - "include": "#punctuation" - }, - { - "include": "#strings" - }, - { - "include": "#types" - }, - { - "include": "#variables" - } - ] - } - ] - }, - "keywords": { - "patterns": [ - { - "comment": "argument visibility", - "name": "keyword.visibility.zokrates", - "match": "\\b(public|private)\\b" - }, - { - "comment": "control flow keywords", - "name": "keyword.control.zokrates", - "match": "\\b(do|else|for|do|endfor|if|then|fi|return|assert)\\b" - }, - { - "comment": "storage keywords", - "name": "storage.type.zokrates", - "match": "\\b(struct)\\b" - }, - { - "comment": "def", - "name": "keyword.other.def.zokrates", - "match": "\\bdef\\b" - }, - { - "comment": "import keywords", - "name": "keyword.other.import.zokrates", - "match": "\\b(import|from|as)\\b" - }, - { - "comment": "logical operators", - "name": "keyword.operator.logical.zokrates", - "match": "(\\^|\\||\\|\\||&|&&|<<|>>|!)(?!=)" - }, - { - "comment": "single equal", - "name": "keyword.operator.assignment.equal.zokrates", - "match": "(?])=(?!=|>)" - }, - { - "comment": "comparison operators", - "name": "keyword.operator.comparison.zokrates", - "match": "(=(=)?(?!>)|!=|<=|(?=)" - }, - { - "comment": "math operators", - "name": "keyword.operator.math.zokrates", - "match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))" - }, - { - "comment": "less than, greater than (special case)", - "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))", - "captures": { - "1": { - "name": "punctuation.brackets.round.zokrates" - }, - "2": { - "name": "punctuation.brackets.square.zokrates" - }, - "3": { - "name": "punctuation.brackets.curly.zokrates" - }, - "4": { - "name": "keyword.operator.comparison.zokrates" - }, - "5": { - "name": "punctuation.brackets.round.zokrates" - }, - "6": { - "name": "punctuation.brackets.square.zokrates" - }, - "7": { - "name": "punctuation.brackets.curly.zokrates" - } - } - }, - { - "comment": "dot access", - "name": "keyword.operator.access.dot.zokrates", - "match": "\\.(?!\\.)" - }, - { - "comment": "ranges, range patterns", - "name": "keyword.operator.range.zokrates", - "match": "\\.{2}(=|\\.)?" - }, - { - "comment": "colon", - "name": "keyword.operator.colon.zokrates", - "match": ":(?!:)" - }, - { - "comment": "dashrocket, skinny arrow", - "name": "keyword.operator.arrow.skinny.zokrates", - "match": "->" - } - ] - }, - "types": { - "patterns": [ - { - "comment": "numeric types", - "match": "(?", - "endCaptures": { - "0": { - "name": "punctuation.brackets.angle.zokrates" - } - }, - "patterns": [ - { - "include": "#block-comments" - }, - { - "include": "#comments" - }, - { - "include": "#keywords" - }, - { - "include": "#punctuation" - }, - { - "include": "#types" - }, - { - "include": "#variables" - } - ] - }, - { - "comment": "primitive types", - "name": "entity.name.type.primitive.zokrates", - "match": "\\b(bool)\\b" - }, - { - "comment": "struct declarations", - "match": "\\b(struct)\\s+([A-Z][A-Za-z0-9]*)\\b", - "captures": { - "1": { - "name": "storage.type.zokrates" - }, - "2": { - "name": "entity.name.type.struct.zokrates" - } - } - }, - { - "comment": "types", - "name": "entity.name.type.zokrates", - "match": "\\b[A-Z][A-Za-z0-9]*\\b(?!!)" - } - ] - }, - "punctuation": { - "patterns": [ - { - "comment": "comma", - "name": "punctuation.comma.zokrates", - "match": "," - }, - { - "comment": "parentheses, round brackets", - "name": "punctuation.brackets.round.zokrates", - "match": "[()]" - }, - { - "comment": "square brackets", - "name": "punctuation.brackets.square.zokrates", - "match": "[\\[\\]]" - }, - { - "comment": "angle brackets", - "name": "punctuation.brackets.angle.zokrates", - "match": "(?]" - } - ] - }, - "strings": { - "patterns": [ - { - "comment": "double-quoted strings and byte strings", - "name": "string.quoted.double.zokrates", - "begin": "(b?)(\")", - "beginCaptures": { - "1": { - "name": "string.quoted.byte.raw.zokrates" - }, - "2": { - "name": "punctuation.definition.string.zokrates" - } - }, - "end": "\"", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.zokrates" - } - } - }, - { - "comment": "double-quoted raw strings and raw byte strings", - "name": "string.quoted.double.zokrates", - "begin": "(b?r)(#*)(\")", - "beginCaptures": { - "1": { - "name": "string.quoted.byte.raw.zokrates" - }, - "2": { - "name": "punctuation.definition.string.raw.zokrates" - }, - "3": { - "name": "punctuation.definition.string.zokrates" - } - }, - "end": "(\")(\\2)", - "endCaptures": { - "1": { - "name": "punctuation.definition.string.zokrates" - }, - "2": { - "name": "punctuation.definition.string.raw.zokrates" - } - } - } - ] - }, - "variables": { - "patterns": [ - { - "comment": "variables", - "name": "variable.other.zokrates", - "match": "\\b(?\\()", + "beginCaptures": { + "1": { + "name": "entity.name.function.zokrates" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.brackets.round.zokrates" + } + }, + "patterns": [ + { + "include": "#block-comments" + }, + { + "include": "#comments" + }, + { + "include": "#keywords" + }, + { + "include": "#constants" + }, + { + "include": "#functions" + }, + { + "include": "#punctuation" + }, + { + "include": "#strings" + }, + { + "include": "#types" + }, + { + "include": "#variables" + } + ] + } + ] + }, + "keywords": { + "patterns": [ + { + "comment": "argument visibility", + "name": "keyword.visibility.zokrates", + "match": "\\b(public|private)\\b" + }, + { + "comment": "control flow keywords", + "name": "keyword.control.zokrates", + "match": "\\b(do|else|for|do|endfor|if|then|fi|return|assert)\\b" + }, + { + "comment": "storage keywords", + "name": "storage.type.zokrates", + "match": "\\b(struct)\\b" + }, + { + "comment": "const", + "name": "keyword.other.const.zokrates", + "match": "\\bconst\\b" + }, + { + "comment": "def", + "name": "keyword.other.def.zokrates", + "match": "\\bdef\\b" + }, + { + "comment": "import keywords", + "name": "keyword.other.import.zokrates", + "match": "\\b(import|from|as)\\b" + }, + { + "comment": "logical operators", + "name": "keyword.operator.logical.zokrates", + "match": "(\\^|\\||\\|\\||&|&&|<<|>>|!)(?!=)" + }, + { + "comment": "single equal", + "name": "keyword.operator.assignment.equal.zokrates", + "match": "(?])=(?!=|>)" + }, + { + "comment": "comparison operators", + "name": "keyword.operator.comparison.zokrates", + "match": "(=(=)?(?!>)|!=|<=|(?=)" + }, + { + "comment": "math operators", + "name": "keyword.operator.math.zokrates", + "match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))" + }, + { + "comment": "less than, greater than (special case)", + "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))", + "captures": { + "1": { + "name": "punctuation.brackets.round.zokrates" + }, + "2": { + "name": "punctuation.brackets.square.zokrates" + }, + "3": { + "name": "punctuation.brackets.curly.zokrates" + }, + "4": { + "name": "keyword.operator.comparison.zokrates" + }, + "5": { + "name": "punctuation.brackets.round.zokrates" + }, + "6": { + "name": "punctuation.brackets.square.zokrates" + }, + "7": { + "name": "punctuation.brackets.curly.zokrates" + } + } + }, + { + "comment": "dot access", + "name": "keyword.operator.access.dot.zokrates", + "match": "\\.(?!\\.)" + }, + { + "comment": "ranges, range patterns", + "name": "keyword.operator.range.zokrates", + "match": "\\.{2}(=|\\.)?" + }, + { + "comment": "colon", + "name": "keyword.operator.colon.zokrates", + "match": ":(?!:)" + }, + { + "comment": "dashrocket, skinny arrow", + "name": "keyword.operator.arrow.skinny.zokrates", + "match": "->" + } + ] + }, + "types": { + "patterns": [ + { + "comment": "numeric types", + "match": "(?", + "endCaptures": { + "0": { + "name": "punctuation.brackets.angle.zokrates" + } + }, + "patterns": [ + { + "include": "#block-comments" + }, + { + "include": "#comments" + }, + { + "include": "#keywords" + }, + { + "include": "#punctuation" + }, + { + "include": "#types" + }, + { + "include": "#variables" + } + ] + }, + { + "comment": "primitive types", + "name": "entity.name.type.primitive.zokrates", + "match": "\\b(bool)\\b" + }, + { + "comment": "struct declarations", + "match": "\\b(struct)\\s+([A-Z][A-Za-z0-9]*)\\b", + "captures": { + "1": { + "name": "storage.type.zokrates" + }, + "2": { + "name": "entity.name.type.struct.zokrates" + } + } + }, + { + "comment": "types", + "name": "entity.name.type.zokrates", + "match": "\\b[A-Z][A-Za-z0-9]*\\b(?!!)" + } + ] + }, + "punctuation": { + "patterns": [ + { + "comment": "comma", + "name": "punctuation.comma.zokrates", + "match": "," + }, + { + "comment": "parentheses, round brackets", + "name": "punctuation.brackets.round.zokrates", + "match": "[()]" + }, + { + "comment": "square brackets", + "name": "punctuation.brackets.square.zokrates", + "match": "[\\[\\]]" + }, + { + "comment": "angle brackets", + "name": "punctuation.brackets.angle.zokrates", + "match": "(?]" + } + ] + }, + "strings": { + "patterns": [ + { + "comment": "double-quoted strings and byte strings", + "name": "string.quoted.double.zokrates", + "begin": "(b?)(\")", + "beginCaptures": { + "1": { + "name": "string.quoted.byte.raw.zokrates" + }, + "2": { + "name": "punctuation.definition.string.zokrates" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.zokrates" + } + } + }, + { + "comment": "double-quoted raw strings and raw byte strings", + "name": "string.quoted.double.zokrates", + "begin": "(b?r)(#*)(\")", + "beginCaptures": { + "1": { + "name": "string.quoted.byte.raw.zokrates" + }, + "2": { + "name": "punctuation.definition.string.raw.zokrates" + }, + "3": { + "name": "punctuation.definition.string.zokrates" + } + }, + "end": "(\")(\\2)", + "endCaptures": { + "1": { + "name": "punctuation.definition.string.zokrates" + }, + "2": { + "name": "punctuation.definition.string.raw.zokrates" + } + } + } + ] + }, + "variables": { + "patterns": [ + { + "comment": "variables", + "name": "variable.other.zokrates", + "match": "\\b(?\()' + beginCaptures: + '1': {name: entity.name.function.zokrates} + end: \) + endCaptures: + '0': {name: punctuation.brackets.round.zokrates} + patterns: + - {include: '#block-comments'} + - {include: '#comments'} + - {include: '#keywords'} + - {include: '#constants'} + - {include: '#functions'} + - {include: '#punctuation'} + - {include: '#strings'} + - {include: '#types'} + - {include: '#variables'} + keywords: + patterns: + - + comment: 'argument visibility' + name: keyword.visibility.zokrates + match: \b(public|private)\b + - + comment: 'control flow keywords' + name: keyword.control.zokrates + match: \b(do|else|for|do|endfor|if|then|fi|return|assert)\b + - + comment: 'storage keywords' + name: storage.type.zokrates + match: \b(struct)\b + - + comment: const + name: keyword.other.const.zokrates + match: \bconst\b + - + comment: def + name: keyword.other.def.zokrates + match: \bdef\b + - + comment: 'import keywords' + name: keyword.other.import.zokrates + match: \b(import|from|as)\b + - + comment: 'logical operators' + name: keyword.operator.logical.zokrates + match: '(\^|\||\|\||&|&&|<<|>>|!)(?!=)' + - + comment: 'single equal' + name: keyword.operator.assignment.equal.zokrates + match: '(?])=(?!=|>)' + - + comment: 'comparison operators' + name: keyword.operator.comparison.zokrates + match: '(=(=)?(?!>)|!=|<=|(?=)' + - + comment: 'math operators' + name: keyword.operator.math.zokrates + match: '(([+%]|(\*(?!\w)))(?!=))|(-(?!>))|(/(?!/))' + - + comment: 'less than, greater than (special case)' + match: '(?:\b|(?:(\))|(\])|(\})))[ \t]+([<>])[ \t]+(?:\b|(?:(\()|(\[)|(\{)))' + captures: + '1': {name: punctuation.brackets.round.zokrates} + '2': {name: punctuation.brackets.square.zokrates} + '3': {name: punctuation.brackets.curly.zokrates} + '4': {name: keyword.operator.comparison.zokrates} + '5': {name: punctuation.brackets.round.zokrates} + '6': {name: punctuation.brackets.square.zokrates} + '7': {name: punctuation.brackets.curly.zokrates} + - + comment: 'dot access' + name: keyword.operator.access.dot.zokrates + match: '\.(?!\.)' + - + comment: 'ranges, range patterns' + name: keyword.operator.range.zokrates + match: '\.{2}(=|\.)?' + - + comment: colon + name: keyword.operator.colon.zokrates + match: ':(?!:)' + - + comment: 'dashrocket, skinny arrow' + name: keyword.operator.arrow.skinny.zokrates + match: '->' + types: + patterns: + - + comment: 'numeric types' + match: '(?' + endCaptures: + '0': {name: punctuation.brackets.angle.zokrates} + patterns: + - {include: '#block-comments'} + - {include: '#comments'} + - {include: '#keywords'} + - {include: '#punctuation'} + - {include: '#types'} + - {include: '#variables'} + - + comment: 'primitive types' + name: entity.name.type.primitive.zokrates + match: \b(bool)\b + - + comment: 'struct declarations' + match: '\b(struct)\s+([A-Z][A-Za-z0-9]*)\b' + captures: + '1': {name: storage.type.zokrates} + '2': {name: entity.name.type.struct.zokrates} + - + comment: types + name: entity.name.type.zokrates + match: '\b[A-Z][A-Za-z0-9]*\b(?!!)' + punctuation: + patterns: + - + comment: comma + name: punctuation.comma.zokrates + match: ',' + - + comment: 'parentheses, round brackets' + name: punctuation.brackets.round.zokrates + match: '[()]' + - + comment: 'square brackets' + name: punctuation.brackets.square.zokrates + match: '[\[\]]' + - + comment: 'angle brackets' + name: punctuation.brackets.angle.zokrates + match: '(?]' + strings: + patterns: + - + comment: 'double-quoted strings and byte strings' + name: string.quoted.double.zokrates + begin: '(b?)(")' + beginCaptures: + '1': {name: string.quoted.byte.raw.zokrates} + '2': {name: punctuation.definition.string.zokrates} + end: '"' + endCaptures: + '0': {name: punctuation.definition.string.zokrates} + - + comment: 'double-quoted raw strings and raw byte strings' + name: string.quoted.double.zokrates + begin: '(b?r)(#*)(")' + beginCaptures: + '1': {name: string.quoted.byte.raw.zokrates} + '2': {name: punctuation.definition.string.raw.zokrates} + '3': {name: punctuation.definition.string.zokrates} + end: '(")(\2)' + endCaptures: + '1': {name: punctuation.definition.string.zokrates} + '2': {name: punctuation.definition.string.raw.zokrates} + variables: + patterns: + - + comment: variables + name: variable.other.zokrates + match: '\b(? Date: Mon, 19 Apr 2021 18:46:13 +0200 Subject: [PATCH 39/95] generic equivalence, add tests --- zokrates_cli/examples/array_overload.zok | 8 ++ .../generics/conflicting_call.zok | 11 ++ .../generics/conflicting_functions.zok | 8 ++ .../generics/non_conflicting_call.zok | 14 ++ zokrates_core/src/embed.rs | 12 +- zokrates_core/src/semantics.rs | 73 ++++++---- .../src/static_analysis/reducer/mod.rs | 92 +++++++++---- .../static_analysis/reducer/shallow_ssa.rs | 30 +++- zokrates_core/src/typed_absy/types.rs | 130 +++++++++++++++--- 9 files changed, 293 insertions(+), 85 deletions(-) create mode 100644 zokrates_cli/examples/array_overload.zok create mode 100644 zokrates_cli/examples/compile_errors/generics/conflicting_call.zok create mode 100644 zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok create mode 100644 zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok diff --git a/zokrates_cli/examples/array_overload.zok b/zokrates_cli/examples/array_overload.zok new file mode 100644 index 000000000..7f380548e --- /dev/null +++ b/zokrates_cli/examples/array_overload.zok @@ -0,0 +1,8 @@ +def foo(field[2] a) -> bool: + return true + +def foo(field[1] a) -> bool: + return true + +def main() -> bool: + return foo([1]) \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/generics/conflicting_call.zok b/zokrates_cli/examples/compile_errors/generics/conflicting_call.zok new file mode 100644 index 000000000..6b3baa79b --- /dev/null +++ b/zokrates_cli/examples/compile_errors/generics/conflicting_call.zok @@ -0,0 +1,11 @@ +def foo(field[N] a) -> field[P]: + return a + +def foo(field[P] a) -> field[N]: + return a + +def bar(field[Q] a) -> field[Q]: + return foo(a) + +def main() -> field[1]: + return bar([1]) \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok b/zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok new file mode 100644 index 000000000..bfdbf6b68 --- /dev/null +++ b/zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok @@ -0,0 +1,8 @@ +def foo(field[N] a) -> bool: + return true + +def foo

(field[P] a) -> bool: + return true + +def main(): + return \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok b/zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok new file mode 100644 index 000000000..5d0b71e08 --- /dev/null +++ b/zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok @@ -0,0 +1,14 @@ +// this should compile but requires looking at the generic parameter values, and they are not known at semantic check time. +// It is enough of an edge case to not be worth fixing + +def foo(field[N] a) -> field[P]: + return [1; P] + +def foo(field[P] a) -> field[N]: + return [1; N] + +def main() -> field[2]: + u32 X = 1 + u32 Y = 2 + field[2] a = foo::([1]) + return a \ No newline at end of file diff --git a/zokrates_core/src/embed.rs b/zokrates_core/src/embed.rs index e1b0326df..cd93ea1db 100644 --- a/zokrates_core/src/embed.rs +++ b/zokrates_core/src/embed.rs @@ -4,7 +4,7 @@ use crate::flat_absy::{ }; use crate::solvers::Solver; use crate::typed_absy::types::{ - ConcreteGenericsAssignment, Constant, DeclarationSignature, DeclarationType, + ConcreteGenericsAssignment, Constant, DeclarationSignature, DeclarationType, GenericIdentifier, }; use std::collections::HashMap; use zokrates_field::{Bn128Field, Field}; @@ -43,11 +43,17 @@ impl FlatEmbed { .inputs(vec![DeclarationType::uint(32)]) .outputs(vec![DeclarationType::FieldElement]), FlatEmbed::Unpack => DeclarationSignature::new() - .generics(vec![Some(Constant::Generic("N"))]) + .generics(vec![Some(Constant::Generic(GenericIdentifier { + name: "N", + index: 0, + }))]) .inputs(vec![DeclarationType::FieldElement]) .outputs(vec![DeclarationType::array(( DeclarationType::Boolean, - "N", + GenericIdentifier { + name: "N", + index: 0, + }, ))]), FlatEmbed::U8ToBits => DeclarationSignature::new() .inputs(vec![DeclarationType::uint(8)]) diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 3bd4f160d..192417a42 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -20,7 +20,8 @@ use crate::absy::types::{UnresolvedSignature, UnresolvedType, UserTypeId}; use crate::typed_absy::types::{ ArrayType, Constant, DeclarationArrayType, DeclarationFunctionKey, DeclarationSignature, - DeclarationStructMember, DeclarationStructType, DeclarationType, StructLocation, + DeclarationStructMember, DeclarationStructType, DeclarationType, GenericIdentifier, + StructLocation, }; use std::hash::{Hash, Hasher}; @@ -325,7 +326,7 @@ impl<'ast, T: Field> Checker<'ast, T> { for field in s.fields { let member_id = field.value.id.to_string(); match self - .check_declaration_type(field.value.ty, module_id, &types, &HashSet::new()) + .check_declaration_type(field.value.ty, module_id, &types, &HashMap::new()) .map(|t| (member_id, t)) { Ok(f) => match fields_set.insert(f.0.clone()) { @@ -696,7 +697,7 @@ impl<'ast, T: Field> Checker<'ast, T> { let v = Variable::with_id_and_type( match generic { - Constant::Generic(g) => g, + Constant::Generic(g) => g.name, _ => unreachable!(), }, Type::Uint(UBitwidth::B32), @@ -818,12 +819,15 @@ impl<'ast, T: Field> Checker<'ast, T> { let mut outputs = vec![]; let mut generics = vec![]; - let mut constants = HashSet::new(); + let mut generics_map = HashMap::new(); - for g in signature.generics { - match constants.insert(g.value) { + for (index, g) in signature.generics.iter().enumerate() { + match generics_map.insert(g.value, index).is_none() { true => { - generics.push(Some(Constant::Generic(g.value))); + generics.push(Some(Constant::Generic(GenericIdentifier { + name: g.value, + index, + }))); } false => { errors.push(ErrorInner { @@ -835,7 +839,7 @@ impl<'ast, T: Field> Checker<'ast, T> { } for t in signature.inputs { - match self.check_declaration_type(t, module_id, types, &constants) { + match self.check_declaration_type(t, module_id, types, &generics_map) { Ok(t) => { inputs.push(t); } @@ -846,7 +850,7 @@ impl<'ast, T: Field> Checker<'ast, T> { } for t in signature.outputs { - match self.check_declaration_type(t, module_id, types, &constants) { + match self.check_declaration_type(t, module_id, types, &generics_map) { Ok(t) => { outputs.push(t); } @@ -936,6 +940,7 @@ impl<'ast, T: Field> Checker<'ast, T> { fn check_generic_expression( &mut self, expr: ExpressionNode<'ast>, + generics_map: &HashMap, usize>, ) -> Result, ErrorInner> { let pos = expr.pos(); @@ -956,7 +961,16 @@ impl<'ast, T: Field> Checker<'ast, T> { }) } } - Expression::Identifier(name) => Ok(Constant::Generic(name)), + Expression::Identifier(name) => { + // check that this generic parameter is defined + match generics_map.get(&name) { + Some(index) => Ok(Constant::Generic(GenericIdentifier {name, index: *index})), + None => Err(ErrorInner { + pos: Some(pos), + message: format!("Undeclared generic parameter in function definition: `{}` isn\'t declared as a generic constant", name) + }) + } + } e => Err(ErrorInner { pos: Some(pos), message: format!( @@ -972,7 +986,7 @@ impl<'ast, T: Field> Checker<'ast, T> { ty: UnresolvedTypeNode<'ast>, module_id: &ModuleId, types: &TypeMap<'ast>, - constants: &HashSet>, + generics_map: &HashMap, usize>, ) -> Result, ErrorInner> { let pos = ty.pos(); let ty = ty.value; @@ -982,19 +996,10 @@ impl<'ast, T: Field> Checker<'ast, T> { UnresolvedType::Boolean => Ok(DeclarationType::Boolean), UnresolvedType::Uint(bitwidth) => Ok(DeclarationType::uint(bitwidth)), UnresolvedType::Array(t, size) => { - let checked_size = self.check_generic_expression(size.clone())?; - - if let Constant::Generic(g) = checked_size { - if !constants.contains(g) { - return Err(ErrorInner { - pos: Some(pos), - message: format!("Undeclared generic parameter in function definition: `{}` isn\'t declared as a generic constant", g) - }); - } - }; + let checked_size = self.check_generic_expression(size.clone(), &generics_map)?; Ok(DeclarationType::Array(DeclarationArrayType::new( - self.check_declaration_type(*t, module_id, types, constants)?, + self.check_declaration_type(*t, module_id, types, generics_map)?, checked_size, ))) } @@ -3022,17 +3027,21 @@ mod tests { assert!(!unifier.insert_function( "bar", DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into() + )]) .inputs(vec![DeclarationType::FieldElement]) )); // a `bar` function with a different signature assert!(unifier.insert_function( "bar", DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into() + )]) .inputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - "K" + GenericIdentifier::with_name("K").index(0) ))]) )); // a `bar` function with a different signature, but which could conflict with the previous one @@ -3609,12 +3618,18 @@ mod tests { ), Ok(DeclarationSignature::new() .inputs(vec![DeclarationType::array(( - DeclarationType::array((DeclarationType::FieldElement, "K")), - "L" + DeclarationType::array(( + DeclarationType::FieldElement, + GenericIdentifier::with_name("K").index(0) + )), + GenericIdentifier::with_name("L").index(1) ))]) .outputs(vec![DeclarationType::array(( - DeclarationType::array((DeclarationType::FieldElement, "L")), - "K" + DeclarationType::array(( + DeclarationType::FieldElement, + GenericIdentifier::with_name("L").index(1) + )), + GenericIdentifier::with_name("K").index(0) ))])) ); } diff --git a/zokrates_core/src/static_analysis/reducer/mod.rs b/zokrates_core/src/static_analysis/reducer/mod.rs index db5704dc6..ce1e5ce9d 100644 --- a/zokrates_core/src/static_analysis/reducer/mod.rs +++ b/zokrates_core/src/static_analysis/reducer/mod.rs @@ -657,8 +657,9 @@ mod tests { use crate::typed_absy::types::DeclarationSignature; use crate::typed_absy::{ ArrayExpressionInner, DeclarationFunctionKey, DeclarationType, DeclarationVariable, - FieldElementExpression, Identifier, OwnedTypedModuleId, Select, Type, TypedExpression, - TypedExpressionList, TypedExpressionOrSpread, UBitwidth, UExpressionInner, Variable, + FieldElementExpression, GenericIdentifier, Identifier, OwnedTypedModuleId, Select, Type, + TypedExpression, TypedExpressionList, TypedExpressionOrSpread, UBitwidth, UExpressionInner, + Variable, }; use zokrates_field::Bn128Field; @@ -865,20 +866,25 @@ mod tests { // return a_2 + b_1[0] let foo_signature = DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]) .inputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ))]) .outputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ))]); let foo: TypedFunction = TypedFunction { - arguments: vec![ - DeclarationVariable::array("a", DeclarationType::FieldElement, "K").into(), - ], + arguments: vec![DeclarationVariable::array( + "a", + DeclarationType::FieldElement, + GenericIdentifier::with_name("K").index(0), + ) + .into()], statements: vec![TypedStatement::Return(vec![ ArrayExpressionInner::Identifier("a".into()) .annotate(Type::FieldElement, 1u32) @@ -983,7 +989,11 @@ mod tests { TypedStatement::PushCallLog( DeclarationFunctionKey::with_location("main", "foo") .signature(foo_signature.clone()), - GGenericsAssignment(vec![("K", 1)].into_iter().collect()), + GGenericsAssignment( + vec![(GenericIdentifier::with_name("K").index(0), 1)] + .into_iter() + .collect(), + ), ), TypedStatement::Definition( Variable::array(Identifier::from("a").version(1), Type::FieldElement, 1u32) @@ -1073,20 +1083,25 @@ mod tests { // return a_2 + b_1[0] let foo_signature = DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]) .inputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ))]) .outputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ))]); let foo: TypedFunction = TypedFunction { - arguments: vec![ - DeclarationVariable::array("a", DeclarationType::FieldElement, "K").into(), - ], + arguments: vec![DeclarationVariable::array( + "a", + DeclarationType::FieldElement, + GenericIdentifier::with_name("K").index(0), + ) + .into()], statements: vec![TypedStatement::Return(vec![ ArrayExpressionInner::Identifier("a".into()) .annotate(Type::FieldElement, 1u32) @@ -1200,7 +1215,11 @@ mod tests { TypedStatement::PushCallLog( DeclarationFunctionKey::with_location("main", "foo") .signature(foo_signature.clone()), - GGenericsAssignment(vec![("K", 1)].into_iter().collect()), + GGenericsAssignment( + vec![(GenericIdentifier::with_name("K").index(0), 1)] + .into_iter() + .collect(), + ), ), TypedStatement::Definition( Variable::array(Identifier::from("a").version(1), Type::FieldElement, 1u32) @@ -1299,19 +1318,21 @@ mod tests { let foo_signature = DeclarationSignature::new() .inputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ))]) .outputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ))]) - .generics(vec![Some("K".into())]); + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]); let foo: TypedFunction = TypedFunction { arguments: vec![DeclarationVariable::array( "a", DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ) .into()], statements: vec![ @@ -1375,7 +1396,7 @@ mod tests { arguments: vec![DeclarationVariable::array( "a", DeclarationType::FieldElement, - Constant::Generic("K"), + Constant::Generic(GenericIdentifier::with_name("K").index(0)), ) .into()], statements: vec![TypedStatement::Return(vec![ @@ -1448,12 +1469,20 @@ mod tests { TypedStatement::PushCallLog( DeclarationFunctionKey::with_location("main", "foo") .signature(foo_signature.clone()), - GGenericsAssignment(vec![("K", 1)].into_iter().collect()), + GGenericsAssignment( + vec![(GenericIdentifier::with_name("K").index(0), 1)] + .into_iter() + .collect(), + ), ), TypedStatement::PushCallLog( DeclarationFunctionKey::with_location("main", "bar") .signature(foo_signature.clone()), - GGenericsAssignment(vec![("K", 2)].into_iter().collect()), + GGenericsAssignment( + vec![(GenericIdentifier::with_name("K").index(0), 2)] + .into_iter() + .collect(), + ), ), TypedStatement::Definition( Variable::array(Identifier::from("a").version(1), Type::FieldElement, 2u32) @@ -1558,20 +1587,25 @@ mod tests { // Error: Incompatible let foo_signature = DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]) .inputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + GenericIdentifier::with_name("K").index(0), ))]) .outputs(vec![DeclarationType::array(( DeclarationType::FieldElement, - Constant::Generic("K"), + GenericIdentifier::with_name("K").index(0), ))]); let foo: TypedFunction = TypedFunction { - arguments: vec![ - DeclarationVariable::array("a", DeclarationType::FieldElement, "K").into(), - ], + arguments: vec![DeclarationVariable::array( + "a", + DeclarationType::FieldElement, + GenericIdentifier::with_name("K").index(0), + ) + .into()], statements: vec![TypedStatement::Return(vec![ ArrayExpressionInner::Identifier("a".into()) .annotate(Type::FieldElement, 1u32) diff --git a/zokrates_core/src/static_analysis/reducer/shallow_ssa.rs b/zokrates_core/src/static_analysis/reducer/shallow_ssa.rs index a40ebbfd4..f582cbb65 100644 --- a/zokrates_core/src/static_analysis/reducer/shallow_ssa.rs +++ b/zokrates_core/src/static_analysis/reducer/shallow_ssa.rs @@ -105,7 +105,7 @@ impl<'ast, 'a> ShallowTransformer<'ast, 'a> { .map(|(g, v)| { TypedStatement::Definition( TypedAssignee::Identifier(Variable::with_id_and_type( - *g, + g.name, Type::Uint(UBitwidth::B32), )), UExpression::from(*v as u32).into(), @@ -731,7 +731,9 @@ mod tests { ]), ], signature: DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]) .inputs(vec![DeclarationType::FieldElement]) .outputs(vec![DeclarationType::FieldElement]), }; @@ -740,7 +742,11 @@ mod tests { let ssa = ShallowTransformer::transform( f, - &GGenericsAssignment(vec![("K", 1)].into_iter().collect()), + &GGenericsAssignment( + vec![(GenericIdentifier::with_name("K").index(0), 1)] + .into_iter() + .collect(), + ), &mut versions, ); @@ -805,7 +811,9 @@ mod tests { .into()]), ], signature: DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]) .inputs(vec![DeclarationType::FieldElement]) .outputs(vec![DeclarationType::FieldElement]), }; @@ -912,7 +920,9 @@ mod tests { ]), ], signature: DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]) .inputs(vec![DeclarationType::FieldElement]) .outputs(vec![DeclarationType::FieldElement]), }; @@ -921,7 +931,11 @@ mod tests { let ssa = ShallowTransformer::transform( f, - &GGenericsAssignment(vec![("K", 1)].into_iter().collect()), + &GGenericsAssignment( + vec![(GenericIdentifier::with_name("K").index(0), 1)] + .into_iter() + .collect(), + ), &mut versions, ); @@ -989,7 +1003,9 @@ mod tests { .into()]), ], signature: DeclarationSignature::new() - .generics(vec![Some("K".into())]) + .generics(vec![Some( + GenericIdentifier::with_name("K").index(0).into(), + )]) .inputs(vec![DeclarationType::FieldElement]) .outputs(vec![DeclarationType::FieldElement]), }; diff --git a/zokrates_core/src/typed_absy/types.rs b/zokrates_core/src/typed_absy/types.rs index 9c905fc8d..02b35784c 100644 --- a/zokrates_core/src/typed_absy/types.rs +++ b/zokrates_core/src/typed_absy/types.rs @@ -6,7 +6,46 @@ use std::fmt; use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; -pub type GenericIdentifier<'ast> = &'ast str; +#[derive(Debug, Clone, Eq, Ord)] +pub struct GenericIdentifier<'ast> { + pub name: &'ast str, + pub index: usize, +} + +impl<'ast> GenericIdentifier<'ast> { + pub fn with_name(name: &'ast str) -> Self { + Self { name, index: 0 } + } + + pub fn index(mut self, index: usize) -> Self { + self.index = index; + self + } +} + +impl<'ast> PartialEq for GenericIdentifier<'ast> { + fn eq(&self, other: &Self) -> bool { + self.index == other.index + } +} + +impl<'ast> PartialOrd for GenericIdentifier<'ast> { + fn partial_cmp(&self, other: &Self) -> Option { + self.index.partial_cmp(&other.index) + } +} + +impl<'ast> Hash for GenericIdentifier<'ast> { + fn hash(&self, state: &mut H) { + self.index.hash(state); + } +} + +impl<'ast> fmt::Display for GenericIdentifier<'ast> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.name) + } +} #[derive(Debug)] pub struct SpecializationError; @@ -53,7 +92,9 @@ impl<'ast, T> From for UExpression<'ast, T> { impl<'ast, T> From> for UExpression<'ast, T> { fn from(c: Constant<'ast>) -> Self { match c { - Constant::Generic(i) => UExpressionInner::Identifier(i.into()).annotate(UBitwidth::B32), + Constant::Generic(i) => { + UExpressionInner::Identifier(i.name.into()).annotate(UBitwidth::B32) + } Constant::Concrete(v) => UExpressionInner::Value(v as u128).annotate(UBitwidth::B32), } } @@ -819,13 +860,41 @@ pub mod signature { use super::*; use std::fmt; - #[derive(Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[derive(Clone, Serialize, Deserialize, Eq)] pub struct GSignature { pub generics: Vec>, pub inputs: Vec>, pub outputs: Vec>, } + impl PartialEq for GSignature { + fn eq(&self, other: &Self) -> bool { + self.inputs == other.inputs && self.outputs == other.outputs + } + } + + impl PartialOrd for GSignature { + fn partial_cmp(&self, other: &Self) -> Option { + self.inputs + .partial_cmp(&other.inputs) + .map(|c| self.outputs.partial_cmp(&other.outputs).map(|d| c.then(d))) + .unwrap() + } + } + + impl Ord for GSignature { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.partial_cmp(&other).unwrap() + } + } + + impl Hash for GSignature { + fn hash(&self, state: &mut H) { + self.inputs.hash(state); + self.outputs.hash(state); + } + } + impl Default for GSignature { fn default() -> Self { GSignature { @@ -853,17 +922,17 @@ pub mod signature { // both the inner type and the size must match check_type(&t0.ty, &t1.ty, constants) - && match t0.size { + && match &t0.size { // if the declared size is an identifier, we insert into the map, or check if the concrete size // matches if this identifier is already in the map - Constant::Generic(id) => match constants.0.entry(id) { + Constant::Generic(id) => match constants.0.entry(id.clone()) { Entry::Occupied(e) => *e.get() == s1, Entry::Vacant(e) => { e.insert(s1); true } }, - Constant::Concrete(s0) => s1 == s0 as usize, + Constant::Concrete(s0) => s1 == *s0 as usize, } } (DeclarationType::FieldElement, GType::FieldElement) @@ -1169,34 +1238,61 @@ pub mod signature { #[test] fn signature_equivalence() { - let generic = DeclarationSignature::new() - .generics(vec![Some("P".into())]) + // check equivalence of: + //

(field[P]) + // (field[Q]) + + let generic1 = DeclarationSignature::new() + .generics(vec![Some( + GenericIdentifier { + name: "P", + index: 0, + } + .into(), + )]) + .inputs(vec![DeclarationType::array(DeclarationArrayType::new( + DeclarationType::FieldElement, + GenericIdentifier { + name: "P", + index: 0, + } + .into(), + ))]); + let generic2 = DeclarationSignature::new() + .generics(vec![Some( + GenericIdentifier { + name: "Q", + index: 0, + } + .into(), + )]) .inputs(vec![DeclarationType::array(DeclarationArrayType::new( DeclarationType::FieldElement, - "P".into(), + GenericIdentifier { + name: "Q", + index: 0, + } + .into(), ))]); - let specialized = DeclarationSignature::new().inputs(vec![DeclarationType::array( - DeclarationArrayType::new(DeclarationType::FieldElement, 3u32.into()), - )]); - assert_eq!(generic, specialized); + assert_eq!(generic1, generic2); assert_eq!( { let mut hasher = std::collections::hash_map::DefaultHasher::new(); - generic.hash(&mut hasher); + generic1.hash(&mut hasher); hasher.finish() }, { let mut hasher = std::collections::hash_map::DefaultHasher::new(); - specialized.hash(&mut hasher); + generic2.hash(&mut hasher); hasher.finish() } ); assert_eq!( - generic.partial_cmp(&specialized), + generic1.partial_cmp(&generic2), Some(std::cmp::Ordering::Equal) ); - assert_eq!(generic.cmp(&specialized), std::cmp::Ordering::Equal); + assert_eq!(generic1.cmp(&generic2), std::cmp::Ordering::Equal); } #[test] From 30e489553c9b5c0447ad712509ce6b226c2816a5 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 19 Apr 2021 18:56:48 +0200 Subject: [PATCH 40/95] clippy, changelog --- changelogs/unreleased/822-schaeff | 1 + zokrates_core/src/semantics.rs | 21 +++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 changelogs/unreleased/822-schaeff diff --git a/changelogs/unreleased/822-schaeff b/changelogs/unreleased/822-schaeff new file mode 100644 index 000000000..cf42ad153 --- /dev/null +++ b/changelogs/unreleased/822-schaeff @@ -0,0 +1 @@ +Make function selection stricter in function calls \ No newline at end of file diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index bfa4a5c64..fc3f03f4b 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -142,18 +142,15 @@ struct FunctionQuery<'ast, T> { impl<'ast, T: fmt::Display> fmt::Display for FunctionQuery<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self.generics_count { - Some(count) => { - write!( - f, - "<{}>", - (0..count) - .map(|_| String::from("_")) - .collect::>() - .join(", ") - )?; - } - None => {} + if let Some(count) = self.generics_count { + write!( + f, + "<{}>", + (0..count) + .map(|_| String::from("_")) + .collect::>() + .join(", ") + )? } write!(f, "(")?; From 2b9bae67c00112b986f269c808b6972cd4a39303 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 19 Apr 2021 20:33:47 +0200 Subject: [PATCH 41/95] fix tests, make constant comparison smarter --- zokrates_cli/src/bin.rs | 4 ++-- zokrates_core/src/semantics.rs | 23 +++++++++++------------ zokrates_core/src/typed_absy/types.rs | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index 4da16054f..2a57f7783 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -95,12 +95,12 @@ mod tests { continue; } + println!("Testing {:?}", path); + assert!(path.extension().expect("extension expected") == "zok"); let should_error = path.to_str().unwrap().contains("compile_errors"); - println!("Testing {:?}", path); - let file = File::open(path.clone()).unwrap(); let mut reader = BufReader::new(file); diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index a4345689b..56468aa77 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -3061,13 +3061,17 @@ mod tests { GenericIdentifier::with_name("K").index(0) ))]) )); - // a `bar` function with a different signature, but which could conflict with the previous one + // a `bar` function with an equivalent signature, just renaming generic parameters assert!(!unifier.insert_function( "bar", - DeclarationSignature::new().inputs(vec![DeclarationType::array(( - DeclarationType::FieldElement, - 42u32 - ))]) + DeclarationSignature::new() + .generics(vec![Some( + GenericIdentifier::with_name("L").index(0).into() + )]) + .inputs(vec![DeclarationType::array(( + DeclarationType::FieldElement, + GenericIdentifier::with_name("L").index(0) + ))]) )); // a `bar` type isn't allowed as the name is already taken by at least one function assert!(!unifier.insert_type("bar")); @@ -3176,7 +3180,7 @@ mod tests { // def foo(private field[3] a): // return // - // should fail as P could be equal to 3 + // should succeed as P could be different from 3 let mut f0 = function0(); @@ -3238,12 +3242,7 @@ mod tests { let mut state = State::new(vec![((*MODULE_ID).clone(), module)].into_iter().collect()); let mut checker: Checker = Checker::new(); - assert_eq!( - checker.check_module(&*MODULE_ID, &mut state).unwrap_err()[0] - .inner - .message, - "foo conflicts with another symbol" - ); + assert!(checker.check_module(&*MODULE_ID, &mut state).is_ok()); } mod generics { diff --git a/zokrates_core/src/typed_absy/types.rs b/zokrates_core/src/typed_absy/types.rs index 6aaf99033..61cc9bf91 100644 --- a/zokrates_core/src/typed_absy/types.rs +++ b/zokrates_core/src/typed_absy/types.rs @@ -673,9 +673,19 @@ impl<'ast, T: fmt::Display + PartialEq + fmt::Debug> Type<'ast, T> { } else { match (self, other) { (Int, FieldElement) | (Int, Uint(..)) => true, - (Array(l), Array(r)) => l.ty.can_be_specialized_to(&r.ty), - // types do not come into play for Struct equality, only the canonical location. Hence no inference - // can change anything + (Array(l), Array(r)) => match l.ty.can_be_specialized_to(&r.ty) { + true => { + // check the size if types match + match (&l.size.as_inner(), &r.size) { + // compare the sizes for concrete ones + (UExpressionInner::Value(v), Constant::Concrete(c)) => { + (*v as u32) == *c + } + _ => true, + } + } + _ => false, + }, (Struct(_), Struct(_)) => false, _ => false, } From 616fcc9b17e1e903f05cc5ee79163c734561c347 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 19 Apr 2021 20:46:01 +0200 Subject: [PATCH 42/95] add changelog --- changelogs/unreleased/826-schaeff | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/826-schaeff diff --git a/changelogs/unreleased/826-schaeff b/changelogs/unreleased/826-schaeff new file mode 100644 index 000000000..d9c712313 --- /dev/null +++ b/changelogs/unreleased/826-schaeff @@ -0,0 +1 @@ +Make function definitions more permissive, and move ambiguity checks to call sites and improve them \ No newline at end of file From aa5a3b4b324e72f9938cea1c69dd63bad10a275d Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 20 Apr 2021 12:39:41 +0200 Subject: [PATCH 43/95] rename and improve example --- .../{return_explicit_generic.zok => explicit_generic.zok} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename zokrates_cli/examples/{return_explicit_generic.zok => explicit_generic.zok} (58%) diff --git a/zokrates_cli/examples/return_explicit_generic.zok b/zokrates_cli/examples/explicit_generic.zok similarity index 58% rename from zokrates_cli/examples/return_explicit_generic.zok rename to zokrates_cli/examples/explicit_generic.zok index 3177b9268..bcc490bef 100644 --- a/zokrates_cli/examples/return_explicit_generic.zok +++ b/zokrates_cli/examples/explicit_generic.zok @@ -2,4 +2,5 @@ def foo() -> field[N]: return [42; N] def main() -> field[2]: - return foo::<2>() \ No newline at end of file + field a = foo::<3>()[0] + return foo::<2>() \ No newline at end of file From 30e695b48d2814ffd6a0b46f8b90c4189a4efafa Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 20 Apr 2021 12:52:38 +0200 Subject: [PATCH 44/95] add changelog --- changelogs/unreleased/798-schaeff | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/798-schaeff diff --git a/changelogs/unreleased/798-schaeff b/changelogs/unreleased/798-schaeff new file mode 100644 index 000000000..f80f85a45 --- /dev/null +++ b/changelogs/unreleased/798-schaeff @@ -0,0 +1 @@ +Accept explicit generic parameters outside of definitions \ No newline at end of file From c105e801e52c5d6d9fc6eea10c797f27cd7e0dd9 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 20 Apr 2021 18:35:03 +0200 Subject: [PATCH 45/95] fix to_bits, improve naming --- lt.zok | 47 -------------------- zokrates_core/src/flatten/mod.rs | 26 ++++++----- zokrates_core_test/tests/tests/native_le.zok | 4 +- zokrates_field/src/lib.rs | 2 +- 4 files changed, 19 insertions(+), 60 deletions(-) delete mode 100644 lt.zok diff --git a/lt.zok b/lt.zok deleted file mode 100644 index 2d657c091..000000000 --- a/lt.zok +++ /dev/null @@ -1,47 +0,0 @@ -from "utils/pack/bool/unpack.zok" import main as unpack -from "utils/casts/u32_to_bits" import main as u32_to_bits - -// this comparison works for any N smaller than the field size, which is the case in practice -def lt(bool[N] a_bits, bool[N] c_bits) -> bool: - - bool[N] is_not_smaller_run = [false; N] - bool[N] size_unknown = [false; N] - - u32 verified_conditions = 0 // `and(conditions) == (sum(conditions) == len(conditions))`, here we initialize `sum(conditions)` - - size_unknown[0] = true - - for u32 i in 0..N - 1 do - is_not_smaller_run[i] = if c_bits[i] then a_bits[i] else is_not_smaller_run[i] fi - size_unknown[i + 1] = if c_bits[i] then size_unknown[i] && is_not_smaller_run[i] else size_unknown[i] fi - verified_conditions = verified_conditions + if c_bits[i] then 1 else if (!size_unknown[i] || !a_bits[i]) then 1 else 0 fi fi - endfor - - u32 i = N - 1 - is_not_smaller_run[i] = if c_bits[i] then a_bits[i] else is_not_smaller_run[i] fi - verified_conditions = verified_conditions + if c_bits[i] then 1 else if (!size_unknown[i] || !a_bits[i]) then 1 else 0 fi fi - - return verified_conditions == N // this checks that all conditions were verified - -// this instanciates comparison starting from field elements -def lt(field a, field c) -> bool: - bool[N] a_bits = unpack(a) - bool[N] c_bits = unpack(c) - - return lt(a_bits, c_bits) - -// this instanciates comparison starting from u32 -def lt(u32 a, u32 c) -> bool: - bool[32] a_bits = u32_to_bits(a) - bool[32] c_bits = u32_to_bits(c) - - return lt(a_bits, c_bits) - -def main(field a) -> bool: - - u32 N = 254 - field c = 42 - - //u32 d = 42 - - return lt::(a, c) \ No newline at end of file diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index c29780dfe..a6a563559 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -204,7 +204,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { // # Returns // // * a vector of FlatExpression which all evaluate to 1 if a <= b and 0 otherwise - fn strict_le_check( + fn constant_le_check( &mut self, statements_flattened: &mut FlatStatements, a: &[FlatVariable], @@ -217,6 +217,8 @@ impl<'ast, T: Field> Flattener<'ast, T> { let mut is_not_smaller_run = vec![]; let mut size_unknown = vec![]; + println!("B {:?}", b); + for _ in 0..len { is_not_smaller_run.push(self.use_sym()); size_unknown.push(self.use_sym()); @@ -326,14 +328,14 @@ impl<'ast, T: Field> Flattener<'ast, T> { res } - fn enforce_strict_le_check( + fn enforce_constant_le_check( &mut self, statements_flattened: &mut FlatStatements, a: &[FlatVariable], b: &[bool], ) { let statements: Vec<_> = self - .strict_le_check(statements_flattened, a, b) + .constant_le_check(statements_flattened, a, b) .into_iter() .map(|c| FlatStatement::Condition(FlatExpression::Number(T::from(1)), c)) .collect(); @@ -422,7 +424,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { return T::zero().into(); } - self.constant_le_check(statements_flattened, e, c - T::one()) + self.constant_field_le_check(statements_flattened, e, c - T::one()) } /// Compute a range check against a constant @@ -435,7 +437,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { /// /// # Returns /// * a `FlatExpression` which evaluates to `1` if `0 <= e <= c`, and to `0` otherwise - fn constant_le_check( + fn constant_field_le_check( &mut self, statements_flattened: &mut FlatStatements, e: FlatExpression, @@ -485,13 +487,15 @@ impl<'ast, T: Field> Flattener<'ast, T> { )); // check that this decomposition does not overflow the field - self.enforce_strict_le_check( + self.enforce_constant_le_check( statements_flattened, &e_bits_be, &T::max_value().bit_vector_be(), ); - let conditions = self.strict_le_check(statements_flattened, &e_bits_be, &c.bit_vector_be()); + println!("YOOOOOO"); + let conditions = + self.constant_le_check(statements_flattened, &e_bits_be, &c.bit_vector_be()); // return `len(conditions) == sum(conditions)` self.eq_check( @@ -521,6 +525,8 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened: &mut FlatStatements, expression: BooleanExpression<'ast, T>, ) -> FlatExpression { + println!("{}", expression); + // those will be booleans in the future match expression { BooleanExpression::Identifier(x) => { @@ -538,7 +544,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { match (lhs_flattened, rhs_flattened) { (x, FlatExpression::Number(constant)) => { - println!("yo"); + println!("yo {} < {}", x, constant); self.constant_lt_check(statements_flattened, x, constant) } // (c < x <= p - 1) <=> (0 <= p - 1 - x < p - 1 - c) @@ -687,7 +693,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { } // check that the decomposition is in the field with a strict `< p` checks - self.enforce_strict_le_check( + self.enforce_constant_le_check( statements_flattened, &sub_bits_be, &T::max_value().bit_vector_be(), @@ -840,7 +846,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { } // check that the decomposition is in the field with a strict `< p` checks - self.strict_le_check( + self.constant_le_check( statements_flattened, &sub_bits_be, &T::max_value().bit_vector_be(), diff --git a/zokrates_core_test/tests/tests/native_le.zok b/zokrates_core_test/tests/tests/native_le.zok index abf72e352..294ac7228 100644 --- a/zokrates_core_test/tests/tests/native_le.zok +++ b/zokrates_core_test/tests/tests/native_le.zok @@ -31,10 +31,10 @@ def le(u32 a, u32 c) -> bool: return le(a_bits, c_bits) -def main(field a, field c) -> bool: +def main(field a) -> bool: u32 N = 254 - //field c = 42 + field c = 42 //u32 d = 42 diff --git a/zokrates_field/src/lib.rs b/zokrates_field/src/lib.rs index 51b38892a..9eb7d8da9 100644 --- a/zokrates_field/src/lib.rs +++ b/zokrates_field/src/lib.rs @@ -125,7 +125,7 @@ pub trait Field: .collect() } - let field_bytes_le = Self::to_byte_vector(&Self::max_value()); + let field_bytes_le = self.to_byte_vector(); // reverse for big-endianess let field_bytes_be = field_bytes_le.into_iter().rev().collect::>(); From e830b986fbb29778551bdd18618715dd002dfa4d Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 20 Apr 2021 18:42:47 +0200 Subject: [PATCH 46/95] clippy --- zokrates_core/src/flatten/mod.rs | 2 +- zokrates_field/src/lib.rs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index a6a563559..0215029ad 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -2507,7 +2507,7 @@ mod tests { ZirStatement::Assertion(BooleanExpression::FieldEq( box FieldElementExpression::Add( box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Number(Bn128Field::from(1)).into(), + box FieldElementExpression::Number(Bn128Field::from(1)), ), box FieldElementExpression::Identifier("y".into()), )), diff --git a/zokrates_field/src/lib.rs b/zokrates_field/src/lib.rs index 9eb7d8da9..030841a9f 100644 --- a/zokrates_field/src/lib.rs +++ b/zokrates_field/src/lib.rs @@ -132,14 +132,12 @@ pub trait Field: let field_bits_be = bytes_to_bits(&field_bytes_be); let field_bits_be: Vec<_> = (0..Self::get_required_bits() - .checked_sub(field_bits_be.len()) - .unwrap_or(0)) + .saturating_sub(field_bits_be.len())) .map(|_| &false) .chain( &field_bits_be[field_bits_be .len() - .checked_sub(Self::get_required_bits()) - .unwrap_or(0)..], + .saturating_sub(Self::get_required_bits())..], ) .cloned() .collect(); From 6fddd744329015ab1e4ce58fcf6bb4e62aa4fbef Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 21 Apr 2021 16:33:45 +0200 Subject: [PATCH 47/95] clean, fix native le test --- example.zok | 11 ------- manual.zok | 8 ----- zokrates_core/src/compile.rs | 2 -- zokrates_core/src/flatten/mod.rs | 12 ------- zokrates_core_test/tests/tests/native_le.json | 32 +++++++++---------- zokrates_core_test/tests/tests/native_le.zok | 12 +++++-- 6 files changed, 25 insertions(+), 52 deletions(-) delete mode 100644 example.zok delete mode 100644 manual.zok diff --git a/example.zok b/example.zok deleted file mode 100644 index be818e32b..000000000 --- a/example.zok +++ /dev/null @@ -1,11 +0,0 @@ -def foo(field[N] x) -> field[N]: - return x - -def bar(field[N] x) -> field[N]: - field[N] r = x - return r - -def main(field[3] x) -> field[2]: - field[2] z = foo(x)[0..2] - - return bar(z) \ No newline at end of file diff --git a/manual.zok b/manual.zok deleted file mode 100644 index cb8396d0e..000000000 --- a/manual.zok +++ /dev/null @@ -1,8 +0,0 @@ -def main(field a) -> bool: - - //u32 N = 254 - field c = 42 - - //u32 d = 42 - - return a < c \ No newline at end of file diff --git a/zokrates_core/src/compile.rs b/zokrates_core/src/compile.rs index 812ba473e..af5a91848 100644 --- a/zokrates_core/src/compile.rs +++ b/zokrates_core/src/compile.rs @@ -167,8 +167,6 @@ pub fn compile>( let (typed_ast, abi) = check_with_arena(source, location, resolver, &arena)?; - println!("{}", typed_ast); - // flatten input program let program_flattened = Flattener::flatten(typed_ast, config); diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 0215029ad..28c654e35 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -217,8 +217,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { let mut is_not_smaller_run = vec![]; let mut size_unknown = vec![]; - println!("B {:?}", b); - for _ in 0..len { is_not_smaller_run.push(self.use_sym()); size_unknown.push(self.use_sym()); @@ -493,7 +491,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { &T::max_value().bit_vector_be(), ); - println!("YOOOOOO"); let conditions = self.constant_le_check(statements_flattened, &e_bits_be, &c.bit_vector_be()); @@ -525,8 +522,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened: &mut FlatStatements, expression: BooleanExpression<'ast, T>, ) -> FlatExpression { - println!("{}", expression); - // those will be booleans in the future match expression { BooleanExpression::Identifier(x) => { @@ -544,7 +539,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { match (lhs_flattened, rhs_flattened) { (x, FlatExpression::Number(constant)) => { - println!("yo {} < {}", x, constant); self.constant_lt_check(statements_flattened, x, constant) } // (c < x <= p - 1) <=> (0 <= p - 1 - x < p - 1 - c) @@ -2132,8 +2126,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { } } ZirStatement::Assertion(e) => { - println!("assertion {}", e); - match e { BooleanExpression::And(..) => { for boolean in e.into_conjunction_iterator() { @@ -2144,8 +2136,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { } } BooleanExpression::FieldEq(box lhs, box rhs) => { - println!("field eq assertion"); - let lhs = self.flatten_field_expression(statements_flattened, lhs); let rhs = self.flatten_field_expression(statements_flattened, rhs); @@ -2293,8 +2283,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { lhs: FlatExpression, rhs: FlatExpression, ) { - println!("{} {}", lhs, rhs); - let (lhs, rhs) = match (lhs, rhs) { (FlatExpression::Mult(box x, box y), z) | (z, FlatExpression::Mult(box x, box y)) => ( self.identify_expression(z, statements_flattened), diff --git a/zokrates_core_test/tests/tests/native_le.json b/zokrates_core_test/tests/tests/native_le.json index 6d79147be..65d0cc624 100644 --- a/zokrates_core_test/tests/tests/native_le.json +++ b/zokrates_core_test/tests/tests/native_le.json @@ -4,81 +4,81 @@ "tests": [ { "input": { - "values": ["0"] + "values": ["0", "0"] }, "output": { "Ok": { - "values": ["1"] + "values": ["1", "1"] } } }, { "input": { - "values": ["1"] + "values": ["1", "1"] }, "output": { "Ok": { - "values": ["1"] + "values": ["1", "1"] } } }, { "input": { - "values": ["2"] + "values": ["2", "2"] }, "output": { "Ok": { - "values": ["1"] + "values": ["1", "1"] } } }, { "input": { - "values": ["41"] + "values": ["41", "41"] }, "output": { "Ok": { - "values": ["1"] + "values": ["1", "1"] } } }, { "input": { - "values": ["42"] + "values": ["42", "42"] }, "output": { "Ok": { - "values": ["1"] + "values": ["1", "1"] } } }, { "input": { - "values": ["43"] + "values": ["43", "43"] }, "output": { "Ok": { - "values": ["0"] + "values": ["0", "0"] } } }, { "input": { - "values": ["44"] + "values": ["44", "44"] }, "output": { "Ok": { - "values": ["0"] + "values": ["0", "0"] } } }, { "input": { - "values": ["100"] + "values": ["100", "100"] }, "output": { "Ok": { - "values": ["0"] + "values": ["0", "0"] } } } diff --git a/zokrates_core_test/tests/tests/native_le.zok b/zokrates_core_test/tests/tests/native_le.zok index 294ac7228..d1f50437e 100644 --- a/zokrates_core_test/tests/tests/native_le.zok +++ b/zokrates_core_test/tests/tests/native_le.zok @@ -19,8 +19,14 @@ def le(bool[N] a_bits, bool[N] c_bits) -> bool: // this instanciates comparison starting from field elements def le(field a, field c) -> bool: + + field MAX = 21888242871839275222246405745257275088548364400416034343698204186575808495616 + bool[N] MAX_BITS = unpack::(MAX) + bool[N] a_bits = unpack(a) + assert(le(a_bits, MAX_BITS)) bool[N] c_bits = unpack(c) + assert(le(c_bits, MAX_BITS)) return le(a_bits, c_bits) @@ -31,11 +37,11 @@ def le(u32 a, u32 c) -> bool: return le(a_bits, c_bits) -def main(field a) -> bool: +def main(field a, u32 b) -> (bool, bool): u32 N = 254 field c = 42 - //u32 d = 42 + u32 d = 42 - return le::(a, c) \ No newline at end of file + return le::(a, c), le(b, d) \ No newline at end of file From b1297cac25eefd584b34551e822256a50c598492 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 21 Apr 2021 17:08:26 +0200 Subject: [PATCH 48/95] doc, single constraint range enforcement --- zokrates_core/src/flatten/mod.rs | 104 ++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 31 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 28c654e35..ee931adf1 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -178,32 +178,42 @@ impl<'ast, T: Field> Flattener<'ast, T> { } } - // Let's assume b = [1, 1, 1, 0] - // - // 1. Init `sizeUnknown = true` - // As long as `sizeUnknown` is `true` we don't yet know if a is <= than b. - // 2. Loop over `b`: - // * b[0] = 1 - // when `b` is 1 we check wether `a` is 0 in that particular run and update - // `sizeUnknown` accordingly: - // `sizeUnknown = sizeUnknown && a[0]` - // * b[1] = 1 - // `sizeUnknown = sizeUnknown && a[1]` - // * b[2] = 1 - // `sizeUnknown = sizeUnknown && a[2]` - // * b[3] = 0 - // we need to enforce that `a` is 0 in case `sizeUnknown`is still `true`, - // otherwise `a` can be {0,1}: - // `true == (!sizeUnknown || !a[3])` - // ``` - // **true => a -> 0 - // sizeUnkown * - // **false => a -> {0,1} - // ``` - // - // # Returns - // - // * a vector of FlatExpression which all evaluate to 1 if a <= b and 0 otherwise + /// Compute a range check between the bid endian decomposition of an expression and the + /// big endian decomposition of a constant + /// + /// # Arguments + /// * `a` - the big-endian bit decomposition of the expression to check against the range + /// * `b` - the big-endian bit decomposition of the upper bound we're checking against + /// + /// # Returns + /// * a vector of FlatExpression which all evaluate to `1` if `a <= b` and `0` otherwise + /// + /// # Notes + /// + /// Algorithm from [the sapling spec](https://github.com/zcash/zips/blob/master/protocol/sapling.pdf) A.3.2.2 + /// + /// Let's assume b = [1, 1, 1, 0] + /// + /// 1. Init `sizeUnknown = true` + /// As long as `sizeUnknown` is `true` we don't yet know if a is <= than b. + /// 2. Loop over `b`: + /// * b[0] = 1 + /// when `b` is 1 we check wether `a` is 0 in that particular run and update + /// `sizeUnknown` accordingly: + /// `sizeUnknown = sizeUnknown && a[0]` + /// * b[1] = 1 + /// `sizeUnknown = sizeUnknown && a[1]` + /// * b[2] = 1 + /// `sizeUnknown = sizeUnknown && a[2]` + /// * b[3] = 0 + /// we need to enforce that `a` is 0 in case `sizeUnknown`is still `true`, + /// otherwise `a` can be {0,1}: + /// `true == (!sizeUnknown || !a[3])` + /// ``` + /// **true => a -> 0 + /// sizeUnkown * + /// **false => a -> {0,1} + /// ``` fn constant_le_check( &mut self, statements_flattened: &mut FlatStatements, @@ -282,6 +292,16 @@ impl<'ast, T: Field> Flattener<'ast, T> { res } + /// Compute an equality check between two expressions + /// + /// # Arguments + /// + /// * `statements_flattened` - Vector where new flattened statements can be added. + /// * `left - the first `FlatExpression` + /// * `right` - the second `FlatExpression` + /// + /// # Returns + /// * A FlatExpression which evaluates to `1` if `left == right`, `0` otherwise fn eq_check( &mut self, statements_flattened: &mut Vec>, @@ -326,18 +346,32 @@ impl<'ast, T: Field> Flattener<'ast, T> { res } + /// Enforce a range check against a constant: the range check isn't verified iff a constraint will fail + /// + /// # Arguments + /// + /// * `statements_flattened` - Vector where new flattened statements can be added. + /// * `e` - the `FlatExpression` that's being checked against the range. + /// * `c` - the constant upper bound of the range fn enforce_constant_le_check( &mut self, statements_flattened: &mut FlatStatements, a: &[FlatVariable], b: &[bool], ) { - let statements: Vec<_> = self - .constant_le_check(statements_flattened, a, b) + let conditions = self.constant_le_check(statements_flattened, a, b); + + let conditions_count = conditions.len(); + + let conditions_sum = conditions .into_iter() - .map(|c| FlatStatement::Condition(FlatExpression::Number(T::from(1)), c)) - .collect(); - statements_flattened.extend(statements); + .fold(FlatExpression::from(T::zero()), |acc, e| { + FlatExpression::Add(box acc, box e) + }); + statements_flattened.push(FlatStatement::Condition( + FlatExpression::Number(T::from(0)), + FlatExpression::Sub(box conditions_sum, box T::from(conditions_count).into()), + )); } /// Flatten an if/else expression @@ -411,6 +445,14 @@ impl<'ast, T: Field> Flattener<'ast, T> { } } + /// Compute a strict check against a constant + /// # Arguments + /// * `statements_flattened` - Vector where new flattened statements can be added. + /// * `e` - the `FlatExpression` that's being checked against the range. + /// * `c` - the constant strict upper bound of the range + /// + /// # Returns + /// * a `FlatExpression` which evaluates to `1` if `0 <= e < c`, and to `0` otherwise fn constant_lt_check( &mut self, statements_flattened: &mut FlatStatements, From 852f741e9b3f5a23dce137463efc0dd6c6f2249d Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 21 Apr 2021 17:36:52 +0200 Subject: [PATCH 49/95] fix doc comment --- zokrates_core/src/flatten/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index ee931adf1..38dd0f5a9 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -209,11 +209,9 @@ impl<'ast, T: Field> Flattener<'ast, T> { /// we need to enforce that `a` is 0 in case `sizeUnknown`is still `true`, /// otherwise `a` can be {0,1}: /// `true == (!sizeUnknown || !a[3])` - /// ``` - /// **true => a -> 0 - /// sizeUnkown * - /// **false => a -> {0,1} - /// ``` + /// **true => a -> 0 + /// sizeUnkown * + /// **false => a -> {0,1} fn constant_le_check( &mut self, statements_flattened: &mut FlatStatements, From 9f69ea37719a16ad8fc1887645514cb9ac5e31bb Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 21 Apr 2021 18:15:12 +0200 Subject: [PATCH 50/95] refactoring --- zokrates_book/src/language/constants.md | 4 +- zokrates_core/src/absy/from_ast.rs | 1 - zokrates_core/src/absy/mod.rs | 13 +- zokrates_core/src/semantics.rs | 152 +++++++----- .../src/static_analysis/constant_inliner.rs | 224 +++++++++--------- .../src/static_analysis/propagation.rs | 2 +- .../src/static_analysis/reducer/mod.rs | 20 +- zokrates_core/src/typed_absy/abi.rs | 2 +- zokrates_core/src/typed_absy/folder.rs | 6 +- zokrates_core/src/typed_absy/mod.rs | 11 +- zokrates_core/src/typed_absy/result_folder.rs | 22 +- 11 files changed, 251 insertions(+), 206 deletions(-) diff --git a/zokrates_book/src/language/constants.md b/zokrates_book/src/language/constants.md index 8bad07217..a6c16db73 100644 --- a/zokrates_book/src/language/constants.md +++ b/zokrates_book/src/language/constants.md @@ -6,9 +6,9 @@ Constants must be globally defined outside all other scopes by using a `const` k {{#include ../../../zokrates_cli/examples/book/constant_definition.zok}} ``` -The value of a constant can't be changed through reassignment, and it can't be redeclared. Constants are essentially inlined wherever they are used, meaning that they are copied directly into the relevant context when used. +The value of a constant can't be changed through reassignment, and it can't be redeclared. -Constants must be explicitly typed. One can reference other constants inside the expression, as long as the referenced constant is defined before the constant. +Constants must be explicitly typed. One can reference other constants inside the expression, as long as the referenced constant is already defined. ```zokrates {{#include ../../../zokrates_cli/examples/book/constant_reference.zok}} diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 3f6edb31b..10436d86b 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -112,7 +112,6 @@ impl<'ast> From> for absy::SymbolDeclarationNode< let id = definition.id.span.as_str(); let ty = absy::ConstantDefinition { - id, ty: definition.ty.into(), expression: definition.expression.into(), } diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index 028212a5f..b9fccd77a 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -90,7 +90,11 @@ impl<'ast> fmt::Display for SymbolDeclaration<'ast> { match self.symbol { Symbol::Here(ref kind) => match kind { SymbolDefinition::Struct(t) => write!(f, "struct {} {}", self.id, t), - SymbolDefinition::Constant(c) => write!(f, "{}", c), + SymbolDefinition::Constant(c) => write!( + f, + "const {} {} = {}", + c.value.ty, self.id, c.value.expression + ), SymbolDefinition::Function(func) => write!(f, "def {}{}", self.id, func), }, Symbol::There(ref import) => write!(f, "import {} as {}", import, self.id), @@ -166,7 +170,6 @@ type StructDefinitionFieldNode<'ast> = Node>; #[derive(Clone, PartialEq)] pub struct ConstantDefinition<'ast> { - pub id: Identifier<'ast>, pub ty: UnresolvedTypeNode<'ast>, pub expression: ExpressionNode<'ast>, } @@ -175,7 +178,7 @@ pub type ConstantDefinitionNode<'ast> = Node>; impl<'ast> fmt::Display for ConstantDefinition<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "const {} {} = {}", self.ty, self.id, self.expression) + write!(f, "const {}({})", self.ty, self.expression) } } @@ -183,8 +186,8 @@ impl<'ast> fmt::Debug for ConstantDefinition<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "ConstantDefinition({:?}, {:?}, {:?})", - self.ty, self.id, self.expression + "ConstantDefinition({:?}, {:?})", + self.ty, self.expression ) } } diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index b76f6f1d9..6debe4211 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -46,6 +46,7 @@ impl ErrorInner { } type TypeMap<'ast> = HashMap>>; +type ConstantMap<'ast, T> = HashMap>; /// The global state of the program during semantic checks #[derive(Debug)] @@ -56,6 +57,8 @@ struct State<'ast, T> { typed_modules: TypedModules<'ast, T>, /// The user-defined types, which we keep track at this phase only. In later phases, we rely only on basic types and combinations thereof types: TypeMap<'ast>, + // The user-defined constants + constants: ConstantMap<'ast, T>, } /// A symbol for a given name: either a type or a group of functions. Not both! @@ -73,14 +76,27 @@ struct SymbolUnifier<'ast> { } impl<'ast> SymbolUnifier<'ast> { - fn insert_symbol>(&mut self, id: S, ty: SymbolType<'ast>) -> bool { - let s_type = self.symbols.entry(id.into()); - match s_type { - // if anything is already called `id`, we cannot introduce this type + fn insert_type>(&mut self, id: S) -> bool { + let e = self.symbols.entry(id.into()); + match e { + // if anything is already called `id`, we cannot introduce the symbol Entry::Occupied(..) => false, // otherwise, we can! Entry::Vacant(v) => { - v.insert(ty); + v.insert(SymbolType::Type); + true + } + } + } + + fn insert_constant>(&mut self, id: S) -> bool { + let e = self.symbols.entry(id.into()); + match e { + // if anything is already called `id`, we cannot introduce this constant + Entry::Occupied(..) => false, + // otherwise, we can! + Entry::Vacant(v) => { + v.insert(SymbolType::Constant); true } } @@ -117,6 +133,7 @@ impl<'ast, T: Field> State<'ast, T> { modules, typed_modules: HashMap::new(), types: HashMap::new(), + constants: HashMap::new(), } } } @@ -230,7 +247,12 @@ impl<'ast, T: Field> FunctionQuery<'ast, T> { pub struct ScopedVariable<'ast, T> { id: Variable<'ast, T>, level: usize, - constant: bool, +} + +impl<'ast, T> ScopedVariable<'ast, T> { + fn is_constant(&self) -> bool { + self.level == 0 + } } /// Identifiers of different `ScopedVariable`s should not conflict, so we define them as equivalent @@ -312,6 +334,7 @@ impl<'ast, T: Field> Checker<'ast, T> { fn check_constant_definition( &mut self, + id: &'ast str, c: ConstantDefinitionNode<'ast>, module_id: &ModuleId, types: &TypeMap<'ast>, @@ -320,7 +343,7 @@ impl<'ast, T: Field> Checker<'ast, T> { let ty = self.check_type(c.value.ty.clone(), module_id, &types)?; let checked_expr = self.check_expression(c.value.expression.clone(), module_id, types)?; - match ty.clone() { + match ty { Type::FieldElement => { FieldElementExpression::try_from_typed(checked_expr).map(TypedExpression::from) } @@ -330,10 +353,13 @@ impl<'ast, T: Field> Checker<'ast, T> { Type::Uint(bitwidth) => { UExpression::try_from_typed(checked_expr, bitwidth).map(TypedExpression::from) } - Type::Array(array_ty) => ArrayExpression::try_from_typed(checked_expr, *array_ty.ty) - .map(TypedExpression::from), - Type::Struct(struct_ty) => { - StructExpression::try_from_typed(checked_expr, struct_ty).map(TypedExpression::from) + Type::Array(ref array_ty) => { + ArrayExpression::try_from_typed(checked_expr, *array_ty.ty.clone()) + .map(TypedExpression::from) + } + Type::Struct(ref struct_ty) => { + StructExpression::try_from_typed(checked_expr, struct_ty.clone()) + .map(TypedExpression::from) } Type::Int => Err(checked_expr), // Integers cannot be assigned } @@ -343,15 +369,11 @@ impl<'ast, T: Field> Checker<'ast, T> { "Expression `{}` of type `{}` cannot be assigned to constant `{}` of type `{}`", e, e.get_type(), - c.value.id, + id, ty ), }) - .map(|e| TypedConstant { - id: identifier::Identifier::from(c.value.id), - ty, - expression: e, - }) + .map(|e| TypedConstant { ty, expression: e }) } fn check_struct_type_declaration( @@ -425,7 +447,7 @@ impl<'ast, T: Field> Checker<'ast, T> { &state.types, ) { Ok(ty) => { - match symbol_unifier.insert_symbol(declaration.id, SymbolType::Type) { + match symbol_unifier.insert_type(declaration.id) { false => errors.push( ErrorInner { pos: Some(pos), @@ -454,10 +476,10 @@ impl<'ast, T: Field> Checker<'ast, T> { } } SymbolDefinition::Constant(box c) => { - match self.check_constant_definition(c, module_id, &state.types) { + match self.check_constant_definition(declaration.id, c, module_id, &state.types) + { Ok(c) => { - match symbol_unifier.insert_symbol(declaration.id, SymbolType::Constant) - { + match symbol_unifier.insert_constant(declaration.id) { false => errors.push( ErrorInner { pos: Some(pos), @@ -468,10 +490,23 @@ impl<'ast, T: Field> Checker<'ast, T> { } .in_file(module_id), ), - true => {} + true => { + constants.insert( + declaration.id, + TypedConstantSymbol::Here(c.clone()), + ); + self.insert_into_scope(Variable::with_id_and_type( + declaration.id, + c.ty.clone(), + )); + assert!(state + .constants + .entry(module_id.to_path_buf()) + .or_default() + .insert(declaration.id, TypedConstantSymbol::Here(c)) + .is_none()); + } }; - constants.insert(declaration.id, TypedConstantSymbol::Here(c.clone())); - self.insert_into_scope(Variable::with_id_and_type(c.id, c.ty), true); } Err(e) => { errors.push(e.in_file(module_id)); @@ -550,16 +585,15 @@ impl<'ast, T: Field> Checker<'ast, T> { // find constant definition candidate let const_candidate = state - .typed_modules - .get(&import.module_id) - .unwrap() .constants - .as_ref() - .and_then(|tc| tc.get(import.symbol_id)) + .entry(import.module_id.to_path_buf()) + .or_default() + .get(import.symbol_id) .and_then(|sym| match sym { TypedConstantSymbol::Here(tc) => Some(tc), _ => None, - }); + }) + .cloned(); match (function_candidates.len(), type_candidate, const_candidate) { (0, Some(t), None) => { @@ -577,7 +611,7 @@ impl<'ast, T: Field> Checker<'ast, T> { }; // we imported a type, so the symbol it gets bound to should not already exist - match symbol_unifier.insert_symbol(declaration.id, SymbolType::Type) { + match symbol_unifier.insert_type(declaration.id) { false => { errors.push(Error { module_id: module_id.to_path_buf(), @@ -598,7 +632,7 @@ impl<'ast, T: Field> Checker<'ast, T> { .insert(declaration.id.to_string(), t); } (0, None, Some(c)) => { - match symbol_unifier.insert_symbol(declaration.id, SymbolType::Constant) { + match symbol_unifier.insert_constant(declaration.id) { false => { errors.push(Error { module_id: module_id.to_path_buf(), @@ -612,7 +646,13 @@ impl<'ast, T: Field> Checker<'ast, T> { } true => { constants.insert(declaration.id, TypedConstantSymbol::There(import.module_id, declaration.id)); - self.insert_into_scope(Variable::with_id_and_type(c.id.clone(), c.ty.clone()), true); + self.insert_into_scope(Variable::with_id_and_type(declaration.id, c.ty.clone())); + + state + .constants + .entry(module_id.to_path_buf()) + .or_default() + .insert(declaration.id, TypedConstantSymbol::Here(c)); // we insert as `Here` to avoid later recursive search } }; } @@ -732,7 +772,7 @@ impl<'ast, T: Field> Checker<'ast, T> { Some(TypedModule { functions: checked_functions, - constants: Some(checked_constants).filter(|m| !m.is_empty()), + constants: checked_constants, }) } }; @@ -814,7 +854,7 @@ impl<'ast, T: Field> Checker<'ast, T> { Type::Uint(UBitwidth::B32), ); // we don't have to check for conflicts here, because this was done when checking the signature - self.insert_into_scope(v.clone(), false); + self.insert_into_scope(v.clone()); } for (arg, decl_ty) in funct.arguments.into_iter().zip(s.inputs.iter()) { @@ -825,7 +865,7 @@ impl<'ast, T: Field> Checker<'ast, T> { let decl_v = DeclarationVariable::with_id_and_type(arg.id.value.id, decl_ty.clone()); - match self.insert_into_scope(decl_v.clone(), false) { + match self.insert_into_scope(decl_v.clone()) { true => {} false => { errors.push(ErrorInner { @@ -1216,7 +1256,7 @@ impl<'ast, T: Field> Checker<'ast, T> { } .map_err(|e| vec![e])?; - self.insert_into_scope(var.clone(), false); + self.insert_into_scope(var.clone()); let mut checked_statements = vec![]; @@ -1315,7 +1355,7 @@ impl<'ast, T: Field> Checker<'ast, T> { } Statement::Declaration(var) => { let var = self.check_variable(var, module_id, types)?; - match self.insert_into_scope(var.clone(), false) { + match self.insert_into_scope(var.clone()) { true => Ok(TypedStatement::Declaration(var)), false => Err(ErrorInner { pos: Some(pos), @@ -1498,15 +1538,15 @@ impl<'ast, T: Field> Checker<'ast, T> { // check that the assignee is declared match assignee.value { Assignee::Identifier(variable_name) => match self.get_scope(&variable_name) { - Some(var) => match var.constant { - false => Ok(TypedAssignee::Identifier(Variable::with_id_and_type( - variable_name, - var.id._type.clone(), - ))), + Some(var) => match var.is_constant() { true => Err(ErrorInner { pos: Some(assignee.pos()), message: format!("Assignment to constant variable `{}`", variable_name), }), + false => Ok(TypedAssignee::Identifier(Variable::with_id_and_type( + variable_name, + var.id._type.clone(), + ))), }, None => Err(ErrorInner { pos: Some(assignee.pos()), @@ -2919,15 +2959,13 @@ impl<'ast, T: Field> Checker<'ast, T> { Type::FieldElement, ), level: 0, - constant: false, }) } - fn insert_into_scope>>(&mut self, v: U, constant: bool) -> bool { + fn insert_into_scope>>(&mut self, v: U) -> bool { self.scope.insert(ScopedVariable { id: v.into(), level: self.level, - constant, }) } @@ -3123,9 +3161,9 @@ mod tests { let mut unifier = SymbolUnifier::default(); // the `foo` type - assert!(unifier.insert_symbol("foo", SymbolType::Type)); + assert!(unifier.insert_type("foo")); // the `foo` type annot be declared a second time - assert!(!unifier.insert_symbol("foo", SymbolType::Type)); + assert!(!unifier.insert_type("foo")); // the `foo` function cannot be declared as the name is already taken by a type assert!(!unifier.insert_function("foo", DeclarationSignature::new())); // the `bar` type @@ -3163,7 +3201,7 @@ mod tests { ))]) )); // a `bar` type isn't allowed as the name is already taken by at least one function - assert!(!unifier.insert_symbol("bar", SymbolType::Type)); + assert!(!unifier.insert_type("bar")); } #[test] @@ -3220,7 +3258,7 @@ mod tests { )] .into_iter() .collect(), - constants: None + constants: TypedConstantSymbols::default() }) ); } @@ -3755,6 +3793,8 @@ mod tests { let types = HashMap::new(); let mut checker: Checker = Checker::new(); + checker.enter_scope(); + assert_eq!( checker.check_statement(statement, &*MODULE_ID, &types), Err(vec![ErrorInner { @@ -3779,14 +3819,13 @@ mod tests { let mut scope = HashSet::new(); scope.insert(ScopedVariable { id: Variable::field_element("a"), - level: 0, - constant: false, + level: 1, }); scope.insert(ScopedVariable { id: Variable::field_element("b"), - level: 0, - constant: false, + level: 1, }); + let mut checker: Checker = new_with_args(scope, 1, HashSet::new()); assert_eq!( checker.check_statement(statement, &*MODULE_ID, &types), @@ -5770,6 +5809,7 @@ mod tests { let types = HashMap::new(); let mut checker: Checker = Checker::new(); + checker.enter_scope(); checker .check_statement( @@ -5803,6 +5843,8 @@ mod tests { let types = HashMap::new(); let mut checker: Checker = Checker::new(); + checker.enter_scope(); + checker .check_statement( Statement::Declaration( @@ -5853,6 +5895,8 @@ mod tests { let types = HashMap::new(); let mut checker: Checker = Checker::new(); + checker.enter_scope(); + checker .check_statement( Statement::Declaration( diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index 9c04dcaa5..199a5a8b9 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -39,14 +39,13 @@ impl<'ast, T: Field> ConstantInliner<'ast, T> { .get(&self.location) .unwrap() .constants - .as_ref() - .and_then(|c| c.get(id.clone().try_into().unwrap())) + .get(id.clone().try_into().unwrap()) .cloned() .and_then(|tc| { let symbol = self.fold_constant_symbol(tc); match symbol { TypedConstantSymbol::Here(tc) => Some(tc), - _ => None, + _ => unreachable!(), } }) } @@ -67,6 +66,21 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { } } + fn fold_module(&mut self, p: TypedModule<'ast, T>) -> TypedModule<'ast, T> { + TypedModule { + constants: p + .constants + .into_iter() + .map(|(key, tc)| (key, self.fold_constant_symbol(tc))) + .collect(), + functions: p + .functions + .into_iter() + .map(|(key, fun)| (key, self.fold_function_symbol(fun))) + .collect(), + } + } + fn fold_constant_symbol( &mut self, p: TypedConstantSymbol<'ast, T>, @@ -74,13 +88,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { match p { TypedConstantSymbol::There(module_id, id) => { let location = self.change_location(module_id); - let symbol = self - .module() - .constants - .as_ref() - .and_then(|c| c.get(id)) - .unwrap() - .to_owned(); + let symbol = self.module().constants.get(id).cloned().unwrap(); let symbol = self.fold_constant_symbol(symbol); let _ = self.change_location(location); @@ -196,7 +204,6 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_id), ty: GType::FieldElement, expression: (TypedExpression::FieldElement(FieldElementExpression::Number( Bn128Field::from(1), @@ -221,7 +228,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants.clone()), + constants: constants.clone(), }, )] .into_iter() @@ -255,7 +262,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants, }, )] .into_iter() @@ -287,7 +294,6 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_id), ty: GType::Boolean, expression: (TypedExpression::Boolean(BooleanExpression::Value(true))), }), @@ -310,7 +316,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants.clone()), + constants: constants.clone(), }, )] .into_iter() @@ -344,7 +350,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants, }, )] .into_iter() @@ -377,7 +383,6 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_id), ty: GType::Uint(UBitwidth::B32), expression: (UExpressionInner::Value(1u128) .annotate(UBitwidth::B32) @@ -402,7 +407,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants.clone()), + constants: constants.clone(), }, )] .into_iter() @@ -436,7 +441,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants, }, )] .into_iter() @@ -479,7 +484,6 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_id), ty: GType::FieldElement, expression: TypedExpression::Array( ArrayExpressionInner::Value( @@ -511,7 +515,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants.clone()), + constants: constants.clone(), }, )] .into_iter() @@ -569,7 +573,7 @@ mod tests { )] .into_iter() .collect(), - constants: Some(constants), + constants, }, )] .into_iter() @@ -615,37 +619,33 @@ mod tests { )] .into_iter() .collect(), - constants: Some( - vec![ - ( - const_a_id, - TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_a_id), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Number(Bn128Field::from(1)), - )), - }), - ), - ( - const_b_id, - TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_b_id), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Add( - box FieldElementExpression::Identifier( - Identifier::from(const_a_id), - ), - box FieldElementExpression::Number(Bn128Field::from(1)), - ), - )), - }), - ), - ] - .into_iter() - .collect(), - ), + constants: vec![ + ( + const_a_id, + TypedConstantSymbol::Here(TypedConstant { + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Number(Bn128Field::from(1)), + )), + }), + ), + ( + const_b_id, + TypedConstantSymbol::Here(TypedConstant { + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Add( + box FieldElementExpression::Identifier(Identifier::from( + const_a_id, + )), + box FieldElementExpression::Number(Bn128Field::from(1)), + ), + )), + }), + ), + ] + .into_iter() + .collect(), }, )] .into_iter() @@ -681,35 +681,31 @@ mod tests { )] .into_iter() .collect(), - constants: Some( - vec![ - ( - const_a_id, - TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_a_id), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Number(Bn128Field::from(1)), - )), - }), - ), - ( - const_b_id, - TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(const_b_id), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Add( - box FieldElementExpression::Number(Bn128Field::from(1)), - box FieldElementExpression::Number(Bn128Field::from(1)), - ), - )), - }), - ), - ] - .into_iter() - .collect(), - ), + constants: vec![ + ( + const_a_id, + TypedConstantSymbol::Here(TypedConstant { + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Number(Bn128Field::from(1)), + )), + }), + ), + ( + const_b_id, + TypedConstantSymbol::Here(TypedConstant { + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement( + FieldElementExpression::Add( + box FieldElementExpression::Number(Bn128Field::from(1)), + box FieldElementExpression::Number(Bn128Field::from(1)), + ), + )), + }), + ), + ] + .into_iter() + .collect(), }, )] .into_iter() @@ -750,20 +746,17 @@ mod tests { )] .into_iter() .collect(), - constants: Some( - vec![( - foo_const_id, - TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(foo_const_id), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Number(Bn128Field::from(42)), - )), - }), - )] - .into_iter() - .collect(), - ), + constants: vec![( + foo_const_id, + TypedConstantSymbol::Here(TypedConstant { + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement(FieldElementExpression::Number( + Bn128Field::from(42), + ))), + }), + )] + .into_iter() + .collect(), }; let main_module = TypedModule { @@ -785,14 +778,12 @@ mod tests { )] .into_iter() .collect(), - constants: Some( - vec![( - foo_const_id, - TypedConstantSymbol::There(OwnedTypedModuleId::from("foo"), foo_const_id), - )] - .into_iter() - .collect(), - ), + constants: vec![( + foo_const_id, + TypedConstantSymbol::There(OwnedTypedModuleId::from("foo"), foo_const_id), + )] + .into_iter() + .collect(), }; let program = TypedProgram { @@ -825,20 +816,17 @@ mod tests { )] .into_iter() .collect(), - constants: Some( - vec![( - foo_const_id, - TypedConstantSymbol::Here(TypedConstant { - id: Identifier::from(foo_const_id), - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Number(Bn128Field::from(42)), - )), - }), - )] - .into_iter() - .collect(), - ), + constants: vec![( + foo_const_id, + TypedConstantSymbol::Here(TypedConstant { + ty: GType::FieldElement, + expression: (TypedExpression::FieldElement(FieldElementExpression::Number( + Bn128Field::from(42), + ))), + }), + )] + .into_iter() + .collect(), }; let expected_program: TypedProgram = TypedProgram { diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index 45fc1779c..63c7cd5b2 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -250,7 +250,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { } }) .collect::>()?, - constants: m.constants, + ..m }) } diff --git a/zokrates_core/src/static_analysis/reducer/mod.rs b/zokrates_core/src/static_analysis/reducer/mod.rs index 05191af1c..57e17db29 100644 --- a/zokrates_core/src/static_analysis/reducer/mod.rs +++ b/zokrates_core/src/static_analysis/reducer/mod.rs @@ -547,7 +547,7 @@ pub fn reduce_program(p: TypedProgram) -> Result, E )] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -769,7 +769,7 @@ mod tests { ] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -835,7 +835,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -964,7 +964,7 @@ mod tests { ] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -1045,7 +1045,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -1183,7 +1183,7 @@ mod tests { ] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -1264,7 +1264,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -1441,7 +1441,7 @@ mod tests { ] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -1545,7 +1545,7 @@ mod tests { )] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() @@ -1629,7 +1629,7 @@ mod tests { ] .into_iter() .collect(), - constants: None, + constants: Default::default(), }, )] .into_iter() diff --git a/zokrates_core/src/typed_absy/abi.rs b/zokrates_core/src/typed_absy/abi.rs index 7b189e97d..f3adbdea7 100644 --- a/zokrates_core/src/typed_absy/abi.rs +++ b/zokrates_core/src/typed_absy/abi.rs @@ -69,7 +69,7 @@ mod tests { "main".into(), TypedModule { functions, - constants: None, + constants: Default::default(), }, ); diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index 2393b84b8..30385b1b6 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -200,16 +200,12 @@ pub fn fold_module<'ast, T: Field, F: Folder<'ast, T>>( p: TypedModule<'ast, T>, ) -> TypedModule<'ast, T> { TypedModule { - constants: p.constants.map(|tc| { - tc.into_iter() - .map(|(key, tc)| (key, f.fold_constant_symbol(tc))) - .collect() - }), functions: p .functions .into_iter() .map(|(key, fun)| (key, f.fold_function_symbol(fun))) .collect(), + ..p } } diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 2789f0aa7..101e13950 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -153,7 +153,7 @@ pub struct TypedModule<'ast, T> { /// Functions of the module pub functions: TypedFunctionSymbols<'ast, T>, /// Constants defined in module - pub constants: Option>, + pub constants: TypedConstantSymbols<'ast, T>, } #[derive(Clone, PartialEq)] @@ -322,24 +322,19 @@ impl<'ast, T: fmt::Debug> fmt::Debug for TypedFunction<'ast, T> { #[derive(Clone, PartialEq)] pub struct TypedConstant<'ast, T> { - pub id: Identifier<'ast>, pub ty: Type<'ast, T>, pub expression: TypedExpression<'ast, T>, } impl<'ast, T: fmt::Debug> fmt::Debug for TypedConstant<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "TypedConstant({:?}, {:?}, {:?})", - self.id, self.ty, self.expression - ) + write!(f, "TypedConstant({:?}, {:?})", self.ty, self.expression) } } impl<'ast, T: fmt::Display> fmt::Display for TypedConstant<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "const {} {} = {}", self.ty, self.id, self.expression) + write!(f, "const {}({})", self.ty, self.expression) } } diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index 977e04f26..82ae443a3 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -21,6 +21,13 @@ pub trait ResultFolder<'ast, T: Field>: Sized { fold_module(self, p) } + fn fold_constant_symbol( + &mut self, + s: TypedConstantSymbol<'ast, T>, + ) -> Result, Self::Error> { + fold_constant_symbol(self, s) + } + fn fold_function_symbol( &mut self, s: TypedFunctionSymbol<'ast, T>, @@ -793,6 +800,19 @@ pub fn fold_struct_expression<'ast, T: Field, F: ResultFolder<'ast, T>>( }) } +pub fn fold_constant_symbol<'ast, T: Field, F: ResultFolder<'ast, T>>( + f: &mut F, + s: TypedConstantSymbol<'ast, T>, +) -> Result, F::Error> { + match s { + TypedConstantSymbol::Here(tc) => Ok(TypedConstantSymbol::Here(TypedConstant { + expression: f.fold_expression(tc.expression)?, + ..tc + })), + there => Ok(there), + } +} + pub fn fold_function_symbol<'ast, T: Field, F: ResultFolder<'ast, T>>( f: &mut F, s: TypedFunctionSymbol<'ast, T>, @@ -813,7 +833,7 @@ pub fn fold_module<'ast, T: Field, F: ResultFolder<'ast, T>>( .into_iter() .map(|(key, fun)| f.fold_function_symbol(fun).map(|f| (key, f))) .collect::>()?, - constants: p.constants, + ..p }) } From 5bca7d5b874ed79ce77348baf3abbcbbea9564e7 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 21 Apr 2021 19:59:06 +0200 Subject: [PATCH 51/95] remove space --- zokrates_cli/src/ops/compile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_cli/src/ops/compile.rs b/zokrates_cli/src/ops/compile.rs index e02067aaa..fcda43c98 100644 --- a/zokrates_cli/src/ops/compile.rs +++ b/zokrates_cli/src/ops/compile.rs @@ -105,7 +105,7 @@ fn cli_compile(sub_matches: &ArgMatches) -> Result<(), String> { let fmt_error = |e: &CompileError| { let file = e.file().canonicalize().unwrap(); format!( - "{}: {}", + "{}:{}", file.strip_prefix(std::env::current_dir().unwrap()) .unwrap_or_else(|_| file.as_path()) .display(), From c05fc389365fb7c8dd65490965abb4e395d52557 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 21 Apr 2021 20:08:25 +0200 Subject: [PATCH 52/95] changelog --- changelogs/unreleased/828-schaeff | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/828-schaeff diff --git a/changelogs/unreleased/828-schaeff b/changelogs/unreleased/828-schaeff new file mode 100644 index 000000000..af743fda5 --- /dev/null +++ b/changelogs/unreleased/828-schaeff @@ -0,0 +1 @@ +Make command line errors compatible with editor cmd+click \ No newline at end of file From 7169946b21e37e2a95acc694febbf6ac7957a614 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 21 Apr 2021 20:43:26 +0200 Subject: [PATCH 53/95] add custom panic hook --- zokrates_cli/src/bin.rs | 53 +++++++++++++++++++++----- zokrates_cli/src/ops/generate_proof.rs | 6 +-- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index 2a57f7783..ef9fd4ca8 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -1,3 +1,5 @@ +#![feature(panic_info_message)] +#![feature(backtrace)] // // @file bin.rs // @author Jacob Eberhardt @@ -15,6 +17,9 @@ use clap::{App, AppSettings, Arg}; use ops::*; fn main() { + // set a custom panic hook + std::panic::set_hook(Box::new(panic_hook)); + cli().unwrap_or_else(|e| { println!("{}", e); std::process::exit(1); @@ -49,21 +54,49 @@ fn cli() -> Result<(), String> { .get_matches(); match matches.subcommand() { - ("compile", Some(sub_matches)) => compile::exec(sub_matches)?, - ("check", Some(sub_matches)) => check::exec(sub_matches)?, - ("compute-witness", Some(sub_matches)) => compute_witness::exec(sub_matches)?, + ("compile", Some(sub_matches)) => compile::exec(sub_matches), + ("check", Some(sub_matches)) => check::exec(sub_matches), + ("compute-witness", Some(sub_matches)) => compute_witness::exec(sub_matches), #[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] - ("setup", Some(sub_matches)) => setup::exec(sub_matches)?, - ("export-verifier", Some(sub_matches)) => export_verifier::exec(sub_matches)?, + ("setup", Some(sub_matches)) => setup::exec(sub_matches), + ("export-verifier", Some(sub_matches)) => export_verifier::exec(sub_matches), #[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] - ("generate-proof", Some(sub_matches)) => generate_proof::exec(sub_matches)?, - ("print-proof", Some(sub_matches)) => print_proof::exec(sub_matches)?, + ("generate-proof", Some(sub_matches)) => generate_proof::exec(sub_matches), + ("print-proof", Some(sub_matches)) => print_proof::exec(sub_matches), #[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] - ("verify", Some(sub_matches)) => verify::exec(sub_matches)?, + ("verify", Some(sub_matches)) => verify::exec(sub_matches), _ => unreachable!(), - }; + } +} + +fn panic_hook(pi: &std::panic::PanicInfo) { + let location = pi + .location() + .map(|l| format!("({})", l)) + .unwrap_or(String::default()); + + let message = pi.message().map(|m| format!("{}", m)).or(pi + .payload() + .downcast_ref::<&str>() + .map(|p| format!("{}", p))); + + if let Some(s) = message { + println!("{} {}", s, location); + } else { + println!("The compiler unexpectedly panicked {}", location); + } + + #[cfg(debug_assertions)] + { + use std::backtrace::{Backtrace, BacktraceStatus}; + let backtrace = Backtrace::capture(); + match backtrace.status() { + BacktraceStatus::Captured => println!("rust backtrace:\n{}", backtrace), + _ => {} + }; + } - Ok(()) + println!("If you think this is a bug, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues"); } #[cfg(test)] diff --git a/zokrates_cli/src/ops/generate_proof.rs b/zokrates_cli/src/ops/generate_proof.rs index 5b47e463f..f16be7591 100644 --- a/zokrates_cli/src/ops/generate_proof.rs +++ b/zokrates_cli/src/ops/generate_proof.rs @@ -146,10 +146,8 @@ fn cli_generate_proof, B: Backend>( // deserialize witness let witness_path = Path::new(sub_matches.value_of("witness").unwrap()); - let witness_file = match File::open(&witness_path) { - Ok(file) => file, - Err(why) => panic!("Could not open {}: {}", witness_path.display(), why), - }; + let witness_file = File::open(&witness_path) + .map_err(|why| format!("Could not open {}: {}", witness_path.display(), why))?; let witness = ir::Witness::read(witness_file) .map_err(|why| format!("Could not load witness: {:?}", why))?; From 154cdb4827d6e700d74ad710af6fa555bb5c4c70 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 21 Apr 2021 20:47:59 +0200 Subject: [PATCH 54/95] add changelog --- changelogs/unreleased/829-dark64 | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/829-dark64 diff --git a/changelogs/unreleased/829-dark64 b/changelogs/unreleased/829-dark64 new file mode 100644 index 000000000..da661714f --- /dev/null +++ b/changelogs/unreleased/829-dark64 @@ -0,0 +1 @@ +Add a custom panic hook to handle internal compiler errors more gracefully \ No newline at end of file From 623b4714522a53dd4172fb84b7a08bddbe6a37b5 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 21 Apr 2021 20:55:04 +0200 Subject: [PATCH 55/95] clippy --- zokrates_cli/src/bin.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index ef9fd4ca8..23e32a13d 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -73,12 +73,12 @@ fn panic_hook(pi: &std::panic::PanicInfo) { let location = pi .location() .map(|l| format!("({})", l)) - .unwrap_or(String::default()); + .unwrap_or_default(); - let message = pi.message().map(|m| format!("{}", m)).or(pi - .payload() - .downcast_ref::<&str>() - .map(|p| format!("{}", p))); + let message = pi + .message() + .map(|m| format!("{}", m)) + .or_else(|| pi.payload().downcast_ref::<&str>().map(|p| p.to_string())); if let Some(s) = message { println!("{} {}", s, location); @@ -90,10 +90,10 @@ fn panic_hook(pi: &std::panic::PanicInfo) { { use std::backtrace::{Backtrace, BacktraceStatus}; let backtrace = Backtrace::capture(); - match backtrace.status() { - BacktraceStatus::Captured => println!("rust backtrace:\n{}", backtrace), - _ => {} - }; + + if backtrace.status() == BacktraceStatus::Captured { + println!("rust backtrace:\n{}", backtrace); + } } println!("If you think this is a bug, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues"); From 55222bdcc529b09dbb505ec5ccf09176ed4752af Mon Sep 17 00:00:00 2001 From: Darko Macesic Date: Wed, 21 Apr 2021 22:51:08 +0200 Subject: [PATCH 56/95] Update zokrates_cli/src/bin.rs Co-authored-by: Thibaut Schaeffer --- zokrates_cli/src/bin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index 23e32a13d..75ffbcb53 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -96,7 +96,7 @@ fn panic_hook(pi: &std::panic::PanicInfo) { } } - println!("If you think this is a bug, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues"); + println!("This is unexpected, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues"); } #[cfg(test)] From cd276760b1b7c86e9da827c521391b82d39fc6e6 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 22 Apr 2021 13:38:54 +0200 Subject: [PATCH 57/95] allow clippy rule, remove unreachable arms --- zokrates_core/src/absy/from_ast.rs | 2 +- zokrates_core/src/absy/mod.rs | 3 +- zokrates_core/src/semantics.rs | 17 +++---- .../src/static_analysis/constant_inliner.rs | 48 ++++++++++--------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 10436d86b..652932c67 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -119,7 +119,7 @@ impl<'ast> From> for absy::SymbolDeclarationNode< absy::SymbolDeclaration { id, - symbol: absy::Symbol::Here(SymbolDefinition::Constant(box ty)), + symbol: absy::Symbol::Here(SymbolDefinition::Constant(ty)), } .span(span) } diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index b9fccd77a..d070860dc 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -51,10 +51,11 @@ pub struct SymbolDeclaration<'ast> { pub symbol: Symbol<'ast>, } +#[allow(clippy::large_enum_variant)] #[derive(PartialEq, Clone)] pub enum SymbolDefinition<'ast> { Struct(StructDefinitionNode<'ast>), - Constant(Box>), + Constant(ConstantDefinitionNode<'ast>), Function(FunctionNode<'ast>), } diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 6debe4211..443adaa85 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -46,7 +46,8 @@ impl ErrorInner { } type TypeMap<'ast> = HashMap>>; -type ConstantMap<'ast, T> = HashMap>; +type ConstantMap<'ast, T> = + HashMap, Type<'ast, T>>>; /// The global state of the program during semantic checks #[derive(Debug)] @@ -475,7 +476,7 @@ impl<'ast, T: Field> Checker<'ast, T> { })), } } - SymbolDefinition::Constant(box c) => { + SymbolDefinition::Constant(c) => { match self.check_constant_definition(declaration.id, c, module_id, &state.types) { Ok(c) => { @@ -503,7 +504,7 @@ impl<'ast, T: Field> Checker<'ast, T> { .constants .entry(module_id.to_path_buf()) .or_default() - .insert(declaration.id, TypedConstantSymbol::Here(c)) + .insert(declaration.id, c.ty) .is_none()); } }; @@ -589,10 +590,6 @@ impl<'ast, T: Field> Checker<'ast, T> { .entry(import.module_id.to_path_buf()) .or_default() .get(import.symbol_id) - .and_then(|sym| match sym { - TypedConstantSymbol::Here(tc) => Some(tc), - _ => None, - }) .cloned(); match (function_candidates.len(), type_candidate, const_candidate) { @@ -631,7 +628,7 @@ impl<'ast, T: Field> Checker<'ast, T> { .or_default() .insert(declaration.id.to_string(), t); } - (0, None, Some(c)) => { + (0, None, Some(ty)) => { match symbol_unifier.insert_constant(declaration.id) { false => { errors.push(Error { @@ -646,13 +643,13 @@ impl<'ast, T: Field> Checker<'ast, T> { } true => { constants.insert(declaration.id, TypedConstantSymbol::There(import.module_id, declaration.id)); - self.insert_into_scope(Variable::with_id_and_type(declaration.id, c.ty.clone())); + self.insert_into_scope(Variable::with_id_and_type(declaration.id, ty.clone())); state .constants .entry(module_id.to_path_buf()) .or_default() - .insert(declaration.id, TypedConstantSymbol::Here(c)); // we insert as `Here` to avoid later recursive search + .insert(declaration.id, ty); } }; } diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index 199a5a8b9..fff3ca647 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -17,37 +17,50 @@ impl<'ast, T: Field> ConstantInliner<'ast, T> { } pub fn inline(p: TypedProgram<'ast, T>) -> TypedProgram<'ast, T> { - // initialize an inliner over all modules, starting from the main module let mut inliner = ConstantInliner::with_modules_and_location(p.modules.clone(), p.main.clone()); inliner.fold_program(p) } - pub fn module(&self) -> &TypedModule<'ast, T> { + fn module(&self) -> &TypedModule<'ast, T> { self.modules.get(&self.location).unwrap() } - pub fn change_location(&mut self, location: OwnedTypedModuleId) -> OwnedTypedModuleId { + fn change_location(&mut self, location: OwnedTypedModuleId) -> OwnedTypedModuleId { let prev = self.location.clone(); self.location = location; prev } - pub fn get_constant(&mut self, id: &Identifier) -> Option> { + fn get_constant(&mut self, id: &Identifier) -> Option> { self.modules .get(&self.location) .unwrap() .constants .get(id.clone().try_into().unwrap()) .cloned() - .and_then(|tc| { - let symbol = self.fold_constant_symbol(tc); - match symbol { - TypedConstantSymbol::Here(tc) => Some(tc), - _ => unreachable!(), - } - }) + .map(|symbol| self.get_canonical_constant(symbol)) + } + + fn get_canonical_constant( + &mut self, + symbol: TypedConstantSymbol<'ast, T>, + ) -> TypedConstant<'ast, T> { + match symbol { + TypedConstantSymbol::There(module_id, id) => { + let location = self.change_location(module_id); + let symbol = self.module().constants.get(id).cloned().unwrap(); + + let symbol = self.get_canonical_constant(symbol); + let _ = self.change_location(location); + symbol + } + TypedConstantSymbol::Here(tc) => TypedConstant { + expression: self.fold_expression(tc.expression), + ..tc + }, + } } } @@ -85,17 +98,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { &mut self, p: TypedConstantSymbol<'ast, T>, ) -> TypedConstantSymbol<'ast, T> { - match p { - TypedConstantSymbol::There(module_id, id) => { - let location = self.change_location(module_id); - let symbol = self.module().constants.get(id).cloned().unwrap(); - - let symbol = self.fold_constant_symbol(symbol); - let _ = self.change_location(location); - symbol - } - _ => fold_constant_symbol(self, p), - } + let tc = self.get_canonical_constant(p); + TypedConstantSymbol::Here(tc) } fn fold_field_expression( From 06cc180c086635fb6bb9511be3ad1179dd91722e Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 22 Apr 2021 14:07:34 +0200 Subject: [PATCH 58/95] fix stack overflow on fmt::Debug for zir::BooleanExpression --- zokrates_core/src/zir/mod.rs | 48 ++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/zokrates_core/src/zir/mod.rs b/zokrates_core/src/zir/mod.rs index 6fb06c47a..a0916aa8b 100644 --- a/zokrates_core/src/zir/mod.rs +++ b/zokrates_core/src/zir/mod.rs @@ -434,6 +434,7 @@ impl<'ast, T: fmt::Display> fmt::Display for BooleanExpression<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { BooleanExpression::Identifier(ref var) => write!(f, "{}", var), + BooleanExpression::Value(b) => write!(f, "{}", b), BooleanExpression::FieldLt(ref lhs, ref rhs) => write!(f, "{} < {}", lhs, rhs), BooleanExpression::FieldLe(ref lhs, ref rhs) => write!(f, "{} <= {}", lhs, rhs), BooleanExpression::FieldGe(ref lhs, ref rhs) => write!(f, "{} >= {}", lhs, rhs), @@ -448,7 +449,6 @@ impl<'ast, T: fmt::Display> fmt::Display for BooleanExpression<'ast, T> { BooleanExpression::Or(ref lhs, ref rhs) => write!(f, "{} || {}", lhs, rhs), BooleanExpression::And(ref lhs, ref rhs) => write!(f, "{} && {}", lhs, rhs), BooleanExpression::Not(ref exp) => write!(f, "!{}", exp), - BooleanExpression::Value(b) => write!(f, "{}", b), BooleanExpression::IfElse(ref condition, ref consequent, ref alternative) => write!( f, "if {} then {} else {} fi", @@ -460,7 +460,51 @@ impl<'ast, T: fmt::Display> fmt::Display for BooleanExpression<'ast, T> { impl<'ast, T: fmt::Debug> fmt::Debug for BooleanExpression<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}", self) + match *self { + BooleanExpression::Identifier(ref var) => write!(f, "Ide({:?})", var), + BooleanExpression::Value(b) => write!(f, "Value({})", b), + BooleanExpression::FieldLt(ref lhs, ref rhs) => { + write!(f, "FieldLt({:?}, {:?})", lhs, rhs) + } + BooleanExpression::FieldLe(ref lhs, ref rhs) => { + write!(f, "FieldLe({:?}, {:?})", lhs, rhs) + } + BooleanExpression::FieldGe(ref lhs, ref rhs) => { + write!(f, "FieldGe({:?}, {:?})", lhs, rhs) + } + BooleanExpression::FieldGt(ref lhs, ref rhs) => { + write!(f, "FieldGt({:?}, {:?})", lhs, rhs) + } + BooleanExpression::UintLt(ref lhs, ref rhs) => { + write!(f, "UintLt({:?}, {:?})", lhs, rhs) + } + BooleanExpression::UintLe(ref lhs, ref rhs) => { + write!(f, "UintLe({:?}, {:?})", lhs, rhs) + } + BooleanExpression::UintGe(ref lhs, ref rhs) => { + write!(f, "UintGe({:?}, {:?})", lhs, rhs) + } + BooleanExpression::UintGt(ref lhs, ref rhs) => { + write!(f, "UintGt({:?}, {:?})", lhs, rhs) + } + BooleanExpression::FieldEq(ref lhs, ref rhs) => { + write!(f, "FieldEq({:?}, {:?})", lhs, rhs) + } + BooleanExpression::BoolEq(ref lhs, ref rhs) => { + write!(f, "BoolEq({:?}, {:?})", lhs, rhs) + } + BooleanExpression::UintEq(ref lhs, ref rhs) => { + write!(f, "UintEq({:?}, {:?})", lhs, rhs) + } + BooleanExpression::Or(ref lhs, ref rhs) => write!(f, "Or({:?}, {:?})", lhs, rhs), + BooleanExpression::And(ref lhs, ref rhs) => write!(f, "And({:?}, {:?})", lhs, rhs), + BooleanExpression::Not(ref exp) => write!(f, "Not({:?})", exp), + BooleanExpression::IfElse(ref condition, ref consequent, ref alternative) => write!( + f, + "IfElse({:?}, {:?}, {:?})", + condition, consequent, alternative + ), + } } } From 1689385dec8e3da93222185f2fc83f6123a4db21 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 22 Apr 2021 14:57:53 +0200 Subject: [PATCH 59/95] add interactive prompt for overwriting in one_liner.sh --- scripts/one_liner.sh | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/scripts/one_liner.sh b/scripts/one_liner.sh index a061f03d5..a5ee60945 100755 --- a/scripts/one_liner.sh +++ b/scripts/one_liner.sh @@ -286,36 +286,35 @@ main() { # Fetch archive url="$url/download/$tag/zokrates-$tag-$arch.$ext" - say_err "Fetching: $url" td=$(mktemp -d || mktemp -d -t tmp) curl -sLf --show-error $url | tar -C $td -xzf - - # install ZoKrates - for f in $(ls $td); do - # put folders into $dest - if [ -d $td/$f ]; then - if [ -e "$dest/$f" ] && [ $force = false ]; then - err "$f already exists in $dest, use --force to overwrite" - else - mkdir -p $dest - cp -rf $td/$f $dest - rm -rf $td/$f - fi - fi - - # put executables into $dest/bin - if [ -x $td/$f ]; then - if [ -e "$dest/$f" ] && [ $force = false ]; then - err "$f already exists in $dest, use --force to overwrite" - else - mkdir -p $dest/bin - install -m 755 $td/$f $dest/bin - fi - fi - done + if [ -d $dest ]; then + if [ $force = true ]; then + rm -rf $dest/* + cp -r $td/* $dest + else + read -p "ZoKrates is already installed, overwrite (y/n)? " answer + case ${answer:0:1} in + y|Y ) + rm -rf $dest/* + cp -r $td/* $dest + ;; + * ) + rm -rf $td + exit 1 + ;; + esac + fi + else + mkdir -p $dest + cp -r $td/* $dest + fi + mkdir -p $dest/bin + mv $dest/zokrates* $dest/bin && chmod 755 $dest/bin/* rm -rf $td abspath=$(cd "$(dirname "$dest")" && pwd)/$(basename "$dest") From df8d2177f33d7a5f8d02420f0c1a49d49ce1c9d3 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 22 Apr 2021 16:55:35 +0200 Subject: [PATCH 60/95] changelog --- changelogs/unreleased/831-dark64 | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/831-dark64 diff --git a/changelogs/unreleased/831-dark64 b/changelogs/unreleased/831-dark64 new file mode 100644 index 000000000..20197dc59 --- /dev/null +++ b/changelogs/unreleased/831-dark64 @@ -0,0 +1 @@ +Add interactive prompt before overwriting existing files in the `one_liner.sh` script \ No newline at end of file From 42b7ccc95c7058ae8a3eaff104711d514d763d6e Mon Sep 17 00:00:00 2001 From: dark64 Date: Fri, 23 Apr 2021 14:31:39 +0200 Subject: [PATCH 61/95] handle user errors in propagation where applicable --- .../src/static_analysis/propagation.rs | 526 ++++++++++-------- .../src/static_analysis/reducer/mod.rs | 12 +- 2 files changed, 286 insertions(+), 252 deletions(-) diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index 93998febf..bbb6acf32 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -21,12 +21,26 @@ type Constants<'ast, T> = HashMap, TypedExpression<'ast, T>>; #[derive(Debug, PartialEq)] pub enum Error { Type(String), + AssertionFailed(String), + OutOfBounds(u128, u128), + NonConstantExponent(String), } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::Type(s) => write!(f, "{}", s), + Error::AssertionFailed(s) => write!(f, "{}", s), + Error::OutOfBounds(index, size) => write!( + f, + "Out of bounds index ({} >= {}) found during static analysis", + index, size + ), + Error::NonConstantExponent(s) => write!( + f, + "Non-constant exponent `{}` detected during static analysis", + s + ), } } } @@ -661,7 +675,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { let e_str = e.to_string(); let expr = self.fold_boolean_expression(e)?; match expr { - BooleanExpression::Value(v) if !v => Err(Error::Type(format!( + BooleanExpression::Value(v) if !v => Err(Error::AssertionFailed(format!( "Assertion failed on expression `{}`", e_str ))), @@ -679,159 +693,165 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { bitwidth: UBitwidth, e: UExpressionInner<'ast, T>, ) -> Result, Error> { - Ok(match e { + match e { UExpressionInner::Identifier(id) => match self.constants.get(&id) { Some(e) => match e { - TypedExpression::Uint(e) => e.as_inner().clone(), + TypedExpression::Uint(e) => Ok(e.as_inner().clone()), _ => unreachable!("constant stored for a uint should be a uint"), }, - None => UExpressionInner::Identifier(id), + None => Ok(UExpressionInner::Identifier(id)), }, UExpressionInner::Add(box e1, box e2) => match ( self.fold_uint_expression(e1)?.into_inner(), self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value( + Ok(UExpressionInner::Value( (v1 + v2) % 2_u128.pow(bitwidth.to_usize().try_into().unwrap()), - ) + )) } (e, UExpressionInner::Value(v)) | (UExpressionInner::Value(v), e) => match v { - 0 => e, - _ => UExpressionInner::Add( + 0 => Ok(e), + _ => Ok(UExpressionInner::Add( box e.annotate(bitwidth), box UExpressionInner::Value(v).annotate(bitwidth), - ), + )), }, - (e1, e2) => { - UExpressionInner::Add(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) - } + (e1, e2) => Ok(UExpressionInner::Add( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )), }, UExpressionInner::Sub(box e1, box e2) => match ( self.fold_uint_expression(e1)?.into_inner(), self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value( + Ok(UExpressionInner::Value( (v1.wrapping_sub(v2)) % 2_u128.pow(bitwidth.to_usize().try_into().unwrap()), - ) + )) } (e, UExpressionInner::Value(v)) => match v { - 0 => e, - _ => UExpressionInner::Sub( + 0 => Ok(e), + _ => Ok(UExpressionInner::Sub( box e.annotate(bitwidth), box UExpressionInner::Value(v).annotate(bitwidth), - ), + )), }, - (e1, e2) => { - UExpressionInner::Sub(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) - } + (e1, e2) => Ok(UExpressionInner::Sub( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )), }, UExpressionInner::FloorSub(box e1, box e2) => match ( self.fold_uint_expression(e1)?.into_inner(), self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value( + Ok(UExpressionInner::Value( v1.saturating_sub(v2) % 2_u128.pow(bitwidth.to_usize().try_into().unwrap()), - ) + )) } (e, UExpressionInner::Value(v)) => match v { - 0 => e, - _ => UExpressionInner::FloorSub( + 0 => Ok(e), + _ => Ok(UExpressionInner::FloorSub( box e.annotate(bitwidth), box UExpressionInner::Value(v).annotate(bitwidth), - ), + )), }, - (e1, e2) => { - UExpressionInner::Sub(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) - } + (e1, e2) => Ok(UExpressionInner::Sub( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )), }, UExpressionInner::Mult(box e1, box e2) => match ( self.fold_uint_expression(e1)?.into_inner(), self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value( + Ok(UExpressionInner::Value( (v1 * v2) % 2_u128.pow(bitwidth.to_usize().try_into().unwrap()), - ) + )) } (e, UExpressionInner::Value(v)) | (UExpressionInner::Value(v), e) => match v { - 0 => UExpressionInner::Value(0), - 1 => e, - _ => UExpressionInner::Mult( + 0 => Ok(UExpressionInner::Value(0)), + 1 => Ok(e), + _ => Ok(UExpressionInner::Mult( box e.annotate(bitwidth), box UExpressionInner::Value(v).annotate(bitwidth), - ), + )), }, - (e1, e2) => { - UExpressionInner::Mult(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) - } + (e1, e2) => Ok(UExpressionInner::Mult( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )), }, UExpressionInner::Div(box e1, box e2) => match ( self.fold_uint_expression(e1)?.into_inner(), self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value( + Ok(UExpressionInner::Value( (v1 / v2) % 2_u128.pow(bitwidth.to_usize().try_into().unwrap()), - ) + )) } (e, UExpressionInner::Value(v)) => match v { - 1 => e, - _ => UExpressionInner::Div( + 1 => Ok(e), + _ => Ok(UExpressionInner::Div( box e.annotate(bitwidth), box UExpressionInner::Value(v).annotate(bitwidth), - ), + )), }, - (e1, e2) => { - UExpressionInner::Div(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) - } + (e1, e2) => Ok(UExpressionInner::Div( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )), }, UExpressionInner::Rem(box e1, box e2) => match ( self.fold_uint_expression(e1)?.into_inner(), self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value( + Ok(UExpressionInner::Value( (v1 % v2) % 2_u128.pow(bitwidth.to_usize().try_into().unwrap()), - ) + )) } (e, UExpressionInner::Value(v)) => match v { - 1 => UExpressionInner::Value(0), - _ => UExpressionInner::Rem( + 1 => Ok(UExpressionInner::Value(0)), + _ => Ok(UExpressionInner::Rem( box e.annotate(bitwidth), box UExpressionInner::Value(v).annotate(bitwidth), - ), + )), }, - (e1, e2) => { - UExpressionInner::Rem(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) - } + (e1, e2) => Ok(UExpressionInner::Rem( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )), }, UExpressionInner::RightShift(box e, box by) => { let e = self.fold_uint_expression(e)?; let by = self.fold_uint_expression(by)?; match (e.into_inner(), by.into_inner()) { (UExpressionInner::Value(v), UExpressionInner::Value(by)) => { - UExpressionInner::Value(v >> by) + Ok(UExpressionInner::Value(v >> by)) } - (e, by) => UExpressionInner::RightShift( + (e, by) => Ok(UExpressionInner::RightShift( box e.annotate(bitwidth), box by.annotate(UBitwidth::B32), - ), + )), } } UExpressionInner::LeftShift(box e, box by) => { let e = self.fold_uint_expression(e)?; let by = self.fold_uint_expression(by)?; match (e.into_inner(), by.into_inner()) { - (UExpressionInner::Value(v), UExpressionInner::Value(by)) => { - UExpressionInner::Value((v << by) & (2_u128.pow(bitwidth as u32) - 1)) - } - (e, by) => UExpressionInner::LeftShift( + (UExpressionInner::Value(v), UExpressionInner::Value(by)) => Ok( + UExpressionInner::Value((v << by) & (2_u128.pow(bitwidth as u32) - 1)), + ), + (e, by) => Ok(UExpressionInner::LeftShift( box e.annotate(bitwidth), box by.annotate(UBitwidth::B32), - ), + )), } } UExpressionInner::Xor(box e1, box e2) => match ( @@ -839,15 +859,18 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value(v1 ^ v2) + Ok(UExpressionInner::Value(v1 ^ v2)) } - (UExpressionInner::Value(0), e2) => e2, - (e1, UExpressionInner::Value(0)) => e1, + (UExpressionInner::Value(0), e2) => Ok(e2), + (e1, UExpressionInner::Value(0)) => Ok(e1), (e1, e2) => { if e1 == e2 { - UExpressionInner::Value(0) + Ok(UExpressionInner::Value(0)) } else { - UExpressionInner::Xor(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) + Ok(UExpressionInner::Xor( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )) } } }, @@ -856,48 +879,53 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { self.fold_uint_expression(e2)?.into_inner(), ) { (UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => { - UExpressionInner::Value(v1 & v2) + Ok(UExpressionInner::Value(v1 & v2)) } (UExpressionInner::Value(0), _) | (_, UExpressionInner::Value(0)) => { - UExpressionInner::Value(0) - } - (e1, e2) => { - UExpressionInner::And(box e1.annotate(bitwidth), box e2.annotate(bitwidth)) + Ok(UExpressionInner::Value(0)) } + (e1, e2) => Ok(UExpressionInner::And( + box e1.annotate(bitwidth), + box e2.annotate(bitwidth), + )), }, UExpressionInner::IfElse(box condition, box consequence, box alternative) => { let consequence = self.fold_uint_expression(consequence)?; let alternative = self.fold_uint_expression(alternative)?; match self.fold_boolean_expression(condition)? { - BooleanExpression::Value(true) => consequence.into_inner(), - BooleanExpression::Value(false) => alternative.into_inner(), - c => UExpressionInner::IfElse(box c, box consequence, box alternative), + BooleanExpression::Value(true) => Ok(consequence.into_inner()), + BooleanExpression::Value(false) => Ok(alternative.into_inner()), + c => Ok(UExpressionInner::IfElse( + box c, + box consequence, + box alternative, + )), } } UExpressionInner::Not(box e) => { let e = self.fold_uint_expression(e)?.into_inner(); match e { - UExpressionInner::Value(v) => { - UExpressionInner::Value((!v) & (2_u128.pow(bitwidth as u32) - 1)) - } - e => UExpressionInner::Not(box e.annotate(bitwidth)), + UExpressionInner::Value(v) => Ok(UExpressionInner::Value( + (!v) & (2_u128.pow(bitwidth as u32) - 1), + )), + e => Ok(UExpressionInner::Not(box e.annotate(bitwidth))), } } UExpressionInner::Neg(box e) => { let e = self.fold_uint_expression(e)?.into_inner(); match e { - UExpressionInner::Value(v) => UExpressionInner::Value( + UExpressionInner::Value(v) => Ok(UExpressionInner::Value( (0u128.wrapping_sub(v)) % 2_u128.pow(bitwidth.to_usize().try_into().unwrap()), - ), - e => UExpressionInner::Neg(box e.annotate(bitwidth)), + )), + e => Ok(UExpressionInner::Neg(box e.annotate(bitwidth))), } } UExpressionInner::Pos(box e) => { let e = self.fold_uint_expression(e)?.into_inner(); match e { - UExpressionInner::Value(v) => UExpressionInner::Value(v), - e => UExpressionInner::Pos(box e.annotate(bitwidth)), + UExpressionInner::Value(v) => Ok(UExpressionInner::Value(v)), + e => Ok(UExpressionInner::Pos(box e.annotate(bitwidth))), } } UExpressionInner::Select(box array, box index) => { @@ -912,18 +940,15 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (array.into_inner(), index.into_inner()) { (ArrayExpressionInner::Value(v), UExpressionInner::Value(n)) => { if n < size { - UExpression::try_from( + Ok(UExpression::try_from( v.expression_at::>(n as usize) .unwrap() .clone(), ) .unwrap() - .into_inner() + .into_inner()) } else { - unreachable!( - "out of bounds index ({} >= {}) found during static analysis", - n, size - ); + Err(Error::OutOfBounds(n, size)) } } (ArrayExpressionInner::Identifier(id), UExpressionInner::Value(n)) => { @@ -931,128 +956,134 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Some(a) => match a { TypedExpression::Array(a) => match a.as_inner() { ArrayExpressionInner::Value(v) => { - UExpression::try_from( + Ok(UExpression::try_from( TypedExpression::try_from( v.0[n as usize].clone(), ) .unwrap(), ) .unwrap() - .into_inner() + .into_inner()) } _ => unreachable!(), }, _ => unreachable!(""), }, - None => UExpressionInner::Select( + None => Ok(UExpressionInner::Select( box ArrayExpressionInner::Identifier(id) .annotate(inner_type, size as u32), box UExpressionInner::Value(n).annotate(UBitwidth::B32), - ), + )), } } - (a, i) => UExpressionInner::Select( + (a, i) => Ok(UExpressionInner::Select( box a.annotate(inner_type, size as u32), box i.annotate(UBitwidth::B32), - ), + )), } } _ => fold_uint_expression_inner( self, bitwidth, UExpressionInner::Select(box array, box index), - )?, + ), } } - e => fold_uint_expression_inner(self, bitwidth, e)?, - }) + e => fold_uint_expression_inner(self, bitwidth, e), + } } fn fold_field_expression( &mut self, e: FieldElementExpression<'ast, T>, ) -> Result, Error> { - Ok(match e { + match e { FieldElementExpression::Identifier(id) => match self.constants.get(&id) { Some(e) => match e { - TypedExpression::FieldElement(e) => e.clone(), + TypedExpression::FieldElement(e) => Ok(e.clone()), _ => unreachable!( "constant stored for a field element should be a field element" ), }, - None => FieldElementExpression::Identifier(id), + None => Ok(FieldElementExpression::Identifier(id)), }, FieldElementExpression::Add(box e1, box e2) => match ( self.fold_field_expression(e1)?, self.fold_field_expression(e2)?, ) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - FieldElementExpression::Number(n1 + n2) + Ok(FieldElementExpression::Number(n1 + n2)) } - (e1, e2) => FieldElementExpression::Add(box e1, box e2), + (e1, e2) => Ok(FieldElementExpression::Add(box e1, box e2)), }, FieldElementExpression::Sub(box e1, box e2) => match ( self.fold_field_expression(e1)?, self.fold_field_expression(e2)?, ) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - FieldElementExpression::Number(n1 - n2) + Ok(FieldElementExpression::Number(n1 - n2)) } - (e1, e2) => FieldElementExpression::Sub(box e1, box e2), + (e1, e2) => Ok(FieldElementExpression::Sub(box e1, box e2)), }, FieldElementExpression::Mult(box e1, box e2) => match ( self.fold_field_expression(e1)?, self.fold_field_expression(e2)?, ) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - FieldElementExpression::Number(n1 * n2) + Ok(FieldElementExpression::Number(n1 * n2)) } - (e1, e2) => FieldElementExpression::Mult(box e1, box e2), + (e1, e2) => Ok(FieldElementExpression::Mult(box e1, box e2)), }, FieldElementExpression::Div(box e1, box e2) => match ( self.fold_field_expression(e1)?, self.fold_field_expression(e2)?, ) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - FieldElementExpression::Number(n1 / n2) + Ok(FieldElementExpression::Number(n1 / n2)) } - (e1, e2) => FieldElementExpression::Div(box e1, box e2), + (e1, e2) => Ok(FieldElementExpression::Div(box e1, box e2)), }, FieldElementExpression::Neg(box e) => match self.fold_field_expression(e)? { - FieldElementExpression::Number(n) => FieldElementExpression::Number(T::zero() - n), - e => FieldElementExpression::Neg(box e), + FieldElementExpression::Number(n) => { + Ok(FieldElementExpression::Number(T::zero() - n)) + } + e => Ok(FieldElementExpression::Neg(box e)), }, FieldElementExpression::Pos(box e) => match self.fold_field_expression(e)? { - FieldElementExpression::Number(n) => FieldElementExpression::Number(n), - e => FieldElementExpression::Pos(box e), + FieldElementExpression::Number(n) => Ok(FieldElementExpression::Number(n)), + e => Ok(FieldElementExpression::Pos(box e)), }, FieldElementExpression::Pow(box e1, box e2) => { let e1 = self.fold_field_expression(e1)?; let e2 = self.fold_uint_expression(e2)?; match (e1, e2.into_inner()) { (_, UExpressionInner::Value(ref n2)) if *n2 == 0 => { - FieldElementExpression::Number(T::from(1)) + Ok(FieldElementExpression::Number(T::from(1))) } (FieldElementExpression::Number(n1), UExpressionInner::Value(n2)) => { - FieldElementExpression::Number(n1.pow(n2 as usize)) + Ok(FieldElementExpression::Number(n1.pow(n2 as usize))) } - (e1, UExpressionInner::Value(n2)) => FieldElementExpression::Pow( + (e1, UExpressionInner::Value(n2)) => Ok(FieldElementExpression::Pow( box e1, box UExpressionInner::Value(n2).annotate(UBitwidth::B32), - ), - (_, e2) => unreachable!(format!( - "non-constant exponent {} detected during static analysis", - e2.annotate(UBitwidth::B32) )), + (_, e2) => Err(Error::NonConstantExponent(format!( + "{}", + e2.annotate(UBitwidth::B32) + ))), } } FieldElementExpression::IfElse(box condition, box consequence, box alternative) => { let consequence = self.fold_field_expression(consequence)?; let alternative = self.fold_field_expression(alternative)?; match self.fold_boolean_expression(condition)? { - BooleanExpression::Value(true) => consequence, - BooleanExpression::Value(false) => alternative, - c => FieldElementExpression::IfElse(box c, box consequence, box alternative), + BooleanExpression::Value(true) => Ok(consequence), + BooleanExpression::Value(false) => Ok(alternative), + c => Ok(FieldElementExpression::IfElse( + box c, + box consequence, + box alternative, + )), } } FieldElementExpression::Select(box array, box index) => { @@ -1067,19 +1098,16 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (array.into_inner(), index.into_inner()) { (ArrayExpressionInner::Value(v), UExpressionInner::Value(n)) => { if n < size { - FieldElementExpression::try_from( + Ok(FieldElementExpression::try_from( v.expression_at::>( n as usize, ) .unwrap() .clone(), ) - .unwrap() + .unwrap()) } else { - unreachable!( - "out of bounds index ({} >= {}) found during static analysis", - n, size - ); + Err(Error::OutOfBounds(n, size)) } } (ArrayExpressionInner::Identifier(id), UExpressionInner::Value(n)) => { @@ -1087,35 +1115,35 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Some(a) => match a { TypedExpression::Array(a) => match a.as_inner() { ArrayExpressionInner::Value(v) => { - FieldElementExpression::try_from( + Ok(FieldElementExpression::try_from( TypedExpression::try_from( v.0[n as usize].clone(), ) .unwrap(), ) - .unwrap() + .unwrap()) } _ => unreachable!(), }, _ => unreachable!(""), }, - None => FieldElementExpression::Select( + None => Ok(FieldElementExpression::Select( box ArrayExpressionInner::Identifier(id) .annotate(inner_type, size as u32), box UExpressionInner::Value(n).annotate(UBitwidth::B32), - ), + )), } } - (a, i) => FieldElementExpression::Select( + (a, i) => Ok(FieldElementExpression::Select( box a.annotate(inner_type, size as u32), box i.annotate(UBitwidth::B32), - ), + )), } } _ => fold_field_expression( self, FieldElementExpression::Select(box array, box index), - )?, + ), } } FieldElementExpression::Member(box s, m) => { @@ -1135,15 +1163,18 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .unwrap() .1 { - TypedExpression::FieldElement(s) => s, + TypedExpression::FieldElement(s) => Ok(s), _ => unreachable!("????"), } } - inner => FieldElementExpression::Member(box inner.annotate(members), m), + inner => Ok(FieldElementExpression::Member( + box inner.annotate(members), + m, + )), } } - e => fold_field_expression(self, e)?, - }) + e => fold_field_expression(self, e), + } } fn fold_array_expression_inner( @@ -1151,13 +1182,13 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { ty: &ArrayType<'ast, T>, e: ArrayExpressionInner<'ast, T>, ) -> Result, Error> { - Ok(match e { + match e { ArrayExpressionInner::Identifier(id) => match self.constants.get(&id) { Some(e) => match e { - TypedExpression::Array(e) => e.as_inner().clone(), + TypedExpression::Array(e) => Ok(e.as_inner().clone()), _ => panic!("constant stored for an array should be an array"), }, - None => ArrayExpressionInner::Identifier(id), + None => Ok(ArrayExpressionInner::Identifier(id)), }, ArrayExpressionInner::Select(box array, box index) => { let array = self.fold_array_expression(array)?; @@ -1171,18 +1202,15 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { { (ArrayExpressionInner::Value(v), UExpressionInner::Value(n)) => { if n < size { - ArrayExpression::try_from( + Ok(ArrayExpression::try_from( v.expression_at::>(n as usize) .unwrap() .clone(), ) .unwrap() - .into_inner() + .into_inner()) } else { - unreachable!( - "out of bounds index ({} >= {}) found during static analysis", - n, size - ); + Err(Error::OutOfBounds(n, size)) } } (ArrayExpressionInner::Identifier(id), UExpressionInner::Value(n)) => { @@ -1190,7 +1218,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Some(a) => match a { TypedExpression::Array(a) => match a.as_inner() { ArrayExpressionInner::Value(v) => { - ArrayExpression::try_from( + Ok(ArrayExpression::try_from( v.expression_at::>( n as usize, ) @@ -1198,38 +1226,42 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .clone(), ) .unwrap() - .into_inner() + .into_inner()) } _ => unreachable!(), }, _ => unreachable!(""), }, - None => ArrayExpressionInner::Select( + None => Ok(ArrayExpressionInner::Select( box ArrayExpressionInner::Identifier(id) .annotate(inner_type, size as u32), box UExpressionInner::Value(n).annotate(UBitwidth::B32), - ), + )), } } - (a, i) => ArrayExpressionInner::Select( + (a, i) => Ok(ArrayExpressionInner::Select( box a.annotate(inner_type, size as u32), box i.annotate(UBitwidth::B32), - ), + )), }, _ => fold_array_expression_inner( self, ty, ArrayExpressionInner::Select(box array, box index), - )?, + ), } } ArrayExpressionInner::IfElse(box condition, box consequence, box alternative) => { let consequence = self.fold_array_expression(consequence)?; let alternative = self.fold_array_expression(alternative)?; match self.fold_boolean_expression(condition)? { - BooleanExpression::Value(true) => consequence.into_inner(), - BooleanExpression::Value(false) => alternative.into_inner(), - c => ArrayExpressionInner::IfElse(box c, box consequence, box alternative), + BooleanExpression::Value(true) => Ok(consequence.into_inner()), + BooleanExpression::Value(false) => Ok(alternative.into_inner()), + c => Ok(ArrayExpressionInner::IfElse( + box c, + box consequence, + box alternative, + )), } } ArrayExpressionInner::Member(box struc, id) => { @@ -1249,15 +1281,18 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .unwrap() .1 { - TypedExpression::Array(a) => a.into_inner(), + TypedExpression::Array(a) => Ok(a.into_inner()), _ => unreachable!("should be an array"), } } - inner => ArrayExpressionInner::Member(box inner.annotate(members), id), + inner => Ok(ArrayExpressionInner::Member( + box inner.annotate(members), + id, + )), } } - e => fold_array_expression_inner(self, ty, e)?, - }) + e => fold_array_expression_inner(self, ty, e), + } } fn fold_struct_expression_inner( @@ -1265,13 +1300,13 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { ty: &StructType<'ast, T>, e: StructExpressionInner<'ast, T>, ) -> Result, Error> { - Ok(match e { + match e { StructExpressionInner::Identifier(id) => match self.constants.get(&id) { Some(e) => match e { - TypedExpression::Struct(e) => e.as_inner().clone(), + TypedExpression::Struct(e) => Ok(e.as_inner().clone()), _ => panic!("constant stored for an array should be an array"), }, - None => StructExpressionInner::Identifier(id), + None => Ok(StructExpressionInner::Identifier(id)), }, StructExpressionInner::Select(box array, box index) => { let array = self.fold_array_expression(array)?; @@ -1285,18 +1320,15 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { { (ArrayExpressionInner::Value(v), UExpressionInner::Value(n)) => { if n < size { - StructExpression::try_from( + Ok(StructExpression::try_from( v.expression_at::>(n as usize) .unwrap() .clone(), ) .unwrap() - .into_inner() + .into_inner()) } else { - unreachable!( - "out of bounds index ({} >= {}) found during static analysis", - n, size - ); + Err(Error::OutOfBounds(n, size)) } } (ArrayExpressionInner::Identifier(id), UExpressionInner::Value(n)) => { @@ -1304,7 +1336,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Some(a) => match a { TypedExpression::Array(a) => match a.as_inner() { ArrayExpressionInner::Value(v) => { - StructExpression::try_from( + Ok(StructExpression::try_from( v.expression_at::>( n as usize, ) @@ -1312,38 +1344,42 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .clone(), ) .unwrap() - .into_inner() + .into_inner()) } _ => unreachable!(), }, _ => unreachable!(""), }, - None => StructExpressionInner::Select( + None => Ok(StructExpressionInner::Select( box ArrayExpressionInner::Identifier(id) .annotate(inner_type, size as u32), box UExpressionInner::Value(n).annotate(UBitwidth::B32), - ), + )), } } - (a, i) => StructExpressionInner::Select( + (a, i) => Ok(StructExpressionInner::Select( box a.annotate(inner_type, size as u32), box i.annotate(UBitwidth::B32), - ), + )), }, _ => fold_struct_expression_inner( self, ty, StructExpressionInner::Select(box array, box index), - )?, + ), } } StructExpressionInner::IfElse(box condition, box consequence, box alternative) => { let consequence = self.fold_struct_expression(consequence)?; let alternative = self.fold_struct_expression(alternative)?; match self.fold_boolean_expression(condition)? { - BooleanExpression::Value(true) => consequence.into_inner(), - BooleanExpression::Value(false) => alternative.into_inner(), - c => StructExpressionInner::IfElse(box c, box consequence, box alternative), + BooleanExpression::Value(true) => Ok(consequence.into_inner()), + BooleanExpression::Value(false) => Ok(alternative.into_inner()), + c => Ok(StructExpressionInner::IfElse( + box c, + box consequence, + box alternative, + )), } } StructExpressionInner::Member(box s, m) => { @@ -1363,15 +1399,18 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .unwrap() .1 { - TypedExpression::Struct(s) => s.into_inner(), + TypedExpression::Struct(s) => Ok(s.into_inner()), _ => unreachable!("should be a struct"), } } - inner => StructExpressionInner::Member(box inner.annotate(members), m), + inner => Ok(StructExpressionInner::Member( + box inner.annotate(members), + m, + )), } } - e => fold_struct_expression_inner(self, ty, e)?, - }) + e => fold_struct_expression_inner(self, ty, e), + } } fn fold_boolean_expression( @@ -1383,13 +1422,13 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { // For example, `2 * a` is equivalent to `a + a`, but our notion of equality would not detect that here // These kind of reduction rules are easier to apply later in the process, when we have canonical representations // of expressions, ie `a + a` would always be written `2 * a` - Ok(match e { + match e { BooleanExpression::Identifier(id) => match self.constants.get(&id) { Some(e) => match e { - TypedExpression::Boolean(e) => e.clone(), + TypedExpression::Boolean(e) => Ok(e.clone()), _ => panic!("constant stored for a boolean should be a boolean"), }, - None => BooleanExpression::Identifier(id), + None => Ok(BooleanExpression::Identifier(id)), }, BooleanExpression::FieldEq(box e1, box e2) => { let e1 = self.fold_field_expression(e1)?; @@ -1397,9 +1436,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - BooleanExpression::Value(n1 == n2) + Ok(BooleanExpression::Value(n1 == n2)) } - (e1, e2) => BooleanExpression::FieldEq(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::FieldEq(box e1, box e2)), } } BooleanExpression::UintEq(box e1, box e2) => { @@ -1408,9 +1447,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1.as_inner(), e2.as_inner()) { (UExpressionInner::Value(n1), UExpressionInner::Value(n2)) => { - BooleanExpression::Value(n1 == n2) + Ok(BooleanExpression::Value(n1 == n2)) } - _ => BooleanExpression::UintEq(box e1, box e2), + _ => Ok(BooleanExpression::UintEq(box e1, box e2)), } } BooleanExpression::BoolEq(box e1, box e2) => { @@ -1419,9 +1458,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { (BooleanExpression::Value(n1), BooleanExpression::Value(n2)) => { - BooleanExpression::Value(n1 == n2) + Ok(BooleanExpression::Value(n1 == n2)) } - (e1, e2) => BooleanExpression::BoolEq(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::BoolEq(box e1, box e2)), } } BooleanExpression::ArrayEq(box e1, box e2) => { @@ -1440,7 +1479,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { } }; - BooleanExpression::ArrayEq(box e1, box e2) + Ok(BooleanExpression::ArrayEq(box e1, box e2)) } BooleanExpression::FieldLt(box e1, box e2) => { let e1 = self.fold_field_expression(e1)?; @@ -1448,9 +1487,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - BooleanExpression::Value(n1 < n2) + Ok(BooleanExpression::Value(n1 < n2)) } - (e1, e2) => BooleanExpression::FieldLt(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::FieldLt(box e1, box e2)), } } BooleanExpression::FieldLe(box e1, box e2) => { @@ -1459,9 +1498,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - BooleanExpression::Value(n1 <= n2) + Ok(BooleanExpression::Value(n1 <= n2)) } - (e1, e2) => BooleanExpression::FieldLe(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::FieldLe(box e1, box e2)), } } BooleanExpression::FieldGt(box e1, box e2) => { @@ -1470,9 +1509,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - BooleanExpression::Value(n1 > n2) + Ok(BooleanExpression::Value(n1 > n2)) } - (e1, e2) => BooleanExpression::FieldGt(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::FieldGt(box e1, box e2)), } } BooleanExpression::FieldGe(box e1, box e2) => { @@ -1481,9 +1520,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { (FieldElementExpression::Number(n1), FieldElementExpression::Number(n2)) => { - BooleanExpression::Value(n1 >= n2) + Ok(BooleanExpression::Value(n1 >= n2)) } - (e1, e2) => BooleanExpression::FieldGe(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::FieldGe(box e1, box e2)), } } BooleanExpression::UintLt(box e1, box e2) => { @@ -1492,9 +1531,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1.as_inner(), e2.as_inner()) { (UExpressionInner::Value(n1), UExpressionInner::Value(n2)) => { - BooleanExpression::Value(n1 < n2) + Ok(BooleanExpression::Value(n1 < n2)) } - _ => BooleanExpression::UintLt(box e1, box e2), + _ => Ok(BooleanExpression::UintLt(box e1, box e2)), } } BooleanExpression::UintLe(box e1, box e2) => { @@ -1503,9 +1542,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1.as_inner(), e2.as_inner()) { (UExpressionInner::Value(n1), UExpressionInner::Value(n2)) => { - BooleanExpression::Value(n1 <= n2) + Ok(BooleanExpression::Value(n1 <= n2)) } - _ => BooleanExpression::UintLe(box e1, box e2), + _ => Ok(BooleanExpression::UintLe(box e1, box e2)), } } BooleanExpression::UintGt(box e1, box e2) => { @@ -1514,9 +1553,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1.as_inner(), e2.as_inner()) { (UExpressionInner::Value(n1), UExpressionInner::Value(n2)) => { - BooleanExpression::Value(n1 > n2) + Ok(BooleanExpression::Value(n1 > n2)) } - _ => BooleanExpression::UintGt(box e1, box e2), + _ => Ok(BooleanExpression::UintGt(box e1, box e2)), } } BooleanExpression::UintGe(box e1, box e2) => { @@ -1525,9 +1564,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1.as_inner(), e2.as_inner()) { (UExpressionInner::Value(n1), UExpressionInner::Value(n2)) => { - BooleanExpression::Value(n1 >= n2) + Ok(BooleanExpression::Value(n1 >= n2)) } - _ => BooleanExpression::UintGe(box e1, box e2), + _ => Ok(BooleanExpression::UintGe(box e1, box e2)), } } BooleanExpression::Or(box e1, box e2) => { @@ -1537,17 +1576,17 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { // reduction of constants (BooleanExpression::Value(v1), BooleanExpression::Value(v2)) => { - BooleanExpression::Value(v1 || v2) + Ok(BooleanExpression::Value(v1 || v2)) } // x || true == true (_, BooleanExpression::Value(true)) | (BooleanExpression::Value(true), _) => { - BooleanExpression::Value(true) + Ok(BooleanExpression::Value(true)) } // x || false == x (e, BooleanExpression::Value(false)) | (BooleanExpression::Value(false), e) => { - e + Ok(e) } - (e1, e2) => BooleanExpression::Or(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::Or(box e1, box e2)), } } BooleanExpression::And(box e1, box e2) => { @@ -1557,31 +1596,37 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { match (e1, e2) { // reduction of constants (BooleanExpression::Value(v1), BooleanExpression::Value(v2)) => { - BooleanExpression::Value(v1 && v2) + Ok(BooleanExpression::Value(v1 && v2)) } // x && true == x - (e, BooleanExpression::Value(true)) | (BooleanExpression::Value(true), e) => e, + (e, BooleanExpression::Value(true)) | (BooleanExpression::Value(true), e) => { + Ok(e) + } // x && false == false (_, BooleanExpression::Value(false)) | (BooleanExpression::Value(false), _) => { - BooleanExpression::Value(false) + Ok(BooleanExpression::Value(false)) } - (e1, e2) => BooleanExpression::And(box e1, box e2), + (e1, e2) => Ok(BooleanExpression::And(box e1, box e2)), } } BooleanExpression::Not(box e) => { let e = self.fold_boolean_expression(e)?; match e { - BooleanExpression::Value(v) => BooleanExpression::Value(!v), - e => BooleanExpression::Not(box e), + BooleanExpression::Value(v) => Ok(BooleanExpression::Value(!v)), + e => Ok(BooleanExpression::Not(box e)), } } BooleanExpression::IfElse(box condition, box consequence, box alternative) => { let consequence = self.fold_boolean_expression(consequence)?; let alternative = self.fold_boolean_expression(alternative)?; match self.fold_boolean_expression(condition)? { - BooleanExpression::Value(true) => consequence, - BooleanExpression::Value(false) => alternative, - c => BooleanExpression::IfElse(box c, box consequence, box alternative), + BooleanExpression::Value(true) => Ok(consequence), + BooleanExpression::Value(false) => Ok(alternative), + c => Ok(BooleanExpression::IfElse( + box c, + box consequence, + box alternative, + )), } } BooleanExpression::Select(box array, box index) => { @@ -1596,17 +1641,14 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { { (ArrayExpressionInner::Value(v), UExpressionInner::Value(n)) => { if n < size { - BooleanExpression::try_from( + Ok(BooleanExpression::try_from( v.expression_at::>(n as usize) .unwrap() .clone(), ) - .unwrap() + .unwrap()) } else { - unreachable!( - "out of bounds index ({} >= {}) found during static analysis", - n, size - ); + Err(Error::OutOfBounds(n, size)) } } (ArrayExpressionInner::Identifier(id), UExpressionInner::Value(n)) => { @@ -1614,32 +1656,32 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Some(a) => match a { TypedExpression::Array(a) => match a.as_inner() { ArrayExpressionInner::Value(v) => { - BooleanExpression::try_from( + Ok(BooleanExpression::try_from( TypedExpression::try_from(v.0[n as usize].clone()) .unwrap(), ) - .unwrap() + .unwrap()) } _ => unreachable!(), }, _ => unreachable!(""), }, - None => BooleanExpression::Select( + None => Ok(BooleanExpression::Select( box ArrayExpressionInner::Identifier(id) .annotate(inner_type, size as u32), box UExpressionInner::Value(n).annotate(UBitwidth::B32), - ), + )), } } - (a, i) => BooleanExpression::Select( + (a, i) => Ok(BooleanExpression::Select( box a.annotate(inner_type, size as u32), box i.annotate(UBitwidth::B32), - ), + )), }, _ => fold_boolean_expression( self, BooleanExpression::Select(box array, box index), - )?, + ), } } BooleanExpression::Member(box s, m) => { @@ -1659,15 +1701,15 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .unwrap() .1 { - TypedExpression::Boolean(s) => s, + TypedExpression::Boolean(s) => Ok(s), _ => unreachable!("should be a boolean"), } } - inner => BooleanExpression::Member(box inner.annotate(members), m), + inner => Ok(BooleanExpression::Member(box inner.annotate(members), m)), } } - e => fold_boolean_expression(self, e)?, - }) + e => fold_boolean_expression(self, e), + } } } diff --git a/zokrates_core/src/static_analysis/reducer/mod.rs b/zokrates_core/src/static_analysis/reducer/mod.rs index ce1e5ce9d..f0f846231 100644 --- a/zokrates_core/src/static_analysis/reducer/mod.rs +++ b/zokrates_core/src/static_analysis/reducer/mod.rs @@ -607,11 +607,7 @@ fn reduce_function<'ast, T: Field>( let new_f = Propagator::with_constants(&mut constants) .fold_function(new_f) - .map_err(|e| match e { - crate::static_analysis::propagation::Error::Type(e) => { - Error::Incompatible(e) - } - })?; + .map_err(|e| Error::Incompatible(format!("{}", e)))?; break Ok(new_f); } @@ -622,11 +618,7 @@ fn reduce_function<'ast, T: Field>( f = Propagator::with_constants(&mut constants) .fold_function(new_f) - .map_err(|e| match e { - crate::static_analysis::propagation::Error::Type(e) => { - Error::Incompatible(e) - } - })?; + .map_err(|e| Error::Incompatible(format!("{}", e)))?; let new_hash = Some(compute_hash(&f)); From e8ad90e4070442b78a4d2eda751489aa96d980d3 Mon Sep 17 00:00:00 2001 From: dark64 Date: Fri, 23 Apr 2021 14:35:11 +0200 Subject: [PATCH 62/95] add changelog --- changelogs/unreleased/832-dark64 | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/832-dark64 diff --git a/changelogs/unreleased/832-dark64 b/changelogs/unreleased/832-dark64 new file mode 100644 index 000000000..3ae3758df --- /dev/null +++ b/changelogs/unreleased/832-dark64 @@ -0,0 +1 @@ +Handle errors more gracefully in propagation step where applicable \ No newline at end of file From a0f19d78e825600ca6e3fbfade7fc56551bd90a9 Mon Sep 17 00:00:00 2001 From: dark64 Date: Fri, 23 Apr 2021 15:04:39 +0200 Subject: [PATCH 63/95] use to_string instead of format!(), fix messages --- .../src/static_analysis/propagation.rs | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index bbb6acf32..39f6409f8 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -88,9 +88,9 @@ impl<'ast, 'a, T: Field> Propagator<'ast, 'a, T> { } _ => unreachable!(), }, - _ => unreachable!(), + _ => unreachable!("should be an array value"), }, - _ => unreachable!(), + _ => unreachable!("should be an array expression"), }, _ => Err(variable), }, @@ -107,15 +107,15 @@ impl<'ast, 'a, T: Field> Propagator<'ast, 'a, T> { .iter() .position(|member| *m == member.id) .unwrap(), - _ => unreachable!(), + _ => unreachable!("should be a struct type"), }; match c { TypedExpression::Struct(a) => match a.as_inner_mut() { StructExpressionInner::Value(value) => Ok((v, &mut value[index])), - _ => unreachable!(), + _ => unreachable!("should be a struct value"), }, - _ => unreachable!(), + _ => unreachable!("should be a struct expression"), } } e => e, @@ -182,17 +182,17 @@ fn remove_spreads(e: TypedExpression) -> TypedExpression { ArrayExpressionInner::Slice(box a, box from, box to) => { let from = match from.into_inner() { UExpressionInner::Value(from) => from as usize, - _ => unreachable!(), + _ => unreachable!("should be a uint value"), }; let to = match to.into_inner() { UExpressionInner::Value(to) => to as usize, - _ => unreachable!(), + _ => unreachable!("should be a uint value"), }; let v = match a.into_inner() { ArrayExpressionInner::Value(v) => v, - _ => unreachable!(), + _ => unreachable!("should be an array value"), }; ArrayExpressionInner::Value( @@ -211,7 +211,7 @@ fn remove_spreads(e: TypedExpression) -> TypedExpression { ArrayExpressionInner::Repeat(box e, box count) => { let count = match count.into_inner() { UExpressionInner::Value(from) => from as usize, - _ => unreachable!(), + _ => unreachable!("should be a uint value"), }; let e = remove_spreads(e); @@ -405,7 +405,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { ) .annotate(bitwidth) .into(), - v => unreachable!("should be an array value, found {}", v), + _ => unreachable!("should be an array value"), } } @@ -965,9 +965,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .unwrap() .into_inner()) } - _ => unreachable!(), + _ => unreachable!("should be an array value"), }, - _ => unreachable!(""), + _ => unreachable!("should be an array expression"), }, None => Ok(UExpressionInner::Select( box ArrayExpressionInner::Identifier(id) @@ -1067,10 +1067,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { box e1, box UExpressionInner::Value(n2).annotate(UBitwidth::B32), )), - (_, e2) => Err(Error::NonConstantExponent(format!( - "{}", - e2.annotate(UBitwidth::B32) - ))), + (_, e2) => Err(Error::NonConstantExponent( + e2.annotate(UBitwidth::B32).to_string(), + )), } } FieldElementExpression::IfElse(box condition, box consequence, box alternative) => { @@ -1123,9 +1122,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { ) .unwrap()) } - _ => unreachable!(), + _ => unreachable!("should be an array value"), }, - _ => unreachable!(""), + _ => unreachable!("should be an array expression"), }, None => Ok(FieldElementExpression::Select( box ArrayExpressionInner::Identifier(id) @@ -1151,7 +1150,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { let members = match s.get_type() { Type::Struct(members) => members, - _ => unreachable!("???"), + _ => unreachable!("should be a struct type"), }; match s.into_inner() { @@ -1164,7 +1163,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .1 { TypedExpression::FieldElement(s) => Ok(s), - _ => unreachable!("????"), + _ => unreachable!("should be a field element expression"), } } inner => Ok(FieldElementExpression::Member( @@ -1228,9 +1227,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .unwrap() .into_inner()) } - _ => unreachable!(), + _ => unreachable!("should be an array value"), }, - _ => unreachable!(""), + _ => unreachable!("should be an array expression"), }, None => Ok(ArrayExpressionInner::Select( box ArrayExpressionInner::Identifier(id) @@ -1269,7 +1268,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { let members = match struc.get_type() { Type::Struct(members) => members, - _ => unreachable!("should be a struct"), + _ => unreachable!("should be a struct type"), }; match struc.into_inner() { @@ -1282,7 +1281,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .1 { TypedExpression::Array(a) => Ok(a.into_inner()), - _ => unreachable!("should be an array"), + _ => unreachable!("should be an array expression"), } } inner => Ok(ArrayExpressionInner::Member( @@ -1346,9 +1345,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .unwrap() .into_inner()) } - _ => unreachable!(), + _ => unreachable!("should be an array value"), }, - _ => unreachable!(""), + _ => unreachable!("should be an array expression"), }, None => Ok(StructExpressionInner::Select( box ArrayExpressionInner::Identifier(id) @@ -1387,7 +1386,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { let members = match s.get_type() { Type::Struct(members) => members, - _ => unreachable!("should be a struct"), + _ => unreachable!("should be a struct type"), }; match s.into_inner() { @@ -1400,7 +1399,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .1 { TypedExpression::Struct(s) => Ok(s.into_inner()), - _ => unreachable!("should be a struct"), + _ => unreachable!("should be a struct expression"), } } inner => Ok(StructExpressionInner::Member( @@ -1662,9 +1661,9 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { ) .unwrap()) } - _ => unreachable!(), + _ => unreachable!("should be an array value"), }, - _ => unreachable!(""), + _ => unreachable!("should be an array expression"), }, None => Ok(BooleanExpression::Select( box ArrayExpressionInner::Identifier(id) @@ -1689,7 +1688,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { let members = match s.get_type() { Type::Struct(members) => members, - _ => unreachable!("should be a struct"), + _ => unreachable!("should be a struct type"), }; match s.into_inner() { @@ -1702,7 +1701,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { .1 { TypedExpression::Boolean(s) => Ok(s), - _ => unreachable!("should be a boolean"), + _ => unreachable!("should be a boolean expression"), } } inner => Ok(BooleanExpression::Member(box inner.annotate(members), m)), From ae7e095cacdab3367b35c25fe32b813704b43b75 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 26 Apr 2021 13:16:25 +0200 Subject: [PATCH 64/95] refactoring, fix constant aliasing --- .../examples/imports/import_with_alias.zok | 4 +- zokrates_core/src/semantics.rs | 8 +- .../src/static_analysis/constant_inliner.rs | 145 +++++++++--------- zokrates_core/src/typed_absy/folder.rs | 27 +++- zokrates_core/src/typed_absy/mod.rs | 90 ++++++++++- zokrates_core/src/typed_absy/result_folder.rs | 22 ++- 6 files changed, 196 insertions(+), 100 deletions(-) diff --git a/zokrates_cli/examples/imports/import_with_alias.zok b/zokrates_cli/examples/imports/import_with_alias.zok index dd8994bf4..5e0136913 100644 --- a/zokrates_cli/examples/imports/import_with_alias.zok +++ b/zokrates_cli/examples/imports/import_with_alias.zok @@ -1,8 +1,8 @@ from "./bar" import main as bar -from "./baz" import main as baz +from "./baz" import BAZ as baz import "./foo" as f def main() -> field: field foo = f() - assert(foo == bar() + baz()) + assert(foo == bar() + baz) return foo \ No newline at end of file diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 443adaa85..4c9836c67 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -374,7 +374,7 @@ impl<'ast, T: Field> Checker<'ast, T> { ty ), }) - .map(|e| TypedConstant { ty, expression: e }) + .map(|e| TypedConstant::new(ty, e)) } fn check_struct_type_declaration( @@ -498,13 +498,13 @@ impl<'ast, T: Field> Checker<'ast, T> { ); self.insert_into_scope(Variable::with_id_and_type( declaration.id, - c.ty.clone(), + c.get_type(), )); assert!(state .constants .entry(module_id.to_path_buf()) .or_default() - .insert(declaration.id, c.ty) + .insert(declaration.id, c.get_type()) .is_none()); } }; @@ -642,7 +642,7 @@ impl<'ast, T: Field> Checker<'ast, T> { }}); } true => { - constants.insert(declaration.id, TypedConstantSymbol::There(import.module_id, declaration.id)); + constants.insert(declaration.id, TypedConstantSymbol::There(import.module_id, import.symbol_id)); self.insert_into_scope(Variable::with_id_and_type(declaration.id, ty.clone())); state diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index fff3ca647..3e082fbf5 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -9,17 +9,12 @@ pub struct ConstantInliner<'ast, T: Field> { } impl<'ast, T: Field> ConstantInliner<'ast, T> { - fn with_modules_and_location( - modules: TypedModules<'ast, T>, - location: OwnedTypedModuleId, - ) -> Self { + pub fn new(modules: TypedModules<'ast, T>, location: OwnedTypedModuleId) -> Self { ConstantInliner { modules, location } } pub fn inline(p: TypedProgram<'ast, T>) -> TypedProgram<'ast, T> { - let mut inliner = - ConstantInliner::with_modules_and_location(p.modules.clone(), p.main.clone()); - + let mut inliner = ConstantInliner::new(p.modules.clone(), p.main.clone()); inliner.fold_program(p) } @@ -56,10 +51,7 @@ impl<'ast, T: Field> ConstantInliner<'ast, T> { let _ = self.change_location(location); symbol } - TypedConstantSymbol::Here(tc) => TypedConstant { - expression: self.fold_expression(tc.expression), - ..tc - }, + TypedConstantSymbol::Here(tc) => self.fold_constant(tc), } } } @@ -96,9 +88,9 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { fn fold_constant_symbol( &mut self, - p: TypedConstantSymbol<'ast, T>, + s: TypedConstantSymbol<'ast, T>, ) -> TypedConstantSymbol<'ast, T> { - let tc = self.get_canonical_constant(p); + let tc = self.get_canonical_constant(s); TypedConstantSymbol::Here(tc) } @@ -108,7 +100,10 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { ) -> FieldElementExpression<'ast, T> { match e { FieldElementExpression::Identifier(ref id) => match self.get_constant(id) { - Some(c) => fold_field_expression(self, c.expression.try_into().unwrap()), + Some(c) => { + let c = self.fold_constant(c); + fold_field_expression(self, c.try_into().unwrap()) + } None => fold_field_expression(self, e), }, e => fold_field_expression(self, e), @@ -121,7 +116,10 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { ) -> BooleanExpression<'ast, T> { match e { BooleanExpression::Identifier(ref id) => match self.get_constant(id) { - Some(c) => fold_boolean_expression(self, c.expression.try_into().unwrap()), + Some(c) => { + let c = self.fold_constant(c); + fold_boolean_expression(self, c.try_into().unwrap()) + } None => fold_boolean_expression(self, e), }, e => fold_boolean_expression(self, e), @@ -136,7 +134,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { match e { UExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - fold_uint_expression(self, c.expression.try_into().unwrap()).into_inner() + let c = self.fold_constant(c); + fold_uint_expression(self, c.try_into().unwrap()).into_inner() } None => fold_uint_expression_inner(self, size, e), }, @@ -152,7 +151,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { match e { ArrayExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - fold_array_expression(self, c.expression.try_into().unwrap()).into_inner() + let c = self.fold_constant(c); + fold_array_expression(self, c.try_into().unwrap()).into_inner() } None => fold_array_expression_inner(self, ty, e), }, @@ -168,7 +168,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { match e { StructExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - fold_struct_expression(self, c.expression.try_into().unwrap()).into_inner() + let c = self.fold_constant(c); + fold_struct_expression(self, c.try_into().unwrap()).into_inner() } None => fold_struct_expression_inner(self, ty, e), }, @@ -207,12 +208,10 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement(FieldElementExpression::Number( - Bn128Field::from(1), - ))), - }), + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::FieldElement(FieldElementExpression::Number(Bn128Field::from(1))), + )), )] .into_iter() .collect(); @@ -297,10 +296,10 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::Boolean, - expression: (TypedExpression::Boolean(BooleanExpression::Value(true))), - }), + TypedConstantSymbol::Here(TypedConstant::new( + GType::Boolean, + TypedExpression::Boolean(BooleanExpression::Value(true)), + )), )] .into_iter() .collect(); @@ -386,12 +385,12 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::Uint(UBitwidth::B32), - expression: (UExpressionInner::Value(1u128) + TypedConstantSymbol::Here(TypedConstant::new( + GType::Uint(UBitwidth::B32), + UExpressionInner::Value(1u128) .annotate(UBitwidth::B32) - .into()), - }), + .into(), + )), )] .into_iter() .collect(); @@ -487,9 +486,9 @@ mod tests { let constants: TypedConstantSymbols<_> = vec![( const_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: TypedExpression::Array( + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::Array( ArrayExpressionInner::Value( vec![ FieldElementExpression::Number(Bn128Field::from(2)).into(), @@ -499,7 +498,7 @@ mod tests { ) .annotate(GType::FieldElement, 2usize), ), - }), + )), )] .into_iter() .collect(); @@ -626,26 +625,24 @@ mod tests { constants: vec![ ( const_a_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Number(Bn128Field::from(1)), + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::FieldElement(FieldElementExpression::Number( + Bn128Field::from(1), )), - }), + )), ), ( const_b_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Add( - box FieldElementExpression::Identifier(Identifier::from( - const_a_id, - )), - box FieldElementExpression::Number(Bn128Field::from(1)), - ), + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::FieldElement(FieldElementExpression::Add( + box FieldElementExpression::Identifier(Identifier::from( + const_a_id, + )), + box FieldElementExpression::Number(Bn128Field::from(1)), )), - }), + )), ), ] .into_iter() @@ -688,24 +685,22 @@ mod tests { constants: vec![ ( const_a_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Number(Bn128Field::from(1)), + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::FieldElement(FieldElementExpression::Number( + Bn128Field::from(1), )), - }), + )), ), ( const_b_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement( - FieldElementExpression::Add( - box FieldElementExpression::Number(Bn128Field::from(1)), - box FieldElementExpression::Number(Bn128Field::from(1)), - ), + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::FieldElement(FieldElementExpression::Add( + box FieldElementExpression::Number(Bn128Field::from(1)), + box FieldElementExpression::Number(Bn128Field::from(1)), )), - }), + )), ), ] .into_iter() @@ -752,12 +747,12 @@ mod tests { .collect(), constants: vec![( foo_const_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement(FieldElementExpression::Number( + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::FieldElement(FieldElementExpression::Number( Bn128Field::from(42), - ))), - }), + )), + )), )] .into_iter() .collect(), @@ -822,12 +817,12 @@ mod tests { .collect(), constants: vec![( foo_const_id, - TypedConstantSymbol::Here(TypedConstant { - ty: GType::FieldElement, - expression: (TypedExpression::FieldElement(FieldElementExpression::Number( + TypedConstantSymbol::Here(TypedConstant::new( + GType::FieldElement, + TypedExpression::FieldElement(FieldElementExpression::Number( Bn128Field::from(42), - ))), - }), + )), + )), )] .into_iter() .collect(), diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index 30385b1b6..610aa7106 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -13,11 +13,15 @@ pub trait Folder<'ast, T: Field>: Sized { fold_module(self, p) } + fn fold_constant(&mut self, c: TypedConstant<'ast, T>) -> TypedConstant<'ast, T> { + fold_constant(self, c) + } + fn fold_constant_symbol( &mut self, - p: TypedConstantSymbol<'ast, T>, + s: TypedConstantSymbol<'ast, T>, ) -> TypedConstantSymbol<'ast, T> { - fold_constant_symbol(self, p) + fold_constant_symbol(self, s) } fn fold_function_symbol( @@ -719,15 +723,22 @@ pub fn fold_struct_expression<'ast, T: Field, F: Folder<'ast, T>>( } } +pub fn fold_constant<'ast, T: Field, F: Folder<'ast, T>>( + f: &mut F, + c: TypedConstant<'ast, T>, +) -> TypedConstant<'ast, T> { + TypedConstant { + expression: f.fold_expression(c.expression), + ..c + } +} + pub fn fold_constant_symbol<'ast, T: Field, F: Folder<'ast, T>>( f: &mut F, - p: TypedConstantSymbol<'ast, T>, + s: TypedConstantSymbol<'ast, T>, ) -> TypedConstantSymbol<'ast, T> { - match p { - TypedConstantSymbol::Here(tc) => TypedConstantSymbol::Here(TypedConstant { - expression: f.fold_expression(tc.expression), - ..tc - }), + match s { + TypedConstantSymbol::Here(tc) => TypedConstantSymbol::Here(f.fold_constant(tc)), there => there, } } diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 101e13950..408920d28 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -196,22 +196,31 @@ impl<'ast, T: Field> TypedFunctionSymbol<'ast, T> { impl<'ast, T: fmt::Display> fmt::Display for TypedModule<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let res = self - .functions + .constants .iter() .map(|(key, symbol)| match symbol { + TypedConstantSymbol::Here(tc) => { + format!("const {} {} = {}", tc.ty, key, tc.expression) + } + TypedConstantSymbol::There(module_id, id) => { + format!("from \"{}\" import {} as {}", module_id.display(), id, key) + } + }) + .chain(self.functions.iter().map(|(key, symbol)| match symbol { TypedFunctionSymbol::Here(ref function) => format!("def {}{}", key.id, function), TypedFunctionSymbol::There(ref fun_key) => format!( - "import {} from \"{}\" as {} // with signature {}", - fun_key.id, + "from \"{}\" import {} as {} // with signature {}", fun_key.module.display(), + fun_key.id, key.id, key.signature ), TypedFunctionSymbol::Flat(ref flat_fun) => { format!("def {}{}:\n\t// hidden", key.id, flat_fun.signature()) } - }) + })) .collect::>(); + write!(f, "{}", res.join("\n")) } } @@ -220,8 +229,13 @@ impl<'ast, T: fmt::Debug> fmt::Debug for TypedModule<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "module(\n\tfunctions:\n\t\t{:?}\n)", + "TypedModule(\n\tFunctions:\n\t\t{:?}\n\tConstants:\n\t\t{:?}\n)", self.functions + .iter() + .map(|x| format!("{:?}", x)) + .collect::>() + .join("\n\t\t"), + self.constants .iter() .map(|x| format!("{:?}", x)) .collect::>() @@ -322,8 +336,14 @@ impl<'ast, T: fmt::Debug> fmt::Debug for TypedFunction<'ast, T> { #[derive(Clone, PartialEq)] pub struct TypedConstant<'ast, T> { - pub ty: Type<'ast, T>, - pub expression: TypedExpression<'ast, T>, + ty: Type<'ast, T>, + expression: TypedExpression<'ast, T>, +} + +impl<'ast, T> TypedConstant<'ast, T> { + pub fn new(ty: Type<'ast, T>, expression: TypedExpression<'ast, T>) -> Self { + TypedConstant { ty, expression } + } } impl<'ast, T: fmt::Debug> fmt::Debug for TypedConstant<'ast, T> { @@ -338,6 +358,12 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedConstant<'ast, T> { } } +impl<'ast, T: Clone> Typed<'ast, T> for TypedConstant<'ast, T> { + fn get_type(&self) -> Type<'ast, T> { + self.ty.clone() + } +} + /// Something we can assign to. #[derive(Clone, PartialEq, Hash, Eq)] pub enum TypedAssignee<'ast, T> { @@ -1256,6 +1282,56 @@ impl<'ast, T> TryFrom> for StructExpression<'ast, T> { } } +impl<'ast, T> TryFrom> for FieldElementExpression<'ast, T> { + type Error = (); + + fn try_from( + tc: TypedConstant<'ast, T>, + ) -> Result, Self::Error> { + tc.expression.try_into() + } +} + +impl<'ast, T> TryFrom> for BooleanExpression<'ast, T> { + type Error = (); + + fn try_from(tc: TypedConstant<'ast, T>) -> Result, Self::Error> { + tc.expression.try_into() + } +} + +impl<'ast, T> TryFrom> for UExpression<'ast, T> { + type Error = (); + + fn try_from(tc: TypedConstant<'ast, T>) -> Result, Self::Error> { + tc.expression.try_into() + } +} + +impl<'ast, T> TryFrom> for ArrayExpression<'ast, T> { + type Error = (); + + fn try_from(tc: TypedConstant<'ast, T>) -> Result, Self::Error> { + tc.expression.try_into() + } +} + +impl<'ast, T> TryFrom> for StructExpression<'ast, T> { + type Error = (); + + fn try_from(tc: TypedConstant<'ast, T>) -> Result, Self::Error> { + tc.expression.try_into() + } +} + +impl<'ast, T> TryFrom> for IntExpression<'ast, T> { + type Error = (); + + fn try_from(tc: TypedConstant<'ast, T>) -> Result, Self::Error> { + tc.expression.try_into() + } +} + impl<'ast, T: fmt::Display> fmt::Display for FieldElementExpression<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index 82ae443a3..a939b296a 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -21,6 +21,13 @@ pub trait ResultFolder<'ast, T: Field>: Sized { fold_module(self, p) } + fn fold_constant( + &mut self, + s: TypedConstant<'ast, T>, + ) -> Result, Self::Error> { + fold_constant(self, s) + } + fn fold_constant_symbol( &mut self, s: TypedConstantSymbol<'ast, T>, @@ -800,15 +807,22 @@ pub fn fold_struct_expression<'ast, T: Field, F: ResultFolder<'ast, T>>( }) } +pub fn fold_constant<'ast, T: Field, F: ResultFolder<'ast, T>>( + f: &mut F, + c: TypedConstant<'ast, T>, +) -> Result, F::Error> { + Ok(TypedConstant { + expression: f.fold_expression(c.expression)?, + ..c + }) +} + pub fn fold_constant_symbol<'ast, T: Field, F: ResultFolder<'ast, T>>( f: &mut F, s: TypedConstantSymbol<'ast, T>, ) -> Result, F::Error> { match s { - TypedConstantSymbol::Here(tc) => Ok(TypedConstantSymbol::Here(TypedConstant { - expression: f.fold_expression(tc.expression)?, - ..tc - })), + TypedConstantSymbol::Here(tc) => Ok(TypedConstantSymbol::Here(f.fold_constant(tc)?)), there => Ok(there), } } From 3fa3f3978b08645394521b51d275a10993bd0752 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 26 Apr 2021 18:58:01 +0200 Subject: [PATCH 65/95] fix type of repeat after inference --- zokrates_cli/examples/arrays/multi_init.zok | 5 +++++ zokrates_core/src/typed_absy/integer.rs | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 zokrates_cli/examples/arrays/multi_init.zok diff --git a/zokrates_cli/examples/arrays/multi_init.zok b/zokrates_cli/examples/arrays/multi_init.zok new file mode 100644 index 000000000..b6ec0201f --- /dev/null +++ b/zokrates_cli/examples/arrays/multi_init.zok @@ -0,0 +1,5 @@ +def identity(field[N][N] t) -> field[N][N]: + return t + +def main() -> field[1][1]: + return identity([[0]; 1]) \ No newline at end of file diff --git a/zokrates_core/src/typed_absy/integer.rs b/zokrates_core/src/typed_absy/integer.rs index 6a30cafa7..e811eec84 100644 --- a/zokrates_core/src/typed_absy/integer.rs +++ b/zokrates_core/src/typed_absy/integer.rs @@ -476,7 +476,7 @@ impl<'ast, T: Field> ArrayExpression<'ast, T> { } } - // precondition: `array` is only made of inline arrays unless it does not contain the Integer type + // precondition: `array` is only made of inline arrays and repeat constructs unless it does not contain the Integer type pub fn try_from_int( array: Self, target_inner_ty: Type<'ast, T>, @@ -518,8 +518,10 @@ impl<'ast, T: Field> ArrayExpression<'ast, T> { // try to convert the repeated element to the target type t => TypedExpression::align_to_type(e, t) .map(|e| { + let ty = e.get_type().clone(); + ArrayExpressionInner::Repeat(box e, box count) - .annotate(target_inner_ty, array_ty.size) + .annotate(ty, array_ty.size) }) .map_err(|(e, _)| e), } From 35f4d93dd3dbc7466aea3d3ee794a82264f4134c Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 26 Apr 2021 19:18:36 +0200 Subject: [PATCH 66/95] changelog --- changelogs/unreleased/834-schaeff | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/834-schaeff diff --git a/changelogs/unreleased/834-schaeff b/changelogs/unreleased/834-schaeff new file mode 100644 index 000000000..6a9f52a38 --- /dev/null +++ b/changelogs/unreleased/834-schaeff @@ -0,0 +1 @@ +Fix integer inference on repeat operators \ No newline at end of file From 231204d7a2288ecd4caca00d73bf90368d25170c Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 26 Apr 2021 19:53:09 +0200 Subject: [PATCH 67/95] fold type --- .../src/static_analysis/constant_inliner.rs | 28 ++++++++----------- zokrates_core/src/typed_absy/folder.rs | 12 ++++---- zokrates_core/src/typed_absy/mod.rs | 4 +-- zokrates_core/src/typed_absy/result_folder.rs | 16 +++++------ 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index 3e082fbf5..676932823 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -71,14 +71,14 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { } } - fn fold_module(&mut self, p: TypedModule<'ast, T>) -> TypedModule<'ast, T> { + fn fold_module(&mut self, m: TypedModule<'ast, T>) -> TypedModule<'ast, T> { TypedModule { - constants: p + constants: m .constants .into_iter() .map(|(key, tc)| (key, self.fold_constant_symbol(tc))) .collect(), - functions: p + functions: m .functions .into_iter() .map(|(key, fun)| (key, self.fold_function_symbol(fun))) @@ -100,10 +100,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { ) -> FieldElementExpression<'ast, T> { match e { FieldElementExpression::Identifier(ref id) => match self.get_constant(id) { - Some(c) => { - let c = self.fold_constant(c); - fold_field_expression(self, c.try_into().unwrap()) - } + Some(c) => self.fold_constant(c).try_into().unwrap(), None => fold_field_expression(self, e), }, e => fold_field_expression(self, e), @@ -116,10 +113,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { ) -> BooleanExpression<'ast, T> { match e { BooleanExpression::Identifier(ref id) => match self.get_constant(id) { - Some(c) => { - let c = self.fold_constant(c); - fold_boolean_expression(self, c.try_into().unwrap()) - } + Some(c) => self.fold_constant(c).try_into().unwrap(), None => fold_boolean_expression(self, e), }, e => fold_boolean_expression(self, e), @@ -134,8 +128,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { match e { UExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - let c = self.fold_constant(c); - fold_uint_expression(self, c.try_into().unwrap()).into_inner() + let e: UExpression<'ast, T> = self.fold_constant(c).try_into().unwrap(); + e.into_inner() } None => fold_uint_expression_inner(self, size, e), }, @@ -151,8 +145,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { match e { ArrayExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - let c = self.fold_constant(c); - fold_array_expression(self, c.try_into().unwrap()).into_inner() + let e: ArrayExpression<'ast, T> = self.fold_constant(c).try_into().unwrap(); + e.into_inner() } None => fold_array_expression_inner(self, ty, e), }, @@ -168,8 +162,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { match e { StructExpressionInner::Identifier(ref id) => match self.get_constant(id) { Some(c) => { - let c = self.fold_constant(c); - fold_struct_expression(self, c.try_into().unwrap()).into_inner() + let e: StructExpression<'ast, T> = self.fold_constant(c).try_into().unwrap(); + e.into_inner() } None => fold_struct_expression_inner(self, ty, e), }, diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index 610aa7106..db19977bd 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -9,8 +9,8 @@ pub trait Folder<'ast, T: Field>: Sized { fold_program(self, p) } - fn fold_module(&mut self, p: TypedModule<'ast, T>) -> TypedModule<'ast, T> { - fold_module(self, p) + fn fold_module(&mut self, m: TypedModule<'ast, T>) -> TypedModule<'ast, T> { + fold_module(self, m) } fn fold_constant(&mut self, c: TypedConstant<'ast, T>) -> TypedConstant<'ast, T> { @@ -201,15 +201,15 @@ pub trait Folder<'ast, T: Field>: Sized { pub fn fold_module<'ast, T: Field, F: Folder<'ast, T>>( f: &mut F, - p: TypedModule<'ast, T>, + m: TypedModule<'ast, T>, ) -> TypedModule<'ast, T> { TypedModule { - functions: p + functions: m .functions .into_iter() .map(|(key, fun)| (key, f.fold_function_symbol(fun))) .collect(), - ..p + ..m } } @@ -728,8 +728,8 @@ pub fn fold_constant<'ast, T: Field, F: Folder<'ast, T>>( c: TypedConstant<'ast, T>, ) -> TypedConstant<'ast, T> { TypedConstant { + ty: f.fold_type(c.ty), expression: f.fold_expression(c.expression), - ..c } } diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 408920d28..07b1391cd 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -199,10 +199,10 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedModule<'ast, T> { .constants .iter() .map(|(key, symbol)| match symbol { - TypedConstantSymbol::Here(tc) => { + TypedConstantSymbol::Here(ref tc) => { format!("const {} {} = {}", tc.ty, key, tc.expression) } - TypedConstantSymbol::There(module_id, id) => { + TypedConstantSymbol::There(ref module_id, ref id) => { format!("from \"{}\" import {} as {}", module_id.display(), id, key) } }) diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index a939b296a..c42d8df36 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -16,16 +16,16 @@ pub trait ResultFolder<'ast, T: Field>: Sized { fn fold_module( &mut self, - p: TypedModule<'ast, T>, + m: TypedModule<'ast, T>, ) -> Result, Self::Error> { - fold_module(self, p) + fold_module(self, m) } fn fold_constant( &mut self, - s: TypedConstant<'ast, T>, + c: TypedConstant<'ast, T>, ) -> Result, Self::Error> { - fold_constant(self, s) + fold_constant(self, c) } fn fold_constant_symbol( @@ -812,8 +812,8 @@ pub fn fold_constant<'ast, T: Field, F: ResultFolder<'ast, T>>( c: TypedConstant<'ast, T>, ) -> Result, F::Error> { Ok(TypedConstant { + ty: f.fold_type(c.ty)?, expression: f.fold_expression(c.expression)?, - ..c }) } @@ -839,15 +839,15 @@ pub fn fold_function_symbol<'ast, T: Field, F: ResultFolder<'ast, T>>( pub fn fold_module<'ast, T: Field, F: ResultFolder<'ast, T>>( f: &mut F, - p: TypedModule<'ast, T>, + m: TypedModule<'ast, T>, ) -> Result, F::Error> { Ok(TypedModule { - functions: p + functions: m .functions .into_iter() .map(|(key, fun)| f.fold_function_symbol(fun).map(|f| (key, f))) .collect::>()?, - ..p + ..m }) } From 9ec3ac3cf779a9fc78a292693fe9428e30a1ea8d Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 13:34:16 +0200 Subject: [PATCH 68/95] visit constants in default folder --- .../src/static_analysis/constant_inliner.rs | 15 --------------- zokrates_core/src/typed_absy/folder.rs | 6 +++++- zokrates_core/src/typed_absy/result_folder.rs | 6 +++++- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index 676932823..360927d75 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -71,21 +71,6 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> { } } - fn fold_module(&mut self, m: TypedModule<'ast, T>) -> TypedModule<'ast, T> { - TypedModule { - constants: m - .constants - .into_iter() - .map(|(key, tc)| (key, self.fold_constant_symbol(tc))) - .collect(), - functions: m - .functions - .into_iter() - .map(|(key, fun)| (key, self.fold_function_symbol(fun))) - .collect(), - } - } - fn fold_constant_symbol( &mut self, s: TypedConstantSymbol<'ast, T>, diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index db19977bd..36c1453f0 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -204,12 +204,16 @@ pub fn fold_module<'ast, T: Field, F: Folder<'ast, T>>( m: TypedModule<'ast, T>, ) -> TypedModule<'ast, T> { TypedModule { + constants: m + .constants + .into_iter() + .map(|(key, tc)| (key, f.fold_constant_symbol(tc))) + .collect(), functions: m .functions .into_iter() .map(|(key, fun)| (key, f.fold_function_symbol(fun))) .collect(), - ..m } } diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index c42d8df36..245ab2a51 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -842,12 +842,16 @@ pub fn fold_module<'ast, T: Field, F: ResultFolder<'ast, T>>( m: TypedModule<'ast, T>, ) -> Result, F::Error> { Ok(TypedModule { + constants: m + .constants + .into_iter() + .map(|(key, tc)| f.fold_constant_symbol(tc).map(|tc| (key, tc))) + .collect::>()?, functions: m .functions .into_iter() .map(|(key, fun)| f.fold_function_symbol(fun).map(|f| (key, f))) .collect::>()?, - ..m }) } From b2344aa4599be6fa0b98f07de5a935fc3d08597c Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 27 Apr 2021 14:43:00 +0200 Subject: [PATCH 69/95] remove internal identifier --- zokrates_core/src/typed_absy/identifier.rs | 2 -- zokrates_core/src/zir/identifier.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/zokrates_core/src/typed_absy/identifier.rs b/zokrates_core/src/typed_absy/identifier.rs index 145950e08..00bc7425d 100644 --- a/zokrates_core/src/typed_absy/identifier.rs +++ b/zokrates_core/src/typed_absy/identifier.rs @@ -4,7 +4,6 @@ use std::fmt; #[derive(Debug, PartialEq, Clone, Hash, Eq)] pub enum CoreIdentifier<'ast> { Source(&'ast str), - Internal(&'static str, usize), Call(usize), } @@ -12,7 +11,6 @@ impl<'ast> fmt::Display for CoreIdentifier<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { CoreIdentifier::Source(s) => write!(f, "{}", s), - CoreIdentifier::Internal(s, i) => write!(f, "#INTERNAL#_{}_{}", s, i), CoreIdentifier::Call(i) => write!(f, "#CALL_RETURN_AT_INDEX_{}", i), } } diff --git a/zokrates_core/src/zir/identifier.rs b/zokrates_core/src/zir/identifier.rs index 6ef1ec8b1..87eea34d1 100644 --- a/zokrates_core/src/zir/identifier.rs +++ b/zokrates_core/src/zir/identifier.rs @@ -6,7 +6,6 @@ use crate::typed_absy::Identifier as CoreIdentifier; #[derive(Debug, PartialEq, Clone, Hash, Eq)] pub enum Identifier<'ast> { Source(SourceIdentifier<'ast>), - Internal(&'static str, usize), } #[derive(Debug, PartialEq, Clone, Hash, Eq)] @@ -30,7 +29,6 @@ impl<'ast> fmt::Display for Identifier<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Identifier::Source(s) => write!(f, "{}", s), - Identifier::Internal(s, i) => write!(f, "#INTERNAL#_{}_{}", s, i), } } } From d4d0545c350147533a1a9c5154d2b3ffa60d60bb Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 27 Apr 2021 16:06:32 +0200 Subject: [PATCH 70/95] fix doc --- zokrates_core/src/flatten/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 38dd0f5a9..cb9468b1d 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -349,8 +349,8 @@ impl<'ast, T: Field> Flattener<'ast, T> { /// # Arguments /// /// * `statements_flattened` - Vector where new flattened statements can be added. - /// * `e` - the `FlatExpression` that's being checked against the range. - /// * `c` - the constant upper bound of the range + /// * `a` - the big-endian bit decomposition of the expression we enforce to be in range + /// * `b` - the big-endian bit decomposition of the upper bound of the range fn enforce_constant_le_check( &mut self, statements_flattened: &mut FlatStatements, From 9b377e67dde848ffa888a4e0249897480219fa28 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 16:30:01 +0200 Subject: [PATCH 71/95] wip --- .circleci/config.yml | 326 ++++++++++++++++++++++++------------------- 1 file changed, 183 insertions(+), 143 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 97a1d2feb..2b1f7077f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,151 +1,191 @@ -version: 2 +version: 2.1 -jobs: - build: - docker: - - image: zokrates/env:latest - resource_class: large - steps: - - checkout - - run: - name: Version information - command: rustc --version; cargo --version; rustup --version - - run: - name: Calculate dependencies - command: cargo generate-lockfile - - restore_cache: - keys: - - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} - - run: - name: Build - command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./build.sh - - save_cache: - paths: - - /usr/local/cargo/registry - - target/debug/.fingerprint - - target/debug/build - - target/debug/deps - key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} - test: - docker: - - image: zokrates/env:latest - resource_class: large - steps: - - checkout - - run: - name: Version information - command: rustc --version; cargo --version; rustup --version - - run: - name: Calculate dependencies - command: cargo generate-lockfile - - restore_cache: - keys: - - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} - - run: - name: Check format - command: cargo fmt --all -- --check - - run: - name: Run clippy - command: cargo clippy -- -D warnings - - run: - name: Build - command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./build.sh - - run: - name: Run tests - command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./test.sh - # - run: - # name: Generate code coverage report - # command: ./scripts/cov.sh - cpp_format: - docker: - - image: zokrates/env:latest - steps: - - checkout - - run: - name: Check cpp format (clang-format) - command: run-clang-format.py -r $(pwd)/zokrates_core/lib - wasm_test: - docker: - - image: zokrates/env:latest - steps: - - checkout - - run: - name: Version information - command: rustc --version; cargo --version; rustup --version - - run: - name: Calculate dependencies - command: cargo generate-lockfile - - restore_cache: - keys: - - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} - - run: - name: Test on firefox - command: cd zokrates_core && wasm-pack test --firefox --headless -- --no-default-features --features "wasm bellman" - integration_test: - docker: - - image: zokrates/env:latest - - image: trufflesuite/ganache-cli:next - resource_class: large - steps: - - checkout - - run: - name: Version information - command: rustc --version; cargo --version; rustup --version - - run: - name: Calculate dependencies - command: cargo generate-lockfile - - restore_cache: - keys: - - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} - - run: - name: Run integration tests - command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./full_test.sh - deploy: - docker: - - image: circleci/python:latest-node - steps: - - checkout - - setup_remote_docker: - docker_layer_caching: true - - run: - name: Release - command: ./scripts/release.sh - zokrates_js_build: - docker: - - image: zokrates/env:latest - steps: - - checkout - - run: - name: Build - command: cd zokrates_js && npm run build:dev - zokrates_js_test: +executors: + linux: docker: - image: zokrates/env:latest + macos: + macos: + xcode: 12.2.0 + +jobs: + build_artifacts: + parameters: + os: + type: executor + target: + type: string + executor: << parameters.os >> steps: - checkout - - run: - command: cd zokrates_js && npm run test + - setup_remote_docker + - run: | + cross build --bin zokrates --package zokrates_cli --target << parameters.target >> --release + +# build: +# docker: +# - image: zokrates/env:latest +# resource_class: large +# steps: +# - checkout +# - run: +# name: Version information +# command: rustc --version; cargo --version; rustup --version +# - run: +# name: Calculate dependencies +# command: cargo generate-lockfile +# - restore_cache: +# keys: +# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} +# - run: +# name: Build +# command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./build.sh +# - save_cache: +# paths: +# - /usr/local/cargo/registry +# - target/debug/.fingerprint +# - target/debug/build +# - target/debug/deps +# key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} +# test: +# docker: +# - image: zokrates/env:latest +# resource_class: large +# steps: +# - checkout +# - run: +# name: Version information +# command: rustc --version; cargo --version; rustup --version +# - run: +# name: Calculate dependencies +# command: cargo generate-lockfile +# - restore_cache: +# keys: +# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} +# - run: +# name: Check format +# command: cargo fmt --all -- --check +# - run: +# name: Run clippy +# command: cargo clippy -- -D warnings +# - run: +# name: Run tests +# command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./test.sh +# # - run: +# # name: Generate code coverage report +# # command: ./scripts/cov.sh +# cpp_format: +# docker: +# - image: zokrates/env:latest +# steps: +# - checkout +# - run: +# name: Check cpp format (clang-format) +# command: run-clang-format.py -r $(pwd)/zokrates_core/lib +# wasm_test: +# docker: +# - image: zokrates/env:latest +# steps: +# - checkout +# - run: +# name: Version information +# command: rustc --version; cargo --version; rustup --version +# - run: +# name: Calculate dependencies +# command: cargo generate-lockfile +# - restore_cache: +# keys: +# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} +# - run: +# name: Test on firefox +# command: cd zokrates_core && wasm-pack test --firefox --headless -- --no-default-features --features "wasm bellman" +# integration_test: +# docker: +# - image: zokrates/env:latest +# - image: trufflesuite/ganache-cli:next +# resource_class: large +# steps: +# - checkout +# - run: +# name: Version information +# command: rustc --version; cargo --version; rustup --version +# - run: +# name: Calculate dependencies +# command: cargo generate-lockfile +# - restore_cache: +# keys: +# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} +# - run: +# name: Run integration tests +# command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./full_test.sh +# deploy: +# docker: +# - image: circleci/python:latest-node +# steps: +# - checkout +# - setup_remote_docker: +# docker_layer_caching: true +# - run: +# name: Release +# command: ./scripts/release.sh +# zokrates_js_build: +# docker: +# - image: zokrates/env:latest +# steps: +# - checkout +# - run: +# name: Build +# command: cd zokrates_js && npm run build:dev +# zokrates_js_test: +# docker: +# - image: zokrates/env:latest +# steps: +# - checkout +# - run: +# command: cd zokrates_js && npm run test +# publish_artifacts: +# docker: +# - image: cibuilds/github:0.10 +# steps: +# - attach_workspace: +# at: ./artifacts +# - run: +# name: "Publish Release on GitHub" +# command: ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ./artifacts/ + workflows: - version: 2 build-test-and-deploy: jobs: - - build - - test - - cpp_format - - wasm_test - - integration_test - - zokrates_js_build - - zokrates_js_test - - deploy: - filters: - branches: - only: - - deploy - requires: - - build - - test - - cpp_format - - wasm_test - - integration_test - - zokrates_js_build - - zokrates_js_test + - build_artifacts: + pre-steps: + - run: + command: cargo install cross + matrix: + parameters: + os: + - linux + target: + - aarch64-unknown-linux-gnu + - arm-unknown-linux-gnueabi + - x86_64-unknown-linux-gnu + - x86_64-pc-windows-gnu +# - build +# - test +# - cpp_format +# - wasm_test +# - integration_test +# - zokrates_js_build +# - zokrates_js_test +# - deploy: +# filters: +# branches: +# only: +# - deploy +# requires: +# - build +# - test +# - cpp_format +# - wasm_test +# - integration_test +# - zokrates_js_build +# - zokrates_js_test From 0ded0c4f39923fa0f39a7673e7dc4b68154f6d78 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 16:36:16 +0200 Subject: [PATCH 72/95] docker in docker --- .circleci/config.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2b1f7077f..fb847e020 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2.1 executors: linux: docker: - - image: zokrates/env:latest + - image: cimg/rust:1.51.0 macos: macos: xcode: 12.2.0 @@ -16,11 +16,14 @@ jobs: target: type: string executor: << parameters.os >> + environment: + CROSS_DOCKER_IN_DOCKER: "true" steps: - checkout - setup_remote_docker - run: | - cross build --bin zokrates --package zokrates_cli --target << parameters.target >> --release + rustup default nightly + cross build -v --target << parameters.target >> --release # build: # docker: @@ -159,16 +162,17 @@ workflows: - build_artifacts: pre-steps: - run: - command: cargo install cross + command: | + cargo install --git https://github.com/rust-embedded/cross matrix: parameters: os: - linux target: - - aarch64-unknown-linux-gnu - - arm-unknown-linux-gnueabi +# - aarch64-unknown-linux-gnu +# - arm-unknown-linux-gnueabi - x86_64-unknown-linux-gnu - - x86_64-pc-windows-gnu +# - x86_64-pc-windows-gnu # - build # - test # - cpp_format From dfcc65da440a893cd183efbaacb64c110f9b5f28 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 18:46:14 +0200 Subject: [PATCH 73/95] test build matrix --- .circleci/config.yml | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fb847e020..ad22c6fec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,28 +2,25 @@ version: 2.1 executors: linux: - docker: - - image: cimg/rust:1.51.0 + machine: + image: ubuntu-2004:202101-01 macos: macos: xcode: 12.2.0 jobs: - build_artifacts: + cross_build: parameters: os: type: executor target: type: string executor: << parameters.os >> - environment: - CROSS_DOCKER_IN_DOCKER: "true" steps: - checkout - - setup_remote_docker - run: | rustup default nightly - cross build -v --target << parameters.target >> --release + cross build --target << parameters.target >> --release # build: # docker: @@ -159,20 +156,36 @@ jobs: workflows: build-test-and-deploy: jobs: - - build_artifacts: + - cross_build: pre-steps: - run: command: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + source $HOME/.cargo/env cargo install --git https://github.com/rust-embedded/cross matrix: parameters: os: - linux + - macos target: -# - aarch64-unknown-linux-gnu -# - arm-unknown-linux-gnueabi + - aarch64-unknown-linux-gnu + - arm-unknown-linux-gnueabi - x86_64-unknown-linux-gnu -# - x86_64-pc-windows-gnu + - x86_64-pc-windows-gnu + - aarch64-apple-darwin + - x86_64-apple-darwin + exclude: + - os: linux + target: + - aarch64-apple-darwin + - x86_64-apple-darwin + - os: macos + target: + - x86_64-unknown-linux-gnu + - arm-unknown-linux-gnueabi + - x86_64-unknown-linux-gnu + - x86_64-pc-windows-gnu # - build # - test # - cpp_format From a89641f5238cc8e899b8f9b68888908404197e32 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 19:12:28 +0200 Subject: [PATCH 74/95] Update config.yml --- .circleci/config.yml | 60 +++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ad22c6fec..9eff77b13 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,9 +18,22 @@ jobs: executor: << parameters.os >> steps: - checkout - - run: | - rustup default nightly - cross build --target << parameters.target >> --release + - run: + name: Calculate dependencies + command: cargo generate-lockfile + - restore_cache: + keys: + - v1-cargo-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} + - run: + no_output_timeout: "30m" + command: cross build --target << parameters.target >> --release + - save_cache: + paths: + - /usr/local/cargo/registry + - target/<< parameters.target >>/.fingerprint + - target/<< parameters.target >>/build + - target/<< parameters.target >>/deps + key: v1-cargo-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} # build: # docker: @@ -153,39 +166,46 @@ jobs: # name: "Publish Release on GitHub" # command: ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ./artifacts/ +commands: + install_rust: + description: "Install Rust nightly" + steps: + - run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y + source $HOME/.cargo/env + install_cross: + description: "Install cross" + steps: + - run: cargo install --git https://github.com/rust-embedded/cross + workflows: build-test-and-deploy: jobs: - cross_build: pre-steps: - - run: - command: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - source $HOME/.cargo/env - cargo install --git https://github.com/rust-embedded/cross + - install_rust + - install_cross matrix: parameters: os: - linux - - macos target: - aarch64-unknown-linux-gnu - arm-unknown-linux-gnueabi - x86_64-unknown-linux-gnu - x86_64-pc-windows-gnu + - cross_build: + pre-steps: + - install_rust + - install_cross + - run: rustup target add aarch64-apple-darwin + matrix: + parameters: + os: + - macos + target: - aarch64-apple-darwin - x86_64-apple-darwin - exclude: - - os: linux - target: - - aarch64-apple-darwin - - x86_64-apple-darwin - - os: macos - target: - - x86_64-unknown-linux-gnu - - arm-unknown-linux-gnueabi - - x86_64-unknown-linux-gnu - - x86_64-pc-windows-gnu # - build # - test # - cpp_format From 4afb1378572f59b01acf680319de716d4e050fff Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 20:00:14 +0200 Subject: [PATCH 75/95] store artifacts --- .circleci/config.yml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9eff77b13..ac5dbe3a0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ executors: image: ubuntu-2004:202101-01 macos: macos: - xcode: 12.2.0 + xcode: 12.4.0 jobs: cross_build: @@ -27,12 +27,15 @@ jobs: - run: no_output_timeout: "30m" command: cross build --target << parameters.target >> --release + - upload_artifacts: + tag: test + target: << parameters.target >> - save_cache: paths: - /usr/local/cargo/registry - - target/<< parameters.target >>/.fingerprint - - target/<< parameters.target >>/build - - target/<< parameters.target >>/deps + - target/<< parameters.target >>/release/.fingerprint + - target/<< parameters.target >>/release/build + - target/<< parameters.target >>/release/deps key: v1-cargo-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} # build: @@ -177,6 +180,22 @@ commands: description: "Install cross" steps: - run: cargo install --git https://github.com/rust-embedded/cross + upload_artifacts: + parameters: + tag: + type: string + target: + type: string + description: "Store build artifacts in CircleCI" + steps: + - run: | + mkdir -p /tmp/artifacts + cp target/<< parameters.target >>/release/zokrates?(.exe) /tmp/artifacts + cp -r zokrates_stdlib/stdlib /tmp/artifacts/ + cd /tmp/artifacts/ + tar czf zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz * + - store_artifacts: + path: /tmp/artifacts/zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz workflows: build-test-and-deploy: @@ -198,13 +217,11 @@ workflows: pre-steps: - install_rust - install_cross - - run: rustup target add aarch64-apple-darwin matrix: parameters: os: - macos target: - - aarch64-apple-darwin - x86_64-apple-darwin # - build # - test From eed1f761cb15dd1c739d65865ebacf4c90f04803 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 20:50:16 +0200 Subject: [PATCH 76/95] update copy cmd --- .circleci/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ac5dbe3a0..c60ab0f9c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -189,13 +189,13 @@ commands: description: "Store build artifacts in CircleCI" steps: - run: | - mkdir -p /tmp/artifacts - cp target/<< parameters.target >>/release/zokrates?(.exe) /tmp/artifacts - cp -r zokrates_stdlib/stdlib /tmp/artifacts/ - cd /tmp/artifacts/ + mkdir -p /build + find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -i cp {} /build/ + cp -r zokrates_stdlib/stdlib /build/ + cd /build tar czf zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz * - store_artifacts: - path: /tmp/artifacts/zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz + path: /build/zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz workflows: build-test-and-deploy: From 109b9a6043c191b6e0f4701d81c2469ec64ea367 Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 22:24:44 +0200 Subject: [PATCH 77/95] change dest folder --- .circleci/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c60ab0f9c..2a322b724 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -189,13 +189,13 @@ commands: description: "Store build artifacts in CircleCI" steps: - run: | - mkdir -p /build - find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -i cp {} /build/ - cp -r zokrates_stdlib/stdlib /build/ - cd /build + mkdir -p /tmp/artifacts + find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -i cp {} /tmp/artifacts/ + cp -r zokrates_stdlib/stdlib /tmp/artifacts/ + cd /tmp/artifacts tar czf zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz * - store_artifacts: - path: /build/zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz + path: /tmp/artifacts/zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz workflows: build-test-and-deploy: From 22ea066abfcccb92c40860b6998cdd05ca74917b Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Apr 2021 22:46:44 +0200 Subject: [PATCH 78/95] update cmd for macos --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2a322b724..c8fde5172 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -190,7 +190,7 @@ commands: steps: - run: | mkdir -p /tmp/artifacts - find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -i cp {} /tmp/artifacts/ + find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ cp -r zokrates_stdlib/stdlib /tmp/artifacts/ cd /tmp/artifacts tar czf zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz * From 3c262ca6695edcaea472348e91102ae553a11d36 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 02:00:18 +0200 Subject: [PATCH 79/95] add publish artifacts step --- .circleci/config.yml | 367 +++++++++++++++++++++++-------------------- 1 file changed, 198 insertions(+), 169 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c8fde5172..c72d2f507 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,6 +9,129 @@ executors: xcode: 12.4.0 jobs: + build: + docker: + - image: zokrates/env:latest + resource_class: large + steps: + - checkout + - run: + name: Version information + command: rustc --version; cargo --version; rustup --version + - run: + name: Calculate dependencies + command: cargo generate-lockfile + - restore_cache: + keys: + - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} + - run: + name: Build + command: RUSTFLAGS="-D warnings" cargo build --features="libsnark" + - save_cache: + paths: + - /usr/local/cargo/registry + - target/debug/.fingerprint + - target/debug/build + - target/debug/deps + key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} + test: + docker: + - image: zokrates/env:latest + resource_class: large + steps: + - checkout + - run: + name: Version information + command: rustc --version; cargo --version; rustup --version + - run: + name: Calculate dependencies + command: cargo generate-lockfile + - restore_cache: + keys: + - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} + - run: + name: Check format + command: cargo fmt --all -- --check + - run: + name: Run clippy + command: cargo clippy -- -D warnings + - run: + name: Run tests + command: RUSTFLAGS="-D warnings" cargo test --release --features="libsnark" + # - run: + # name: Generate code coverage report + # command: ./scripts/cov.sh + cpp_format: + docker: + - image: zokrates/env:latest + steps: + - checkout + - run: + name: Check cpp format (clang-format) + command: run-clang-format.py -r $(pwd)/zokrates_core/lib + wasm_test: + docker: + - image: zokrates/env:latest + steps: + - checkout + - run: + name: Version information + command: rustc --version; cargo --version; rustup --version + - run: + name: Calculate dependencies + command: cargo generate-lockfile + - restore_cache: + keys: + - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} + - run: + name: Test on firefox + command: | + cd zokrates_core + wasm-pack test --firefox --headless -- --no-default-features --features "wasm bellman" + integration_test: + docker: + - image: zokrates/env:latest + - image: trufflesuite/ganache-cli:next + resource_class: large + steps: + - checkout + - run: + name: Version information + command: rustc --version; cargo --version; rustup --version + - run: + name: Calculate dependencies + command: cargo generate-lockfile + - restore_cache: + keys: + - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} + - run: + name: Run integration tests + command: RUSTFLAGS="-D warnings" cargo test --release --features="libsnark" -- --ignored + deploy: + docker: + - image: circleci/python:latest-node + steps: + - checkout + - setup_remote_docker: + docker_layer_caching: true + - run: + name: Release + command: ./scripts/release.sh + zokrates_js_build: + docker: + - image: zokrates/env:latest + steps: + - checkout + - run: + name: Build + command: cd zokrates_js && npm run build:dev + zokrates_js_test: + docker: + - image: zokrates/env:latest + steps: + - checkout + - run: + command: cd zokrates_js && npm run test cross_build: parameters: os: @@ -23,12 +146,12 @@ jobs: command: cargo generate-lockfile - restore_cache: keys: - - v1-cargo-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} + - v1-cross-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} - run: no_output_timeout: "30m" command: cross build --target << parameters.target >> --release - - upload_artifacts: - tag: test + - tar_artifacts: + tag: ${CIRCLE_TAG} target: << parameters.target >> - save_cache: paths: @@ -36,171 +159,79 @@ jobs: - target/<< parameters.target >>/release/.fingerprint - target/<< parameters.target >>/release/build - target/<< parameters.target >>/release/deps - key: v1-cargo-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} - -# build: -# docker: -# - image: zokrates/env:latest -# resource_class: large -# steps: -# - checkout -# - run: -# name: Version information -# command: rustc --version; cargo --version; rustup --version -# - run: -# name: Calculate dependencies -# command: cargo generate-lockfile -# - restore_cache: -# keys: -# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} -# - run: -# name: Build -# command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./build.sh -# - save_cache: -# paths: -# - /usr/local/cargo/registry -# - target/debug/.fingerprint -# - target/debug/build -# - target/debug/deps -# key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} -# test: -# docker: -# - image: zokrates/env:latest -# resource_class: large -# steps: -# - checkout -# - run: -# name: Version information -# command: rustc --version; cargo --version; rustup --version -# - run: -# name: Calculate dependencies -# command: cargo generate-lockfile -# - restore_cache: -# keys: -# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} -# - run: -# name: Check format -# command: cargo fmt --all -- --check -# - run: -# name: Run clippy -# command: cargo clippy -- -D warnings -# - run: -# name: Run tests -# command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./test.sh -# # - run: -# # name: Generate code coverage report -# # command: ./scripts/cov.sh -# cpp_format: -# docker: -# - image: zokrates/env:latest -# steps: -# - checkout -# - run: -# name: Check cpp format (clang-format) -# command: run-clang-format.py -r $(pwd)/zokrates_core/lib -# wasm_test: -# docker: -# - image: zokrates/env:latest -# steps: -# - checkout -# - run: -# name: Version information -# command: rustc --version; cargo --version; rustup --version -# - run: -# name: Calculate dependencies -# command: cargo generate-lockfile -# - restore_cache: -# keys: -# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} -# - run: -# name: Test on firefox -# command: cd zokrates_core && wasm-pack test --firefox --headless -- --no-default-features --features "wasm bellman" -# integration_test: -# docker: -# - image: zokrates/env:latest -# - image: trufflesuite/ganache-cli:next -# resource_class: large -# steps: -# - checkout -# - run: -# name: Version information -# command: rustc --version; cargo --version; rustup --version -# - run: -# name: Calculate dependencies -# command: cargo generate-lockfile -# - restore_cache: -# keys: -# - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} -# - run: -# name: Run integration tests -# command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./full_test.sh -# deploy: -# docker: -# - image: circleci/python:latest-node -# steps: -# - checkout -# - setup_remote_docker: -# docker_layer_caching: true -# - run: -# name: Release -# command: ./scripts/release.sh -# zokrates_js_build: -# docker: -# - image: zokrates/env:latest -# steps: -# - checkout -# - run: -# name: Build -# command: cd zokrates_js && npm run build:dev -# zokrates_js_test: -# docker: -# - image: zokrates/env:latest -# steps: -# - checkout -# - run: -# command: cd zokrates_js && npm run test -# publish_artifacts: -# docker: -# - image: cibuilds/github:0.10 -# steps: -# - attach_workspace: -# at: ./artifacts -# - run: -# name: "Publish Release on GitHub" -# command: ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ./artifacts/ + key: v1-cross-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} + publish_artifacts: + docker: + - image: circleci/golang + steps: + - attach_workspace: + at: ~/artifacts + - run: + name: "Publish artifacts on GitHub" + command: | + go get github.com/github-release/github-release + find ~/artifacts -type f -name *.tar.gz -exec basename {} \; | xargs -I {} github-release upload \ + -s ${GH_TOKEN} \ + -u ${CIRCLE_PROJECT_USERNAME} \ + -r ${CIRCLE_PROJECT_REPONAME} \ + -t ${CIRCLE_TAG} \ + -n "{}" \ + -f ~/artifacts/{} commands: install_rust: - description: "Install Rust nightly" steps: - - run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y - source $HOME/.cargo/env + - run: + name: Install Rust nightly + command: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y + source $HOME/.cargo/env install_cross: - description: "Install cross" steps: - - run: cargo install --git https://github.com/rust-embedded/cross - upload_artifacts: + - run: + name: Install rust-embedded/cross + command: cargo install --git https://github.com/rust-embedded/cross + tar_artifacts: parameters: tag: type: string target: type: string - description: "Store build artifacts in CircleCI" steps: - - run: | - mkdir -p /tmp/artifacts - find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ - cp -r zokrates_stdlib/stdlib /tmp/artifacts/ - cd /tmp/artifacts - tar czf zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz * + - run: + name: Store build artifacts + command: | + mkdir -p /tmp/artifacts + find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ + cp -r zokrates_stdlib/stdlib /tmp/artifacts/ + cd /tmp/artifacts + tar czf zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz * - store_artifacts: path: /tmp/artifacts/zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz + - persist_to_workspace: + root: ~/artifacts + paths: + - zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz + +tag-only: &tag-only + filters: + branches: + ignore: /.*/ + tags: + only: /^\d+\.\d+\.\d+$/ workflows: build-test-and-deploy: jobs: + - build + - test + - cpp_format + - wasm_test + - integration_test + - zokrates_js_build + - zokrates_js_test - cross_build: + <<: *tag-only pre-steps: - install_rust - install_cross @@ -214,6 +245,7 @@ workflows: - x86_64-unknown-linux-gnu - x86_64-pc-windows-gnu - cross_build: + <<: *tag-only pre-steps: - install_rust - install_cross @@ -223,23 +255,20 @@ workflows: - macos target: - x86_64-apple-darwin -# - build -# - test -# - cpp_format -# - wasm_test -# - integration_test -# - zokrates_js_build -# - zokrates_js_test -# - deploy: -# filters: -# branches: -# only: -# - deploy -# requires: -# - build -# - test -# - cpp_format -# - wasm_test -# - integration_test -# - zokrates_js_build -# - zokrates_js_test + - publish_artifacts: + <<: *tag-only + requires: + - cross_build + - deploy: + filters: + branches: + only: + - deploy + requires: + - build + - test + - cpp_format + - wasm_test + - integration_test + - zokrates_js_build + - zokrates_js_test \ No newline at end of file From a150f2974c14e91622298b30676d40287dd272ca Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 02:02:47 +0200 Subject: [PATCH 80/95] add matrix alias --- .circleci/config.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c72d2f507..9472b9bb5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -236,6 +236,7 @@ workflows: - install_rust - install_cross matrix: + alias: cross-build-linux parameters: os: - linux @@ -250,6 +251,7 @@ workflows: - install_rust - install_cross matrix: + alias: cross-build-macos parameters: os: - macos @@ -258,7 +260,8 @@ workflows: - publish_artifacts: <<: *tag-only requires: - - cross_build + - cross-build-linux + - cross-build-macos - deploy: filters: branches: From 7dd0271f3e3ec75cd3d1e68892e9e6afa1417198 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 15:33:29 +0200 Subject: [PATCH 81/95] revert commands --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9472b9bb5..12b9d9ae5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ jobs: - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} - run: name: Build - command: RUSTFLAGS="-D warnings" cargo build --features="libsnark" + command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./build.sh - save_cache: paths: - /usr/local/cargo/registry @@ -57,7 +57,7 @@ jobs: command: cargo clippy -- -D warnings - run: name: Run tests - command: RUSTFLAGS="-D warnings" cargo test --release --features="libsnark" + command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./test.sh # - run: # name: Generate code coverage report # command: ./scripts/cov.sh @@ -106,7 +106,7 @@ jobs: - v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }} - run: name: Run integration tests - command: RUSTFLAGS="-D warnings" cargo test --release --features="libsnark" -- --ignored + command: WITH_LIBSNARK=1 RUSTFLAGS="-D warnings" ./full_test.sh deploy: docker: - image: circleci/python:latest-node From d35fdc09ec56b05f55ece3b0cf3df4eac0ff5db3 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 15:45:21 +0200 Subject: [PATCH 82/95] remove travis files --- .travis.yml | 75 --------------------------------------------- ci/before_deploy.sh | 53 -------------------------------- ci/install.sh | 49 ----------------------------- ci/script.sh | 13 -------- 4 files changed, 190 deletions(-) delete mode 100644 .travis.yml delete mode 100755 ci/before_deploy.sh delete mode 100755 ci/install.sh delete mode 100644 ci/script.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0d3be6e81..000000000 --- a/.travis.yml +++ /dev/null @@ -1,75 +0,0 @@ -# Based on the "trust" template v0.1.2 -# https://github.com/japaric/trust/tree/v0.1.2 - -dist: trusty -language: rust -rust: - - nightly -services: docker -sudo: required - -env: - global: - - CRATE_NAME=zokrates - - -matrix: - include: - # Linux - - env: TARGET=aarch64-unknown-linux-gnu - - env: TARGET=arm-unknown-linux-gnueabi - #- env: TARGET=i686-unknown-linux-gnu - - env: TARGET=x86_64-unknown-linux-gnu - - # OSX - # - env: TARGET=i686-apple-darwin - # os: osx - - env: TARGET=x86_64-apple-darwin - os: osx - - # *BSD - # - env: TARGET=x86_64-unknown-freebsd - - # Windows - - env: TARGET=x86_64-pc-windows-gnu - -before_install: - - set -e - - rustup self update - -install: - - sh ci/install.sh - - source ~/.cargo/env || true - -script: - - bash ci/script.sh - -after_script: set +e - -before_deploy: - - sh ci/before_deploy.sh - -deploy: - api_key: - secure: cpo6ukDxL+h6Dw2A4eVaC0ddU/zguuds2yhHp1UE0DUWo/lpBNtg3bw51o/GrX8JyTWJCUMLZOKJyoyUWiht41BtlqRl5Egp/ugFEfCoPS+J6u0BIBEULwXrvOmxxF+K+DLH1MX179z1R2SYBYcm8V7GvygzAwaSP4fRq3Uwqr2l3lc6Q+V2kQ0Hylmeguaqhj9lG5BQA/fG1qlWdUMTHMInCCnb2z7SP3/kWEhkdCavCWtRjaeKoWSgKDcB/UUVVnRwnq5dE76DTJU6wEqG4njityxPTTZ+u0a5FiFnUhmqtqszicAs3jAKAcekyeM0B2prTF/xPGsPqLnce4ljoSK93VU08Ut1bJNMyfRLBzd/jEwOCp6ADUQnCTDxUP4Z2iK0EGya2ciXnZi/sCwPJZPV8uqUnfHdHYOdky1+64MJE1tBgC9ZaTcLFsATD6KkffKa2rmqgZCZNeHITs6HOGZhatw6u0eLknNqqBkQIMKvGRLjI6kZxDA2HsMYNTHPevUOKu68Kebi3aQG3H3OODXO3cKvGGoPHFx4uf3E5Gn4GJEePQqC1r5zYpdrQyOEN3VyLRZVHlAR/Kzm+5mameP4CyT8ppfLfQhy+sl6OfAV6X0Ap96gbWWj0I6w0CrZ10VLgJD2W5sllyiBnsNzkccW3Yg9DCuf75/ydme/JCc= - file_glob: true - file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* - on: - tags: true - provider: releases - skip_cleanup: true - -cache: cargo -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -branches: - only: - # release tags - - /^\d+\.\d+\.\d+.*$/ - - deploy - -notifications: - email: - on_success: never diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh deleted file mode 100755 index 7dc2dff62..000000000 --- a/ci/before_deploy.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# This script takes care of building your crate and packaging it for release - -set -ex - -main() { - local src=$(pwd) \ - stage= - - case $TRAVIS_OS_NAME in - linux) - stage=$(mktemp -d) - ;; - osx) - stage=$(mktemp -d -t tmp) - ;; - esac - - case $TARGET in - x86_64-pc-windows-gnu) - BINARY_NAME=zokrates.exe - ;; - *) - BINARY_NAME=zokrates - ;; - esac - - test -f Cargo.lock || cargo generate-lockfile - - case $TRAVIS_OS_NAME in - linux) - cross build --bin zokrates --package zokrates_cli --features="libsnark" --target $TARGET --release - ;; - *) - cross build --bin zokrates --package zokrates_cli --target $TARGET --release - ;; - esac - - # Package artifacts - # Binary - cp target/$TARGET/release/$BINARY_NAME $stage/ - # Standard library - cp -r zokrates_stdlib/stdlib $stage - - cd $stage - tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz * - cd $src - - rm -rf $stage -} - -main diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100755 index 719af4170..000000000 --- a/ci/install.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -set -ex - -main() { - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-musl - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # Builds for iOS are done on OSX, but require the specific target to be - # installed. - case $TARGET in - aarch64-apple-ios) - rustup target install aarch64-apple-ios - ;; - armv7-apple-ios) - rustup target install armv7-apple-ios - ;; - armv7s-apple-ios) - rustup target install armv7s-apple-ios - ;; - i386-apple-ios) - rustup target install i386-apple-ios - ;; - x86_64-apple-ios) - rustup target install x86_64-apple-ios - ;; - esac - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index ee7b49695..000000000 --- a/ci/script.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# This script takes care of testing your crate - -set -ex - -# This is the test phase. We will only build if tests happened before. -main() { - cross build --target $TARGET - cross build --target $TARGET --release -} - -main From 7bef8f4975e11d37bb2e22107a0644c99014973e Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 19:19:45 +0200 Subject: [PATCH 83/95] add rust-toolchain, wip --- .circleci/config.yml | 47 ++++++++++++++++++++++---------------------- rust-toolchain | 1 + rust-toolchain.toml | 2 ++ 3 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 rust-toolchain create mode 100644 rust-toolchain.toml diff --git a/.circleci/config.yml b/.circleci/config.yml index 12b9d9ae5..7fdad430c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -182,9 +182,9 @@ commands: install_rust: steps: - run: - name: Install Rust nightly + name: Install Rust command: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y source $HOME/.cargo/env install_cross: steps: @@ -218,18 +218,19 @@ tag-only: &tag-only branches: ignore: /.*/ tags: - only: /^\d+\.\d+\.\d+$/ + only: testing +# only: /^\d+\.\d+\.\d+$/ workflows: build-test-and-deploy: jobs: - - build - - test - - cpp_format - - wasm_test - - integration_test - - zokrates_js_build - - zokrates_js_test +# - build +# - test +# - cpp_format +# - wasm_test +# - integration_test +# - zokrates_js_build +# - zokrates_js_test - cross_build: <<: *tag-only pre-steps: @@ -262,16 +263,16 @@ workflows: requires: - cross-build-linux - cross-build-macos - - deploy: - filters: - branches: - only: - - deploy - requires: - - build - - test - - cpp_format - - wasm_test - - integration_test - - zokrates_js_build - - zokrates_js_test \ No newline at end of file +# - deploy: +# filters: +# branches: +# only: +# - deploy +# requires: +# - build +# - test +# - cpp_format +# - wasm_test +# - integration_test +# - zokrates_js_build +# - zokrates_js_test \ No newline at end of file diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 000000000..25e8f0de7 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2021-03-05 \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..f2cd19548 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2021-03-05" \ No newline at end of file From d91a31aebc9807b8d7599e4724e3058319eccc1e Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 19:39:54 +0200 Subject: [PATCH 84/95] update nightly version --- rust-toolchain | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 25e8f0de7..1cfd57a1d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2021-03-05 \ No newline at end of file +nightly-2021-04-25 \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f2cd19548..41d688e55 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2021-03-05" \ No newline at end of file +channel = "nightly-2021-04-25" \ No newline at end of file From e9f65eef0babb8a676fa9838f69928249e64bed8 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 20:05:11 +0200 Subject: [PATCH 85/95] fix interpolation issue --- .circleci/config.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7fdad430c..fb192535d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -151,7 +151,6 @@ jobs: no_output_timeout: "30m" command: cross build --target << parameters.target >> --release - tar_artifacts: - tag: ${CIRCLE_TAG} target: << parameters.target >> - save_cache: paths: @@ -193,8 +192,6 @@ commands: command: cargo install --git https://github.com/rust-embedded/cross tar_artifacts: parameters: - tag: - type: string target: type: string steps: @@ -205,13 +202,13 @@ commands: find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ cp -r zokrates_stdlib/stdlib /tmp/artifacts/ cd /tmp/artifacts - tar czf zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz * + tar czf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * - store_artifacts: - path: /tmp/artifacts/zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz + path: /tmp/artifacts - persist_to_workspace: root: ~/artifacts paths: - - zokrates-<< parameters.tag >>-<< parameters.target >>.tar.gz + - zokrates-*-<< parameters.target >>.tar.gz tag-only: &tag-only filters: From 9d1a9d85346b18372f65e133aa78e6ad6411aec0 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 20:33:28 +0200 Subject: [PATCH 86/95] fix workspace dir --- .circleci/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fb192535d..5be60f7e8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -164,18 +164,18 @@ jobs: - image: circleci/golang steps: - attach_workspace: - at: ~/artifacts + at: /tmp/artifacts - run: name: "Publish artifacts on GitHub" command: | go get github.com/github-release/github-release - find ~/artifacts -type f -name *.tar.gz -exec basename {} \; | xargs -I {} github-release upload \ + find /tmp/artifacts -type f -name *.tar.gz -exec basename {} \; | xargs -I {} github-release upload \ -s ${GH_TOKEN} \ -u ${CIRCLE_PROJECT_USERNAME} \ -r ${CIRCLE_PROJECT_REPONAME} \ -t ${CIRCLE_TAG} \ -n "{}" \ - -f ~/artifacts/{} + -f /tmp/artifacts/{} commands: install_rust: @@ -202,11 +202,11 @@ commands: find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ cp -r zokrates_stdlib/stdlib /tmp/artifacts/ cd /tmp/artifacts - tar czf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * + tar czf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * --remove-files - store_artifacts: path: /tmp/artifacts - persist_to_workspace: - root: ~/artifacts + root: /tmp/artifacts paths: - zokrates-*-<< parameters.target >>.tar.gz From 2e9db99a67611fd4103121c678d13c44e74e2df9 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 22:44:27 +0200 Subject: [PATCH 87/95] remove gnu specific extension on tar --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5be60f7e8..df068bcfa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -202,7 +202,7 @@ commands: find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ cp -r zokrates_stdlib/stdlib /tmp/artifacts/ cd /tmp/artifacts - tar czf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * --remove-files + tar cvzf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * | xargs rm -rf - store_artifacts: path: /tmp/artifacts - persist_to_workspace: From d92cbb7354e46b7f448735270aafaacd7ec9bb69 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 23:04:27 +0200 Subject: [PATCH 88/95] remove cache --- .circleci/config.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index df068bcfa..8d5c6bccc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -144,21 +144,11 @@ jobs: - run: name: Calculate dependencies command: cargo generate-lockfile - - restore_cache: - keys: - - v1-cross-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} - run: no_output_timeout: "30m" command: cross build --target << parameters.target >> --release - tar_artifacts: target: << parameters.target >> - - save_cache: - paths: - - /usr/local/cargo/registry - - target/<< parameters.target >>/release/.fingerprint - - target/<< parameters.target >>/release/build - - target/<< parameters.target >>/release/deps - key: v1-cross-cache-<< parameters.target >>-{{ checksum "Cargo.lock" }} publish_artifacts: docker: - image: circleci/golang @@ -202,7 +192,7 @@ commands: find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ cp -r zokrates_stdlib/stdlib /tmp/artifacts/ cd /tmp/artifacts - tar cvzf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * | xargs rm -rf + tar -czvf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * | xargs -I {} rm -rf {} - store_artifacts: path: /tmp/artifacts - persist_to_workspace: From 22c1ec332de098b45e3b17bc7bfa2837016a03f1 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 28 Apr 2021 23:28:32 +0200 Subject: [PATCH 89/95] remove files after packing with tar --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8d5c6bccc..80cdc8091 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -192,7 +192,8 @@ commands: find target/<< parameters.target >>/release -maxdepth 1 -type f | grep -E "zokrates(\.exe)?$" | xargs -I {} cp {} /tmp/artifacts/ cp -r zokrates_stdlib/stdlib /tmp/artifacts/ cd /tmp/artifacts - tar -czvf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * | xargs -I {} rm -rf {} + tar czf zokrates-${CIRCLE_TAG}-<< parameters.target >>.tar.gz * + ls | grep -v *.tar.gz | xargs rm -rf - store_artifacts: path: /tmp/artifacts - persist_to_workspace: From a2cbe65cbb092acd0200622ac1c027c98f3fb247 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 29 Apr 2021 00:15:07 +0200 Subject: [PATCH 90/95] release before uploading assets --- .circleci/config.yml | 48 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 80cdc8091..a44fef55a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -159,6 +159,11 @@ jobs: name: "Publish artifacts on GitHub" command: | go get github.com/github-release/github-release + github-release release \ + -s ${GH_TOKEN} \ + -u ${CIRCLE_PROJECT_USERNAME} \ + -r ${CIRCLE_PROJECT_REPONAME} \ + -t ${CIRCLE_TAG} || true find /tmp/artifacts -type f -name *.tar.gz -exec basename {} \; | xargs -I {} github-release upload \ -s ${GH_TOKEN} \ -u ${CIRCLE_PROJECT_USERNAME} \ @@ -206,19 +211,18 @@ tag-only: &tag-only branches: ignore: /.*/ tags: - only: testing -# only: /^\d+\.\d+\.\d+$/ + only: /^\d+\.\d+\.\d+$/ workflows: build-test-and-deploy: jobs: -# - build -# - test -# - cpp_format -# - wasm_test -# - integration_test -# - zokrates_js_build -# - zokrates_js_test + - build + - test + - cpp_format + - wasm_test + - integration_test + - zokrates_js_build + - zokrates_js_test - cross_build: <<: *tag-only pre-steps: @@ -251,16 +255,16 @@ workflows: requires: - cross-build-linux - cross-build-macos -# - deploy: -# filters: -# branches: -# only: -# - deploy -# requires: -# - build -# - test -# - cpp_format -# - wasm_test -# - integration_test -# - zokrates_js_build -# - zokrates_js_test \ No newline at end of file + - deploy: + filters: + branches: + only: + - deploy + requires: + - build + - test + - cpp_format + - wasm_test + - integration_test + - zokrates_js_build + - zokrates_js_test \ No newline at end of file From aa1b9056242528210f2c8fb5d93c6f7bc0d8bc33 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 29 Apr 2021 13:11:56 +0200 Subject: [PATCH 91/95] make clippy happy --- zokrates_core/src/embed.rs | 3 +- zokrates_core/src/flatten/mod.rs | 31 ++++++++----------- zokrates_core/src/ir/interpreter.rs | 2 +- .../src/static_analysis/reducer/mod.rs | 2 +- zokrates_core/src/typed_absy/types.rs | 4 +-- zokrates_core/src/zir/types.rs | 2 +- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/zokrates_core/src/embed.rs b/zokrates_core/src/embed.rs index cd93ea1db..8a782e34e 100644 --- a/zokrates_core/src/embed.rs +++ b/zokrates_core/src/embed.rs @@ -127,8 +127,7 @@ impl FlatEmbed { }); assert_eq!(gen.len(), assignment.0.len()); - gen.map(|g| *assignment.0.get(&g).clone().unwrap() as u32) - .collect() + gen.map(|g| *assignment.0.get(&g).unwrap() as u32).collect() } pub fn id(&self) -> &'static str { diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index e3e092381..b5a355cd8 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -228,7 +228,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { if *b { statements_flattened.push(FlatStatement::Definition( is_not_smaller_run[i], - a[i].clone().into(), + a[i].into(), )); // don't need to update size_unknown in the last round @@ -254,12 +254,10 @@ impl<'ast, T: Field> Flattener<'ast, T> { let or_left = FlatExpression::Sub( box FlatExpression::Number(T::from(1)), - box size_unknown[i].clone().into(), - ); - let or_right: FlatExpression<_> = FlatExpression::Sub( - box FlatExpression::Number(T::from(1)), - box a[i].clone().into(), + box size_unknown[i].into(), ); + let or_right: FlatExpression<_> = + FlatExpression::Sub(box FlatExpression::Number(T::from(1)), box a[i].into()); let and_name = self.use_sym(); let and = FlatExpression::Mult(box or_left.clone(), box or_right.clone()); @@ -316,7 +314,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened.push(FlatStatement::Definition( term0_id, FlatExpression::Mult( - box condition_id.clone().into(), + box condition_id.into(), box FlatExpression::from(consequence_id), ), )); @@ -770,7 +768,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened.push(FlatStatement::Condition( FlatExpression::Add( box x.clone(), - box FlatExpression::Sub(box y.clone(), box name_x_or_y.clone().into()), + box FlatExpression::Sub(box y.clone(), box name_x_or_y.into()), ), FlatExpression::Mult(box x.clone(), box y.clone()), )); @@ -1042,7 +1040,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { FlatStatement::Condition( FlatExpression::Add( box x.clone(), - box FlatExpression::Sub(box y.clone(), box name.clone().into()), + box FlatExpression::Sub(box y.clone(), box name.into()), ), FlatExpression::Mult( box FlatExpression::Add(box x.clone(), box x.clone()), @@ -1443,7 +1441,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { vec![a.clone(), b.clone(), c.clone()], )), FlatStatement::Condition( - bc.clone().into(), + bc.into(), FlatExpression::Mult( box b.clone(), box c.clone(), @@ -1451,14 +1449,14 @@ impl<'ast, T: Field> Flattener<'ast, T> { ), FlatStatement::Condition( FlatExpression::Sub( - box bc.clone().into(), + box bc.into(), box maj.into(), ), FlatExpression::Mult( box FlatExpression::Sub( box FlatExpression::Add( - box bc.clone().into(), - box bc.clone().into(), + box bc.into(), + box bc.into(), ), box FlatExpression::Add(box b, box c), ), @@ -1582,10 +1580,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { FlatStatement::Condition( FlatExpression::Add( box x.clone(), - box FlatExpression::Sub( - box y.clone(), - box name.clone().into(), - ), + box FlatExpression::Sub(box y.clone(), box name.into()), ), FlatExpression::Mult(box x, box y), ), @@ -2074,7 +2069,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { .get_field_unchecked() }) .collect(); - self.bits_cache.insert(vars[0].clone().into(), bits); + self.bits_cache.insert(vars[0].into(), bits); } _ => {} } diff --git a/zokrates_core/src/ir/interpreter.rs b/zokrates_core/src/ir/interpreter.rs index 34df954c3..8dc603ff0 100644 --- a/zokrates_core/src/ir/interpreter.rs +++ b/zokrates_core/src/ir/interpreter.rs @@ -259,7 +259,7 @@ impl LinComb { } fn is_assignee(&self, witness: &BTreeMap) -> bool { - self.0.iter().count() == 1 + self.0.len() == 1 && self.0.get(0).unwrap().1 == T::from(1) && !witness.contains_key(&self.0.get(0).unwrap().0) } diff --git a/zokrates_core/src/static_analysis/reducer/mod.rs b/zokrates_core/src/static_analysis/reducer/mod.rs index f0f846231..24fd36ed3 100644 --- a/zokrates_core/src/static_analysis/reducer/mod.rs +++ b/zokrates_core/src/static_analysis/reducer/mod.rs @@ -147,7 +147,7 @@ fn register<'ast>( ) { for (id, key, value) in substitute .iter() - .filter_map(|(id, version)| with.get(&id).clone().map(|to| (id, version, to))) + .filter_map(|(id, version)| with.get(&id).map(|to| (id, version, to))) .filter(|(_, key, value)| key != value) { let sub = substitutions.0.entry(id.clone()).or_default(); diff --git a/zokrates_core/src/typed_absy/types.rs b/zokrates_core/src/typed_absy/types.rs index af206018c..4efde7dc2 100644 --- a/zokrates_core/src/typed_absy/types.rs +++ b/zokrates_core/src/typed_absy/types.rs @@ -403,8 +403,8 @@ pub enum UBitwidth { } impl UBitwidth { - pub fn to_usize(&self) -> usize { - *self as u32 as usize + pub fn to_usize(self) -> usize { + self as u32 as usize } } diff --git a/zokrates_core/src/zir/types.rs b/zokrates_core/src/zir/types.rs index de0142d38..e4d7e8a11 100644 --- a/zokrates_core/src/zir/types.rs +++ b/zokrates_core/src/zir/types.rs @@ -23,7 +23,7 @@ pub enum UBitwidth { } impl UBitwidth { - pub fn to_usize(&self) -> usize { + pub fn to_usize(self) -> usize { match self { UBitwidth::B8 => 8, UBitwidth::B16 => 16, From ef001314265b3b492f1872f98d4dd04fe9a7d40e Mon Sep 17 00:00:00 2001 From: schaeff Date: Fri, 30 Apr 2021 11:15:37 +0200 Subject: [PATCH 92/95] fix comment --- zokrates_core/src/typed_absy/integer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_core/src/typed_absy/integer.rs b/zokrates_core/src/typed_absy/integer.rs index e811eec84..61a18748e 100644 --- a/zokrates_core/src/typed_absy/integer.rs +++ b/zokrates_core/src/typed_absy/integer.rs @@ -515,7 +515,7 @@ impl<'ast, T: Field> ArrayExpression<'ast, T> { match target_inner_ty.clone() { Type::Int => Ok(ArrayExpressionInner::Repeat(box e, box count) .annotate(Type::Int, array_ty.size)), - // try to convert the repeated element to the target type + // try to align the repeated element to the target type t => TypedExpression::align_to_type(e, t) .map(|e| { let ty = e.get_type().clone(); From 0e56ff7c5713a282b6697f43f43ad5c5b31dc406 Mon Sep 17 00:00:00 2001 From: schaeff Date: Fri, 30 Apr 2021 11:34:00 +0200 Subject: [PATCH 93/95] bump versions, generate changelog --- CHANGELOG.md | 21 +++++++++++++++++++++ changelogs/unreleased/761-schaeff | 1 - changelogs/unreleased/792-dark64 | 1 - changelogs/unreleased/798-schaeff | 1 - changelogs/unreleased/800-dark64 | 1 - changelogs/unreleased/806-dark64 | 1 - changelogs/unreleased/809-dark64 | 1 - changelogs/unreleased/822-schaeff | 1 - changelogs/unreleased/823-dark64 | 1 - changelogs/unreleased/826-schaeff | 1 - changelogs/unreleased/828-schaeff | 1 - changelogs/unreleased/829-dark64 | 1 - changelogs/unreleased/831-dark64 | 1 - changelogs/unreleased/832-dark64 | 1 - changelogs/unreleased/834-schaeff | 1 - zokrates_cli/Cargo.toml | 2 +- zokrates_core/Cargo.toml | 2 +- zokrates_core_test/Cargo.toml | 2 +- zokrates_parser/Cargo.toml | 2 +- zokrates_pest_ast/Cargo.toml | 2 +- zokrates_stdlib/Cargo.toml | 2 +- 21 files changed, 27 insertions(+), 20 deletions(-) delete mode 100644 changelogs/unreleased/761-schaeff delete mode 100644 changelogs/unreleased/792-dark64 delete mode 100644 changelogs/unreleased/798-schaeff delete mode 100644 changelogs/unreleased/800-dark64 delete mode 100644 changelogs/unreleased/806-dark64 delete mode 100644 changelogs/unreleased/809-dark64 delete mode 100644 changelogs/unreleased/822-schaeff delete mode 100644 changelogs/unreleased/823-dark64 delete mode 100644 changelogs/unreleased/826-schaeff delete mode 100644 changelogs/unreleased/828-schaeff delete mode 100644 changelogs/unreleased/829-dark64 delete mode 100644 changelogs/unreleased/831-dark64 delete mode 100644 changelogs/unreleased/832-dark64 delete mode 100644 changelogs/unreleased/834-schaeff diff --git a/CHANGELOG.md b/CHANGELOG.md index c82363d9d..d052abfab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file. ## [Unreleased] https://github.com/Zokrates/ZoKrates/compare/latest...develop +## [0.7.1] - 2021-04-30 + +### Release +- https://github.com/Zokrates/ZoKrates/releases/tag/0.7.1 + +### Changes +- Fix integer inference on repeat operators (#834, @schaeff) +- Introduce constant definitions to the language (`const` keyword) (#792, @dark64) +- Introduce constant range checks for checks of the form `x < c` where `p` is a compile-time constant, also for other comparison operators. This works for any `x` and `p`, unlike dynamic `x < y` comparison (#761, @schaeff) +- Handle errors more gracefully in propagation step where applicable (#832, @dark64) +- Add interactive prompt before overwriting existing files in the `one_liner.sh` script (#831, @dark64) +- Add a custom panic hook to handle internal compiler errors more gracefully (#829, @dark64) +- Make command line errors compatible with editor cmd+click (#828, @schaeff) +- Make function definitions more permissive, and move ambiguity checks to call sites and improve them (#826, @schaeff) +- Detect assertion failures at compile time on constant expressions (#823, @dark64) +- Make function selection stricter in function calls (#822, @schaeff) +- Add the ability to import multiple symbols in a single import statement (#809, @dark64) +- Add [poseidon](https://www.poseidon-hash.info/) zk-friendly hashing algorithm to stdlib (#806, @dark64) +- Allow optional underscore before type suffix (e.g. `42_u32`) (#800, @dark64) +- Accept explicit generic parameters outside of definitions (#798, @schaeff) + ## [0.7.0] - 2021-04-09 ### Release diff --git a/changelogs/unreleased/761-schaeff b/changelogs/unreleased/761-schaeff deleted file mode 100644 index f51dfda32..000000000 --- a/changelogs/unreleased/761-schaeff +++ /dev/null @@ -1 +0,0 @@ -Introduce constant range checks for checks of the form `x < c` where `p` is a compile-time constant, also for other comparison operators. This works for any `x` and `p`, unlike dynamic `x < y` comparison \ No newline at end of file diff --git a/changelogs/unreleased/792-dark64 b/changelogs/unreleased/792-dark64 deleted file mode 100644 index fbc1a5dca..000000000 --- a/changelogs/unreleased/792-dark64 +++ /dev/null @@ -1 +0,0 @@ -Introduce constant definitions to the language (`const` keyword) \ No newline at end of file diff --git a/changelogs/unreleased/798-schaeff b/changelogs/unreleased/798-schaeff deleted file mode 100644 index f80f85a45..000000000 --- a/changelogs/unreleased/798-schaeff +++ /dev/null @@ -1 +0,0 @@ -Accept explicit generic parameters outside of definitions \ No newline at end of file diff --git a/changelogs/unreleased/800-dark64 b/changelogs/unreleased/800-dark64 deleted file mode 100644 index 36b13d678..000000000 --- a/changelogs/unreleased/800-dark64 +++ /dev/null @@ -1 +0,0 @@ -Allow optional underscore before type suffix (e.g. `42_u32`) \ No newline at end of file diff --git a/changelogs/unreleased/806-dark64 b/changelogs/unreleased/806-dark64 deleted file mode 100644 index fd1cbd944..000000000 --- a/changelogs/unreleased/806-dark64 +++ /dev/null @@ -1 +0,0 @@ -Add [poseidon](https://www.poseidon-hash.info/) zk-friendly hashing algorithm to stdlib \ No newline at end of file diff --git a/changelogs/unreleased/809-dark64 b/changelogs/unreleased/809-dark64 deleted file mode 100644 index 07749eb32..000000000 --- a/changelogs/unreleased/809-dark64 +++ /dev/null @@ -1 +0,0 @@ -Add the ability to import multiple symbols in a single import statement \ No newline at end of file diff --git a/changelogs/unreleased/822-schaeff b/changelogs/unreleased/822-schaeff deleted file mode 100644 index cf42ad153..000000000 --- a/changelogs/unreleased/822-schaeff +++ /dev/null @@ -1 +0,0 @@ -Make function selection stricter in function calls \ No newline at end of file diff --git a/changelogs/unreleased/823-dark64 b/changelogs/unreleased/823-dark64 deleted file mode 100644 index ab39e6c68..000000000 --- a/changelogs/unreleased/823-dark64 +++ /dev/null @@ -1 +0,0 @@ -Detect assertion failures at compile time on constant expressions \ No newline at end of file diff --git a/changelogs/unreleased/826-schaeff b/changelogs/unreleased/826-schaeff deleted file mode 100644 index d9c712313..000000000 --- a/changelogs/unreleased/826-schaeff +++ /dev/null @@ -1 +0,0 @@ -Make function definitions more permissive, and move ambiguity checks to call sites and improve them \ No newline at end of file diff --git a/changelogs/unreleased/828-schaeff b/changelogs/unreleased/828-schaeff deleted file mode 100644 index af743fda5..000000000 --- a/changelogs/unreleased/828-schaeff +++ /dev/null @@ -1 +0,0 @@ -Make command line errors compatible with editor cmd+click \ No newline at end of file diff --git a/changelogs/unreleased/829-dark64 b/changelogs/unreleased/829-dark64 deleted file mode 100644 index da661714f..000000000 --- a/changelogs/unreleased/829-dark64 +++ /dev/null @@ -1 +0,0 @@ -Add a custom panic hook to handle internal compiler errors more gracefully \ No newline at end of file diff --git a/changelogs/unreleased/831-dark64 b/changelogs/unreleased/831-dark64 deleted file mode 100644 index 20197dc59..000000000 --- a/changelogs/unreleased/831-dark64 +++ /dev/null @@ -1 +0,0 @@ -Add interactive prompt before overwriting existing files in the `one_liner.sh` script \ No newline at end of file diff --git a/changelogs/unreleased/832-dark64 b/changelogs/unreleased/832-dark64 deleted file mode 100644 index 3ae3758df..000000000 --- a/changelogs/unreleased/832-dark64 +++ /dev/null @@ -1 +0,0 @@ -Handle errors more gracefully in propagation step where applicable \ No newline at end of file diff --git a/changelogs/unreleased/834-schaeff b/changelogs/unreleased/834-schaeff deleted file mode 100644 index 6a9f52a38..000000000 --- a/changelogs/unreleased/834-schaeff +++ /dev/null @@ -1 +0,0 @@ -Fix integer inference on repeat operators \ No newline at end of file diff --git a/zokrates_cli/Cargo.toml b/zokrates_cli/Cargo.toml index d4344c914..2ce05d258 100644 --- a/zokrates_cli/Cargo.toml +++ b/zokrates_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zokrates_cli" -version = "0.7.0" +version = "0.7.1" authors = ["Jacob Eberhardt ", "Dennis Kuhnert ", "Thibaut Schaeffer "] repository = "https://github.com/JacobEberhardt/ZoKrates.git" edition = "2018" diff --git a/zokrates_core/Cargo.toml b/zokrates_core/Cargo.toml index cbff9f5a6..cb6f46428 100644 --- a/zokrates_core/Cargo.toml +++ b/zokrates_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zokrates_core" -version = "0.6.0" +version = "0.6.1" edition = "2018" authors = ["Jacob Eberhardt ", "Dennis Kuhnert "] repository = "https://github.com/JacobEberhardt/ZoKrates" diff --git a/zokrates_core_test/Cargo.toml b/zokrates_core_test/Cargo.toml index e0dbcfc10..5230cd3f4 100644 --- a/zokrates_core_test/Cargo.toml +++ b/zokrates_core_test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zokrates_core_test" -version = "0.2.0" +version = "0.2.1" authors = ["schaeff "] edition = "2018" diff --git a/zokrates_parser/Cargo.toml b/zokrates_parser/Cargo.toml index df7b876d1..4ccdb4f0c 100644 --- a/zokrates_parser/Cargo.toml +++ b/zokrates_parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zokrates_parser" -version = "0.2.0" +version = "0.2.1" authors = ["JacobEberhardt "] edition = "2018" diff --git a/zokrates_pest_ast/Cargo.toml b/zokrates_pest_ast/Cargo.toml index 3cbe56e70..a6a04e78c 100644 --- a/zokrates_pest_ast/Cargo.toml +++ b/zokrates_pest_ast/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zokrates_pest_ast" -version = "0.2.0" +version = "0.2.1" authors = ["schaeff "] edition = "2018" diff --git a/zokrates_stdlib/Cargo.toml b/zokrates_stdlib/Cargo.toml index 84264cb43..28be84810 100644 --- a/zokrates_stdlib/Cargo.toml +++ b/zokrates_stdlib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zokrates_stdlib" -version = "0.2.0" +version = "0.2.1" authors = ["Stefan Deml ", "schaeff "] edition = "2018" From b4c0b1974ca2451214ff330b915e014425722db3 Mon Sep 17 00:00:00 2001 From: schaeff Date: Fri, 30 Apr 2021 11:42:28 +0200 Subject: [PATCH 94/95] bump zjs --- zokrates_js/Cargo.toml | 2 +- zokrates_js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zokrates_js/Cargo.toml b/zokrates_js/Cargo.toml index bb2585a7d..d6ff9a1d8 100644 --- a/zokrates_js/Cargo.toml +++ b/zokrates_js/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zokrates_js" -version = "1.0.29" +version = "1.0.30" authors = ["Darko Macesic"] edition = "2018" diff --git a/zokrates_js/package.json b/zokrates_js/package.json index 294ccf46a..e73afa15d 100644 --- a/zokrates_js/package.json +++ b/zokrates_js/package.json @@ -2,7 +2,7 @@ "name": "zokrates-js", "main": "index.js", "author": "Darko Macesic ", - "version": "1.0.29", + "version": "1.0.30", "keywords": [ "zokrates", "wasm-bindgen", From 810e12e980076ac5c48476f287ace9e61a971a44 Mon Sep 17 00:00:00 2001 From: schaeff Date: Fri, 30 Apr 2021 11:45:09 +0200 Subject: [PATCH 95/95] bump syntax packages --- zokrates_parser/src/ace_mode/package.json | 2 +- zokrates_parser/src/textmate/CHANGELOG.md | 4 ++++ zokrates_parser/src/textmate/package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/zokrates_parser/src/ace_mode/package.json b/zokrates_parser/src/ace_mode/package.json index 25f7ca2b7..66b2f5c6e 100644 --- a/zokrates_parser/src/ace_mode/package.json +++ b/zokrates_parser/src/ace_mode/package.json @@ -1,6 +1,6 @@ { "name": "ace-mode-zokrates", - "version": "1.0.2", + "version": "1.0.3", "description": "Ace Mode for ZoKrates DSL", "main": "index.js", "scripts": { diff --git a/zokrates_parser/src/textmate/CHANGELOG.md b/zokrates_parser/src/textmate/CHANGELOG.md index acd435404..afef5e74c 100644 --- a/zokrates_parser/src/textmate/CHANGELOG.md +++ b/zokrates_parser/src/textmate/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.0.2] - 2021-03-01 + +- Add new syntax for ZoKrates 0.7.1 + ## [0.0.1] - 2021-03-01 - Initial release \ No newline at end of file diff --git a/zokrates_parser/src/textmate/package.json b/zokrates_parser/src/textmate/package.json index a72f04a05..ade960a89 100644 --- a/zokrates_parser/src/textmate/package.json +++ b/zokrates_parser/src/textmate/package.json @@ -4,7 +4,7 @@ "description": "Syntax highlighting for the ZoKrates language", "publisher": "zokrates", "repository": "https://github.com/ZoKrates/ZoKrates", - "version": "0.0.1", + "version": "0.0.2", "engines": { "vscode": "^1.53.0" },