Skip to content

Commit

Permalink
Remove toxic_waste once its used
Browse files Browse the repository at this point in the history
Removed the toxic waste once its used.
Added assert to make sure the deletion.
  • Loading branch information
0xAdriaTorralba committed Dec 2, 2024
1 parent 8f64225 commit 6d09863
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions crypto/src/commitments/kzg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(clippy::all)]
use super::traits::IsCommitmentScheme;
use alloc::{borrow::ToOwned, vec::Vec};
use core::{marker::PhantomData, mem};
Expand Down Expand Up @@ -290,26 +291,40 @@ mod tests {
<BLS12381AtePairing as IsPairing>::G2Point,
> {
let mut rng = rand::thread_rng();
let toxic_waste = FrElement::new(U256 {
let mut toxic_waste = Some(FrElement::new(U256 {
limbs: [
rng.gen::<u64>(),
rng.gen::<u64>(),
rng.gen::<u64>(),
rng.gen::<u64>(),
],
});
let g1 = BLS12381Curve::generator();
let g2 = BLS12381TwistCurve::generator();
let powers_main_group: Vec<G1> = (0..MAX_POLYNOMIAL_DEGREE)
.map(|exponent| {
g1.operate_with_self(toxic_waste.pow(exponent as u128).representative())
})
.collect();
let powers_secondary_group = [
g2.clone(),
g2.operate_with_self(toxic_waste.representative()),
];
std::mem::drop(toxic_waste);
}));

let powers_main_group: Vec<G1> = {
let g1 = BLS12381Curve::generator();
(0..MAX_POLYNOMIAL_DEGREE)
.map(|exponent| {
let tw = toxic_waste.as_ref().expect("toxic_waste should be available");
g1.operate_with_self(tw.pow(exponent as u128).representative())
})
.collect()
};

let powers_secondary_group = {
let g2 = BLS12381TwistCurve::generator();
[
g2.clone(),
g2.operate_with_self(
toxic_waste
.as_ref()
.expect("toxic_waste should be available")
.representative(),
),
]
};

toxic_waste = None;
assert!(toxic_waste.is_none(), "toxic_waste should be poisoned");
StructuredReferenceString::new(&powers_main_group, &powers_secondary_group)
}

Expand Down

0 comments on commit 6d09863

Please sign in to comment.