Skip to content

Commit

Permalink
remove memoization of AIR constraints and degree bounds
Browse files Browse the repository at this point in the history
fix #121
  • Loading branch information
jan-ferdinand committed Nov 21, 2022
1 parent cb7c29c commit 88fa26e
Show file tree
Hide file tree
Showing 19 changed files with 691 additions and 484 deletions.
28 changes: 6 additions & 22 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ impl Stark {
prof_stop!(maybe_profiler, "Fiat-Shamir 1");

prof_start!(maybe_profiler, "extend");
let ext_trace_tables = ExtTableCollection::extend_tables(
&base_trace_tables,
&extension_challenges,
self.parameters.num_trace_randomizers,
);
let ext_trace_tables =
ExtTableCollection::extend_tables(&base_trace_tables, &extension_challenges);
prof_stop!(maybe_profiler, "extend");

prof_start!(maybe_profiler, "dual LDE 2");
Expand Down Expand Up @@ -672,12 +669,7 @@ impl Stark {

prof_start!(maybe_profiler, "degree bounds");
prof_start!(maybe_profiler, "generate tables");
let ext_table_collection = ExtTableCollection::for_verifier(
self.parameters.num_trace_randomizers,
padded_height,
&extension_challenges,
maybe_profiler,
);
let ext_table_collection = ExtTableCollection::for_verifier(padded_height, maybe_profiler);
prof_stop!(maybe_profiler, "generate tables");

prof_start!(maybe_profiler, "base");
Expand Down Expand Up @@ -1208,11 +1200,7 @@ pub(crate) mod triton_stark_tests {
parse_simulate_pad(code, stdin, secret_in);

let dummy_challenges = AllChallenges::placeholder();
let ext_tables = ExtTableCollection::extend_tables(
&base_tables,
&dummy_challenges,
num_trace_randomizers,
);
let ext_tables = ExtTableCollection::extend_tables(&base_tables, &dummy_challenges);

(
stdout,
Expand Down Expand Up @@ -1457,15 +1445,11 @@ pub(crate) mod triton_stark_tests {

#[test]
fn extend_does_not_change_base_table() {
let (base_tables, _, num_trace_randomizers, _) =
let (base_tables, _, _, _) =
parse_simulate_pad(sample_programs::FIBONACCI_LT, vec![], vec![]);

let dummy_challenges = AllChallenges::placeholder();
let ext_tables = ExtTableCollection::extend_tables(
&base_tables,
&dummy_challenges,
num_trace_randomizers,
);
let ext_tables = ExtTableCollection::extend_tables(&base_tables, &dummy_challenges);

for (base_table, extension_table) in base_tables.into_iter().zip(ext_tables.into_iter()) {
for column in 0..base_table.base_width() {
Expand Down
59 changes: 0 additions & 59 deletions triton-vm/src/table/base_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ pub struct Table<FieldElement: FiniteField> {

/// The name of the table. Mostly for debugging purpose.
pub name: String,

/// AIR constraints, to be populated upon extension
pub(crate) initial_constraints: Option<Vec<MPolynomial<FieldElement>>>,
pub(crate) consistency_constraints: Option<Vec<MPolynomial<FieldElement>>>,
pub(crate) transition_constraints: Option<Vec<MPolynomial<FieldElement>>>,
pub(crate) terminal_constraints: Option<Vec<MPolynomial<FieldElement>>>,

/// quotient degrees, to be populated upon extension
pub(crate) initial_quotient_degree_bounds: Option<Vec<i64>>,
pub(crate) consistency_quotient_degree_bounds: Option<Vec<i64>>,
pub(crate) transition_quotient_degree_bounds: Option<Vec<i64>>,
pub(crate) terminal_quotient_degree_bounds: Option<Vec<i64>>,
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -46,14 +34,6 @@ impl<FF: FiniteField> Table<FF> {
full_width,
matrix,
name,
initial_constraints: None,
consistency_constraints: None,
transition_constraints: None,
terminal_constraints: None,
initial_quotient_degree_bounds: None,
consistency_quotient_degree_bounds: None,
transition_quotient_degree_bounds: None,
terminal_quotient_degree_bounds: None,
}
}

Expand Down Expand Up @@ -201,45 +181,6 @@ pub trait Extendable: TableLike<BFieldElement> {
full_width,
)
}

#[allow(clippy::too_many_arguments)]
fn extension(
&self,
extended_matrix: Vec<Vec<XFieldElement>>,
interpolant_degree: Degree,
padded_height: usize,
initial_constraints: Vec<MPolynomial<XFieldElement>>,
consistency_constraints: Vec<MPolynomial<XFieldElement>>,
transition_constraints: Vec<MPolynomial<XFieldElement>>,
terminal_constraints: Vec<MPolynomial<XFieldElement>>,
) -> Table<XFieldElement> {
let bqdb =
self.get_initial_quotient_degree_bounds(&initial_constraints, interpolant_degree);
let cqdb = self.get_consistency_quotient_degree_bounds(
&consistency_constraints,
interpolant_degree,
padded_height,
);
let tqdb = self.get_transition_quotient_degree_bounds(
&transition_constraints,
interpolant_degree,
padded_height,
);
let termqdb =
self.get_terminal_quotient_degree_bounds(&terminal_constraints, interpolant_degree);
let new_table = self.new_from_lifted_matrix(extended_matrix);
Table {
initial_constraints: Some(initial_constraints),
consistency_constraints: Some(consistency_constraints),
transition_constraints: Some(transition_constraints),
terminal_constraints: Some(terminal_constraints),
initial_quotient_degree_bounds: Some(bqdb),
consistency_quotient_degree_bounds: Some(cqdb),
transition_quotient_degree_bounds: Some(tqdb),
terminal_quotient_degree_bounds: Some(termqdb),
..new_table
}
}
}

fn disjoint_domain<FF: FiniteField>(domain_length: usize, disjoint_domain: &[FF]) -> Vec<FF> {
Expand Down
89 changes: 87 additions & 2 deletions triton-vm/src/table/constraints/hash_table_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,95 @@
use twenty_first::shared_math::mpolynomial::Degree;
use twenty_first::shared_math::x_field_element::XFieldElement;

use crate::table::challenges::AllChallenges;
use crate::table::extension_table::Evaluable;
use crate::table::extension_table::Quotientable;
use crate::table::hash_table::ExtHashTable;

// This file is a placeholder for auto-generated code
// Run `cargo run --bin constraint-evaluation-generator`
// to fill in this file with optimized constraints.
impl Evaluable for ExtHashTable {}
impl Evaluable for ExtHashTable {
fn evaluate_initial_constraints(
&self,
_evaluation_point: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn evaluate_consistency_constraints(
&self,
_evaluation_point: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn evaluate_transition_constraints(
&self,
_current_row: &[XFieldElement],
_next_row: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn evaluate_terminal_constraints(
&self,
_evaluation_point: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}
}

impl Quotientable for ExtHashTable {
fn get_initial_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn get_consistency_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn get_transition_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

impl Quotientable for ExtHashTable {}
fn get_terminal_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}
}
89 changes: 87 additions & 2 deletions triton-vm/src/table/constraints/instruction_table_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,95 @@
use twenty_first::shared_math::mpolynomial::Degree;
use twenty_first::shared_math::x_field_element::XFieldElement;

use crate::table::challenges::AllChallenges;
use crate::table::extension_table::Evaluable;
use crate::table::extension_table::Quotientable;
use crate::table::instruction_table::ExtInstructionTable;

// This file is a placeholder for auto-generated code
// Run `cargo run --bin constraint-evaluation-generator`
// to fill in this file with optimized constraints.
impl Evaluable for ExtInstructionTable {}
impl Evaluable for ExtInstructionTable {
fn evaluate_initial_constraints(
&self,
_evaluation_point: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn evaluate_consistency_constraints(
&self,
_evaluation_point: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn evaluate_transition_constraints(
&self,
_current_row: &[XFieldElement],
_next_row: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn evaluate_terminal_constraints(
&self,
_evaluation_point: &[XFieldElement],
_challenges: &AllChallenges,
) -> Vec<XFieldElement> {
panic!(
"Constraints must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}
}

impl Quotientable for ExtInstructionTable {
fn get_initial_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn get_consistency_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

fn get_transition_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}

impl Quotientable for ExtInstructionTable {}
fn get_terminal_quotient_degree_bounds(
&self,
_padded_height: usize,
_num_trace_randomizers: usize,
) -> Vec<Degree> {
panic!(
"Degree bounds must be in place. Run `cargo run --bin constraint-evaluation-generator`."
)
}
}
Loading

0 comments on commit 88fa26e

Please sign in to comment.