22
33use crate :: circuit:: { calculate_rln_witness, qap:: CircomReduction , Curve } ;
44use crate :: error:: { ComputeIdSecretError , ConversionError , ProofError , ProtocolError } ;
5- use crate :: hashers:: { hash_to_field, poseidon_hash, poseidon_hash_mut } ;
5+ use crate :: hashers:: { hash_to_field, poseidon_hash} ;
66use crate :: poseidon_tree:: { MerkleProof , PoseidonTree } ;
77use crate :: public:: RLN_IDENTIFIER ;
88use crate :: utils:: {
@@ -298,13 +298,14 @@ pub fn proof_values_from_witness(
298298 message_id_range_check ( & rln_witness. message_id , & rln_witness. user_message_limit ) ?;
299299
300300 // y share
301- let mut a_0: Fr = * rln_witness. identity_secret ;
302- let a_1 = poseidon_hash ( & [ a_0, rln_witness. external_nullifier , rln_witness. message_id ] ) ;
303- let y = a_0 + rln_witness . x * a_1 ;
304- a_0. zeroize ( ) ;
301+ let a_0 = & rln_witness. identity_secret ;
302+ let mut to_hash = [ * ( a_0. clone ( ) ) , rln_witness. external_nullifier , rln_witness. message_id ] ;
303+ let a_1 = poseidon_hash ( & to_hash ) ;
304+ let y = * ( a_0. clone ( ) ) + rln_witness . x * a_1 ;
305305
306306 // Nullifier
307307 let nullifier = poseidon_hash ( & [ a_1] ) ;
308+ to_hash[ 0 ] . zeroize ( ) ;
308309
309310 // Merkle tree root computations
310311 let root = compute_tree_root (
@@ -421,7 +422,10 @@ pub fn compute_tree_root(
421422 path_elements : & [ Fr ] ,
422423 identity_path_index : & [ u8 ] ,
423424) -> Fr {
424- let id_commitment = poseidon_hash_mut ( & mut [ * * identity_secret] ) ;
425+ let mut to_hash = [ * identity_secret. clone ( ) ] ;
426+ let id_commitment = poseidon_hash ( & to_hash) ;
427+ to_hash[ 0 ] . zeroize ( ) ;
428+
425429 let mut root = poseidon_hash ( & [ id_commitment, * user_message_limit] ) ;
426430
427431 for i in 0 ..identity_path_index. len ( ) {
@@ -445,7 +449,9 @@ pub fn compute_tree_root(
445449pub fn keygen ( ) -> ( IdSecret , Fr ) {
446450 let mut rng = thread_rng ( ) ;
447451 let identity_secret_hash = IdSecret :: rand ( & mut rng) ;
448- let id_commitment = poseidon_hash_mut ( & mut [ * identity_secret_hash] ) ;
452+ let mut to_hash = [ * identity_secret_hash. clone ( ) ] ;
453+ let id_commitment = poseidon_hash ( & to_hash) ;
454+ to_hash[ 0 ] . zeroize ( ) ;
449455 ( identity_secret_hash, id_commitment)
450456}
451457
0 commit comments