Simplify range proof verification syntax for merged transfer
This commit is contained in:
parent
a5d1efc207
commit
db69128825
|
@ -50,16 +50,14 @@ impl RangeProof {
|
||||||
let t_1_blinding = PedersenOpening::random(&mut OsRng);
|
let t_1_blinding = PedersenOpening::random(&mut OsRng);
|
||||||
let t_2_blinding = PedersenOpening::random(&mut OsRng);
|
let t_2_blinding = PedersenOpening::random(&mut OsRng);
|
||||||
|
|
||||||
let (range_proof, _, _) = Self::create_with(
|
Self::create_with(
|
||||||
amounts,
|
amounts,
|
||||||
bit_lengths,
|
bit_lengths,
|
||||||
opens,
|
opens,
|
||||||
&t_1_blinding,
|
&t_1_blinding,
|
||||||
&t_2_blinding,
|
&t_2_blinding,
|
||||||
transcript,
|
transcript,
|
||||||
);
|
)
|
||||||
|
|
||||||
range_proof
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::many_single_char_names)]
|
#[allow(clippy::many_single_char_names)]
|
||||||
|
@ -71,7 +69,7 @@ impl RangeProof {
|
||||||
t_1_blinding: &PedersenOpening,
|
t_1_blinding: &PedersenOpening,
|
||||||
t_2_blinding: &PedersenOpening,
|
t_2_blinding: &PedersenOpening,
|
||||||
transcript: &mut Transcript,
|
transcript: &mut Transcript,
|
||||||
) -> (Self, Scalar, Scalar) {
|
) -> Self {
|
||||||
let nm = bit_lengths.iter().sum();
|
let nm = bit_lengths.iter().sum();
|
||||||
|
|
||||||
// Computing the generators online for now. It should ultimately be precomputed.
|
// Computing the generators online for now. It should ultimately be precomputed.
|
||||||
|
@ -195,7 +193,7 @@ impl RangeProof {
|
||||||
transcript,
|
transcript,
|
||||||
);
|
);
|
||||||
|
|
||||||
let range_proof = RangeProof {
|
RangeProof {
|
||||||
A: A.compress(),
|
A: A.compress(),
|
||||||
S: S.compress(),
|
S: S.compress(),
|
||||||
T_1,
|
T_1,
|
||||||
|
@ -204,9 +202,7 @@ impl RangeProof {
|
||||||
t_x_blinding,
|
t_x_blinding,
|
||||||
e_blinding,
|
e_blinding,
|
||||||
ipp_proof,
|
ipp_proof,
|
||||||
};
|
}
|
||||||
|
|
||||||
(range_proof, x, z)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::many_single_char_names)]
|
#[allow(clippy::many_single_char_names)]
|
||||||
|
@ -216,18 +212,23 @@ impl RangeProof {
|
||||||
bit_lengths: Vec<usize>,
|
bit_lengths: Vec<usize>,
|
||||||
transcript: &mut Transcript,
|
transcript: &mut Transcript,
|
||||||
) -> Result<(), ProofError> {
|
) -> Result<(), ProofError> {
|
||||||
self.verify_with(comms, bit_lengths, None, None, transcript)
|
if self
|
||||||
|
.verify_challenges(comms, bit_lengths, transcript)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(ProofError::VerificationError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::many_single_char_names)]
|
#[allow(clippy::many_single_char_names)]
|
||||||
pub fn verify_with(
|
pub fn verify_challenges(
|
||||||
&self,
|
&self,
|
||||||
comms: Vec<&CompressedRistretto>,
|
comms: Vec<&CompressedRistretto>,
|
||||||
bit_lengths: Vec<usize>,
|
bit_lengths: Vec<usize>,
|
||||||
x_ver: Option<Scalar>,
|
|
||||||
z_ver: Option<Scalar>,
|
|
||||||
transcript: &mut Transcript,
|
transcript: &mut Transcript,
|
||||||
) -> Result<(), ProofError> {
|
) -> Result<(Scalar, Scalar), ProofError> {
|
||||||
let G = PedersenBase::default().G;
|
let G = PedersenBase::default().G;
|
||||||
let H = PedersenBase::default().H;
|
let H = PedersenBase::default().H;
|
||||||
|
|
||||||
|
@ -245,10 +246,6 @@ impl RangeProof {
|
||||||
let y = transcript.challenge_scalar(b"y");
|
let y = transcript.challenge_scalar(b"y");
|
||||||
let z = transcript.challenge_scalar(b"z");
|
let z = transcript.challenge_scalar(b"z");
|
||||||
|
|
||||||
if z_ver.is_some() && z_ver.unwrap() != z {
|
|
||||||
return Err(ProofError::VerificationError);
|
|
||||||
}
|
|
||||||
|
|
||||||
let zz = z * z;
|
let zz = z * z;
|
||||||
let minus_z = -z;
|
let minus_z = -z;
|
||||||
|
|
||||||
|
@ -257,10 +254,6 @@ impl RangeProof {
|
||||||
|
|
||||||
let x = transcript.challenge_scalar(b"x");
|
let x = transcript.challenge_scalar(b"x");
|
||||||
|
|
||||||
if x_ver.is_some() && x_ver.unwrap() != x {
|
|
||||||
return Err(ProofError::VerificationError);
|
|
||||||
}
|
|
||||||
|
|
||||||
transcript.append_scalar(b"t_x", &self.t_x);
|
transcript.append_scalar(b"t_x", &self.t_x);
|
||||||
transcript.append_scalar(b"t_x_blinding", &self.t_x_blinding);
|
transcript.append_scalar(b"t_x_blinding", &self.t_x_blinding);
|
||||||
transcript.append_scalar(b"e_blinding", &self.e_blinding);
|
transcript.append_scalar(b"e_blinding", &self.e_blinding);
|
||||||
|
@ -325,7 +318,7 @@ impl RangeProof {
|
||||||
.ok_or(ProofError::VerificationError)?;
|
.ok_or(ProofError::VerificationError)?;
|
||||||
|
|
||||||
if mega_check.is_identity() {
|
if mega_check.is_identity() {
|
||||||
Ok(())
|
Ok((z, x))
|
||||||
} else {
|
} else {
|
||||||
Err(ProofError::VerificationError)
|
Err(ProofError::VerificationError)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue