Skip to main content

sp1_hypercube/verifier/
config.rs

1use serde::{Deserialize, Serialize};
2use slop_algebra::AbstractField;
3use slop_challenger::VariableLengthChallenger;
4use slop_challenger::{CanObserve, IopCtx};
5
6use crate::septic_digest::SepticDigest;
7
8#[allow(clippy::disallowed_types)]
9use slop_basefold::Poseidon2KoalaBear16BasefoldConfig;
10
11#[allow(clippy::disallowed_types)]
12/// The basefold configuration (field, extension field, challenger, tensor commitment scheme)
13/// for SP1.
14pub type SP1BasefoldConfig = Poseidon2KoalaBear16BasefoldConfig;
15
16#[allow(clippy::disallowed_types)]
17pub use slop_koala_bear::Poseidon2KoalaBearConfig;
18
19#[allow(clippy::disallowed_types)]
20/// The Merkle tree configuration for SP1.
21pub type SP1MerkleTreeConfig = Poseidon2KoalaBearConfig;
22
23/// A specification of preprocessed polynomial batch dimensions.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
25pub struct ChipDimensions<T> {
26    /// The height of the preprocessed polynomial.
27    pub height: T,
28    /// The number of polynomials in the preprocessed batch.
29    pub num_polynomials: T,
30}
31
32/// A verifying key.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct MachineVerifyingKey<C: IopCtx> {
35    /// The start pc of the program.
36    pub pc_start: [C::F; 3],
37    /// The starting global digest of the program, after incorporating the initial memory.
38    pub initial_global_cumulative_sum: SepticDigest<C::F>,
39    /// The preprocessed commitments.
40    pub preprocessed_commit: C::Digest,
41    /// Flag indicating if untrusted programs are allowed.
42    pub enable_untrusted_programs: C::F,
43}
44
45impl<C: IopCtx> PartialEq for MachineVerifyingKey<C> {
46    fn eq(&self, other: &Self) -> bool {
47        self.pc_start == other.pc_start
48            && self.initial_global_cumulative_sum == other.initial_global_cumulative_sum
49            && self.preprocessed_commit == other.preprocessed_commit
50            && self.enable_untrusted_programs == other.enable_untrusted_programs
51    }
52}
53
54impl<C: IopCtx> Eq for MachineVerifyingKey<C> {}
55
56impl<C: IopCtx> MachineVerifyingKey<C> {
57    /// Observes the values of the proving key into the challenger.
58    pub fn observe_into(&self, challenger: &mut C::Challenger) {
59        challenger.observe(self.preprocessed_commit);
60        challenger.observe_constant_length_slice(&self.pc_start);
61        challenger.observe_constant_length_slice(&self.initial_global_cumulative_sum.0.x.0);
62        challenger.observe_constant_length_slice(&self.initial_global_cumulative_sum.0.y.0);
63        challenger.observe(self.enable_untrusted_programs);
64        // Observe the padding.
65        challenger.observe_constant_length_slice(&[C::F::zero(); 6]);
66    }
67}