@@ -6,13 +6,9 @@ use aztec::macros::aztec;
66pub contract ProofOfPassword {
77
88 use aztec:: {
9- macros ::{functions ::{external , initializer , internal }, storage:: storage },
9+ macros ::{functions ::{external , initializer , only_self }, storage:: storage },
1010 oracle::notes:: set_sender_for_tags ,
11- protocol_types ::{
12- address::AztecAddress ,
13- hash:: poseidon2_hash ,
14- traits ::{Serialize , ToField },
15- },
11+ protocol_types ::{address::AztecAddress , hash:: poseidon2_hash , traits ::{Serialize , ToField }},
1612 state_vars::PublicImmutable ,
1713 };
1814 use compressed_string::FieldCompressedString ;
@@ -29,30 +25,31 @@ pub contract ProofOfPassword {
2925 fn constructor (grego_coin_address : AztecAddress , password : str <31 >) {
3026 let field_compressed_str = FieldCompressedString ::from_string (password );
3127 let password_hash = poseidon2_hash (field_compressed_str .serialize ());
32- ProofOfPassword ::at (context .this_address ())
33- ._init_storage (grego_coin_address , password_hash )
34- .enqueue (&mut context );
28+ self .enqueue (ProofOfPassword ::at (self .address )._init_storage (
29+ grego_coin_address ,
30+ password_hash ,
31+ ));
3532 }
3633
3734 #[external("public")]
38- #[internal ]
35+ #[only_self ]
3936 fn _init_storage (grego_coin_address : AztecAddress , password_hash : Field ) {
40- storage .grego_coin_address .initialize (grego_coin_address );
41- storage .password_hash .initialize (password_hash );
37+ self . storage .grego_coin_address .initialize (grego_coin_address );
38+ self . storage .password_hash .initialize (password_hash );
4239 }
4340
4441 #[external("private")]
4542 fn check_password_and_mint (password : str <31 >, to : AztecAddress ) {
4643 let field_compressed_str = FieldCompressedString ::from_string (password );
47- let password_hash = storage .password_hash .read ();
44+ let password_hash = self . storage .password_hash .read ();
4845 assert (
4946 poseidon2_hash (field_compressed_str .serialize ()) == password_hash ,
5047 f"Invalid password { password} " ,
5148 );
5249
5350 // Safety: PXE will enforce a sender for the tags of the notes created
5451 // in the Token.mint function, but this one intented to be called by anyone
55- // that knows the passord, not necessarily the recipient. Chances are this fn
52+ // that knows the passord, not necessarily the recipient. Chances are this fn
5653 // will be invoked by the MultiCallEntrypoint protocol contract,
5754 // which does not set a sender for tags.
5855 // We intend the "to" of this function to claim the notes, so we're just calling
@@ -61,13 +58,13 @@ pub contract ProofOfPassword {
6158 set_sender_for_tags (to );
6259 }
6360
64- let address = storage .grego_coin_address .read ();
65- Token ::at (address ).mint_to_private (to , 1000 ). call (& mut context );
61+ let address = self . storage .grego_coin_address .read ();
62+ self . call ( Token ::at (address ).mint_to_private (to , 1000 ));
6663
67- // Derive nullifier from sender and password. This is still a privacy leak, since
64+ // Derive nullifier from sender and password. This is still a privacy leak, since
6865 // knowing the password and an address is sufficient to know if someone has used this
6966 // contract or not. But at least, they need the password
70- let nullifier = poseidon2_hash ([to .to_field (), field_compressed_str .serialize ()[0 ]]);
71- context .push_nullifier (nullifier );
67+ let nullifier = poseidon2_hash ([to .to_field (), field_compressed_str .serialize ()[0 ]]);
68+ self . context .push_nullifier (nullifier );
7269 }
7370}
0 commit comments