Skip to content

Commit 0209643

Browse files
AztecBotalejoamiras
andcommitted
fix(noir-contracts): change variable and migrate to poseidon
This is part of addressing Zac's feedback on Slack. Co-authored-by: Alejo Amiras <[email protected]>
1 parent db151be commit 0209643

File tree

1 file changed

+9
-4
lines changed
  • noir-projects/noir-contracts/contracts/app/private_voting_contract/src

1 file changed

+9
-4
lines changed

noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ pub contract PrivateVoting {
1010
keys::getters::get_public_keys,
1111
macros::{functions::{initializer, internal, private, public, utility}, storage::storage},
1212
};
13-
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Hash, ToField}};
13+
use dep::aztec::protocol_types::{
14+
address::AztecAddress,
15+
hash::poseidon2_hash,
16+
traits::{Hash, ToField},
17+
};
1418
use dep::aztec::state_vars::{Map, PublicImmutable, PublicMutable};
1519

1620
// docs:end:imports
@@ -39,10 +43,11 @@ pub contract PrivateVoting {
3943
#[private]
4044
// annotation to mark function as private and expose private context
4145
fn cast_vote(candidate: Field) {
42-
let msg_sender_npk_m_hash = get_public_keys(context.msg_sender()).npk_m.hash();
46+
let msg_sender_nullifier_public_key_message_hash =
47+
get_public_keys(context.msg_sender()).npk_m.hash();
4348

44-
let secret = context.request_nsk_app(msg_sender_npk_m_hash); // get secret key of caller of function
45-
let nullifier = std::hash::pedersen_hash([context.msg_sender().to_field(), secret]); // derive nullifier from sender and secret
49+
let secret = context.request_nsk_app(msg_sender_nullifier_public_key_message_hash); // get secret key of caller of function
50+
let nullifier = poseidon2_hash([context.msg_sender().to_field(), secret]); // derive nullifier from sender and secret
4651
context.push_nullifier(nullifier);
4752
PrivateVoting::at(context.this_address()).add_to_tally_public(candidate).enqueue(
4853
&mut context,

0 commit comments

Comments
 (0)