diff --git a/src/commitment_scheme/merkle_decommitment.rs b/src/commitment_scheme/merkle_decommitment.rs index 4273a230f..6aab27249 100644 --- a/src/commitment_scheme/merkle_decommitment.rs +++ b/src/commitment_scheme/merkle_decommitment.rs @@ -178,12 +178,12 @@ mod tests { use crate::commitment_scheme::hasher::Hasher; use crate::commitment_scheme::merkle_tree::MerkleTree; use crate::commitment_scheme::utils::tests::generate_test_queries; - use crate::commitment_scheme::utils::ColumnArray; use crate::core::fields::m31::M31; + use crate::core::ColumnVec; #[test] pub fn verify_test() { - let trace: ColumnArray = vec![(0..4096).map(M31::from_u32_unchecked).collect(); 7]; + let trace: ColumnVec = vec![(0..4096).map(M31::from_u32_unchecked).collect(); 7]; let tree = MerkleTree::::commit(trace); let queries = generate_test_queries(100, 4096); let decommitment = tree.generate_decommitment(queries.clone()); @@ -194,7 +194,7 @@ mod tests { #[test] pub fn verify_false_proof_test() { let trace_column_length = 1 << 12; - let trace: ColumnArray = vec![ + let trace: ColumnVec = vec![ (0..trace_column_length) .map(M31::from_u32_unchecked) .collect(); @@ -225,7 +225,7 @@ mod tests { .map(M31::from_u32_unchecked) .collect::>(); let reversed_trace_column = trace_column.iter().rev().cloned().collect::>(); - let trace: ColumnArray = vec![trace_column, reversed_trace_column]; + let trace: ColumnVec = vec![trace_column, reversed_trace_column]; let tree = MerkleTree::::commit(trace.clone()); let random_queries = generate_test_queries(10, trace_column_length as usize); let test_skip_queries = vec![17, 50]; diff --git a/src/commitment_scheme/merkle_tree.rs b/src/commitment_scheme/merkle_tree.rs index b83fdda07..6116c3612 100644 --- a/src/commitment_scheme/merkle_tree.rs +++ b/src/commitment_scheme/merkle_tree.rs @@ -7,9 +7,10 @@ use super::hasher::Hasher; use super::merkle_decommitment::MerkleDecommitment; use crate::commitment_scheme::utils::{ allocate_balanced_tree, column_to_row_major, hash_merkle_tree_from_bottom_layer, - tree_data_as_mut_ref, ColumnArray, TreeData, + tree_data_as_mut_ref, TreeData, }; use crate::core::fields::{Field, IntoSlice}; +use crate::core::ColumnVec; use crate::math::utils::{prev_pow_two, usize_div_ceil}; pub struct MerkleTree { @@ -26,7 +27,7 @@ where T: IntoSlice, { /// Commits on a given trace(matrix). - pub fn commit(trace: ColumnArray) -> Self { + pub fn commit(trace: ColumnVec) -> Self { let mut tree = Self::init_from_column_array(trace); hash_merkle_tree_from_bottom_layer::( @@ -41,7 +42,7 @@ where /// Builds the base layer of the tree from the given trace. /// Allocates the rest of the tree. // TODO(Ohad): add support for columns of different lengths. - fn init_from_column_array(trace: ColumnArray) -> Self { + fn init_from_column_array(trace: ColumnVec) -> Self { assert!(!trace.is_empty()); assert!(trace[0].len().is_power_of_two()); trace.iter().for_each(|column| { diff --git a/src/commitment_scheme/utils.rs b/src/commitment_scheme/utils.rs index f5d913539..025f53447 100644 --- a/src/commitment_scheme/utils.rs +++ b/src/commitment_scheme/utils.rs @@ -3,10 +3,10 @@ use std::slice::Iter; use super::hasher::Hasher; use crate::core::fields::{Field, IntoSlice}; +use crate::core::ColumnVec; use crate::math::utils::{log2_ceil, usize_safe_div}; -pub type ColumnArray = Vec>; -pub type ColumnLengthMap = BTreeMap>; +pub type ColumnLengthMap = BTreeMap>; pub type TreeLayer = Box<[T]>; pub type TreeData = Box<[TreeLayer]>; @@ -87,7 +87,7 @@ pub fn hash_merkle_tree_from_bottom_layer<'a, F: Field, H: Hasher>( /// Maps columns by length. /// Mappings are sorted by length. i.e the first entry is a matrix of the shortest columns. -pub fn map_columns_sorted(cols: ColumnArray) -> ColumnLengthMap { +pub fn map_columns_sorted(cols: ColumnVec) -> ColumnLengthMap { let mut columns_length_map: ColumnLengthMap = BTreeMap::new(); for c in cols { let length_index_entry = columns_length_map.entry(c.len()).or_default(); @@ -104,7 +104,7 @@ pub fn map_columns_sorted(cols: ColumnArray) -> ColumnLengthMap /// Pointers in 'dst' should point to pre-allocated memory with enough space to store /// column_array.len() amount of u32 elements. // TODO(Ohad): Change tree impl and remove. -pub unsafe fn transpose_to_bytes(column_array: &ColumnArray, dst: &[*mut u8]) { +pub unsafe fn transpose_to_bytes(column_array: &ColumnVec, dst: &[*mut u8]) { let column_length = column_array[0].len(); for (i, ptr) in dst.iter().enumerate().take(column_length) { @@ -138,7 +138,7 @@ pub fn tree_data_as_mut_ref(tree_data: &mut TreeData) -> Vec<&mut [ /// offset*(n_rows/n_rows_in_node) amount of T elements. // TODO(Ohad): Change tree impl and remove. pub unsafe fn inject( - column_array: &ColumnArray, + column_array: &ColumnVec, dst: &mut [u8], n_rows_in_node: usize, gap_offset: usize, @@ -154,7 +154,7 @@ pub unsafe fn inject( /// Given a matrix, returns a vector of the matrix elements in row-major order. /// Assumes all columns are of the same length and non-zero. // TODO(Ohad): Change tree impl and remove. -pub fn column_to_row_major(mut mat: ColumnArray) -> Vec { +pub fn column_to_row_major(mut mat: ColumnVec) -> Vec { if mat.len() == 1 { return mat.remove(0); }; @@ -318,7 +318,7 @@ pub mod tests { use super::{ allocate_balanced_tree, inject_and_hash_layer, inject_column_chunks, map_columns_sorted, - ColumnArray, + ColumnVec, }; use crate::commitment_scheme::blake3_hash::Blake3Hasher; use crate::commitment_scheme::hasher::Hasher; @@ -339,22 +339,22 @@ pub mod tests { queries } - fn init_test_trace() -> ColumnArray { + fn init_test_trace() -> ColumnVec { let col0 = std::iter::repeat(0).take(8).collect(); let col1 = vec![1, 2, 3, 4]; let col2 = vec![5, 6]; let col3 = vec![7, 8]; let col4 = vec![9]; - let cols: ColumnArray = vec![col0, col1, col2, col3, col4]; + let cols: ColumnVec = vec![col0, col1, col2, col3, col4]; cols } - fn init_transpose_test_trace() -> ColumnArray { + fn init_transpose_test_trace() -> ColumnVec { let col1 = vec![1, 2, 3, 4]; let col2 = vec![5, 6, 7, 8]; let col3 = vec![9, 10]; let col4 = vec![11]; - let cols: ColumnArray = vec![col1, col2, col3, col4]; + let cols: ColumnVec = vec![col1, col2, col3, col4]; cols } diff --git a/src/core/air/mod.rs b/src/core/air/mod.rs index db974c236..6cfab166d 100644 --- a/src/core/air/mod.rs +++ b/src/core/air/mod.rs @@ -6,6 +6,7 @@ use super::circle::CirclePoint; use super::fields::m31::BaseField; use super::fields::qm31::SecureField; use super::poly::circle::{CanonicCoset, CirclePoly}; +use super::ColumnVec; pub mod evaluation; @@ -28,14 +29,14 @@ pub trait ComponentVisitor { /// Holds the mask offsets at each column. /// Holds a vector with an entry for each column. Each entry holds the offsets /// of the mask at that column. -pub struct Mask(pub Vec>); +pub struct Mask(pub ColumnVec); impl Mask { pub fn to_points( &self, domains: Vec, point: CirclePoint, - ) -> Vec>> { + ) -> ColumnVec> { self.iter() .zip(domains.iter()) .map(|(col, domain)| { @@ -48,7 +49,7 @@ impl Mask { } impl Deref for Mask { - type Target = Vec>; + type Target = ColumnVec; fn deref(&self) -> &Self::Target { &self.0 @@ -83,7 +84,7 @@ pub trait Component { &self, point: CirclePoint, trace: &ComponentTrace<'_>, - ) -> (Vec>>, Vec>) { + ) -> (ColumnVec>, ColumnVec) { let domains = trace .columns .iter() diff --git a/src/core/mod.rs b/src/core/mod.rs index d8c7aeaf4..3ab1552eb 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -11,3 +11,5 @@ pub mod poly; pub mod proof_of_work; pub mod queries; pub mod utils; + +pub type ColumnVec = Vec>; diff --git a/src/fibonacci/mod.rs b/src/fibonacci/mod.rs index 30a2df07a..999710990 100644 --- a/src/fibonacci/mod.rs +++ b/src/fibonacci/mod.rs @@ -22,6 +22,7 @@ use crate::core::oods::{get_oods_quotient, get_pair_oods_quotient, quotient_log_ use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, CirclePoly}; use crate::core::poly::BitReversedOrder; use crate::core::proof_of_work::{ProofOfWork, ProofOfWorkProof}; +use crate::core::ColumnVec; type Channel = Blake2sChannel; type MerkleHasher = Blake2sHasher; @@ -55,7 +56,7 @@ pub struct FibonacciProof { pub trace_decommitments: Vec>, pub composition_polynomial_commitment: ::Hash, pub composition_polynomial_decommitment: MerkleDecommitment, - pub trace_oods_values: Vec>, + pub trace_oods_values: ColumnVec, pub composition_polynomial_opened_values: Vec, pub trace_opened_values: Vec, pub proof_of_work: ProofOfWorkProof,