Skip to content

Commit

Permalink
perform low-degree extension over two domains: arithmetic and fri (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Nov 16, 2022
1 parent 4204444 commit 613e084
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 156 deletions.
33 changes: 24 additions & 9 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use triton_profiler::{prof_itr0, prof_start, prof_stop};
use crate::cross_table_arguments::{
CrossTableArg, EvalArg, GrandCrossTableArg, NUM_CROSS_TABLE_ARGS, NUM_PUBLIC_EVAL_ARGS,
};
use crate::domain::Domain;
use crate::fri::{Fri, FriValidationError};
use crate::proof::{Claim, Proof};
use crate::proof_item::ProofItem;
Expand Down Expand Up @@ -147,13 +148,17 @@ impl Stark {

let (x_rand_codeword, b_rand_codewords) = self.get_randomizer_codewords();

prof_start!(maybe_profiler, "LDE 1");
let base_fri_domain_tables = base_trace_tables
.to_fri_domain_tables(&self.fri.domain, self.parameters.num_trace_randomizers);
prof_start!(maybe_profiler, "dual LDE 1");
let arithmetic_domain = self.arithmetic_domain();
let base_fri_domain_tables = base_trace_tables.to_arithmetic_and_fri_domain_tables(
&arithmetic_domain,
&self.fri.domain,
self.parameters.num_trace_randomizers,
);
let base_fri_domain_codewords = base_fri_domain_tables.get_all_base_columns();
let randomizer_and_base_fri_domain_codewords =
vec![b_rand_codewords, base_fri_domain_codewords.clone()].concat();
prof_stop!(maybe_profiler, "LDE 1");
prof_stop!(maybe_profiler, "dual LDE 1");

prof_start!(maybe_profiler, "Merkle tree 1");
let transposed_base_codewords = transpose(&randomizer_and_base_fri_domain_codewords);
Expand Down Expand Up @@ -182,12 +187,14 @@ impl Stark {
);
prof_stop!(maybe_profiler, "extend");

prof_start!(maybe_profiler, "LDE 2");
let ext_fri_domain_tables = ext_trace_tables
.to_fri_domain_tables(&self.fri.domain, self.parameters.num_trace_randomizers);
prof_start!(maybe_profiler, "dual LDE 2");
let ext_fri_domain_tables = ext_trace_tables.to_arithmetic_and_fri_domain_tables(
&arithmetic_domain,
&self.fri.domain,
self.parameters.num_trace_randomizers,
);
let extension_fri_domain_codewords = ext_fri_domain_tables.collect_all_columns();

prof_stop!(maybe_profiler, "LDE 2");
prof_stop!(maybe_profiler, "dual LDE 2");

prof_start!(maybe_profiler, "Merkle tree 2");
let transposed_ext_codewords = transpose(&extension_fri_domain_codewords);
Expand Down Expand Up @@ -384,6 +391,14 @@ impl Stark {
proof_stream.to_proof()
}

fn arithmetic_domain(&self) -> Domain<BFieldElement> {
let offset = self.fri.domain.offset;
let expansion_factor = self.fri.expansion_factor;
let generator = self.fri.domain.generator.mod_pow(expansion_factor as u64);
let length = self.fri.domain.length / expansion_factor;
Domain::new(offset, generator, length)
}

fn get_revealed_indices(
&self,
unit_distance: usize,
Expand Down
36 changes: 27 additions & 9 deletions triton-vm/src/table/base_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,44 @@ where
self.inherited_table().name.clone()
}

fn low_degree_extension(
/// Low-degree extends the trace that is `self` over the indicated columns `columns` and
/// returns two codewords per column:
/// - one codeword evaluated on the `arithmetic_domain`, and
/// - one codeword evaluated on the `fri_domain`,
/// in that order.
fn dual_low_degree_extension(
&self,
arithmetic_domain: &Domain<BFieldElement>,
fri_domain: &Domain<BFieldElement>,
omicron: BFieldElement,
trace_domain_generator: BFieldElement,
num_trace_randomizers: usize,
columns: Range<usize>,
) -> Vec<Vec<FF>> {
// FIXME: Table<> supports Vec<[FF; WIDTH]>, but FriDomain does not (yet).
self.interpolate_columns(omicron, num_trace_randomizers, columns)
) -> (Table<FF>, Table<FF>) {
// FIXME: Table<> supports Vec<[FF; WIDTH]>, but Domain does not (yet).
let interpolated_columns =
self.interpolate_columns(trace_domain_generator, num_trace_randomizers, columns);
let arithmetic_domain_codewords = interpolated_columns
.par_iter()
.map(|polynomial| arithmetic_domain.evaluate(polynomial))
.collect();
let arithmetic_domain_codeword_table = self
.inherited_table()
.with_data(arithmetic_domain_codewords);
let fri_domain_codewords = interpolated_columns
.par_iter()
.map(|polynomial| fri_domain.evaluate(polynomial))
.collect()
.collect();
let fri_domain_codeword_table = self.inherited_table().with_data(fri_domain_codewords);

(arithmetic_domain_codeword_table, fri_domain_codeword_table)
}

/// Return the interpolation of columns. The `column_indices` variable
/// must be called with *all* the column indices for this particular table,
/// if it is called with a subset, it *will* fail.
fn interpolate_columns(
&self,
omicron: BFieldElement,
trace_domain_generator: BFieldElement,
num_trace_randomizers: usize,
columns: Range<usize>,
) -> Vec<Polynomial<FF>> {
Expand All @@ -302,8 +320,8 @@ where
self.name()
);

let trace_domain =
Domain::new(BFieldElement::one(), omicron, padded_height).domain_values();
let trace_domain = Domain::new(BFieldElement::one(), trace_domain_generator, padded_height)
.domain_values();

let randomizer_domain = disjoint_domain(num_trace_randomizers, &trace_domain);
let interpolation_domain = vec![trace_domain, randomizer_domain].concat();
Expand Down
53 changes: 38 additions & 15 deletions triton-vm/src/table/hash_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,22 +631,34 @@ impl ExtHashTable {
}

impl HashTable {
pub fn new(inherited_table: Table<BFieldElement>) -> Self {
Self { inherited_table }
}

pub fn new_prover(matrix: Vec<Vec<BFieldElement>>) -> Self {
let inherited_table = Table::new(BASE_WIDTH, FULL_WIDTH, matrix, "HashTable".to_string());
Self { inherited_table }
}

pub fn to_fri_domain_table(
pub fn to_arithmetic_and_fri_domain_table(
&self,
arithmetic_domain: &Domain<BFieldElement>,
fri_domain: &Domain<BFieldElement>,
omicron: BFieldElement,
trace_domain_generator: BFieldElement,
num_trace_randomizers: usize,
) -> Self {
) -> (Self, Self) {
let base_columns = 0..self.base_width();
let fri_domain_codewords =
self.low_degree_extension(fri_domain, omicron, num_trace_randomizers, base_columns);
let inherited_table = self.inherited_table.with_data(fri_domain_codewords);
Self { inherited_table }
let (arithmetic_domain_table, fri_domain_table) = self.dual_low_degree_extension(
arithmetic_domain,
fri_domain,
trace_domain_generator,
num_trace_randomizers,
base_columns,
);
(
Self::new(arithmetic_domain_table),
Self::new(fri_domain_table),
)
}

pub fn extend(
Expand Down Expand Up @@ -784,18 +796,29 @@ impl HashTable {
}

impl ExtHashTable {
pub fn to_fri_domain_table(
pub fn new(inherited_table: Table<XFieldElement>) -> Self {
Self { inherited_table }
}

pub fn to_arithmetic_and_fri_domain_table(
&self,
arithmetic_domain: &Domain<BFieldElement>,
fri_domain: &Domain<BFieldElement>,
omicron: BFieldElement,
trace_domain_generator: BFieldElement,
num_trace_randomizers: usize,
) -> Self {
) -> (Self, Self) {
let ext_columns = self.base_width()..self.full_width();
let fri_domain_codewords_ext =
self.low_degree_extension(fri_domain, omicron, num_trace_randomizers, ext_columns);

let inherited_table = self.inherited_table.with_data(fri_domain_codewords_ext);
ExtHashTable { inherited_table }
let (arithmetic_domain_table_ext, fri_domain_table_ext) = self.dual_low_degree_extension(
arithmetic_domain,
fri_domain,
trace_domain_generator,
num_trace_randomizers,
ext_columns,
);
(
Self::new(arithmetic_domain_table_ext),
Self::new(fri_domain_table_ext),
)
}
}

Expand Down
48 changes: 36 additions & 12 deletions triton-vm/src/table/instruction_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ impl ExtInstructionTable {
}

impl InstructionTable {
pub fn new(inherited_table: Table<BFieldElement>) -> Self {
Self { inherited_table }
}

pub fn new_prover(matrix: Vec<Vec<BFieldElement>>) -> Self {
let inherited_table = Table::new(
BASE_WIDTH,
Expand All @@ -340,17 +344,25 @@ impl InstructionTable {
Self { inherited_table }
}

pub fn to_fri_domain_table(
pub fn to_arithmetic_and_fri_domain_table(
&self,
arithmetic_domain: &Domain<BFieldElement>,
fri_domain: &Domain<BFieldElement>,
omicron: BFieldElement,
num_trace_randomizers: usize,
) -> Self {
) -> (Self, Self) {
let base_columns = 0..self.base_width();
let fri_domain_codewords =
self.low_degree_extension(fri_domain, omicron, num_trace_randomizers, base_columns);
let inherited_table = self.inherited_table.with_data(fri_domain_codewords);
Self { inherited_table }
let (arithmetic_domain_table, fri_domain_table) = self.dual_low_degree_extension(
arithmetic_domain,
fri_domain,
omicron,
num_trace_randomizers,
base_columns,
);
(
Self::new(arithmetic_domain_table),
Self::new(fri_domain_table),
)
}

pub fn extend(
Expand Down Expand Up @@ -469,18 +481,30 @@ impl InstructionTable {
}

impl ExtInstructionTable {
pub fn to_fri_domain_table(
pub fn new(inherited_table: Table<XFieldElement>) -> Self {
Self { inherited_table }
}

pub fn to_arithmetic_and_fri_domain_table(
&self,
arithmetic_domain: &Domain<BFieldElement>,
fri_domain: &Domain<BFieldElement>,
omicron: BFieldElement,
num_trace_randomizers: usize,
) -> Self {
) -> (Self, Self) {
let ext_columns = self.base_width()..self.full_width();
let fri_domain_codewords_ext =
self.low_degree_extension(fri_domain, omicron, num_trace_randomizers, ext_columns);
let (arithmetic_domain_table, fri_domain_table) = self.dual_low_degree_extension(
arithmetic_domain,
fri_domain,
omicron,
num_trace_randomizers,
ext_columns,
);

let inherited_table = self.inherited_table.with_data(fri_domain_codewords_ext);
ExtInstructionTable { inherited_table }
(
Self::new(arithmetic_domain_table),
Self::new(fri_domain_table),
)
}
}

Expand Down
50 changes: 37 additions & 13 deletions triton-vm/src/table/jump_stack_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,23 +320,36 @@ impl ExtJumpStackTable {
}

impl JumpStackTable {
pub fn new(inherited_table: Table<BFieldElement>) -> Self {
Self { inherited_table }
}

pub fn new_prover(matrix: Vec<Vec<BFieldElement>>) -> Self {
let inherited_table =
Table::new(BASE_WIDTH, FULL_WIDTH, matrix, "JumpStackTable".to_string());
Self { inherited_table }
}

pub fn to_fri_domain_table(
pub fn to_arithmetic_and_fri_domain_table(
&self,
arithmetic_domain: &Domain<BFieldElement>,
fri_domain: &Domain<BFieldElement>,
omicron: BFieldElement,
num_trace_randomizers: usize,
) -> Self {
) -> (Self, Self) {
let base_columns = 0..self.base_width();
let fri_domain_codewords =
self.low_degree_extension(fri_domain, omicron, num_trace_randomizers, base_columns);
let inherited_table = self.inherited_table.with_data(fri_domain_codewords);
Self { inherited_table }
let (arithmetic_domain_table, fri_domain_table) = self.dual_low_degree_extension(
arithmetic_domain,
fri_domain,
omicron,
num_trace_randomizers,
base_columns,
);

(
Self::new(arithmetic_domain_table),
Self::new(fri_domain_table),
)
}

pub fn extend(
Expand Down Expand Up @@ -448,18 +461,29 @@ impl JumpStackTable {
}

impl ExtJumpStackTable {
pub fn to_fri_domain_table(
pub fn new(inherited_table: Table<XFieldElement>) -> Self {
Self { inherited_table }
}

pub fn to_arithmetic_and_fri_domain_table(
&self,
arithmetic_domain: &Domain<BFieldElement>,
fri_domain: &Domain<BFieldElement>,
omicron: BFieldElement,
num_trace_randomizers: usize,
) -> Self {
) -> (Self, Self) {
let ext_columns = self.base_width()..self.full_width();
let fri_domain_codewords_ext =
self.low_degree_extension(fri_domain, omicron, num_trace_randomizers, ext_columns);

let inherited_table = self.inherited_table.with_data(fri_domain_codewords_ext);
ExtJumpStackTable { inherited_table }
let (arithmetic_domain_table, fri_domain_table) = self.dual_low_degree_extension(
arithmetic_domain,
fri_domain,
omicron,
num_trace_randomizers,
ext_columns,
);
(
Self::new(arithmetic_domain_table),
Self::new(fri_domain_table),
)
}
}

Expand Down
Loading

0 comments on commit 613e084

Please sign in to comment.