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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{util::bytes_to_field, Share};
use core::marker::PhantomData;
use ff::PrimeField;
use group::{Group, GroupEncoding, ScalarMul};
#[derive(Copy, Clone, Debug)]
pub struct FeldmanVerifier<F: PrimeField, G: Group + GroupEncoding + ScalarMul<F>, const T: usize> {
pub generator: G,
pub commitments: [G; T],
pub marker: PhantomData<F>,
}
impl<F: PrimeField, G: Group + GroupEncoding + ScalarMul<F>, const T: usize>
FeldmanVerifier<F, G, T>
{
pub fn verify<const S: usize>(&self, share: &Share<S>) -> bool {
let s = bytes_to_field::<F>(share.value());
if s.is_none().unwrap_u8() == 1 {
return false;
}
let s = s.unwrap();
let x = F::from(share.identifier() as u64);
let mut i = F::one();
let mut rhs = self.commitments[0];
for v in &self.commitments[1..] {
i *= x;
rhs += *v * i;
}
let lhs: G = -self.generator * s;
let res: G = lhs + rhs;
res.is_identity().unwrap_u8() == 1
}
}