Skip to content

Commit 6256342

Browse files
authored
fix(noir-contracts): remove easy reference from voting contract (#16619)
This is part of addressing Zac's feedback on Slack.
2 parents 94e0477 + af16f24 commit 6256342

File tree

19 files changed

+64
-65
lines changed

19 files changed

+64
-65
lines changed

boxes/boxes/vanilla/app/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type AccountWallet,
77
} from '@aztec/aztec.js';
88
import { EmbeddedWallet } from './embedded-wallet';
9-
import { EasyPrivateVotingContract } from '../artifacts/EasyPrivateVoting';
9+
import { PrivateVotingContract } from '../artifacts/PrivateVoting';
1010

1111
// DOM Elements
1212
const createAccountButton =
@@ -45,7 +45,7 @@ document.addEventListener('DOMContentLoaded', async () => {
4545
// Register voting contract with wallet/PXE
4646
displayStatusMessage('Registering contracts...');
4747
await wallet.registerContract(
48-
EasyPrivateVotingContract.artifact,
48+
PrivateVotingContract.artifact,
4949
AztecAddress.fromString(deployerAddress),
5050
Fr.fromString(deploymentSalt),
5151
[AztecAddress.fromString(deployerAddress)]
@@ -145,7 +145,7 @@ voteButton.addEventListener('click', async (e) => {
145145
}
146146

147147
// Prepare contract interaction
148-
const votingContract = await EasyPrivateVotingContract.at(
148+
const votingContract = await PrivateVotingContract.at(
149149
AztecAddress.fromString(contractAddress),
150150
connectedAccount
151151
);
@@ -177,7 +177,7 @@ async function updateVoteTally(account: Wallet) {
177177
displayStatusMessage('Updating vote tally...');
178178

179179
// Prepare contract interaction
180-
const votingContract = await EasyPrivateVotingContract.at(
180+
const votingContract = await PrivateVotingContract.at(
181181
AztecAddress.fromString(contractAddress),
182182
account
183183
);

boxes/boxes/vanilla/contracts/src/main.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use dep::aztec::macros::aztec;
22

33
#[aztec]
4-
pub contract EasyPrivateVoting {
4+
pub contract PrivateVoting {
55
use dep::aztec::keys::getters::get_public_keys;
66
use dep::aztec::macros::{
77
functions::{initializer, internal, private, public, utility},
@@ -33,7 +33,7 @@ pub contract EasyPrivateVoting {
3333
let secret = context.request_nsk_app(msg_sender_npk_m_hash); // get secret key of caller of function
3434
let nullifier = std::hash::pedersen_hash([context.msg_sender().to_field(), secret]); // derive nullifier from sender and secret
3535
context.push_nullifier(nullifier);
36-
EasyPrivateVoting::at(context.this_address()).add_to_tally_public(candidate).enqueue(
36+
PrivateVoting::at(context.this_address()).add_to_tally_public(candidate).enqueue(
3737
&mut context,
3838
);
3939
}

boxes/boxes/vanilla/scripts/deploy.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { getDefaultInitializer } from '@aztec/stdlib/abi';
1818
import { SponsoredFPCContractArtifact } from '@aztec/noir-contracts.js/SponsoredFPC';
1919
import { SPONSORED_FPC_SALT } from '@aztec/constants';
2020
// @ts-ignore
21-
import { EasyPrivateVotingContract } from '../artifacts/EasyPrivateVoting.ts';
21+
import { PrivateVotingContract } from '../artifacts/PrivateVoting.ts';
2222

2323
const AZTEC_NODE_URL = process.env.AZTEC_NODE_URL || 'http://localhost:8080';
2424
const PROVER_ENABLED = process.env.PROVER_ENABLED === 'false' ? false : true;
@@ -96,11 +96,11 @@ async function createAccount(pxe: PXE) {
9696
async function deployContract(pxe: PXE, deployer: Wallet) {
9797
const salt = Fr.random();
9898
const contract = await getContractInstanceFromInstantiationParams(
99-
EasyPrivateVotingContract.artifact,
99+
PrivateVotingContract.artifact,
100100
{
101101
publicKeys: PublicKeys.default(),
102102
constructorArtifact: getDefaultInitializer(
103-
EasyPrivateVotingContract.artifact
103+
PrivateVotingContract.artifact
104104
),
105105
constructorArgs: [deployer.getAddress().toField()],
106106
deployer: deployer.getAddress(),
@@ -111,11 +111,11 @@ async function deployContract(pxe: PXE, deployer: Wallet) {
111111
const deployMethod = new DeployMethod(
112112
contract.publicKeys,
113113
deployer,
114-
EasyPrivateVotingContract.artifact,
114+
PrivateVotingContract.artifact,
115115
(address: AztecAddress, wallet: Wallet) =>
116-
EasyPrivateVotingContract.at(address, wallet),
116+
PrivateVotingContract.at(address, wallet),
117117
[deployer.getAddress().toField()],
118-
getDefaultInitializer(EasyPrivateVotingContract.artifact)?.name
118+
getDefaultInitializer(PrivateVotingContract.artifact)?.name
119119
);
120120

121121
const sponsoredPFCContract = await getSponsoredPFCContract();
@@ -132,7 +132,7 @@ async function deployContract(pxe: PXE, deployer: Wallet) {
132132
await provenInteraction.send().wait({ timeout: 120 });
133133
await pxe.registerContract({
134134
instance: contract,
135-
artifact: EasyPrivateVotingContract.artifact,
135+
artifact: PrivateVotingContract.artifact,
136136
});
137137

138138
return {

docs/docs/developers/guides/smart_contracts/profiling_transactions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ For example, if you want to flamegraph the `cast_vote` function [aztec-starter](
9292
```bash
9393
aztec-nargo compile # generate contract artifacts
9494
aztec-postprocess-contract # transpile contract and generate verification keys
95-
aztec flamegraph target/easy_private_voting_contract-EasyPrivateVoting.json cast_vote
95+
aztec flamegraph target/private_voting_contract-PrivateVoting.json cast_vote
9696
```
9797

9898
This will generate a flamegraph of the `cast_vote` function and save the output svg to the `target` directory. You can open the svg file in your browser to visualize the flamegraph.
9999

100100
You can also run the same command with `SERVE=1` to serve the flamegraph on a local server.
101101

102102
```bash
103-
SERVE=1 aztec flamegraph target/easy_private_voting_contract-EasyPrivateVoting.json cast_vote
103+
SERVE=1 aztec flamegraph target/private_voting_contract-PrivateVoting.json cast_vote
104104
```
105105

106106
This will serve the flamegraph on `http://localhost:8000`.

docs/docs/developers/guides/smart_contracts/writing_contracts/common_patterns/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,4 @@ E.g. for a voting contract, if your nullifier simply emits just the `user_addres
151151

152152
Here is an example from the voting contract:
153153

154-
#include_code cast_vote /noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
154+
#include_code cast_vote /noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust

docs/docs/developers/guides/smart_contracts/writing_contracts/index.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ To write a contract:
1313
1. Import aztec.nr and declare your contract
1414

1515
```rust
16-
#include_code declaration /noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr raw
16+
#include_code declaration /noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr raw
1717
```
1818

1919
2. Define imports in your contract block
2020

21-
#include_code imports /noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
21+
#include_code imports /noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
2222

2323
3. Declare your contract storage below your imports
2424

25-
#include_code storage_struct /noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
25+
#include_code storage_struct /noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
2626

2727
4. Declare a constructor with `#[initializer]`. Constructors can be private or public functions.
2828

29-
#include_code constructor /noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
29+
#include_code constructor /noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
3030

3131
5. Declare your contract functions
3232

33-
#include_code cast_vote /noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
33+
#include_code cast_vote /noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
3434

3535
There is a lot more detail and nuance to writing contracts, but this should give you a good starting point.
3636
Read contents of this section for more details about authorizing contract to act on your behalf (authenticaion witnesses),

docs/docs/developers/reference/environment_reference/sandbox-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ CounterContractArtifact
119119
CrowdfundingContractArtifact
120120
DocsExampleContractArtifact
121121
EasyPrivateTokenContractArtifact
122-
EasyPrivateVotingContractArtifact
122+
PrivateVotingContractArtifact
123123
EcdsaAccountContractArtifact
124124
EscrowContractArtifact
125125
FPCContractArtifact

docs/docs/developers/tutorials/contract_tutorials/private_voting_contract.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_
5959
Go to `main.nr` and delete the sample code. Replace it with this contract initialization:
6060

6161
```rust
62-
#include_code declaration noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr raw
62+
#include_code declaration noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr raw
6363
}
6464
```
6565

6666
This defines a contract called `Voter`. Everything will sit inside this block.
6767

6868
Inside this, paste these imports:
6969

70-
#include_code imports noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
70+
#include_code imports noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
7171

7272
We are using various utils within the Aztec `prelude` library:
7373

@@ -93,7 +93,7 @@ We are using various utils within the Aztec `prelude` library:
9393
Under these imports, we need to set up our contract storage.
9494
Define the storage struct like so:
9595

96-
#include_code storage_struct noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
96+
#include_code storage_struct noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
9797

9898
In this contract, we will store three vars:
9999

@@ -106,7 +106,7 @@ In this contract, we will store three vars:
106106

107107
The next step is to initialize the contract with a constructor. The constructor will take an address as a parameter and set the admin.
108108

109-
#include_code constructor noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
109+
#include_code constructor noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
110110

111111
This function takes the admin argument and writes it to the storage. We are also using this function to set the `vote_ended` boolean as false in the same way.
112112

@@ -122,7 +122,7 @@ To ensure someone only votes once, we will create a nullifier as part of the fun
122122

123123
Create a private function called `cast_vote`:
124124

125-
#include_code cast_vote noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
125+
#include_code cast_vote noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
126126

127127
In this function, we do not create a nullifier with the address directly. This would leak privacy as it would be easy to reverse-engineer. We must add some randomness or some form of secret, like nullifier secrets.
128128

@@ -132,7 +132,7 @@ After pushing the nullifier, we update the `tally` to reflect this vote. As we k
132132

133133
Create this new public function like this:
134134

135-
#include_code add_to_tally_public noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
135+
#include_code add_to_tally_public noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
136136

137137
The first thing we do here is assert that the vote has not ended.
138138

@@ -144,7 +144,7 @@ The code after the assertion will only run if the assertion is true. In this sni
144144

145145
We will create a function that anyone can call that will return the number of votes at a given vote Id. Paste this in your contract:
146146

147-
#include_code get_vote noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
147+
#include_code get_vote noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
148148

149149
We set it as `utility` because we don't intend to call this as part of a transaction: we want to call it from our application code to e.g. display the result in a UI.
150150

@@ -154,7 +154,7 @@ To ensure that only an `admin` can end a voting period, we can use another `asse
154154

155155
Paste this function in your contract:
156156

157-
#include_code end_vote noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/src/main.nr rust
157+
#include_code end_vote noir-projects/noir-contracts/contracts/app/private_voting_contract/src/main.nr rust
158158

159159
Here, we are asserting that the `msg_sender()` is equal to the `admin` stored in public state.
160160

noir-projects/noir-contracts/Nargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ members = [
1313
"contracts/app/claim_contract",
1414
"contracts/app/crowdfunding_contract",
1515
"contracts/app/easy_private_token_contract",
16-
"contracts/app/easy_private_voting_contract",
16+
"contracts/app/private_voting_contract",
1717
"contracts/app/escrow_contract",
1818
"contracts/app/lending_contract",
1919
"contracts/app/nft_contract",

noir-projects/noir-contracts/contracts/app/easy_private_voting_contract/Nargo.toml renamed to noir-projects/noir-contracts/contracts/app/private_voting_contract/Nargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "easy_private_voting_contract"
2+
name = "private_voting_contract"
33
authors = [""]
44
compiler_version = ">=0.25.0"
55
type = "contract"

0 commit comments

Comments
 (0)