Skip to content

Commit

Permalink
test: assert table-linking arguments' properties
Browse files Browse the repository at this point in the history
Computing the terminal of any of the three table-linking arguments
“Permutation Argument”, “Evaluation Argument”, and “Lookup Argument”
corresponds to some function involving polynomials. Test that this
correspondence holds.
  • Loading branch information
jan-ferdinand committed Apr 23, 2024
1 parent 21ab79d commit 6b8ffd9
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions triton-vm/src/table/cross_table_argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,56 @@ impl GrandCrossTableArg {
]
}
}

#[cfg(test)]
mod tests {
use proptest::prelude::*;
use proptest_arbitrary_interop::arb;
use test_strategy::proptest;

use super::*;

#[proptest]
fn permutation_argument_is_identical_to_evaluating_zerofier_polynomial(
#[strategy(arb())] roots: Vec<BFieldElement>,
#[strategy(arb())] initial: XFieldElement,
#[strategy(arb())] challenge: BFieldElement,
) {
let poly_evaluation = initial * Polynomial::zerofier(&roots).evaluate(challenge);
let perm_arg_terminal = PermArg::compute_terminal(&roots, initial, challenge.lift());
prop_assert_eq!(poly_evaluation, perm_arg_terminal);
}

#[proptest]
fn evaluation_argument_is_identical_to_evaluating_polynomial(
#[strategy(arb())] polynomial: Polynomial<BFieldElement>,
#[strategy(arb())] challenge: BFieldElement,
) {
let poly_evaluation = polynomial.evaluate(challenge).lift();

let mut polynomial = polynomial;
polynomial.normalize(); // remove leading zeros
let initial = polynomial.coefficients.pop();
let initial = initial.ok_or(TestCaseError::Reject("polynomial must be non-zero".into()))?;
polynomial.coefficients.reverse();
let eval_arg_terminal =
EvalArg::compute_terminal(&polynomial.coefficients, initial.lift(), challenge.lift());

prop_assert_eq!(poly_evaluation, eval_arg_terminal);
}

#[proptest]
fn lookup_argument_is_identical_to_inverse_of_evaluation_of_zerofier_polynomial(
#[strategy(arb())]
#[filter(#roots.iter().all(|&r| r != #challenge) )]
roots: Vec<BFieldElement>,
#[strategy(arb())] initial: XFieldElement,
#[strategy(arb())] challenge: BFieldElement,
) {
let polynomial = Polynomial::zerofier(&roots);
let derivative = polynomial.formal_derivative();
let poly_evaluation = derivative.evaluate(challenge) / polynomial.evaluate(challenge);
let lookup_arg_terminal = LookupArg::compute_terminal(&roots, initial, challenge.lift());
prop_assert_eq!(initial + poly_evaluation, lookup_arg_terminal);
}
}

0 comments on commit 6b8ffd9

Please sign in to comment.