Skip to content

Commit c08518e

Browse files
committed
refactor: add comments for all .zeroize() places
1 parent 3443d08 commit c08518e

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

rln/src/circuit/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ impl IdSecret {
250250
pub(crate) fn to_u256(&self) -> U256 {
251251
let mut big_int = self.0.into_bigint();
252252
let res = U256::from_limbs(big_int.0);
253-
big_int.zeroize();
253+
big_int.zeroize(); // wipe the secret limbs after copying them into the leaked U256
254254
res
255255
}
256256
}
257257

258258
impl From<&mut Fr> for IdSecret {
259259
fn from(value: &mut Fr) -> Self {
260260
let id_secret = Self(*value);
261-
value.zeroize();
261+
value.zeroize(); // clear the caller-owned source Fr after the secret moved into IdSecret
262262
id_secret
263263
}
264264
}

rln/src/protocol/keygen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn keygen() -> (IdSecret, Fr) {
1717
let identity_secret = IdSecret::rand(&mut rng);
1818
let mut to_hash = [*identity_secret.clone()];
1919
let id_commitment = poseidon_hash(&to_hash);
20-
to_hash[0].zeroize();
20+
to_hash[0].zeroize(); // wipe the identity secret copy from the stack buffer
2121
(identity_secret, id_commitment)
2222
}
2323

@@ -33,7 +33,7 @@ pub fn extended_keygen() -> (Fr, Fr, Fr, Fr) {
3333
let identity_secret = poseidon_hash_pair(identity_trapdoor, identity_nullifier);
3434
let mut to_hash = [identity_secret];
3535
let id_commitment = poseidon_hash(&to_hash);
36-
to_hash[0].zeroize();
36+
to_hash[0].zeroize(); // wipe the identity secret copy from the stack buffer
3737
(
3838
identity_trapdoor,
3939
identity_nullifier,
@@ -58,7 +58,7 @@ pub fn seeded_keygen(signal: &[u8]) -> (Fr, Fr) {
5858
let identity_secret = Fr::rand(&mut rng);
5959
let mut to_hash = [identity_secret];
6060
let id_commitment = poseidon_hash(&to_hash);
61-
to_hash[0].zeroize();
61+
to_hash[0].zeroize(); // wipe the identity secret copy from the stack buffer
6262
(identity_secret, id_commitment)
6363
}
6464

@@ -81,7 +81,7 @@ pub fn extended_seeded_keygen(signal: &[u8]) -> (Fr, Fr, Fr, Fr) {
8181
let identity_secret = poseidon_hash_pair(identity_trapdoor, identity_nullifier);
8282
let mut to_hash = [identity_secret];
8383
let id_commitment = poseidon_hash(&to_hash);
84-
to_hash[0].zeroize();
84+
to_hash[0].zeroize(); // wipe the identity secret copy from the stack buffer
8585
(
8686
identity_trapdoor,
8787
identity_nullifier,

rln/src/protocol/proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl From<&RLNWitnessInputSingle> for RLNProofValuesSingle {
144144
let a_1 = poseidon_hash(&to_hash);
145145
let y = *(a_0.clone()) + w.x * a_1;
146146
let nullifier = poseidon_hash(&[a_1]);
147-
to_hash[0].zeroize();
147+
to_hash[0].zeroize(); // wipe the identity secret copy from the stack buffer
148148
RLNProofValuesSingle {
149149
y,
150150
root,
@@ -206,7 +206,7 @@ impl From<&RLNWitnessInputMulti> for RLNProofValuesMulti {
206206
let selector = Fr::from(selected);
207207
let y = (*w.identity_secret + w.x * a_1) * selector;
208208
let nullifier = poseidon_hash(&[a_1]) * selector;
209-
to_hash[0].zeroize();
209+
to_hash[0].zeroize(); // wipe the identity secret copy from the stack buffer
210210
ys.push(y);
211211
nullifiers.push(nullifier);
212212
}

0 commit comments

Comments
 (0)