jf_plonk/transcript/
standard.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2022 Espresso Systems (espressosys.com)
// This file is part of the Jellyfish library.

// You should have received a copy of the MIT License
// along with the Jellyfish library. If not, see <https://mit-license.org/>.

//! This module is a wrapper of the Merlin transcript.
use super::PlonkTranscript;
use crate::errors::PlonkError;
use ark_ec::pairing::Pairing;
use ark_ff::PrimeField;
use merlin::Transcript;

/// A wrapper of `merlin::Transcript`.
pub struct StandardTranscript(Transcript);

impl<F> PlonkTranscript<F> for StandardTranscript {
    /// create a new plonk transcript
    fn new(label: &'static [u8]) -> Self {
        Self(Transcript::new(label))
    }

    // append the message to the transcript
    fn append_message(&mut self, label: &'static [u8], msg: &[u8]) -> Result<(), PlonkError> {
        self.0.append_message(label, msg);

        Ok(())
    }

    fn get_challenge<E>(&mut self, label: &'static [u8]) -> Result<E::ScalarField, PlonkError>
    where
        E: Pairing,
    {
        let mut buf = [0u8; 64];
        self.0.challenge_bytes(label, &mut buf);
        let challenge = E::ScalarField::from_le_bytes_mod_order(&buf);
        Ok(challenge)
    }
}