Skip to main content
Version: v3.x

MACI

A contract which allows users to sign up, and deploy new polls

stateTreeDepth​

uint8 stateTreeDepth

The state tree depth is fixed. As such it should be as large as feasible so that there can be as many users as possible. i.e. 2 ** 23 = 8388608 this should also match the parameter of the circom circuits. IMPORTANT: remember to change the ballot tree depth in contracts/ts/generateEmptyBallotRoots.ts file if we change the state tree depth!

maxSignups​

uint256 maxSignups

STATE_TREE_ARITY​

uint8 STATE_TREE_ARITY

PAD_KEY_HASH​

uint256 PAD_KEY_HASH

This is the poseidon hash of the pad key. Check crypto/SnarkConstants.sol for more info about the pad key.

POSEIDON_VALIDITY_CHECK_VALUE​

uint256 POSEIDON_VALIDITY_CHECK_VALUE

This is poseidon_hash2([1,1]), used to verify that hash libraries are linked correctly

emptyBallotRoots​

uint256[5] emptyBallotRoots

The roots of the empty ballot trees

nextPollId​

uint256 nextPollId

Each poll has an incrementing ID

polls​

mapping(uint256 => struct IMACI.PollContracts) polls

A mapping of poll IDs to Poll contracts.

pollFactory​

contract IPollFactory pollFactory

Factory contract that deploy a Poll contract

messageProcessorFactory​

contract IMessageProcessorFactory messageProcessorFactory

Factory contract that deploy a MessageProcessor contract

tallyFactory​

contract ITallyFactory tallyFactory

Factory contract that deploy a Tally contract

leanIMTData​

struct LeanIMTData leanIMTData

The state tree. Stores users' public keys

signUpPolicy​

contract IBasePolicy signUpPolicy

Address of the signup policy, a contract which determines whether a user may sign up to vote

verifier​

contract IVerifier verifier

The verifier contract for zk-SNARK proofs This is send to the poll when deploying

verifyingKeysRegistry​

contract IVerifyingKeysRegistry verifyingKeysRegistry

The verifying keys registry contract This is send to the poll when deploying

stateRootsOnSignUp​

uint256[] stateRootsOnSignUp

The array of the state tree roots for each sign up For the N'th sign up, the state tree root will be stored at the index N

InitParams​

struct InitParams {
contract IPollFactory pollFactory;
contract IMessageProcessorFactory messageProcessorFactory;
contract ITallyFactory tallyFactory;
contract IBasePolicy signUpPolicy;
contract IVerifier verifier;
contract IVerifyingKeysRegistry verifyingKeysRegistry;
uint8 stateTreeDepth;
uint256[5] emptyBallotRoots;
}

SignUp​

event SignUp(uint256 _stateIndex, uint256 _timestamp, uint256 _userPublicKeyX, uint256 _userPublicKeyY)

DeployPoll​

event DeployPoll(uint256 _pollId, uint256 _coordinatorPublicKeyX, uint256 _coordinatorPublicKeyY, enum DomainObjs.Mode _mode)

PoseidonHashLibrariesNotLinked​

error PoseidonHashLibrariesNotLinked()

custom errors

TooManySignups​

error TooManySignups()

InvalidPublicKey​

error InvalidPublicKey()

InvalidVoteOptionTreeDepth​

error InvalidVoteOptionTreeDepth(uint8 depth)

PollDoesNotExist​

error PollDoesNotExist(uint256 pollId)

UserNotSignedUp​

error UserNotSignedUp()

constructor​

constructor(struct MACI.InitParams initParams) public payable

Create a new instance of the MACI contract.

Parameters​

NameTypeDescription
initParamsstruct MACI.InitParamsThe initialization parameters defined above

signUp​

function signUp(struct DomainObjs.PublicKey _publicKey, bytes _signUpPolicyData) public virtual

Allows any eligible user sign up. The sign-up policy should prevent double sign-ups or ineligible users from doing so. This function will only succeed if the sign-up deadline has not passed.

Parameters​

NameTypeDescription
_publicKeystruct DomainObjs.PublicKeyThe user's desired public key.
_signUpPolicyDatabytesData to pass to the sign-up policy register() function. For instance, the POAPPolicy or TokenPolicy requires this value to be the ABI-encoded token ID.

deployPoll​

function deployPoll(struct IMACI.DeployPollArgs args) public virtual returns (struct IMACI.PollContracts)

Deploy a new Poll contract.

Parameters​

NameTypeDescription
argsstruct IMACI.DeployPollArgs

getStateTreeRoot​

function getStateTreeRoot() public view returns (uint256 root)

Return the main root of the StateAq contract

Return Values​

NameTypeDescription
rootuint256The Merkle root

getPoll​

function getPoll(uint256 _pollId) public view returns (struct IMACI.PollContracts pollContracts)

Get the Poll details

Parameters​

NameTypeDescription
_pollIduint256The identifier of the Poll to retrieve

Return Values​

NameTypeDescription
pollContractsstruct IMACI.PollContractsThe Poll contract object

totalSignups​

function totalSignups() public view returns (uint256 signUps)

Get the number of signups

Return Values​

NameTypeDescription
signUpsuint256totalSignups The number of signups

getStateRootOnIndexedSignUp​

function getStateRootOnIndexedSignUp(uint256 _index) external view returns (uint256 stateRoot)

Return the state root when the '_index' user signed up

Parameters​

NameTypeDescription
_indexuint256The serial number when the user signed up

Return Values​

NameTypeDescription
stateRootuint256The Merkle root

getStateIndex​

function getStateIndex(uint256 _publicKeyHash) external view returns (uint256)

Get the index of a public key in the state tree

Parameters​

NameTypeDescription
_publicKeyHashuint256The hash of the public key

Return Values​

NameTypeDescription
[0]uint256index The index of the public key in the state tree