|
| 1 | +# Sumcheck |
| 2 | + |
| 3 | +## Sumcheck API Overview |
| 4 | + |
| 5 | +### **Structs** |
| 6 | + |
| 7 | +#### `SumcheckTranscriptConfig` |
| 8 | +Configuration structure for the SumCheck protocol’s transcript. |
| 9 | + |
| 10 | +##### **Fields:** |
| 11 | +- `hash: &Hasher` - Reference to the hashing function used. |
| 12 | +- `domain_separator_label: Vec<u8>` - Domain separator label for transcript uniqueness. |
| 13 | +- `round_poly_label: Vec<u8>` - Label for the polynomial at each round. |
| 14 | +- `round_challenge_label: Vec<u8>` - Label for the challenge at each round. |
| 15 | +- `little_endian: bool` - Whether to use little-endian encoding. |
| 16 | +- `seed_rng: F` - Random number generator seed. |
| 17 | + |
| 18 | +##### **Methods:** |
| 19 | +- **`new(hash, domain_separator_label, round_poly_label, round_challenge_label, little_endian, seed_rng) -> Self`**: |
| 20 | + Constructs a new `SumcheckTranscriptConfig` with explicit parameters. |
| 21 | + |
| 22 | +- **`from_string_labels(hash, domain_separator_label, round_poly_label, round_challenge_label, little_endian, seed_rng) -> Self`**: |
| 23 | + Convenience constructor using string labels. |
| 24 | + |
| 25 | +#### `SumcheckConfig` |
| 26 | +General configuration for the SumCheck execution. |
| 27 | + |
| 28 | +##### **Fields:** |
| 29 | +- `stream: IcicleStreamHandle` - Stream for asynchronous execution (default: `nullptr`). |
| 30 | +- `use_extension_field: bool` - Whether to use an extension field for Fiat-Shamir transformation. Sumcheck currently does not support extension fields, always set to `false` otherwise return an error. |
| 31 | +- `batch: u64` - Number of input chunks to hash in batch (default: 1). |
| 32 | +- `are_inputs_on_device: bool` - Whether inputs reside on the device (e.g., GPU). |
| 33 | +- `is_async: bool` - Whether hashing is run asynchronously. |
| 34 | +- `ext: ConfigExtension` - Pointer to backend-specific configuration extensions. |
| 35 | + |
| 36 | +##### **Methods:** |
| 37 | +- **`default() -> Self`**: |
| 38 | + Returns a default `SumcheckConfig` instance. |
| 39 | + |
| 40 | +### **Traits** |
| 41 | + |
| 42 | +#### `Sumcheck` |
| 43 | +Defines the main API for SumCheck operations. |
| 44 | + |
| 45 | +##### **Associated Types:** |
| 46 | +- `Field: FieldImpl + Arithmetic` - The field implementation used. |
| 47 | +- `FieldConfig: FieldConfig + GenerateRandom<Self::Field> + FieldArithmetic<Self::Field>` - Field configuration. |
| 48 | +- `Proof: SumcheckProofOps<Self::Field>` - Type representing the proof. |
| 49 | + |
| 50 | +##### **Methods:** |
| 51 | +- **`new() -> Result<Self, eIcicleError>`**: |
| 52 | + Initializes a new instance. |
| 53 | + |
| 54 | +- **`prove(mle_polys, mle_poly_size, claimed_sum, combine_function, transcript_config, sumcheck_config) -> Self::Proof`**: |
| 55 | + Generates a proof for the polynomial sum over the Boolean hypercube. |
| 56 | + |
| 57 | +- **`verify(proof, claimed_sum, transcript_config) -> Result<bool, eIcicleError>`**: |
| 58 | + Verifies the provided proof. |
| 59 | + |
| 60 | + |
| 61 | +#### `SumcheckProofOps` |
| 62 | +Operations for handling SumCheck proofs. |
| 63 | + |
| 64 | +##### **Methods:** |
| 65 | +- **`get_round_polys(&self) -> Result<Vec<Vec<F>>, eIcicleError>`**: |
| 66 | + Retrieves the polynomials for each round. |
| 67 | + |
| 68 | +- **`print(&self) -> eIcicleError`**:: |
| 69 | + Prints the proof. |
| 70 | + |
| 71 | + |
| 72 | +## **Usage Example** |
| 73 | + |
| 74 | +Below is an example demonstrating how to use the `sumcheck` module, adapted from the `check_sumcheck_simple` test. |
| 75 | + |
| 76 | +```rust |
| 77 | +use icicle_core::sumcheck::{Sumcheck, SumcheckConfig, SumcheckTranscriptConfig}; |
| 78 | +use icicle_core::field::FieldElement; |
| 79 | +use icicle_core::polynomial::Polynomial; |
| 80 | +use icicle_hash::keccak::Keccak256; |
| 81 | + |
| 82 | +fn main() { |
| 83 | + // Initialize hashing function |
| 84 | + let hash = Keccak256::new(0).unwrap(); |
| 85 | + |
| 86 | + // Define a polynomial, e.g., f(x, y) = x + y |
| 87 | + let coefficients = vec![ |
| 88 | + FieldElement::from(0), // Constant term |
| 89 | + FieldElement::from(1), // Coefficient for x |
| 90 | + FieldElement::from(1), // Coefficient for y |
| 91 | + ]; |
| 92 | + let poly = Polynomial::new(coefficients); |
| 93 | + |
| 94 | + // Geerate mle polynomial |
| 95 | + let mut mle_poly = Vec::with_capacity(2); |
| 96 | + for _ in 0..4 { |
| 97 | + mle_poly.push(poly); |
| 98 | + } |
| 99 | + |
| 100 | + // Calculate the expected sum over the Boolean hypercube {0,1}^2 |
| 101 | + let expected_sum = FieldElement::from(4); |
| 102 | + |
| 103 | + // Configure transcript and execution settings |
| 104 | + let transcript_config = SumcheckTranscriptConfig::from_string_labels( |
| 105 | + &hash, |
| 106 | + "domain_separator", |
| 107 | + "round_poly", |
| 108 | + "round_challenge", |
| 109 | + false, // big endian |
| 110 | + FieldElement::from(0), |
| 111 | + ); |
| 112 | + let sumcheck_config = SumcheckConfig::default(); |
| 113 | + |
| 114 | + // define sumcheck lambda |
| 115 | + let combine_func = P::new_predefined(PreDefinedProgram::EQtimesABminusC).unwrap(); |
| 116 | + |
| 117 | + // Initialize prover |
| 118 | + let prover = Sumcheck::new().expect("Failed to create Sumcheck instance"); |
| 119 | + |
| 120 | + // Generate proof |
| 121 | + let proof = prover.prove( |
| 122 | + mle_poly.as_slice(), |
| 123 | + 2, // Number of variables in the polynomial |
| 124 | + expected_sum, |
| 125 | + combine_func, // Use pre-defined combine function eq * (a * b - c) |
| 126 | + &transcript_config, |
| 127 | + &sumcheck_config, |
| 128 | + ); |
| 129 | + |
| 130 | + // Verify the proof |
| 131 | + let result = prover.verify(&proof, expected_sum, &transcript_config); |
| 132 | + assert!(result.is_ok() && result.unwrap(), "SumCheck proof verification failed!"); |
| 133 | +} |
0 commit comments