diff --git a/triton-vm/src/error.rs b/triton-vm/src/error.rs index 5fa922992..ea4dba23e 100644 --- a/triton-vm/src/error.rs +++ b/triton-vm/src/error.rs @@ -114,7 +114,7 @@ pub enum ProofStreamError { #[non_exhaustive] #[derive(Debug, Error)] pub enum FriValidationError { - #[error("the number of revealed leaves does not match the number of colinearity checks")] + #[error("the number of revealed leaves does not match the number of collinearity checks")] IncorrectNumberOfRevealedLeaves, #[error("Merkle tree authentication failed")] diff --git a/triton-vm/src/fri.rs b/triton-vm/src/fri.rs index abc258f24..d2ee67839 100644 --- a/triton-vm/src/fri.rs +++ b/triton-vm/src/fri.rs @@ -31,7 +31,7 @@ pub type AuthenticationStructure = Vec; #[derive(Debug, Clone, Copy)] pub struct Fri { pub expansion_factor: usize, - pub num_colinearity_checks: usize, + pub num_collinearity_checks: usize, pub domain: ArithmeticDomain, _hasher: PhantomData, } @@ -41,8 +41,8 @@ struct FriProver<'stream, H: AlgebraicHasher> { rounds: Vec>, first_round_domain: ArithmeticDomain, num_rounds: usize, - num_colinearity_checks: usize, - first_round_colinearity_check_indices: Vec, + num_collinearity_checks: usize, + first_round_collinearity_check_indices: Vec, } struct ProverRound { @@ -97,34 +97,34 @@ impl<'stream, H: AlgebraicHasher> FriProver<'stream, H> { } fn query(&mut self) { - self.sample_first_round_colinearity_check_indices(); + self.sample_first_round_collinearity_check_indices(); - let initial_a_indices = self.first_round_colinearity_check_indices.clone(); + let initial_a_indices = self.first_round_collinearity_check_indices.clone(); self.authentically_reveal_codeword_of_round_at_indices(0, &initial_a_indices); let num_rounds_that_have_a_next_round = self.rounds.len() - 1; for round_number in 0..num_rounds_that_have_a_next_round { - let b_indices = self.colinearity_check_b_indices_for_round(round_number); + let b_indices = self.collinearity_check_b_indices_for_round(round_number); self.authentically_reveal_codeword_of_round_at_indices(round_number, &b_indices); } } - fn sample_first_round_colinearity_check_indices(&mut self) { + fn sample_first_round_collinearity_check_indices(&mut self) { let indices_upper_bound = self.first_round_domain.length; - self.first_round_colinearity_check_indices = self + self.first_round_collinearity_check_indices = self .proof_stream - .sample_indices(indices_upper_bound, self.num_colinearity_checks); + .sample_indices(indices_upper_bound, self.num_collinearity_checks); } - fn all_top_level_colinearity_check_indices(&self) -> Vec { - let a_indices = self.first_round_colinearity_check_indices.clone(); - let b_indices = self.colinearity_check_b_indices_for_round(0); + fn all_top_level_collinearity_check_indices(&self) -> Vec { + let a_indices = self.first_round_collinearity_check_indices.clone(); + let b_indices = self.collinearity_check_b_indices_for_round(0); a_indices.into_iter().chain(b_indices).collect() } - fn colinearity_check_b_indices_for_round(&self, round_number: usize) -> Vec { + fn collinearity_check_b_indices_for_round(&self, round_number: usize) -> Vec { let domain_length = self.rounds[round_number].domain.length; - self.first_round_colinearity_check_indices + self.first_round_collinearity_check_indices .iter() .map(|&a_index| (a_index + domain_length / 2) % domain_length) .collect() @@ -192,8 +192,8 @@ struct FriVerifier<'stream, H: AlgebraicHasher> { last_round_codeword: Vec, last_round_max_degree: usize, num_rounds: usize, - num_colinearity_checks: usize, - first_round_colinearity_check_indices: Vec, + num_collinearity_checks: usize, + first_round_collinearity_check_indices: Vec, } struct VerifierRound { @@ -282,17 +282,17 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { } fn compute_last_round_folded_partial_codeword(&mut self) -> Result<()> { - self.sample_first_round_colinearity_check_indices(); + self.sample_first_round_collinearity_check_indices(); self.receive_authentic_partially_revealed_codewords()?; self.successively_fold_partial_codeword_of_each_round(); Ok(()) } - fn sample_first_round_colinearity_check_indices(&mut self) { + fn sample_first_round_collinearity_check_indices(&mut self) { let upper_bound = self.first_round_domain.length; - self.first_round_colinearity_check_indices = self + self.first_round_collinearity_check_indices = self .proof_stream - .sample_indices(upper_bound, self.num_colinearity_checks); + .sample_indices(upper_bound, self.num_collinearity_checks); } fn receive_authentic_partially_revealed_codewords(&mut self) -> Result<()> { @@ -335,7 +335,7 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { } fn assert_enough_leaves_were_received(&self, leaves: &[XFieldElement]) -> Result<()> { - match self.num_colinearity_checks == leaves.len() { + match self.num_collinearity_checks == leaves.len() { true => Ok(()), false => Err(IncorrectNumberOfRevealedLeaves), } @@ -351,7 +351,7 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { let revealed_digests = codeword_as_digests(revealed_leaves); let merkle_tree_height = round.domain.length.ilog2() as usize; - let indices = &self.colinearity_check_a_indices_for_round(0); + let indices = &self.collinearity_check_a_indices_for_round(0); match MerkleTree::::verify_authentication_structure( round.merkle_root, @@ -376,7 +376,7 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { let revealed_digests = codeword_as_digests(revealed_leaves); let merkle_tree_height = round.domain.length.ilog2() as usize; - let indices = &self.colinearity_check_b_indices_for_round(round_number); + let indices = &self.collinearity_check_b_indices_for_round(round_number); match MerkleTree::::verify_authentication_structure( round.merkle_root, @@ -401,14 +401,14 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { fn fold_partial_codeword_of_round(&self, round_number: usize) -> Vec { let round = &self.rounds[round_number]; - let a_indices = self.colinearity_check_a_indices_for_round(round_number); - let b_indices = self.colinearity_check_b_indices_for_round(round_number); + let a_indices = self.collinearity_check_a_indices_for_round(round_number); + let b_indices = self.collinearity_check_b_indices_for_round(round_number); let partial_codeword_a = &round.partial_codeword_a; let partial_codeword_b = &round.partial_codeword_b; let domain = round.domain; let folding_challenge = round.folding_challenge.unwrap(); - (0..self.num_colinearity_checks) + (0..self.num_collinearity_checks) .into_par_iter() .map(|i| { let point_a_x = domain.domain_value(a_indices[i] as u32).lift(); @@ -420,24 +420,24 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { .collect() } - fn colinearity_check_a_indices_for_round(&self, round_number: usize) -> Vec { + fn collinearity_check_a_indices_for_round(&self, round_number: usize) -> Vec { let domain_length = self.rounds[round_number].domain.length; let a_offset = 0; - self.colinearity_check_indices_with_offset_and_modulus(a_offset, domain_length) + self.collinearity_check_indices_with_offset_and_modulus(a_offset, domain_length) } - fn colinearity_check_b_indices_for_round(&self, round_number: usize) -> Vec { + fn collinearity_check_b_indices_for_round(&self, round_number: usize) -> Vec { let domain_length = self.rounds[round_number].domain.length; let b_offset = domain_length / 2; - self.colinearity_check_indices_with_offset_and_modulus(b_offset, domain_length) + self.collinearity_check_indices_with_offset_and_modulus(b_offset, domain_length) } - fn colinearity_check_indices_with_offset_and_modulus( + fn collinearity_check_indices_with_offset_and_modulus( &self, offset: usize, modulus: usize, ) -> Vec { - self.first_round_colinearity_check_indices + self.first_round_collinearity_check_indices .iter() .map(|&i| (i + offset) % modulus) .collect() @@ -481,7 +481,7 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { fn received_last_round_codeword_at_indices_a(&self) -> Vec { let last_round_number = self.rounds.len() - 1; - let last_round_indices_a = self.colinearity_check_a_indices_for_round(last_round_number); + let last_round_indices_a = self.collinearity_check_a_indices_for_round(last_round_number); last_round_indices_a .iter() .map(|&last_round_index_a| self.last_round_codeword[last_round_index_a]) @@ -504,11 +504,11 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { let partial_codeword_a = self.rounds[0].partial_codeword_a.clone(); let partial_codeword_b = self.rounds[0].partial_codeword_b.clone(); - let indices_a = self.colinearity_check_a_indices_for_round(0).into_iter(); + let indices_a = self.collinearity_check_a_indices_for_round(0).into_iter(); let first_round_codeword_b_has_been_revealed = self.num_rounds > 0; let indices_b = match first_round_codeword_b_has_been_revealed { - true => self.colinearity_check_b_indices_for_round(0).into_iter(), + true => self.collinearity_check_b_indices_for_round(0).into_iter(), false => vec![].into_iter(), }; @@ -523,7 +523,7 @@ impl Fri { pub fn new( domain: ArithmeticDomain, expansion_factor: usize, - num_colinearity_checks: usize, + num_collinearity_checks: usize, ) -> Self { assert!(expansion_factor > 1); assert!(expansion_factor.is_power_of_two()); @@ -532,7 +532,7 @@ impl Fri { Self { domain, expansion_factor, - num_colinearity_checks, + num_collinearity_checks, _hasher: PhantomData, } } @@ -548,7 +548,7 @@ impl Fri { prover.commit(codeword); prover.query(); - prover.all_top_level_colinearity_check_indices() + prover.all_top_level_collinearity_check_indices() } fn prover<'stream>(&'stream self, proof_stream: &'stream mut ProofStream) -> FriProver { @@ -557,8 +557,8 @@ impl Fri { rounds: vec![], first_round_domain: self.domain, num_rounds: self.num_rounds(), - num_colinearity_checks: self.num_colinearity_checks, - first_round_colinearity_check_indices: vec![], + num_collinearity_checks: self.num_collinearity_checks, + first_round_collinearity_check_indices: vec![], } } @@ -596,8 +596,8 @@ impl Fri { last_round_codeword: vec![], last_round_max_degree: self.last_round_max_degree(), num_rounds: self.num_rounds(), - num_colinearity_checks: self.num_colinearity_checks, - first_round_colinearity_check_indices: vec![], + num_collinearity_checks: self.num_collinearity_checks, + first_round_collinearity_check_indices: vec![], } } @@ -607,7 +607,7 @@ impl Fri { // Skip rounds for which Merkle tree verification cost exceeds arithmetic cost, // because more than half the codeword's locations are queried. - let num_rounds_checking_all_locations = self.num_colinearity_checks.ilog2() as u64; + let num_rounds_checking_all_locations = self.num_collinearity_checks.ilog2() as u64; let num_rounds_checking_most_locations = num_rounds_checking_all_locations + 1; max_num_rounds.saturating_sub(num_rounds_checking_most_locations) as usize @@ -667,7 +667,7 @@ mod tests { )( log_2_expansion_factor in Just(log_2_expansion_factor), log_2_domain_length in log_2_expansion_factor..=18, - num_colinearity_checks in 1_usize..=320, + num_collinearity_checks in 1_usize..=320, offset in arb(), ) -> Fri { let expansion_factor = (1 << log_2_expansion_factor) as usize; @@ -681,7 +681,7 @@ mod tests { let domain_length = max(sampled_domain_length, min_expanded_domain_length); let fri_domain = ArithmeticDomain::of_length(domain_length).with_offset(offset); - Fri::new(fri_domain, expansion_factor, num_colinearity_checks) + Fri::new(fri_domain, expansion_factor, num_collinearity_checks) } } @@ -695,7 +695,7 @@ mod tests { // todo: Figure out by how much to oversample for the given parameters. let oversampling_summand = 1 << 13; - let num_indices_to_sample = fri.num_colinearity_checks + oversampling_summand; + let num_indices_to_sample = fri.num_collinearity_checks + oversampling_summand; let indices = Tip5::sample_indices( &mut sponge_state, fri.domain.length as u32, @@ -703,7 +703,7 @@ mod tests { ); let num_unique_indices = indices.iter().unique().count(); - let required_unique_indices = min(fri.domain.length, fri.num_colinearity_checks); + let required_unique_indices = min(fri.domain.length, fri.num_collinearity_checks); prop_assert!(num_unique_indices >= required_unique_indices); } @@ -712,8 +712,8 @@ mod tests { let expected_last_round_max_degree = fri.first_round_max_degree() >> fri.num_rounds(); prop_assert_eq!(expected_last_round_max_degree, fri.last_round_max_degree()); if fri.num_rounds() > 0 { - prop_assert!(fri.num_colinearity_checks <= expected_last_round_max_degree); - prop_assert!(expected_last_round_max_degree < 2 * fri.num_colinearity_checks); + prop_assert!(fri.num_collinearity_checks <= expected_last_round_max_degree); + prop_assert!(expected_last_round_max_degree < 2 * fri.num_collinearity_checks); } } @@ -779,8 +779,8 @@ mod tests { fn smallest_fri() -> Fri { let domain = ArithmeticDomain::of_length(2); let expansion_factor = 2; - let num_colinearity_checks = 1; - Fri::new(domain, expansion_factor, num_colinearity_checks) + let num_collinearity_checks = 1; + Fri::new(domain, expansion_factor, num_collinearity_checks) } #[test] @@ -788,8 +788,8 @@ mod tests { fn too_small_expansion_factor_is_rejected() { let domain = ArithmeticDomain::of_length(2); let expansion_factor = 1; - let num_colinearity_checks = 1; - Fri::::new(domain, expansion_factor, num_colinearity_checks); + let num_collinearity_checks = 1; + Fri::::new(domain, expansion_factor, num_collinearity_checks); } #[proptest] @@ -802,8 +802,8 @@ mod tests { return Ok(()); } let domain = ArithmeticDomain::of_length(2 * expansion_factor).with_offset(offset); - let num_colinearity_checks = 1; - Fri::::new(domain, expansion_factor, num_colinearity_checks); + let num_collinearity_checks = 1; + Fri::::new(domain, expansion_factor, num_collinearity_checks); } #[proptest] @@ -814,8 +814,8 @@ mod tests { ) { let expansion_factor = (1 << log_2_expansion_factor) as usize; let domain = ArithmeticDomain::of_length(expansion_factor - 1).with_offset(offset); - let num_colinearity_checks = 1; - Fri::::new(domain, expansion_factor, num_colinearity_checks); + let num_collinearity_checks = 1; + Fri::::new(domain, expansion_factor, num_collinearity_checks); } // todo: add test fuzzing proof_stream @@ -953,7 +953,7 @@ mod tests { rng_seed: u64, ) { let all_authentication_structures_are_trivial = - fri.num_colinearity_checks >= fri.domain.length; + fri.num_collinearity_checks >= fri.domain.length; if all_authentication_structures_are_trivial { return Ok(()); } diff --git a/triton-vm/src/stark.rs b/triton-vm/src/stark.rs index 8de2a71af..1cf2008b2 100644 --- a/triton-vm/src/stark.rs +++ b/triton-vm/src/stark.rs @@ -77,12 +77,12 @@ pub struct StarkParameters { /// in all cases. It is integral for achieving zero-knowledge for the FRI part of the zk-STARK. pub num_randomizer_polynomials: usize, - /// The number of colinearity checks to perform in FRI. - pub num_colinearity_checks: usize, + /// The number of collinearity checks to perform in FRI. + pub num_collinearity_checks: usize, /// The number of combination codeword checks. These checks link the (DEEP) ALI part and the /// FRI part of the zk-STARK. The number of combination codeword checks directly depends on the - /// number of colinearity checks and the FRI folding factor. + /// number of collinearity checks and the FRI folding factor. pub num_combination_codeword_checks: usize, } @@ -95,11 +95,11 @@ impl StarkParameters { let num_randomizer_polynomials = 1; // over the XField let fri_expansion_factor = 1 << log2_of_fri_expansion_factor; - let num_colinearity_checks = security_level / log2_of_fri_expansion_factor; + let num_collinearity_checks = security_level / log2_of_fri_expansion_factor; // For now, the FRI folding factor is hardcoded in our zk-STARK. let fri_folding_factor = 2; - let num_combination_codeword_checks = num_colinearity_checks * fri_folding_factor; + let num_combination_codeword_checks = num_collinearity_checks * fri_folding_factor; let num_out_of_domain_rows = 2; let num_trace_randomizers = num_combination_codeword_checks @@ -110,7 +110,7 @@ impl StarkParameters { fri_expansion_factor, num_trace_randomizers, num_randomizer_polynomials, - num_colinearity_checks, + num_collinearity_checks, num_combination_codeword_checks, } } @@ -645,7 +645,7 @@ impl Stark { Fri::new( domain, parameters.fri_expansion_factor, - parameters.num_colinearity_checks, + parameters.num_collinearity_checks, ) } diff --git a/triton-vm/src/vm.rs b/triton-vm/src/vm.rs index e478d6601..9694c0eb5 100644 --- a/triton-vm/src/vm.rs +++ b/triton-vm/src/vm.rs @@ -2031,7 +2031,7 @@ pub(crate) mod tests { } #[proptest] - fn run_tvm_get_colinear_y( + fn run_tvm_get_collinear_y( #[strategy(arb())] p0: (BFieldElement, BFieldElement), #[strategy(arb())] #[filter(#p0.0 != #p1.0)] @@ -2040,7 +2040,7 @@ pub(crate) mod tests { ) { let p2_y = Polynomial::get_colinear_y(p0, p1, p2_x); - let get_colinear_y_program = triton_program!( + let get_collinear_y_program = triton_program!( read_io 5 // p0 p1 p2_x swap 3 push -1 mul dup 1 add // dy = p0_y - p1_y dup 3 push -1 mul dup 5 add mul // dy·(p2_x - p0_x) @@ -2050,8 +2050,8 @@ pub(crate) mod tests { write_io 1 halt ); - let public_input = vec![p2_x, p1.1, p1.0, p0.1, p0.0].into(); - let output = get_colinear_y_program.run(public_input, [].into()).unwrap(); + let public_input = vec![p2_x, p1.1, p1.0, p0.1, p0.0]; + let_assert!(Ok(output) = get_collinear_y_program.run(public_input.into(), [].into())); prop_assert_eq!(p2_y, output[0]); } @@ -2093,7 +2093,7 @@ pub(crate) mod tests { } #[test] - fn read_mem_unitialized() { + fn read_mem_uninitialized() { let program = triton_program!(read_mem 3 halt); let_assert!(Ok((aet, _)) = program.trace_execution([].into(), [].into())); assert!(2 == aet.processor_trace.nrows());