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

Add integration test for interactions #9

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
stable
nightly-2024-05-01
2 changes: 1 addition & 1 deletion stark-middleware/src/verifier/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub enum VerificationError {
InvalidProofShape,
/// An error occurred while verifying the claimed openings.
Expand Down
23 changes: 19 additions & 4 deletions stark-middleware/tests/fib_selector_air/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@ use std::borrow::Borrow;

use super::columns::FibonacciSelectorCols;
use crate::fib_air::columns::{FibonacciCols, NUM_FIBONACCI_COLS};
use afs_middleware::interaction::Chip;
use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, PairBuilder};
use afs_middleware::interaction::{Chip, Interaction};
use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, PairBuilder, VirtualPairCol};
use p3_field::{AbstractField, Field};
use p3_matrix::{dense::RowMajorMatrix, Matrix};

pub struct FibonacciSelectorAir {
pub sels: Vec<bool>,
pub enable_interactions: bool,
}

// No interactions
impl<F: Field> Chip<F> for FibonacciSelectorAir {}
impl<F: Field> Chip<F> for FibonacciSelectorAir {
fn receives(&self) -> Vec<Interaction<F>> {
if self.enable_interactions {
vec![Interaction::<F> {
fields: vec![VirtualPairCol::<F>::new_main(
vec![(0, F::one()), (1, F::one())],
nyunyunyunyu marked this conversation as resolved.
Show resolved Hide resolved
F::zero(),
nyunyunyunyu marked this conversation as resolved.
Show resolved Hide resolved
)],
count: VirtualPairCol::<F>::single_preprocessed(0),
argument_index: 0,
}]
} else {
vec![]
}
}
}

impl<F: Field> BaseAir<F> for FibonacciSelectorAir {
fn width(&self) -> usize {
Expand Down
27 changes: 23 additions & 4 deletions stark-middleware/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#![feature(trait_upcasting)]
#![allow(incomplete_features)]

use afs_middleware::{
prover::{trace::TraceCommitter, types::ProvenMultiMatrixAirTrace, PartitionProver},
prover::{
trace::TraceCommitter,
types::{ProvenMultiMatrixAirTrace, ProverRap},
PartitionProver,
},
setup::PartitionSetup,
verifier::PartitionVerifier,
verifier::{types::VerifierRap, PartitionVerifier},
};
use p3_air::BaseAir;
use p3_baby_bear::BabyBear;
Expand All @@ -19,6 +26,12 @@ mod config;
mod fib_air;
mod fib_selector_air;

#[cfg(test)]
nyunyunyunyu marked this conversation as resolved.
Show resolved Hide resolved
mod interaction;

trait ProverVerifierRap<SC: StarkGenericConfig>: ProverRap<SC> + VerifierRap<SC> {}
impl<SC: StarkGenericConfig, RAP: ProverRap<SC> + VerifierRap<SC>> ProverVerifierRap<SC> for RAP {}

#[test]
fn test_single_fib_stark() {
use fib_air::air::FibonacciAir;
Expand Down Expand Up @@ -99,7 +112,10 @@ fn test_single_fib_selector_stark() {
let sels: Vec<bool> = (0..n).map(|i| i % 2 == 0).collect();
let pis = [a, b, get_conditional_fib_number(&sels)].map(BabyBear::from_canonical_u32);

let air = FibonacciSelectorAir { sels };
let air = FibonacciSelectorAir {
sels,
enable_interactions: false,
};

let prep_trace = air.preprocessed_trace();
let setup = PartitionSetup::new(&config);
Expand Down Expand Up @@ -154,7 +170,10 @@ fn test_double_fib_starks() {
let pis = [a, b, get_fib_number(n)].map(BabyBear::from_canonical_u32);

let air1 = FibonacciAir {};
let air2 = FibonacciSelectorAir { sels };
let air2 = FibonacciSelectorAir {
sels,
enable_interactions: false,
};

let prep_trace1 = air1.preprocessed_trace();
let prep_trace2 = air2.preprocessed_trace();
Expand Down
48 changes: 48 additions & 0 deletions stark-middleware/tests/interaction/dummy_interaction_air.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use afs_middleware::interaction::{Chip, Interaction};
use p3_air::{Air, AirBuilderWithPublicValues, BaseAir, PairBuilder, VirtualPairCol};
use p3_field::Field;
use p3_matrix::dense::RowMajorMatrix;

pub struct DummyInteractionAir {
Copy link
Contributor

Choose a reason for hiding this comment

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

Side note: this is general enough that we should move it into the sdk once it exists, as a general chip testing util

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keep it here for now. Other tests can still use it.

// Send if true. Receive if false.
pub is_send: bool,
}

impl<F: Field> Chip<F> for DummyInteractionAir {
fn sends(&self) -> Vec<Interaction<F>> {
if self.is_send {
vec![Interaction::<F> {
fields: vec![VirtualPairCol::<F>::single_main(1)],
count: VirtualPairCol::<F>::single_main(0),
argument_index: 0,
}]
} else {
vec![]
}
}
fn receives(&self) -> Vec<Interaction<F>> {
if !self.is_send {
vec![Interaction::<F> {
fields: vec![VirtualPairCol::<F>::single_main(1)],
count: VirtualPairCol::<F>::single_main(0),
argument_index: 0,
}]
} else {
vec![]
}
}
}

impl<F: Field> BaseAir<F> for DummyInteractionAir {
fn width(&self) -> usize {
2
}

fn preprocessed_trace(&self) -> Option<RowMajorMatrix<F>> {
None
}
}

impl<AB: AirBuilderWithPublicValues + PairBuilder> Air<AB> for DummyInteractionAir {
fn eval(&self, _builder: &mut AB) {}
}
Loading
Loading