use processor::Digest; use test_utils::{ crypto::{BatchMerkleProof, ElementHasher, Hasher as HasherTrait, PartialMerkleTree}, math::fft, serde::DeserializationError, Felt, FieldElement, MerkleTreeVC, StarkField, }; use winter_fri::{FriProof, VerifierError}; pub trait UnBatch { fn unbatch( &mut self, positions: &[usize], domain_size: usize, layer_commitments: Vec<::Digest>, ) -> (Vec, Vec<(Digest, Vec)>); } pub struct MidenFriVerifierChannel< E: FieldElement, H: ElementHasher + ElementHasher, > { layer_commitments: Vec, layer_proofs: Vec>, layer_queries: Vec>, remainder: Vec, } impl MidenFriVerifierChannel where E: FieldElement, H: ElementHasher + ElementHasher, { /// Builds a new verifier channel from the specified [FriProof]. /// /// # Errors /// Returns an error if the specified `proof` could not be parsed correctly. pub fn new( proof: FriProof, layer_commitments: Vec, domain_size: usize, folding_factor: usize, ) -> Result { let remainder = proof.parse_remainder()?; let (layer_queries, layer_proofs) = proof.parse_layers::>(domain_size, folding_factor)?; Ok(MidenFriVerifierChannel { layer_commitments, layer_proofs, layer_queries, remainder, }) } pub fn take_fri_remainder(&mut self) -> Vec { self.remainder.clone() } pub fn layer_proofs(&mut self) -> Vec> { self.layer_proofs.drain(..).collect() } pub fn layer_queries(&mut self) -> Vec> { self.layer_queries.clone() } pub fn read_fri_layer_commitments(&mut self) -> Vec { self.layer_commitments.drain(..).collect() } pub fn read_remainder( &mut self, expected_commitment: &::Digest, ) -> Result, VerifierError> { let poly = self.take_fri_remainder(); let commitment = H::hash_elements(&poly); assert_eq!(&commitment, expected_commitment); // Compute remainder codeword corresponding to remainder polynomial let twiddles = fft::get_twiddles(poly.len()); let remainder = fft::evaluate_poly_with_offset(&poly, &twiddles, E::BaseField::GENERATOR, 8); Ok(remainder) } }