diff --git a/triton-vm/src/stark.rs b/triton-vm/src/stark.rs index ba8abf376..74a7e5779 100644 --- a/triton-vm/src/stark.rs +++ b/triton-vm/src/stark.rs @@ -152,7 +152,7 @@ impl Stark { prof_start!(maybe_profiler, "Fiat-Shamir", "hash"); proof_stream.enqueue(ProofItem::MerkleRoot(base_merkle_tree.root())); - let challenges = proof_stream.sample_scalars(Challenges::num_challenges_to_sample()); + let challenges = proof_stream.sample_scalars(Challenges::SAMPLE_COUNT); let challenges = Challenges::new(challenges, claim); prof_stop!(maybe_profiler, "Fiat-Shamir"); @@ -711,8 +711,7 @@ impl Stark { prof_start!(maybe_profiler, "Fiat-Shamir 1", "hash"); let base_merkle_tree_root = proof_stream.dequeue()?.try_into_merkle_root()?; - let extension_challenge_weights = - proof_stream.sample_scalars(Challenges::num_challenges_to_sample()); + let extension_challenge_weights = proof_stream.sample_scalars(Challenges::SAMPLE_COUNT); let challenges = Challenges::new(extension_challenge_weights, claim); let extension_tree_merkle_root = proof_stream.dequeue()?.try_into_merkle_root()?; // Sample weights for quotient codeword, which is a part of the combination codeword. diff --git a/triton-vm/src/table.rs b/triton-vm/src/table.rs index a192720b4..1d47ce609 100644 --- a/triton-vm/src/table.rs +++ b/triton-vm/src/table.rs @@ -103,7 +103,7 @@ impl TasmConstraintEvaluationMemoryLayout { MemoryRegion::new(self.curr_ext_row_ptr, NUM_EXT_COLUMNS), MemoryRegion::new(self.next_base_row_ptr, NUM_BASE_COLUMNS), MemoryRegion::new(self.next_ext_row_ptr, NUM_EXT_COLUMNS), - MemoryRegion::new(self.challenges_ptr, challenges::Challenges::count()), + MemoryRegion::new(self.challenges_ptr, challenges::Challenges::COUNT), ]; Box::new(all_regions) } diff --git a/triton-vm/src/table/challenges.rs b/triton-vm/src/table/challenges.rs index eeb602165..9e2747554 100644 --- a/triton-vm/src/table/challenges.rs +++ b/triton-vm/src/table/challenges.rs @@ -216,14 +216,12 @@ impl ChallengeId { /// convenience methods. #[derive(Debug, Clone, Arbitrary)] pub struct Challenges { - pub challenges: [XFieldElement; Self::count()], + pub challenges: [XFieldElement; Self::COUNT], } impl Challenges { /// The total number of challenges used in Triton VM. - pub const fn count() -> usize { - ChallengeId::COUNT - } + pub const COUNT: usize = ChallengeId::COUNT; /// The number of weights to sample using the Fiat-Shamir heuristic. This number is lower /// than the number of challenges because several challenges are not sampled, but computed @@ -238,15 +236,23 @@ impl Challenges { /// lookup table and the sampled indeterminate [`LookupTablePublicIndeterminate`]. /// - The [`CompressedProgramDigest`] is computed from the program to be executed and the /// sampled indeterminate [`CompressProgramDigestIndeterminate`]. + // When modifying this, be sure to add to the compile-time assertions in the + // `#[test] const fn compile_time_index_assertions() { … }` + // at the end of this file. + pub const SAMPLE_COUNT: usize = Self::COUNT - 4; + + #[deprecated(since = "0.39.0", note = "Use `Self::COUNT` instead")] + pub const fn count() -> usize { + Self::COUNT + } + + #[deprecated(since = "0.39.0", note = "Use `Self::SAMPLE_COUNT` instead")] pub const fn num_challenges_to_sample() -> usize { - // When modifying this, be sure to add to the compile-time assertions in the - // `#[test] const fn compile_time_index_assertions() { … }` - // at the end of this file. - Self::count() - 4 + Self::SAMPLE_COUNT } pub fn new(mut challenges: Vec, claim: &Claim) -> Self { - assert_eq!(Self::num_challenges_to_sample(), challenges.len()); + assert_eq!(Self::SAMPLE_COUNT, challenges.len()); let compressed_digest = EvalArg::compute_terminal( &claim.program_digest.values(), @@ -273,7 +279,7 @@ impl Challenges { challenges.insert(StandardOutputTerminal.index(), output_terminal); challenges.insert(LookupTablePublicTerminal.index(), lookup_terminal); challenges.insert(CompressedProgramDigest.index(), compressed_digest); - assert_eq!(Self::count(), challenges.len()); + assert_eq!(Self::COUNT, challenges.len()); let challenges = challenges.try_into().unwrap(); Self { challenges } @@ -319,7 +325,7 @@ pub(crate) mod tests { /// Stand-in challenges for use in tests. For non-interactive STARKs, use the /// Fiat-Shamir heuristic to derive the actual challenges. pub fn placeholder(claim: &Claim) -> Self { - let stand_in_challenges = (1..=Self::num_challenges_to_sample()) + let stand_in_challenges = (1..=Self::SAMPLE_COUNT) .map(|i| xfe!([42, i as u64, 24])) .collect(); Self::new(stand_in_challenges, claim) diff --git a/triton-vm/src/table/constraint_circuit.rs b/triton-vm/src/table/constraint_circuit.rs index 233d24d18..3eda96473 100644 --- a/triton-vm/src/table/constraint_circuit.rs +++ b/triton-vm/src/table/constraint_circuit.rs @@ -1320,7 +1320,7 @@ mod tests { println!("seed: {seed}"); let dummy_claim = Claim::default(); - let challenges: [XFieldElement; Challenges::num_challenges_to_sample()] = rng.gen(); + let challenges: [XFieldElement; Challenges::SAMPLE_COUNT] = rng.gen(); let challenges = challenges.to_vec(); let challenges = Challenges::new(challenges, &dummy_claim); @@ -1967,7 +1967,7 @@ mod tests { // Use the Schwartz-Zippel lemma to check no two substitution rules are equal. let dummy_claim = Claim::default(); - let challenges: [XFieldElement; Challenges::num_challenges_to_sample()] = rng.gen(); + let challenges: [XFieldElement; Challenges::SAMPLE_COUNT] = rng.gen(); let challenges = challenges.to_vec(); let challenges = Challenges::new(challenges, &dummy_claim);