Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(docs): update documents according to code refactoring #942

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/contracts/MACI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@
mapping(uint256 => uint256) public numStateLeaves;

/// @notice ERC20 contract that hold topup credits
TopupCredit public immutable topupCredit;

Check warning on line 48 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice Factory contract that deploy a Poll contract
IPollFactory public immutable pollFactory;

Check warning on line 51 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice Factory contract that deploy a MessageProcessor contract
IMessageProcessorFactory public immutable messageProcessorFactory;

Check warning on line 54 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice Factory contract that deploy a Tally contract
ITallySubsidyFactory public immutable tallyFactory;

Check warning on line 57 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice Factory contract that deploy a Subsidy contract
ITallySubsidyFactory public immutable subsidyFactory;

Check warning on line 60 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice The state AccQueue. Represents a mapping between each user's public key
/// and their voice credit balance.
AccQueue public immutable stateAq;

Check warning on line 64 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice Address of the SignUpGatekeeper, a contract which determines whether a
/// user may sign up to vote
SignUpGatekeeper public immutable signUpGatekeeper;

Check warning on line 68 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice The contract which provides the values of the initial voice credit
/// balance per user
InitialVoiceCreditProxy public immutable initialVoiceCreditProxy;

Check warning on line 72 in contracts/contracts/MACI.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice A struct holding the addresses of poll, mp and tally
struct PollContracts {
Expand Down Expand Up @@ -104,6 +104,7 @@
/// @param _subsidyFactory The SubsidyFactory contract
/// @param _signUpGatekeeper The SignUpGatekeeper contract
/// @param _initialVoiceCreditProxy The InitialVoiceCreditProxy contract
/// @param _topupCredit The TopupCredit contract
/// @param _stateTreeDepth The depth of the state tree
constructor(
IPollFactory _pollFactory,
Expand Down
8 changes: 4 additions & 4 deletions website/versioned_docs/version-v1.x/circuits.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ The hash is computed using the `sha256` Solidity function and is then subject to
| 4th 50 bits | `numSignUps` |
| 5th 50 bits | `batchStartIndex` |

`numSignUps`, a value provided by the contract, is the number of users who have signed up. This is one less than the number of leaves inserted in the state tree (since the 0th state leaf is a blank state leaf [2.8.1]). `batchStartIndex` is the ballot tree index at which the batch begins.
`numSignUps`, a value provided by the contract, is the number of users who have signed up. This is one less than the number of leaves inserted in the state tree (since the 0th state leaf is a [blank state leaf](./primitives#state-leaf)). `batchStartIndex` is the ballot tree index at which the batch begins.

For instance, if `numSignUps` is 25 and the batch index is `5`, and all other values are 0, the following is the `packedVals` representation in hexadecimal:

Expand All @@ -241,11 +241,11 @@ The commitment to `stateRoot`, `ballotRoot`, and `sbSalt`:

$poseidon_3([stateRoot, ballotRoot, sbSalt])$

Proving preimage of `sbCommitment` is one out of the several steps required to prove that the votes were tallied correctly. By establishing that the coordinator knows `ballotRoot`, the coordinator can (using other parts of the circuit) prove that that they know the preimage of the ballot leaves in the batch being tallied.
Proving preimage of `sbCommitment` is one out of the several steps required to prove that the votes were tallied correctly. By establishing that the coordinator knows `ballotRoot`, the coordinator can (using other parts of the circuit) prove that they know the preimage of the ballot leaves in the batch being tallied.

##### `currentTallyCommitment` and `newTallyCommitment`

A tally is represented by a _tally commitment_, which is the poseidon_3$ hash of:
A tally is represented by a _tally commitment_, which is the $poseidon_3$ hash of:

1. $tc_r$: a commitment to the votes per option
- This is the hash of the Merkle root $r_r$ of the votes and a salt $r_s$, computed as $poseidon_2([r_r, r_s])$
Expand Down Expand Up @@ -354,7 +354,7 @@ Utility circuit used to validate a message. This performs several checks:
- `stateTreeIndex` is valid
- `voteOptionIndex` is valid
- `nonce` is valid
- the signatuer is valid
- the signature is valid
- the user signed up before poll end timestamp
- the user had enough voice credits

Expand Down
16 changes: 8 additions & 8 deletions website/versioned_docs/version-v1.x/cli.md

Large diffs are not rendered by default.

88 changes: 15 additions & 73 deletions website/versioned_docs/version-v1.x/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ The constructor shown below accepts three arguments, a `PollFactory` contract, a
constructor(
PollFactory _pollFactory,
SignUpGatekeeper _signUpGatekeeper,
InitialVoiceCreditProxy _initialVoiceCreditProxy
InitialVoiceCreditProxy _initialVoiceCreditProxy,
TopupCredit _topupCredit,
uint8 _stateTreeDepth
) {
// Deploy the state AccQueue
stateAq = new AccQueueQuinaryBlankSl(STATE_TREE_SUBDEPTH);
stateAq.enqueue(BLANK_STATE_LEAF_HASH);

pollFactory = _pollFactory;
topupCredit = _topupCredit;
signUpGatekeeper = _signUpGatekeeper;
initialVoiceCreditProxy = _initialVoiceCreditProxy;
stateTreeDepth = _stateTreeDepth;

// Verify linked poseidon libraries
require(
Expand All @@ -45,63 +49,6 @@ Should this be changed, it will be necessary to amend the `contracts/ts/genEmpty

After this, the contracts will be stored to state, the current time taken and then the contract will perform a simple sanity check to ensure that the Poseidon hash libraries were linked successfully.

Once the contract is deployed, the owner (set as the deployer address of MACI), is required to call the `init` function, which is shown below:

```javascript
function init(
VkRegistry _vkRegistry,
MessageAqFactory _messageAqFactory,
TopupCredit _topupCredit
) public onlyOwner {
require(!isInitialised, "MACI: already initialised");

isInitialised = true;

vkRegistry = _vkRegistry;
messageAqFactory = _messageAqFactory;
topupCredit = _topupCredit;

// Check that the factory contracts have correct access controls before
// allowing any functions in MACI to run (via the afterInit modifier)
require(
pollFactory.owner() == address(this),
"MACI: PollFactory owner incorrectly set"
);

// The PollFactory needs to store the MessageAqFactory address
pollFactory.setMessageAqFactory(messageAqFactory);

// The MessageAQFactory owner must be the PollFactory contract
require(
messageAqFactory.owner() == address(pollFactory),
"MACI: MessageAqFactory owner incorrectly set"
);

// The VkRegistry owner must be the owner of this contract
require(
vkRegistry.owner() == owner(),
"MACI: VkRegistry owner incorrectly set"
);

emit Init(_vkRegistry, _messageAqFactory);
}
```

This function accepts three arguments:

- `VkRegistry` - the contract holding the verifying keys
- `MessageAqFactory` - the factory contract for deploying new MessageAq contracts
- `TopupCredit` - the contract responsible for topping up voting credits

In more details, the `init` function will check/do the following:

1. That the `PollFactory` contract's owner has been set to be the `MACI` contract
2. Set the `messageAqFactory` contract on the `pollFactory` contract
3. Check that the owner of the `messageAqFactory` is the `pollFactory` contract
4. Confirm that the `vkRegistry` owner is the same as the `MACI` owner

Finally, it will emit an event.

Next, we have the `signUp` function, which allows users to `signUp` using a `SignUpGatekeeper` contract. This contract can use any mean necessary to gatekeep access to MACI's polls. For instance, only wallets with access to a specific ERC721 token can be allowed to sign up. Please note that this function can only be called after the contract is initialized (thanks to the `afterInit` modifier).

This function does the following:
Expand Down Expand Up @@ -163,7 +110,7 @@ function deployPoll(
MaxValues memory _maxValues,
TreeDepths memory _treeDepths,
PubKey memory _coordinatorPubKey
) public afterInit {
) public onlyOwner returns (address pollAddr) {
uint256 pollId = nextPollId;

// Increment the poll ID for the next poll
Expand Down Expand Up @@ -291,8 +238,7 @@ In order for the `processMessages` circuit to access the message root, the follo

`PollFactory` is a smart contract that is used to deploy new Polls. This is used by MACI inside the `deployPoll` function. It only contains two functions:

- `setMessageAqFactory` - owner only function which allows to set the address of the `MessageAqFactory` (a contract used to deploy new AccQueue contracts)
- `deploy` - owner only function which allows to deploy a new Poll
- `deploy` - owner only function which allows to deploy a new Poll, also deploys a messageAq

The arguments required to deploy a new Poll are the following:

Expand All @@ -310,23 +256,19 @@ address _pollOwner

Upon deployment, the ownership of the messageAq contract will be transferred to the deployed poll, as well as the ownership of the new Poll contract be transferred to the poll owner, which in MACI is set as the owner of MACI.

## PollProcessorAndTallyer
## MessageProcessor

This contract is used to prepare parameters for the zk-SNARK circuits as well as for verifying proofs. It should be deployed alongside MACI and ownership assigned to the coordinator.
It will process messages in batches, to increase performance and stay within the block gas limit.
After it finishes processing, the sbCommitment will be used for Tally and Subsidy contracts.

## MessageAqFactory
## Tally

This is a simple factory contract which allows to deploy new `AccQueueQuinaryMaci` contracts. It exposes one function, `deploy`, which can only be called by the contract owner. After deployment of the contract, it will transfer its ownership to the same owner as the factory contract.
The Tally contract is used during votes tallying and by users to verify the tally results.

```javascript
contract MessageAqFactory is Ownable {
function deploy(uint256 _subDepth) public onlyOwner returns (AccQueue) {
AccQueue aq = new AccQueueQuinaryMaci(_subDepth);
aq.transferOwnership(owner());
return aq;
}
}
```
## Subsidy

This contract is used to verify that the subsidy calculations are correct. It is also used to update the subsidy commitment if the proof is valid.

## SignUpToken

Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-v1.x/integrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Here we will be looking at QFI and how it was used. Please note that this will b

## MACI Contract

The MACI contract is the core of the protocol. Contracts can inherit from MACI and thus expose the signup and topup functions. As with standalone MACI, one would need to deploy a sign up gatekeeper as well as the voice credit proxy.
The MACI contract is the core of the protocol. Contracts can inherit from MACI and thus expose the signup and topup functions. As with standalone MACI, one would need to deploy a [sign up gatekeeper](./contracts#signupgatekeeper) as well as the [voice credit proxy](./contracts#voicecreditproxy).

As an example, within the quadratic funding infrastructure project, the QFI contract inherits from MACI and allows sign up via the contribute function.

Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-v1.x/key-change.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Let's take as an example the following:

If messages were processed in the same order as they were submitted, Alice's vote would not be valid, due to it being signed with a private key $priv1$ - which now would not be valid.

On the other hand, due to messages being processed in reverse order, Alice's last message would be counted as valid as the key change would have not been processed yet. Then, Bob's vote would not be counted as valid as the current key for Alice would be $pub2$.
On the other hand, due to messages being processed in reverse order, Alice's last message would be counted as valid as the key change would have not been processed yet. Then, Bob's vote would not be counted as valid as the current key for Alice would be $pub1$.

> Note that a key change message should have the nonce set to 1 in order for it to be valid. We'll see it a code example in the next sections.

Expand Down
4 changes: 2 additions & 2 deletions website/versioned_docs/version-v1.x/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ You can run them with:
pnpm run test
```

## Pre-Compiled Artifacts for testing
### Pre-Compiled Artifacts for testing

The followingcompiled circuits and zkeys are available to download:
The following compiled circuits and zkeys are available to download:

- [Prod](#prod-size) (`7-9-3-4`)
- [Micro](#micro-size) (`10-2-1-2`)
Expand Down
Loading