Add debug assertions to CLSAG/Bulletproofs proving

This commit is contained in:
Luke Parker 2022-12-01 11:50:03 -05:00
parent f0957c8d52
commit 0350cd803d
No known key found for this signature in database
3 changed files with 18 additions and 8 deletions

View file

@ -42,7 +42,8 @@ impl OriginalStruct {
let (logMN, M, MN) = MN(commitments.len());
let (aL, aR) = bit_decompose(commitments);
let (mut cache, _) = hash_commitments(commitments.iter().map(Commitment::calculate));
let commitments_points = commitments.iter().map(Commitment::calculate).collect::<Vec<_>>();
let (mut cache, _) = hash_commitments(commitments_points.clone());
let (sL, sR) =
ScalarVector((0 .. (MN * 2)).map(|_| Scalar::random(&mut *rng)).collect::<Vec<_>>()).split();
@ -74,7 +75,7 @@ impl OriginalStruct {
let t2 = inner_product(&l1, &r1);
let mut tau1 = Scalar::random(&mut *rng);
let mut tau2 = Scalar::random(rng);
let mut tau2 = Scalar::random(&mut *rng);
let T1 = prove_multiexp(&[(t1, *H), (tau1, EdwardsPoint::generator())]);
let T2 = prove_multiexp(&[(t2, *H), (tau2, EdwardsPoint::generator())]);
@ -146,7 +147,7 @@ impl OriginalStruct {
}
}
OriginalStruct {
let res = OriginalStruct {
A: *A,
S: *S,
T1: *T1,
@ -158,7 +159,9 @@ impl OriginalStruct {
a: *a[0],
b: *b[0],
t: *t,
}
};
debug_assert!(res.verify(rng, &commitments_points));
res
}
#[must_use]

View file

@ -60,7 +60,8 @@ impl PlusStruct {
let (logMN, M, MN) = MN(commitments.len());
let (aL, aR) = bit_decompose(commitments);
let (mut cache, _) = hash_plus(commitments.iter().map(Commitment::calculate));
let commitments_points = commitments.iter().map(Commitment::calculate).collect::<Vec<_>>();
let (mut cache, _) = hash_plus(commitments_points.clone());
let (mut alpha1, A) = alpha_rho(&mut *rng, &GENERATORS, &aL, &aR);
let y = hash_cache(&mut cache, &[A.compress().to_bytes()]);
@ -132,7 +133,7 @@ impl PlusStruct {
let mut r = Scalar::random(&mut *rng);
let mut s = Scalar::random(&mut *rng);
let mut d = Scalar::random(&mut *rng);
let mut eta = Scalar::random(rng);
let mut eta = Scalar::random(&mut *rng);
let A1 = prove_multiexp(&[
(r, G_proof[0]),
@ -152,7 +153,7 @@ impl PlusStruct {
eta.zeroize();
alpha1.zeroize();
PlusStruct {
let res = PlusStruct {
A: *A,
A1: *A1,
B: *B,
@ -161,7 +162,9 @@ impl PlusStruct {
d1: *d1,
L: L.drain(..).map(|L| *L).collect(),
R: R.drain(..).map(|R| *R).collect(),
}
};
debug_assert!(res.verify(rng, &commitments_points));
res
}
#[must_use]

View file

@ -265,6 +265,10 @@ impl Clsag {
inputs[i].0.zeroize();
nonce.zeroize();
debug_assert!(clsag
.verify(&inputs[i].2.decoys.ring, &inputs[i].1, &pseudo_out, &msg)
.is_ok());
res.push((clsag, pseudo_out));
}