Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Arrabiata: prepare constraints for cross-terms computation #2702

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions arrabiata/tests/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use num_bigint::BigInt;
use std::collections::HashMap;

use ark_ff::UniformRand;
use arrabiata::{
columns::Gadget,
columns::{ChallengeTerm, Column, Gadget},
constraints,
interpreter::{self, Instruction},
poseidon_3_60_0_5_5_fp, poseidon_3_60_0_5_5_fq,
poseidon_3_60_0_5_5_fp, poseidon_3_60_0_5_5_fq, MAX_DEGREE, NUMBER_OF_COLUMNS,
NUMBER_OF_PUBLIC_INPUTS,
};
use mina_curves::pasta::fields::{Fp, Fq};
use mvpoly::{monomials::Sparse, MVPoly};
use num_bigint::BigInt;
use std::collections::HashMap;

fn helper_compute_constraints_gadget(instr: Instruction, exp_constraints: usize) {
let mut constraints_fp = {
Expand Down Expand Up @@ -164,3 +166,46 @@ fn test_gadget_elliptic_curve_scaling() {

helper_check_gadget_activated(instr, Gadget::EllipticCurveScaling);
}

// This test is mostly an example to show to compute the cross-terms when we do
// have the expressions, and some evaluations.
// It doesn't test anything in particular. It is mostly an "integration" test.
#[test]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A way to make this test test thing would be to checked the cross term property
poly(a +r*b) = poly(a) + r^n poly(b) + \sum_i r^i cross_term_i(a,b)
Also a nit: I wouldn't call that an integration test

Copy link
Member Author

@dannywillems dannywillems Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Also a nit: I wouldn't call that an integration test"

That's the reason "integration" is double quoted.

fn test_integration_with_mvpoly_to_compute_cross_terms() {
let constraints_fp = {
let poseidon_mds = poseidon_3_60_0_5_5_fp::static_params().mds.clone();
constraints::Env::<Fp>::new(poseidon_mds.to_vec(), BigInt::from(0_usize))
};

let constraints = constraints_fp.get_all_constraints_for_ivc();
let mut rng = o1_utils::tests::make_test_rng(None);

// Simulating two homogenising values
let u1 = Fp::rand(&mut rng);
let u2 = Fp::rand(&mut rng);

// Simulating two constraint combiners
let alpha_1 = Fp::rand(&mut rng);
let alpha_2 = Fp::rand(&mut rng);

// Simulating some row evaluations. Only 15 columns for now.
let eval1: [Fp; NUMBER_OF_COLUMNS + NUMBER_OF_PUBLIC_INPUTS] =
std::array::from_fn(|_| Fp::rand(&mut rng));
let eval2: [Fp; NUMBER_OF_COLUMNS + NUMBER_OF_PUBLIC_INPUTS] =
std::array::from_fn(|_| Fp::rand(&mut rng));

let polys = constraints
.iter()
.map(|c| {
println!("Converting into mvpoly the constraint: {:?}", c);
// Adding one to the maximum degree to account for the variable α.
Sparse::<
Fp,
{ NUMBER_OF_COLUMNS + NUMBER_OF_PUBLIC_INPUTS },
{ MAX_DEGREE as usize + 1 },
>::from_expr::<Column, ChallengeTerm>(c.clone())
})
.collect();
let _cross_terms =
mvpoly::compute_combined_cross_terms(polys, alpha_1, alpha_2, eval1, eval2, u1, u2);
}
Loading