Skip to main content

stwo_gpu/core/pcs/
mod.rs

1//! Implements a FRI polynomial commitment scheme.
2//!
3//! This is a protocol where the prover can commit on a set of polynomials and then prove their
4//! opening on a set of points.
5//! Note: This implementation is not really a polynomial commitment scheme, because we are not in
6//! the unique decoding regime. This is enough for a STARK proof though, where we only want to imply
7//! the existence of such polynomials, and are ok with having a small decoding list.
8//! Note: Opened points cannot come from the commitment domain.
9
10pub mod quotients;
11pub mod utils;
12mod verifier;
13
14use serde::{Deserialize, Serialize};
15
16pub use self::utils::TreeVec;
17pub use self::verifier::CommitmentSchemeVerifier;
18use super::channel::Channel;
19use super::fields::qm31::SecureField;
20use super::fri::FriConfig;
21
22#[derive(Copy, Debug, Clone, PartialEq, Eq)]
23pub struct TreeSubspan {
24    pub tree_index: usize,
25    pub col_start: usize,
26    pub col_end: usize,
27}
28
29#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
30pub struct PcsConfig {
31    pub pow_bits: u32,
32    pub fri_config: FriConfig,
33}
34impl PcsConfig {
35    pub const fn security_bits(&self) -> u32 {
36        self.pow_bits + self.fri_config.security_bits()
37    }
38
39    pub fn mix_into(&self, channel: &mut impl Channel) {
40        let PcsConfig {
41            pow_bits,
42            fri_config,
43        } = self;
44        let FriConfig {
45            log_blowup_factor,
46            n_queries,
47            log_last_layer_degree_bound,
48        } = fri_config;
49
50        channel.mix_felts(&[SecureField::from_u32_unchecked(
51            *pow_bits,
52            *log_blowup_factor,
53            *n_queries as u32,
54            *log_last_layer_degree_bound,
55        )]);
56    }
57}
58
59impl Default for PcsConfig {
60    fn default() -> Self {
61        Self {
62            pow_bits: 10,
63            fri_config: FriConfig::new(0, 1, 3),
64        }
65    }
66}
67
68#[cfg(test)]
69mod tests {
70    #[test]
71    fn test_security_bits() {
72        let config = super::PcsConfig {
73            pow_bits: 42,
74            fri_config: super::FriConfig::new(10, 10, 70),
75        };
76        assert!(config.security_bits() == 10 * 70 + 42);
77    }
78}