jf_plonk/transcript/
standard.rs

1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the Jellyfish library.
3
4// You should have received a copy of the MIT License
5// along with the Jellyfish library. If not, see <https://mit-license.org/>.
6
7//! This module is a wrapper of the Merlin transcript.
8use super::PlonkTranscript;
9use crate::errors::PlonkError;
10use ark_ec::pairing::Pairing;
11use ark_ff::PrimeField;
12use merlin::Transcript;
13
14/// A wrapper of `merlin::Transcript`.
15pub struct StandardTranscript(Transcript);
16
17impl<F> PlonkTranscript<F> for StandardTranscript {
18    /// create a new plonk transcript
19    fn new(label: &'static [u8]) -> Self {
20        Self(Transcript::new(label))
21    }
22
23    // append the message to the transcript
24    fn append_message(&mut self, label: &'static [u8], msg: &[u8]) -> Result<(), PlonkError> {
25        self.0.append_message(label, msg);
26
27        Ok(())
28    }
29
30    fn get_challenge<E>(&mut self, label: &'static [u8]) -> Result<E::ScalarField, PlonkError>
31    where
32        E: Pairing,
33    {
34        let mut buf = [0u8; 64];
35        self.0.challenge_bytes(label, &mut buf);
36        let challenge = E::ScalarField::from_le_bytes_mod_order(&buf);
37        Ok(challenge)
38    }
39}