@@ -7,12 +7,13 @@ use std::{
77
88use clap:: { Parser , Subcommand } ;
99use color_eyre:: { eyre:: eyre, Report , Result } ;
10+ use rln:: utils:: IdSecret ;
1011use rln:: {
1112 circuit:: Fr ,
1213 hashers:: { hash_to_field, poseidon_hash} ,
1314 protocol:: { keygen, prepare_prove_input, prepare_verify_input} ,
1415 public:: RLN ,
15- utils:: { bytes_le_to_fr , fr_to_bytes_le, generate_input_buffer} ,
16+ utils:: { fr_to_bytes_le, generate_input_buffer} ,
1617} ;
1718
1819const MESSAGE_LIMIT : u32 = 1 ;
@@ -44,7 +45,7 @@ enum Commands {
4445
4546#[ derive( Debug , Clone ) ]
4647struct Identity {
47- identity_secret_hash : Fr ,
48+ identity_secret_hash : IdSecret ,
4849 id_commitment : Fr ,
4950}
5051
@@ -103,7 +104,7 @@ impl RLNSystem {
103104 println ! ( "Registered users:" ) ;
104105 for ( index, identity) in & self . local_identities {
105106 println ! ( "User Index: {index}" ) ;
106- println ! ( "+ Identity Secret Hash: {}" , identity. identity_secret_hash) ;
107+ println ! ( "+ Identity Secret Hash: {}" , * identity. identity_secret_hash) ;
107108 println ! ( "+ Identity Commitment: {}" , identity. id_commitment) ;
108109 println ! ( ) ;
109110 }
@@ -118,7 +119,7 @@ impl RLNSystem {
118119 match self . rln . set_next_leaf ( & mut buffer) {
119120 Ok ( _) => {
120121 println ! ( "Registered User Index: {index}" ) ;
121- println ! ( "+ Identity secret hash: {}" , identity. identity_secret_hash) ;
122+ println ! ( "+ Identity secret hash: {}" , * identity. identity_secret_hash) ;
122123 println ! ( "+ Identity commitment: {}," , identity. id_commitment) ;
123124 self . local_identities . insert ( index, identity) ;
124125 }
@@ -143,7 +144,7 @@ impl RLNSystem {
143144 } ;
144145
145146 let serialized = prepare_prove_input (
146- identity. identity_secret_hash ,
147+ identity. identity_secret_hash . clone ( ) ,
147148 user_index,
148149 Fr :: from ( MESSAGE_LIMIT ) ,
149150 Fr :: from ( message_id) ,
@@ -211,7 +212,7 @@ impl RLNSystem {
211212 {
212213 Ok ( _) => {
213214 let output_data = output. into_inner ( ) ;
214- let ( leaked_identity_secret_hash, _) = bytes_le_to_fr ( & output_data) ;
215+ let ( leaked_identity_secret_hash, _) = IdSecret :: from_bytes_le ( & output_data) ;
215216
216217 if let Some ( ( user_index, identity) ) = self
217218 . local_identities
@@ -221,20 +222,21 @@ impl RLNSystem {
221222 } )
222223 . map ( |( index, identity) | ( * index, identity) )
223224 {
224- let real_identity_secret_hash = identity. identity_secret_hash ;
225+ let real_identity_secret_hash = identity. identity_secret_hash . clone ( ) ;
225226 if leaked_identity_secret_hash != real_identity_secret_hash {
226- Err ( eyre ! ( "identity secret hash mismatch { leaked_identity_secret_hash} != { real_identity_secret_hash} " ) )
227+ Err ( eyre ! ( "identity secret hash mismatch: leaked_identity_secret_hash != real_identity_secret_hash" ) )
227228 } else {
228- println ! ( "DUPLICATE message ID detected! Reveal identity secret hash: {leaked_identity_secret_hash}" ) ;
229+ println ! (
230+ "DUPLICATE message ID detected! Reveal identity secret hash: {}" ,
231+ * leaked_identity_secret_hash
232+ ) ;
229233 self . local_identities . remove ( & user_index) ;
230234 self . rln . delete_leaf ( user_index) ?;
231235 println ! ( "User index {user_index} has been SLASHED" ) ;
232236 Ok ( ( ) )
233237 }
234238 } else {
235- Err ( eyre ! (
236- "user identity secret hash {leaked_identity_secret_hash} not found"
237- ) )
239+ Err ( eyre ! ( "user identity secret hash ******** not found" ) )
238240 }
239241 }
240242 Err ( err) => Err ( eyre ! ( "Failed to recover identity secret: {err}" ) ) ,
0 commit comments