Skip to main content

provekit_common/
whir_r1cs.rs

1#[cfg(debug_assertions)]
2use whir::transcript::Interaction;
3use {
4    crate::{utils::serde_hex, FieldElement},
5    serde::{Deserialize, Serialize},
6    whir::{
7        algebra::embedding::Identity,
8        protocols::{whir::Config as GenericWhirConfig, whir_zk::Config as GenericWhirZkConfig},
9        transcript,
10    },
11};
12
13pub type WhirConfig = GenericWhirConfig<Identity<FieldElement>>;
14pub type WhirZkConfig = GenericWhirZkConfig<FieldElement>;
15
16/// Type alias for the whir domain separator used in provekit's outer protocol.
17pub type WhirDomainSeparator = transcript::DomainSeparator<'static, ()>;
18
19/// Type alias for the whir prover transcript state.
20pub type WhirProverState = transcript::ProverState;
21
22/// Type alias for the whir proof.
23pub type WhirProof = transcript::Proof;
24
25#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
26pub struct WhirR1CSScheme {
27    pub m:                 usize,
28    pub w1_size:           usize,
29    pub m_0:               usize,
30    pub a_num_terms:       usize,
31    pub num_challenges:    usize,
32    pub challenge_offsets: Vec<usize>,
33    pub has_public_inputs: bool,
34    pub whir_witness:      WhirZkConfig,
35    pub r1cs_hash:         [u8; 32],
36}
37
38impl WhirR1CSScheme {
39    /// Create a domain separator for the provekit outer protocol.
40    pub fn create_domain_separator(&self) -> WhirDomainSeparator {
41        transcript::DomainSeparator::protocol(self)
42    }
43}
44
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
46pub struct WhirR1CSProof {
47    #[serde(with = "serde_hex")]
48    pub narg_string: Vec<u8>,
49    #[serde(with = "serde_hex")]
50    pub hints:       Vec<u8>,
51
52    /// Transcript interaction pattern for debug-mode validation.
53    /// Populated by the prover; absent from serialized proofs on disk.
54    #[cfg(debug_assertions)]
55    #[serde(default, skip_serializing)]
56    pub pattern: Vec<Interaction>,
57}