Skip to content

Commit

Permalink
Merge pull request #2362 from o1-labs/dw/ivc-regression-tests
Browse files Browse the repository at this point in the history
IVC: some regression tests
  • Loading branch information
dannywillems committed Jun 18, 2024
2 parents a60dace + b038f44 commit c1bef1f
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions ivc/src/ivc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ pub const LIMB_BITSIZE_XLARGE: usize = 150;
/// The biggest packing format, 2 limbs.
pub const N_LIMBS_XLARGE: usize = 2;

/// Number of additional columns that a reduction to degree 2 will
/// require.
// This value has been generated using a fake folding config like in
// [folding::tests::test_quadraticization]
pub const N_ADDITIONAL_WIT_COL_QUAD: usize = 48;

#[cfg(test)]
mod tests {
use std::collections::HashMap;

use crate::{
ivc::{
columns::{IVCColumn, IVC_NB_TOTAL_FIXED_SELECTORS, N_BLOCKS},
Expand All @@ -20,7 +28,10 @@ mod tests {
lookups::IVCLookupTable,
},
poseidon_8_56_5_3_2::{
bn254::{PoseidonBN254Parameters, STATE_SIZE as IVC_POSEIDON_STATE_SIZE},
bn254::{
PoseidonBN254Parameters, NB_CONSTRAINTS as IVC_POSEIDON_NB_CONSTRAINTS,
STATE_SIZE as IVC_POSEIDON_STATE_SIZE,
},
interpreter::PoseidonParams,
},
};
Expand All @@ -39,8 +50,13 @@ mod tests {

// Total number of columns in IVC and Application circuits.
pub const TEST_N_COL_TOTAL: usize = IVCColumn::N_COL + 50;
// Absolutely no idea.
pub const TEST_N_CHALS: usize = 200;

// Number of challenges in the IVC circuit.
// It is the maximum number of constraints per row.
// We do suppose it is Poseidon which has the highest number of constraints
// for now.
pub const TEST_N_CHALS: usize = IVC_POSEIDON_NB_CONSTRAINTS;

pub const TEST_DOMAIN_SIZE: usize = 1 << 15;

type IVCWitnessBuilderEnvRaw<LT> = WitnessBuilderEnv<
Expand Down Expand Up @@ -134,6 +150,30 @@ mod tests {
);
}

#[test]
fn test_regression_ivc_constraints() {
let mut constraint_env = ConstraintBuilderEnv::<Fp, IVCLookupTable<Ff1>>::create();
constrain_ivc::<Fp, Ff1, _>(&mut constraint_env);
let constraints = constraint_env.get_relation_constraints();

let mut constraints_degrees = HashMap::new();

// Regression testing for the number of constraints and their degree
{
// Hashes are not included for now.
assert_eq!(constraints.len(), 55);
constraints.iter().for_each(|c| {
let degree = c.degree(1, 0);
*constraints_degrees.entry(degree).or_insert(0) += 1;
});

assert_eq!(constraints_degrees.get(&1), None);
assert_eq!(constraints_degrees.get(&2), Some(&29));
assert_eq!(constraints_degrees.get(&3), Some(&5));
assert_eq!(constraints_degrees.get(&4), Some(&21));
}
}

#[test]
fn test_completeness_ivc() {
let mut rng = o1_utils::tests::make_test_rng(None);
Expand Down

0 comments on commit c1bef1f

Please sign in to comment.