lambdaworks_crypto/fiat_shamir/
is_transcript.rs

1use lambdaworks_math::{
2    field::{
3        element::FieldElement,
4        traits::{IsField, IsSubFieldOf},
5    },
6    traits::AsBytes,
7};
8
9/// The functionality of a transcript to be used in the STARK Prove and Verify protocols.
10pub trait IsTranscript<F: IsField> {
11    /// Appends a field element to the transcript.
12    fn append_field_element(&mut self, element: &FieldElement<F>);
13    /// Appends a bytes to the transcript.
14    fn append_bytes(&mut self, new_bytes: &[u8]);
15    /// Returns the inner state of the transcript that fully determines its outputs.
16    fn state(&self) -> [u8; 32];
17    /// Returns a random field element.
18    fn sample_field_element(&mut self) -> FieldElement<F>;
19    /// Returns a random index between 0 and `upper_bound`.
20    fn sample_u64(&mut self, upper_bound: u64) -> u64;
21    /// Returns a field element not contained in `lde_roots_of_unity_coset` or `trace_roots_of_unity`.
22    fn sample_z_ood<S: IsSubFieldOf<F>>(
23        &mut self,
24        lde_roots_of_unity_coset: &[FieldElement<S>],
25        trace_roots_of_unity: &[FieldElement<S>],
26    ) -> FieldElement<F>
27    where
28        FieldElement<F>: AsBytes,
29    {
30        loop {
31            let value: FieldElement<F> = self.sample_field_element();
32            if !lde_roots_of_unity_coset
33                .iter()
34                .any(|x| x.clone().to_extension() == value)
35                && !trace_roots_of_unity
36                    .iter()
37                    .any(|x| x.clone().to_extension() == value)
38            {
39                return value;
40            }
41        }
42    }
43}