-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifier_challenger.rs
58 lines (49 loc) · 1.92 KB
/
verifier_challenger.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use ark_crypto_primitives::sponge::poseidon::PoseidonConfig;
use ark_crypto_primitives::sponge::poseidon::PoseidonSponge;
use ark_crypto_primitives::sponge::Absorb;
use ark_crypto_primitives::sponge::CryptographicSponge;
use ark_ec::AffineRepr;
use ark_ec::CurveGroup;
use ark_ec::Group;
use ark_ff::Field;
use ark_ff::PrimeField;
use std::fmt::Debug;
use super::BulletproofRecProof;
pub struct DefaultVerifierChallenger;
#[derive(Clone, Debug)]
pub struct BulletproofVerifierChallenge<S: Field + Clone> {
pub random_challenge: S,
}
pub trait VerifierChallenger<S: Field + Clone, G: Group<ScalarField = S> + Clone> {
fn generate_challenge(&self, proof: &BulletproofRecProof<S, G>) -> S;
}
impl<S, G> VerifierChallenger<S, G> for DefaultVerifierChallenger
where
S: PrimeField + Absorb + Clone,
G: CurveGroup<ScalarField = S, BaseField = S> + Clone,
G::Affine: Absorb ,
{
fn generate_challenge(&self, proof: &BulletproofRecProof<S, G>) -> S {
// Obtain Poseidon parameters for field S
let params = PoseidonConfig::<S>::new(
8, // full_rounds
57, // partial_rounds
5, // alpha (exponent)
vec![vec![S::one(); 3]; 3], // mds matrix (placeholder)
vec![vec![S::zero(); 3]; 65], // ark (placeholder)
2, // rate
1 // capacity
);
let mut sponge = PoseidonSponge::<S>::new(¶ms);
let pedersen_commitment_affine = proof.pedersen_commitment.into_affine();
sponge.absorb(&pedersen_commitment_affine.x());
sponge.absorb(&pedersen_commitment_affine.y());
let l_value_affine = proof.l_value.into_affine();
sponge.absorb(&l_value_affine.x());
sponge.absorb(&l_value_affine.y());
let r_value_affine = proof.r_value.into_affine();
sponge.absorb(&r_value_affine.x());
sponge.absorb(&r_value_affine.y());
sponge.squeeze_field_elements(1)[0]
}
}