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
use group::{ff::PrimeField, Group, GroupEncoding};

use crate::{
    plugins::{bytes_modp, bytes_uniform_modp},
    ByteIOPattern, DuplexHash, IOPattern,
};

use super::{FieldIOPattern, GroupIOPattern};

impl<F, H> FieldIOPattern<F> for IOPattern<H>
where
    F: PrimeField,
    H: DuplexHash,
{
    fn add_scalars(self, count: usize, label: &str) -> Self {
        self.add_bytes(count * bytes_modp(F::NUM_BITS), label)
    }

    fn challenge_scalars(self, count: usize, label: &str) -> Self {
        self.challenge_bytes(count * bytes_uniform_modp(F::NUM_BITS), label)
    }
}

impl<G, H> GroupIOPattern<G> for IOPattern<H>
where
    G: Group + GroupEncoding,
    G::Repr: AsRef<[u8]>,
    H: DuplexHash,
{
    fn add_points(self, count: usize, label: &str) -> Self {
        let n = G::Repr::default().as_ref().len();
        self.add_bytes(count * n, label)
    }
}