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/genEmptyBallotRootsContract.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

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

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

SignUp

event SignUp(uint256 _stateIndex, uint256 _timestamp, uint256 _userPubKeyX, uint256 _userPubKeyY)

DeployPoll

event DeployPoll(uint256 _pollId, uint256 _coordinatorPubKeyX, uint256 _coordinatorPubKeyY, enum DomainObjs.Mode _mode)

PoseidonHashLibrariesNotLinked

error PoseidonHashLibrariesNotLinked()

custom errors

TooManySignups

error TooManySignups()

InvalidPubKey

error InvalidPubKey()

PollDoesNotExist

error PollDoesNotExist(uint256 pollId)

UserNotSignedUp

error UserNotSignedUp()

constructor

constructor(contract IPollFactory _pollFactory, contract IMessageProcessorFactory _messageProcessorFactory, contract ITallyFactory _tallyFactory, contract IBasePolicy _signUpPolicy, uint8 _stateTreeDepth, uint256[5] _emptyBallotRoots) public payable

Create a new instance of the MACI contract.

Parameters

NameTypeDescription
_pollFactorycontract IPollFactoryThe PollFactory contract
_messageProcessorFactorycontract IMessageProcessorFactoryThe MessageProcessorFactory contract
_tallyFactorycontract ITallyFactoryThe TallyFactory contract
_signUpPolicycontract IBasePolicyThe signup policy contract
_stateTreeDepthuint8The depth of the state tree
_emptyBallotRootsuint256[5]The roots of the empty ballot trees

signUp

function signUp(struct DomainObjs.PubKey _pubKey, 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
_pubKeystruct DomainObjs.PubKeyThe 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

numSignUps

function numSignUps() public view returns (uint256 signUps)

Get the number of signups

Return Values

NameTypeDescription
signUpsuint256numsignUps 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 _pubKeyHash) external view returns (uint256)

Get the index of a public key in the state tree

Parameters

NameTypeDescription
_pubKeyHashuint256The hash of the public key

Return Values

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