From c97a56e170b4fff25c91c6f4ea52856f3ba089b2 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Mon, 11 Dec 2023 11:22:48 +0000 Subject: [PATCH] chore(repo): rebase master into dev so we can keep only one branch --- .github/workflows/checks.yml | 2 +- .github/workflows/circuit-build.yml | 2 +- .github/workflows/gh-pages.yml | 6 - circuits/ts/snarkjs.d.ts | 1 + cli/test.sh | 53 -- contracts/docs/DomainObjs.md | 47 -- contracts/docs/HasherBenchmarks.md | 15 - contracts/docs/IMACI.md | 45 -- contracts/docs/MACI.md | 380 ----------- contracts/docs/MessageProcessor.md | 196 ------ contracts/docs/Params.md | 33 - contracts/docs/Poll.md | 317 ---------- contracts/docs/SignUpToken.md | 15 - contracts/docs/Subsidy.md | 135 ---- contracts/docs/Tally.md | 245 -------- contracts/docs/TopupCredit.md | 45 -- contracts/docs/VkRegistry.md | 199 ------ contracts/docs/crypto/Hasher.md | 74 --- contracts/docs/crypto/Pairing.md | 65 -- contracts/docs/crypto/SnarkCommon.md | 15 - contracts/docs/crypto/SnarkConstants.md | 27 - contracts/docs/crypto/Verifier.md | 65 -- .../gatekeepers/FreeForAllSignUpGatekeeper.md | 17 - .../docs/gatekeepers/SignUpGatekeeper.md | 15 - .../docs/gatekeepers/SignUpTokenGatekeeper.md | 76 --- .../ConstantInitialVoiceCreditProxy.md | 29 - .../InitialVoiceCreditProxy.md | 9 - contracts/docs/trees/AccQueue.md | 593 ------------------ contracts/docs/trees/EmptyBallotRoots.md | 15 - contracts/docs/utilities/Utility.md | 29 - domainobjs/ts/__tests__/DomainObjs.test.ts | 286 --------- domainobjs/ts/__tests__/test_vk.json | 85 --- 32 files changed, 3 insertions(+), 3133 deletions(-) delete mode 100644 cli/test.sh delete mode 100644 contracts/docs/DomainObjs.md delete mode 100644 contracts/docs/HasherBenchmarks.md delete mode 100644 contracts/docs/IMACI.md delete mode 100644 contracts/docs/MACI.md delete mode 100644 contracts/docs/MessageProcessor.md delete mode 100644 contracts/docs/Params.md delete mode 100644 contracts/docs/Poll.md delete mode 100644 contracts/docs/SignUpToken.md delete mode 100644 contracts/docs/Subsidy.md delete mode 100644 contracts/docs/Tally.md delete mode 100644 contracts/docs/TopupCredit.md delete mode 100644 contracts/docs/VkRegistry.md delete mode 100644 contracts/docs/crypto/Hasher.md delete mode 100644 contracts/docs/crypto/Pairing.md delete mode 100644 contracts/docs/crypto/SnarkCommon.md delete mode 100644 contracts/docs/crypto/SnarkConstants.md delete mode 100644 contracts/docs/crypto/Verifier.md delete mode 100644 contracts/docs/gatekeepers/FreeForAllSignUpGatekeeper.md delete mode 100644 contracts/docs/gatekeepers/SignUpGatekeeper.md delete mode 100644 contracts/docs/gatekeepers/SignUpTokenGatekeeper.md delete mode 100644 contracts/docs/initialVoiceCreditProxy/ConstantInitialVoiceCreditProxy.md delete mode 100644 contracts/docs/initialVoiceCreditProxy/InitialVoiceCreditProxy.md delete mode 100644 contracts/docs/trees/AccQueue.md delete mode 100644 contracts/docs/trees/EmptyBallotRoots.md delete mode 100644 contracts/docs/utilities/Utility.md delete mode 100644 domainobjs/ts/__tests__/DomainObjs.test.ts delete mode 100644 domainobjs/ts/__tests__/test_vk.json diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 0ade690e68..1dc2c8ffd3 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -2,7 +2,7 @@ name: Checks on: push: - branches: [master, dev] + branches: [dev] pull_request: concurrency: diff --git a/.github/workflows/circuit-build.yml b/.github/workflows/circuit-build.yml index aa7427bcae..6117e8ed60 100644 --- a/.github/workflows/circuit-build.yml +++ b/.github/workflows/circuit-build.yml @@ -2,7 +2,7 @@ name: Circuit on: push: - branches: [master, dev] + branches: [dev] pull_request: concurrency: diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index fb7108b0df..776210301c 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -32,7 +32,6 @@ jobs: - name: Fix typedoc links run: | npm install -<<<<<<< HEAD npm run setup-typedoc working-directory: website @@ -44,11 +43,6 @@ jobs: - name: Add CNAME run: | echo 'maci.pse.dev' > ./website/build/CNAME -======= - npm run build - working-directory: website - ->>>>>>> f9fe8a7a (feat(docs) - fix deployment workflow and ensure there are no broken links) - name: Deploy uses: peaceiris/actions-gh-pages@v3 diff --git a/circuits/ts/snarkjs.d.ts b/circuits/ts/snarkjs.d.ts index bdca1fcb8c..ccbb9d753d 100644 --- a/circuits/ts/snarkjs.d.ts +++ b/circuits/ts/snarkjs.d.ts @@ -11,6 +11,7 @@ declare module "snarkjs" { pi_a: NumericString[]; pi_b: NumericString[][]; pi_c: NumericString[]; + protocol: string; curve: string; } diff --git a/cli/test.sh b/cli/test.sh deleted file mode 100644 index 072a696446..0000000000 --- a/cli/test.sh +++ /dev/null @@ -1,53 +0,0 @@ -#! /bin/bash -rm -r ./proofs -rm tally.json -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js deployVkRegistry -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js setVerifyingKeys \ - --state-tree-depth 10 \ - --int-state-tree-depth 1 \ - --msg-tree-depth 2 \ - --vote-option-tree-depth 2 \ - --msg-batch-depth 1 \ - --process-messages-zkey ./zkeys/ProcessMessages_10-2-1-2_test.0.zkey \ - --tally-votes-zkey ./zkeys/TallyVotes_10-1-2_test.0.zkey -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js create -s 10 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js deployPoll \ - -pk macipk.c974f4f168b79727ac98bfd53a65ea0b4e45dc2552fe73df9f8b51ebb0930330 \ - -t 30 -g 25 -mv 25 -i 1 -m 2 -b 1 -v 2 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js signup \ - --pubkey macipk.3e7bb2d7f0a1b7e980f1b6f363d1e3b7a12b9ae354c2cd60a9cfa9fd12917391 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js publish \ - --pubkey macipk.3e7bb2d7f0a1b7e980f1b6f363d1e3b7a12b9ae354c2cd60a9cfa9fd12917391 \ - --privkey macisk.fd7aa614ec4a82716ffc219c24fd7e7b52a2b63b5afb17e81c22fe21515539c \ - --state-index 1 \ - --vote-option-index 0 \ - --new-vote-weight 9 \ - --nonce 1 \ - --poll-id 0 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js publish \ - --pubkey macipk.d5788ea6ccf1ec295df99aaef859031fe7bd359e7e03acb80eb6e8a192f2ce19 \ - --privkey macisk.fd7aa614ec4a82716ffc219c24fd7e7b52a2b63b5afb17e81c22fe21515539c \ - --state-index 1 \ - --vote-option-index 1 \ - --new-vote-weight 9 \ - --nonce 2 \ - --poll-id 0 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js timeTravel -s 100 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js mergeSignups --poll-id 0 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js mergeMessages --poll-id 0 -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js genProofs \ - --privkey macisk.49953af3585856f539d194b46c82f4ed54ec508fb9b882940cbe68bbc57e59e \ - --poll-id 0 \ - --process-zkey ./zkeys/ProcessMessages_10-2-1-2_test.0.zkey \ - --tally-zkey ./zkeys/TallyVotes_10-1-2_test.0.zkey \ - --tally-file tally.json \ - --output proofs/ \ - -tw ./zkeys/TallyVotes_10-1-2_test_js/TallyVotes_10-1-2_test.wasm \ - -pw ./zkeys/ProcessMessages_10-2-1-2_test_js/ProcessMessages_10-2-1-2_test.wasm \ - -w true -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js proveOnChain \ - --poll-id 0 \ - --proof-dir proofs/ -HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js verify \ - --poll-id 0 \ - --tally-file tally.json diff --git a/contracts/docs/DomainObjs.md b/contracts/docs/DomainObjs.md deleted file mode 100644 index 4504386ea5..0000000000 --- a/contracts/docs/DomainObjs.md +++ /dev/null @@ -1,47 +0,0 @@ -# Solidity API - -## IPubKey - -### PubKey - -```solidity -struct PubKey { - uint256 x; - uint256 y; -} -``` - -## IMessage - -### MESSAGE_DATA_LENGTH - -```solidity -uint8 MESSAGE_DATA_LENGTH -``` - -### Message - -```solidity -struct Message { - uint256 msgType; - uint256[10] data; -} -``` - -## DomainObjs - -### StateLeaf - -```solidity -struct StateLeaf { - struct IPubKey.PubKey pubKey; - uint256 voiceCreditBalance; - uint256 timestamp; -} -``` - -### hashStateLeaf - -```solidity -function hashStateLeaf(struct DomainObjs.StateLeaf _stateLeaf) public pure returns (uint256) -``` diff --git a/contracts/docs/HasherBenchmarks.md b/contracts/docs/HasherBenchmarks.md deleted file mode 100644 index e18ebb7322..0000000000 --- a/contracts/docs/HasherBenchmarks.md +++ /dev/null @@ -1,15 +0,0 @@ -# Solidity API - -## HasherBenchmarks - -### hash5Benchmark - -```solidity -function hash5Benchmark(uint256[5] array) public -``` - -### hashLeftRightBenchmark - -```solidity -function hashLeftRightBenchmark(uint256 _left, uint256 _right) public -``` diff --git a/contracts/docs/IMACI.md b/contracts/docs/IMACI.md deleted file mode 100644 index 264540d3c2..0000000000 --- a/contracts/docs/IMACI.md +++ /dev/null @@ -1,45 +0,0 @@ -# Solidity API - -## IMACI - -### stateTreeDepth - -```solidity -function stateTreeDepth() external view returns (uint8) -``` - -### vkRegistry - -```solidity -function vkRegistry() external view returns (contract VkRegistry) -``` - -### getStateAqRoot - -```solidity -function getStateAqRoot() external view returns (uint256) -``` - -### mergeStateAqSubRoots - -```solidity -function mergeStateAqSubRoots(uint256 _numSrQueueOps, uint256 _pollId) external -``` - -### mergeStateAq - -```solidity -function mergeStateAq(uint256 _pollId) external returns (uint256) -``` - -### numSignUps - -```solidity -function numSignUps() external view returns (uint256) -``` - -### stateAq - -```solidity -function stateAq() external view returns (contract AccQueue) -``` diff --git a/contracts/docs/MACI.md b/contracts/docs/MACI.md deleted file mode 100644 index 5b91b1180e..0000000000 --- a/contracts/docs/MACI.md +++ /dev/null @@ -1,380 +0,0 @@ -# Solidity API - -## MACI - -### stateTreeDepth - -```solidity -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. 5 \*\* 10 = 9765625 -this should also match the parameter of the circom circuits. - -### STATE_TREE_SUBDEPTH - -```solidity -uint8 STATE_TREE_SUBDEPTH -``` - -IMPORTANT: remember to change the ballot tree depth -in contracts/ts/genEmptyBallotRootsContract.ts file -if we change the state tree depth! - -### STATE_TREE_ARITY - -```solidity -uint8 STATE_TREE_ARITY -``` - -### MESSAGE_TREE_ARITY - -```solidity -uint8 MESSAGE_TREE_ARITY -``` - -### BLANK_STATE_LEAF_HASH - -```solidity -uint256 BLANK_STATE_LEAF_HASH -``` - -The hash of a blank state leaf - -### nextPollId - -```solidity -uint256 nextPollId -``` - -Each poll has an incrementing ID - -### polls - -```solidity -mapping(uint256 => contract Poll) polls -``` - -A mapping of poll IDs to Poll contracts. - -### numSignUps - -```solidity -uint256 numSignUps -``` - -The number of signups - -### numStateLeaves - -```solidity -mapping(uint256 => uint256) numStateLeaves -``` - -A mapping of block timestamps to the number of state leaves - -### vkRegistry - -```solidity -contract VkRegistry vkRegistry -``` - -The verifying key registry. There may be multiple verifying keys stored -on chain, and Poll contracts must select the correct VK based on the -circuit's compile-time parameters, such as tree depths and batch sizes. - -### topupCredit - -```solidity -contract TopupCredit topupCredit -``` - -### pollFactory - -```solidity -contract PollFactory pollFactory -``` - -### stateAq - -```solidity -contract AccQueue stateAq -``` - -The state AccQueue. Represents a mapping between each user's public key -and their voice credit balance. - -### isInitialised - -```solidity -bool isInitialised -``` - -Whether the init() function has been successfully executed yet. - -### signUpGatekeeper - -```solidity -contract SignUpGatekeeper signUpGatekeeper -``` - -Address of the SignUpGatekeeper, a contract which determines whether a -user may sign up to vote - -### initialVoiceCreditProxy - -```solidity -contract InitialVoiceCreditProxy initialVoiceCreditProxy -``` - -The contract which provides the values of the initial voice credit -balance per user - -### signUpTimestamp - -```solidity -uint256 signUpTimestamp -``` - -When the contract was deployed. We assume that the signup period starts -immediately upon deployment. - -### Init - -```solidity -event Init(contract VkRegistry _vkRegistry, contract TopupCredit _topupCredit) -``` - -### SignUp - -```solidity -event SignUp(uint256 _stateIndex, struct IPubKey.PubKey _userPubKey, uint256 _voiceCreditBalance, uint256 _timestamp) -``` - -### DeployPoll - -```solidity -event DeployPoll(uint256 _pollId, address _pollAddr, struct IPubKey.PubKey _pubKey) -``` - -### MergeStateAqSubRoots - -```solidity -event MergeStateAqSubRoots(uint256 _pollId, uint256 _numSrQueueOps) -``` - -### MergeStateAq - -```solidity -event MergeStateAq(uint256 _pollId) -``` - -### afterInit - -```solidity -modifier afterInit() -``` - -Ensure certain functions only run after the contract has been initialized - -### onlyPoll - -```solidity -modifier onlyPoll(uint256 _pollId) -``` - -Only allow a Poll contract to call the modified function. - -### MaciNotInit - -```solidity -error MaciNotInit() -``` - -### CallerMustBePoll - -```solidity -error CallerMustBePoll(address _caller) -``` - -### AlreadyInitialized - -```solidity -error AlreadyInitialized() -``` - -### PoseidonHashLibrariesNotLinked - -```solidity -error PoseidonHashLibrariesNotLinked() -``` - -### WrongPollOwner - -```solidity -error WrongPollOwner() -``` - -### WrongVkRegistryOwner - -```solidity -error WrongVkRegistryOwner() -``` - -### TooManySignups - -```solidity -error TooManySignups() -``` - -### MaciPubKeyLargerThanSnarkFieldSize - -```solidity -error MaciPubKeyLargerThanSnarkFieldSize() -``` - -### PreviousPollNotCompleted - -```solidity -error PreviousPollNotCompleted(uint256 pollId) -``` - -### PollDoesNotExist - -```solidity -error PollDoesNotExist(uint256 pollId) -``` - -### constructor - -```solidity -constructor(contract PollFactory _pollFactory, contract SignUpGatekeeper _signUpGatekeeper, contract InitialVoiceCreditProxy _initialVoiceCreditProxy, uint8 _stateTreeDepth) public -``` - -### init - -```solidity -function init(contract VkRegistry _vkRegistry, contract TopupCredit _topupCredit) public -``` - -Initialise the various factory/helper contracts. This should only be run -once and it must be run before deploying the first Poll. - -#### Parameters - -| Name | Type | Description | -| ------------- | -------------------- | ------------------------ | -| \_vkRegistry | contract VkRegistry | The VkRegistry contract | -| \_topupCredit | contract TopupCredit | The topupCredit contract | - -### signUp - -```solidity -function signUp(struct IPubKey.PubKey _pubKey, bytes _signUpGatekeeperData, bytes _initialVoiceCreditProxyData) public -``` - -Allows any eligible user sign up. The sign-up gatekeeper should prevent -double sign-ups or ineligible users from doing so. This function will -only succeed if the sign-up deadline has not passed. It also enqueues a -fresh state leaf into the state AccQueue. - -#### Parameters - -| Name | Type | Description | -| ----------------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| \_pubKey | struct IPubKey.PubKey | The user's desired public key. | -| \_signUpGatekeeperData | bytes | Data to pass to the sign-up gatekeeper's register() function. For instance, the POAPGatekeeper or SignUpTokenGatekeeper requires this value to be the ABI-encoded token ID. | -| \_initialVoiceCreditProxyData | bytes | Data to pass to the InitialVoiceCreditProxy, which allows it to determine how many voice credits this user should have. | - -### deployPoll - -```solidity -function deployPoll(uint256 _duration, struct Params.MaxValues _maxValues, struct Params.TreeDepths _treeDepths, struct IPubKey.PubKey _coordinatorPubKey) public returns (address) -``` - -Deploy a new Poll contract. - -#### Parameters - -| Name | Type | Description | -| ------------------- | ------------------------ | --------------------------------- | -| \_duration | uint256 | How long should the Poll last for | -| \_maxValues | struct Params.MaxValues | | -| \_treeDepths | struct Params.TreeDepths | The depth of the Merkle trees | -| \_coordinatorPubKey | struct IPubKey.PubKey | | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | --------------------------- | -| [0] | address | a new Poll contract address | - -### mergeStateAqSubRoots - -```solidity -function mergeStateAqSubRoots(uint256 _numSrQueueOps, uint256 _pollId) public -``` - -Allow Poll contracts to merge the state subroots - -#### Parameters - -| Name | Type | Description | -| --------------- | ------- | -------------------- | -| \_numSrQueueOps | uint256 | Number of operations | -| \_pollId | uint256 | The active Poll ID | - -### mergeStateAq - -```solidity -function mergeStateAq(uint256 _pollId) public returns (uint256) -``` - -Allow Poll contracts to merge the state root - -#### Parameters - -| Name | Type | Description | -| -------- | ------- | ------------------ | -| \_pollId | uint256 | The active Poll ID | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ---------------------------------- | -| [0] | uint256 | uint256 The calculated Merkle root | - -### getStateAqRoot - -```solidity -function getStateAqRoot() public view returns (uint256) -``` - -Return the main root of the StateAq contract - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ----------------------- | -| [0] | uint256 | uint256 The Merkle root | - -### getPoll - -```solidity -function getPoll(uint256 _pollId) public view returns (contract Poll) -``` - -Get the Poll details - -#### Parameters - -| Name | Type | Description | -| -------- | ------- | -------------------------------------- | -| \_pollId | uint256 | The identifier of the Poll to retrieve | - -#### Return Values - -| Name | Type | Description | -| ---- | ------------- | ------------------ | -| [0] | contract Poll | Poll The Poll data | diff --git a/contracts/docs/MessageProcessor.md b/contracts/docs/MessageProcessor.md deleted file mode 100644 index be415002f0..0000000000 --- a/contracts/docs/MessageProcessor.md +++ /dev/null @@ -1,196 +0,0 @@ -# Solidity API - -## MessageProcessor - -_MessageProcessor is used to process messages published by signup users -it will process message by batch due to large size of messages -after it finishes processing, the sbCommitment will be used for Tally and Subsidy contracts_ - -### NoMoreMessages - -```solidity -error NoMoreMessages() -``` - -### StateAqNotMerged - -```solidity -error StateAqNotMerged() -``` - -### MessageAqNotMerged - -```solidity -error MessageAqNotMerged() -``` - -### InvalidProcessMessageProof - -```solidity -error InvalidProcessMessageProof() -``` - -### VkNotSet - -```solidity -error VkNotSet() -``` - -### MaxVoteOptionsTooLarge - -```solidity -error MaxVoteOptionsTooLarge() -``` - -### NumSignUpsTooLarge - -```solidity -error NumSignUpsTooLarge() -``` - -### CurrentMessageBatchIndexTooLarge - -```solidity -error CurrentMessageBatchIndexTooLarge() -``` - -### BatchEndIndexTooLarge - -```solidity -error BatchEndIndexTooLarge() -``` - -### processingComplete - -```solidity -bool processingComplete -``` - -Whether there are unprocessed messages left - -### numBatchesProcessed - -```solidity -uint256 numBatchesProcessed -``` - -The number of batches processed - -### currentMessageBatchIndex - -```solidity -uint256 currentMessageBatchIndex -``` - -The current message batch index. When the coordinator runs -processMessages(), this action relates to messages -currentMessageBatchIndex to currentMessageBatchIndex + messageBatchSize. - -### sbCommitment - -```solidity -uint256 sbCommitment -``` - -The commitment to the state and ballot roots - -### verifier - -```solidity -contract Verifier verifier -``` - -### constructor - -```solidity -constructor(contract Verifier _verifier) public -``` - -### processMessages - -```solidity -function processMessages(contract Poll _poll, uint256 _newSbCommitment, uint256[8] _proof) external -``` - -Update the Poll's currentSbCommitment if the proof is valid. - -#### Parameters - -| Name | Type | Description | -| ----------------- | ------------- | ------------------------------------------------------------------------------ | -| \_poll | contract Poll | The poll to update | -| \_newSbCommitment | uint256 | The new state root and ballot root commitment after all messages are processed | -| \_proof | uint256[8] | The zk-SNARK proof | - -### verifyProcessProof - -```solidity -function verifyProcessProof(contract Poll _poll, uint256 _currentMessageBatchIndex, uint256 _messageRoot, uint256 _currentSbCommitment, uint256 _newSbCommitment, uint256[8] _proof) internal view returns (bool) -``` - -### genProcessMessagesPublicInputHash - -```solidity -function genProcessMessagesPublicInputHash(contract Poll _poll, uint256 _currentMessageBatchIndex, uint256 _messageRoot, uint256 _numSignUps, uint256 _currentSbCommitment, uint256 _newSbCommitment) public view returns (uint256) -``` - -Returns the SHA256 hash of the packed values (see -genProcessMessagesPackedVals), the hash of the coordinator's public key, -the message root, and the commitment to the current state root and -ballot root. By passing the SHA256 hash of these values to the circuit -as a single public input and the preimage as private inputs, we reduce -its verification gas cost though the number of constraints will be -higher and proving time will be higher. - -#### Parameters - -| Name | Type | Description | -| -------------------------- | ------------- | ----------- | -| \_poll | contract Poll | | -| \_currentMessageBatchIndex | uint256 | | -| \_messageRoot | uint256 | | -| \_numSignUps | uint256 | | -| \_currentSbCommitment | uint256 | | -| \_newSbCommitment | uint256 | | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | -------------------------------------------- | -| [0] | uint256 | returns the SHA256 hash of the packed values | - -### genProcessMessagesPackedVals - -```solidity -function genProcessMessagesPackedVals(contract Poll _poll, uint256 _currentMessageBatchIndex, uint256 _numSignUps) public view returns (uint256) -``` - -One of the inputs to the ProcessMessages circuit is a 250-bit -representation of four 50-bit values. This function generates this -250-bit value, which consists of the maximum number of vote options, the -number of signups, the current message batch index, and the end index of -the current batch. - -#### Parameters - -| Name | Type | Description | -| -------------------------- | ------------- | ----------- | -| \_poll | contract Poll | | -| \_currentMessageBatchIndex | uint256 | | -| \_numSignUps | uint256 | | - -### updateMessageProcessingData - -```solidity -function updateMessageProcessingData(uint256 _newSbCommitment, uint256 _currentMessageBatchIndex, bool _processingComplete) internal -``` - -update message processing state variables - -#### Parameters - -| Name | Type | Description | -| -------------------------- | ------- | ----------- | -| \_newSbCommitment | uint256 | | -| \_currentMessageBatchIndex | uint256 | | -| \_processingComplete | bool | | diff --git a/contracts/docs/Params.md b/contracts/docs/Params.md deleted file mode 100644 index 56755b4b9d..0000000000 --- a/contracts/docs/Params.md +++ /dev/null @@ -1,33 +0,0 @@ -# Solidity API - -## Params - -### TreeDepths - -```solidity -struct TreeDepths { - uint8 intStateTreeDepth; - uint8 messageTreeSubDepth; - uint8 messageTreeDepth; - uint8 voteOptionTreeDepth; -} -``` - -### BatchSizes - -```solidity -struct BatchSizes { - uint24 messageBatchSize; - uint24 tallyBatchSize; - uint24 subsidyBatchSize; -} -``` - -### MaxValues - -```solidity -struct MaxValues { - uint256 maxMessages; - uint256 maxVoteOptions; -} -``` diff --git a/contracts/docs/Poll.md b/contracts/docs/Poll.md deleted file mode 100644 index c6a028d1c4..0000000000 --- a/contracts/docs/Poll.md +++ /dev/null @@ -1,317 +0,0 @@ -# Solidity API - -## PollDeploymentParams - -### ExtContracts - -```solidity -struct ExtContracts { - contract VkRegistry vkRegistry; - contract IMACI maci; - contract AccQueue messageAq; - contract TopupCredit topupCredit; -} -``` - -## PollFactory - -### InvalidMaxValues - -```solidity -error InvalidMaxValues() -``` - -### deploy - -```solidity -function deploy(uint256 _duration, struct Params.MaxValues _maxValues, struct Params.TreeDepths _treeDepths, struct Params.BatchSizes _batchSizes, struct IPubKey.PubKey _coordinatorPubKey, contract VkRegistry _vkRegistry, contract IMACI _maci, contract TopupCredit _topupCredit, address _pollOwner) public returns (contract Poll) -``` - -Deploy a new Poll contract and AccQueue contract for messages. - -## Poll - -_Do not deploy this directly. Use PollFactory.deploy() which performs some -checks on the Poll constructor arguments._ - -### isInit - -```solidity -bool isInit -``` - -### coordinatorPubKey - -```solidity -struct IPubKey.PubKey coordinatorPubKey -``` - -### mergedStateRoot - -```solidity -uint256 mergedStateRoot -``` - -### coordinatorPubKeyHash - -```solidity -uint256 coordinatorPubKeyHash -``` - -### deployTime - -```solidity -uint256 deployTime -``` - -### duration - -```solidity -uint256 duration -``` - -### getDeployTimeAndDuration - -```solidity -function getDeployTimeAndDuration() public view returns (uint256, uint256) -``` - -### stateAqMerged - -```solidity -bool stateAqMerged -``` - -### currentSbCommitment - -```solidity -uint256 currentSbCommitment -``` - -### numMessages - -```solidity -uint256 numMessages -``` - -### numSignUpsAndMessages - -```solidity -function numSignUpsAndMessages() public view returns (uint256, uint256) -``` - -### maxValues - -```solidity -struct Params.MaxValues maxValues -``` - -### treeDepths - -```solidity -struct Params.TreeDepths treeDepths -``` - -### batchSizes - -```solidity -struct Params.BatchSizes batchSizes -``` - -### VotingPeriodOver - -```solidity -error VotingPeriodOver() -``` - -### VotingPeriodNotOver - -```solidity -error VotingPeriodNotOver() -``` - -### PollAlreadyInit - -```solidity -error PollAlreadyInit() -``` - -### TooManyMessages - -```solidity -error TooManyMessages() -``` - -### MaciPubKeyLargerThanSnarkFieldSize - -```solidity -error MaciPubKeyLargerThanSnarkFieldSize() -``` - -### StateAqAlreadyMerged - -```solidity -error StateAqAlreadyMerged() -``` - -### StateAqSubtreesNeedMerge - -```solidity -error StateAqSubtreesNeedMerge() -``` - -### PublishMessage - -```solidity -event PublishMessage(struct IMessage.Message _message, struct IPubKey.PubKey _encPubKey) -``` - -### TopupMessage - -```solidity -event TopupMessage(struct IMessage.Message _message) -``` - -### MergeMaciStateAqSubRoots - -```solidity -event MergeMaciStateAqSubRoots(uint256 _numSrQueueOps) -``` - -### MergeMaciStateAq - -```solidity -event MergeMaciStateAq(uint256 _stateRoot) -``` - -### MergeMessageAqSubRoots - -```solidity -event MergeMessageAqSubRoots(uint256 _numSrQueueOps) -``` - -### MergeMessageAq - -```solidity -event MergeMessageAq(uint256 _messageRoot) -``` - -### extContracts - -```solidity -struct PollDeploymentParams.ExtContracts extContracts -``` - -### constructor - -```solidity -constructor(uint256 _duration, struct Params.MaxValues _maxValues, struct Params.TreeDepths _treeDepths, struct Params.BatchSizes _batchSizes, struct IPubKey.PubKey _coordinatorPubKey, struct PollDeploymentParams.ExtContracts _extContracts) public -``` - -Each MACI instance can have multiple Polls. -When a Poll is deployed, its voting period starts immediately. - -### isAfterVotingDeadline - -```solidity -modifier isAfterVotingDeadline() -``` - -A modifier that causes the function to revert if the voting period is -not over. - -### isWithinVotingDeadline - -```solidity -modifier isWithinVotingDeadline() -``` - -### init - -```solidity -function init() public -``` - -Should be called immediately after Poll creation -and messageAq ownership transferred - -### topup - -```solidity -function topup(uint256 stateIndex, uint256 amount) public -``` - -Allows to publish a Topup message - -#### Parameters - -| Name | Type | Description | -| ---------- | ------- | ------------------------------------ | -| stateIndex | uint256 | The index of user in the state queue | -| amount | uint256 | The amount of credits to topup | - -### publishMessage - -```solidity -function publishMessage(struct IMessage.Message _message, struct IPubKey.PubKey _encPubKey) public -``` - -Allows anyone to publish a message (an encrypted command and signature). -This function also enqueues the message. - -#### Parameters - -| Name | Type | Description | -| ----------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -| \_message | struct IMessage.Message | The message to publish | -| \_encPubKey | struct IPubKey.PubKey | An epheremal public key which can be combined with the coordinator's private key to generate an ECDH shared key with which to encrypt the message. | - -### mergeMaciStateAqSubRoots - -```solidity -function mergeMaciStateAqSubRoots(uint256 _numSrQueueOps, uint256 _pollId) public -``` - -The first step of merging the MACI state AccQueue. This allows the -ProcessMessages circuit to access the latest state tree and ballots via -currentSbCommitment. - -### mergeMaciStateAq - -```solidity -function mergeMaciStateAq(uint256 _pollId) public -``` - -The second step of merging the MACI state AccQueue. This allows the -ProcessMessages circuit to access the latest state tree and ballots via -currentSbCommitment. - -#### Parameters - -| Name | Type | Description | -| -------- | ------- | ------------------ | -| \_pollId | uint256 | The ID of the Poll | - -### mergeMessageAqSubRoots - -```solidity -function mergeMessageAqSubRoots(uint256 _numSrQueueOps) public -``` - -The first step in merging the message AccQueue so that the -ProcessMessages circuit can access the message root. - -#### Parameters - -| Name | Type | Description | -| --------------- | ------- | ------------------------------------------------- | -| \_numSrQueueOps | uint256 | The number of subroot queue operations to perform | - -### mergeMessageAq - -```solidity -function mergeMessageAq() public -``` - -The second step in merging the message AccQueue so that the -ProcessMessages circuit can access the message root. diff --git a/contracts/docs/SignUpToken.md b/contracts/docs/SignUpToken.md deleted file mode 100644 index 3aa6ed94ba..0000000000 --- a/contracts/docs/SignUpToken.md +++ /dev/null @@ -1,15 +0,0 @@ -# Solidity API - -## SignUpToken - -### constructor - -```solidity -constructor() public -``` - -### giveToken - -```solidity -function giveToken(address to, uint256 curTokenId) public -``` diff --git a/contracts/docs/Subsidy.md b/contracts/docs/Subsidy.md deleted file mode 100644 index 9105ca2a0d..0000000000 --- a/contracts/docs/Subsidy.md +++ /dev/null @@ -1,135 +0,0 @@ -# Solidity API - -## Subsidy - -### rbi - -```solidity -uint256 rbi -``` - -### cbi - -```solidity -uint256 cbi -``` - -### sbCommitment - -```solidity -uint256 sbCommitment -``` - -### subsidyCommitment - -```solidity -uint256 subsidyCommitment -``` - -### treeArity - -```solidity -uint8 treeArity -``` - -### ProcessingNotComplete - -```solidity -error ProcessingNotComplete() -``` - -### InvalidSubsidyProof - -```solidity -error InvalidSubsidyProof() -``` - -### AllSubsidyCalculated - -```solidity -error AllSubsidyCalculated() -``` - -### VkNotSet - -```solidity -error VkNotSet() -``` - -### NumSignUpsTooLarge - -```solidity -error NumSignUpsTooLarge() -``` - -### RbiTooLarge - -```solidity -error RbiTooLarge() -``` - -### CbiTooLarge - -```solidity -error CbiTooLarge() -``` - -### verifier - -```solidity -contract Verifier verifier -``` - -### constructor - -```solidity -constructor(contract Verifier _verifier) public -``` - -### updateSbCommitment - -```solidity -function updateSbCommitment(contract MessageProcessor _mp) public -``` - -### genSubsidyPackedVals - -```solidity -function genSubsidyPackedVals(uint256 _numSignUps) public view returns (uint256) -``` - -### genSubsidyPublicInputHash - -```solidity -function genSubsidyPublicInputHash(uint256 _numSignUps, uint256 _newSubsidyCommitment) public view returns (uint256) -``` - -### updateSubsidy - -```solidity -function updateSubsidy(contract Poll _poll, contract MessageProcessor _mp, uint256 _newSubsidyCommitment, uint256[8] _proof) external -``` - -### increaseSubsidyIndex - -```solidity -function increaseSubsidyIndex(uint256 batchSize, uint256 numLeaves) internal -``` - -increase subsidy batch index (rbi, cbi) to next, -it will try to cbi++ if the whole batch can fit into numLeaves -otherwise it will increase row index: rbi++ -each batch for subsidy calculation is 2 dimenional: batchSize\*batchSize - -#### Parameters - -| Name | Type | Description | -| --------- | ------- | ----------- | -| batchSize | uint256 | | -| numLeaves | uint256 | | - -### verifySubsidyProof - -```solidity -function verifySubsidyProof(contract Poll _poll, uint256[8] _proof, uint256 _numSignUps, uint256 _newSubsidyCommitment) public view returns (bool) -``` diff --git a/contracts/docs/Tally.md b/contracts/docs/Tally.md deleted file mode 100644 index a35b0a87c8..0000000000 --- a/contracts/docs/Tally.md +++ /dev/null @@ -1,245 +0,0 @@ -# Solidity API - -## Tally - -### ProcessingNotComplete - -```solidity -error ProcessingNotComplete() -``` - -### InvalidTallyVotesProof - -```solidity -error InvalidTallyVotesProof() -``` - -### AllBallotsTallied - -```solidity -error AllBallotsTallied() -``` - -### NumSignUpsTooLarge - -```solidity -error NumSignUpsTooLarge() -``` - -### BatchStartIndexTooLarge - -```solidity -error BatchStartIndexTooLarge() -``` - -### TallyBatchSizeTooLarge - -```solidity -error TallyBatchSizeTooLarge() -``` - -### tallyCommitment - -```solidity -uint256 tallyCommitment -``` - -The commitment to the tally results. Its initial value is 0, but after -the tally of each batch is proven on-chain via a zk-SNARK, it should be -updated to: - -hash3( -hashLeftRight(merkle root of current results, salt0) -hashLeftRight(number of spent voice credits, salt1), -hashLeftRight(merkle root of the no. of spent voice credits per vote option, salt2) -) - -Where each salt is unique and the merkle roots are of arrays of leaves -TREE_ARITY \*\* voteOptionTreeDepth long. - -### tallyBatchNum - -```solidity -uint256 tallyBatchNum -``` - -### sbCommitment - -```solidity -uint256 sbCommitment -``` - -### verifier - -```solidity -contract Verifier verifier -``` - -### constructor - -```solidity -constructor(contract Verifier _verifier) public -``` - -### genTallyVotesPackedVals - -```solidity -function genTallyVotesPackedVals(uint256 _numSignUps, uint256 _batchStartIndex, uint256 _tallyBatchSize) public pure returns (uint256) -``` - -Pack the batch start index and number of signups into a 100-bit value. - -#### Parameters - -| Name | Type | Description | -| ----------------- | ------- | ----------- | -| \_numSignUps | uint256 | | -| \_batchStartIndex | uint256 | | -| \_tallyBatchSize | uint256 | | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ----------------------------------------- | -| [0] | uint256 | an uint256 representing 3 inputs together | - -### genTallyVotesPublicInputHash - -```solidity -function genTallyVotesPublicInputHash(uint256 _numSignUps, uint256 _batchStartIndex, uint256 _tallyBatchSize, uint256 _newTallyCommitment) public view returns (uint256) -``` - -generate hash of public inputs for tally circuit - -#### Parameters - -| Name | Type | Description | -| -------------------- | ------- | ----------- | -| \_numSignUps | uint256 | | -| \_batchStartIndex | uint256 | | -| \_tallyBatchSize | uint256 | | -| \_newTallyCommitment | uint256 | | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | --------------------- | -| [0] | uint256 | hash of public inputs | - -### updateSbCommitment - -```solidity -function updateSbCommitment(contract MessageProcessor _mp) public -``` - -### tallyVotes - -```solidity -function tallyVotes(contract Poll _poll, contract MessageProcessor _mp, uint256 _newTallyCommitment, uint256[8] _proof) public -``` - -### verifyTallyProof - -```solidity -function verifyTallyProof(contract Poll _poll, uint256[8] _proof, uint256 _numSignUps, uint256 _batchStartIndex, uint256 _tallyBatchSize, uint256 _newTallyCommitment) public view returns (bool) -``` - -Verify the tally proof using the verifiying key - -#### Parameters - -| Name | Type | Description | -| -------------------- | ------------- | ---------------------------------------------------------- | -| \_poll | contract Poll | contract address of the poll proof to be verified | -| \_proof | uint256[8] | the proof generated after processing all messages | -| \_numSignUps | uint256 | number of signups for a given poll | -| \_batchStartIndex | uint256 | the number of batches multiplied by the size of the batch | -| \_tallyBatchSize | uint256 | batch size for the tally | -| \_newTallyCommitment | uint256 | the tally commitment to be verified at a given batch index | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ---------------------------------------------------- | -| [0] | bool | valid a boolean representing successful verification | - -### computeMerkleRootFromPath - -```solidity -function computeMerkleRootFromPath(uint8 _depth, uint256 _index, uint256 _leaf, uint256[][] _pathElements) internal pure returns (uint256) -``` - -### verifySpentVoiceCredits - -```solidity -function verifySpentVoiceCredits(uint256 _totalSpent, uint256 _totalSpentSalt, uint256 _resultCommitment, uint256 _perVOSpentVoiceCreditsHash) public view returns (bool) -``` - -Verify the number of spent voice credits from the tally.json - -#### Parameters - -| Name | Type | Description | -| ---------------------------- | ------- | ----------------------------------------------------------------------------------------------------- | -| \_totalSpent | uint256 | spent field retrieved in the totalSpentVoiceCredits object | -| \_totalSpentSalt | uint256 | the corresponding salt in the totalSpentVoiceCredit object | -| \_resultCommitment | uint256 | hashLeftRight(merkle root of the results.tally, results.salt) in tally.json file | -| \_perVOSpentVoiceCreditsHash | uint256 | hashLeftRight(merkle root of the no spent voice credits per vote option, perVOSpentVoiceCredits salt) | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ------------------------------------------------------------------------------------- | -| [0] | bool | a boolean representing the status of the verification (could be either true or false) | - -### verifyPerVOSpentVoiceCredits - -```solidity -function verifyPerVOSpentVoiceCredits(uint256 _voteOptionIndex, uint256 _spent, uint256[][] _spentProof, uint256 _spentSalt, uint8 _voteOptionTreeDepth, uint256 _spentVoiceCreditsHash, uint256 _resultCommitment) public view returns (bool) -``` - -Verify the number of spent voice credits per vote option from the tally.json - -#### Parameters - -| Name | Type | Description | -| ----------------------- | ----------- | -------------------------------------------------------------------------------- | -| \_voteOptionIndex | uint256 | the index of the vote option where credits were spent | -| \_spent | uint256 | the spent voice credits for a given vote option index | -| \_spentProof | uint256[][] | proof generated for the perVOSpentVoiceCredits | -| \_spentSalt | uint256 | the corresponding salt given in the tally perVOSpentVoiceCredits object | -| \_voteOptionTreeDepth | uint8 | depth of the vote option tree | -| \_spentVoiceCreditsHash | uint256 | hashLeftRight(number of spent voice credits, spent salt) | -| \_resultCommitment | uint256 | hashLeftRight(merkle root of the results.tally, results.salt) in tally.json file | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ------------------------------------------------------------------------------------- | -| [0] | bool | a boolean representing the status of the verification (could be either true or false) | - -### verifyTallyResult - -```solidity -function verifyTallyResult(uint256 _voteOptionIndex, uint256 _tallyResult, uint256[][] _tallyResultProof, uint256 _tallyResultSalt, uint8 _voteOptionTreeDepth, uint256 _spentVoiceCreditsHash, uint256 _perVOSpentVoiceCreditsHash) public view returns (bool) -``` - -Verify the result generated from the tally.json - -#### Parameters - -| Name | Type | Description | -| ---------------------------- | ----------- | ----------------------------------------------------------------------------------------------------- | -| \_voteOptionIndex | uint256 | the index of the vote option to verify the correctness of the tally | -| \_tallyResult | uint256 | Flattened array of the tally | -| \_tallyResultProof | uint256[][] | Corresponding proof of the tally result | -| \_tallyResultSalt | uint256 | the respective salt in the results object in the tally.json | -| \_voteOptionTreeDepth | uint8 | depth of the vote option tree | -| \_spentVoiceCreditsHash | uint256 | hashLeftRight(number of spent voice credits, spent salt) | -| \_perVOSpentVoiceCreditsHash | uint256 | hashLeftRight(merkle root of the no spent voice credits per vote option, perVOSpentVoiceCredits salt) | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ------------------------------------------------------------------------------------- | -| [0] | bool | a boolean representing the status of the verification (could be either true or false) | diff --git a/contracts/docs/TopupCredit.md b/contracts/docs/TopupCredit.md deleted file mode 100644 index 1882a8dc09..0000000000 --- a/contracts/docs/TopupCredit.md +++ /dev/null @@ -1,45 +0,0 @@ -# Solidity API - -## TopupCredit - -### MAXIMUM_AIRDROP_AMOUNT - -```solidity -uint256 MAXIMUM_AIRDROP_AMOUNT -``` - -### constructor - -```solidity -constructor() public -``` - -### decimals - -```solidity -function decimals() public pure returns (uint8) -``` - -\_Returns the number of decimals used to get its user representation. -For example, if `decimals` equals `2`, a balance of `505` tokens should -be displayed to a user as `5.05` (`505 / 10 ** 2`). - -Tokens usually opt for a value of 18, imitating the relationship between -Ether and Wei. This is the default value returned by this function, unless -it's overridden. - -NOTE: This information is only used for _display_ purposes: it in -no way affects any of the arithmetic of the contract, including -{IERC20-balanceOf} and {IERC20-transfer}.\_ - -### airdropTo - -```solidity -function airdropTo(address account, uint256 amount) public -``` - -### airdrop - -```solidity -function airdrop(uint256 amount) public -``` diff --git a/contracts/docs/VkRegistry.md b/contracts/docs/VkRegistry.md deleted file mode 100644 index c37d936dce..0000000000 --- a/contracts/docs/VkRegistry.md +++ /dev/null @@ -1,199 +0,0 @@ -# Solidity API - -## VkRegistry - -Stores verifying keys for the circuits. -Each circuit has a signature which is its compile-time constants represented -as a uint256. - -### processVks - -```solidity -mapping(uint256 => struct SnarkCommon.VerifyingKey) processVks -``` - -### processVkSet - -```solidity -mapping(uint256 => bool) processVkSet -``` - -### tallyVks - -```solidity -mapping(uint256 => struct SnarkCommon.VerifyingKey) tallyVks -``` - -### tallyVkSet - -```solidity -mapping(uint256 => bool) tallyVkSet -``` - -### subsidyVks - -```solidity -mapping(uint256 => struct SnarkCommon.VerifyingKey) subsidyVks -``` - -### subsidyVkSet - -```solidity -mapping(uint256 => bool) subsidyVkSet -``` - -### ProcessVkSet - -```solidity -event ProcessVkSet(uint256 _sig) -``` - -### TallyVkSet - -```solidity -event TallyVkSet(uint256 _sig) -``` - -### SubsidyVkSet - -```solidity -event SubsidyVkSet(uint256 _sig) -``` - -### ProcessVkAlreadySet - -```solidity -error ProcessVkAlreadySet() -``` - -### TallyVkAlreadySet - -```solidity -error TallyVkAlreadySet() -``` - -### SubsidyVkAlreadySet - -```solidity -error SubsidyVkAlreadySet() -``` - -### ProcessVkNotSet - -```solidity -error ProcessVkNotSet() -``` - -### TallyVkNotSet - -```solidity -error TallyVkNotSet() -``` - -### SubsidyVkNotSet - -```solidity -error SubsidyVkNotSet() -``` - -### isProcessVkSet - -```solidity -function isProcessVkSet(uint256 _sig) public view returns (bool) -``` - -### isTallyVkSet - -```solidity -function isTallyVkSet(uint256 _sig) public view returns (bool) -``` - -### isSubsidyVkSet - -```solidity -function isSubsidyVkSet(uint256 _sig) public view returns (bool) -``` - -### genProcessVkSig - -```solidity -function genProcessVkSig(uint256 _stateTreeDepth, uint256 _messageTreeDepth, uint256 _voteOptionTreeDepth, uint256 _messageBatchSize) public pure returns (uint256) -``` - -### genTallyVkSig - -```solidity -function genTallyVkSig(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _voteOptionTreeDepth) public pure returns (uint256) -``` - -### genSubsidyVkSig - -```solidity -function genSubsidyVkSig(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _voteOptionTreeDepth) public pure returns (uint256) -``` - -### setVerifyingKeys - -```solidity -function setVerifyingKeys(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _messageTreeDepth, uint256 _voteOptionTreeDepth, uint256 _messageBatchSize, struct SnarkCommon.VerifyingKey _processVk, struct SnarkCommon.VerifyingKey _tallyVk) public -``` - -### setSubsidyKeys - -```solidity -function setSubsidyKeys(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _voteOptionTreeDepth, struct SnarkCommon.VerifyingKey _subsidyVk) public -``` - -### hasProcessVk - -```solidity -function hasProcessVk(uint256 _stateTreeDepth, uint256 _messageTreeDepth, uint256 _voteOptionTreeDepth, uint256 _messageBatchSize) public view returns (bool) -``` - -### getProcessVkBySig - -```solidity -function getProcessVkBySig(uint256 _sig) public view returns (struct SnarkCommon.VerifyingKey) -``` - -### getProcessVk - -```solidity -function getProcessVk(uint256 _stateTreeDepth, uint256 _messageTreeDepth, uint256 _voteOptionTreeDepth, uint256 _messageBatchSize) public view returns (struct SnarkCommon.VerifyingKey) -``` - -### hasTallyVk - -```solidity -function hasTallyVk(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _voteOptionTreeDepth) public view returns (bool) -``` - -### getTallyVkBySig - -```solidity -function getTallyVkBySig(uint256 _sig) public view returns (struct SnarkCommon.VerifyingKey) -``` - -### getTallyVk - -```solidity -function getTallyVk(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _voteOptionTreeDepth) public view returns (struct SnarkCommon.VerifyingKey) -``` - -### hasSubsidyVk - -```solidity -function hasSubsidyVk(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _voteOptionTreeDepth) public view returns (bool) -``` - -### getSubsidyVkBySig - -```solidity -function getSubsidyVkBySig(uint256 _sig) public view returns (struct SnarkCommon.VerifyingKey) -``` - -### getSubsidyVk - -```solidity -function getSubsidyVk(uint256 _stateTreeDepth, uint256 _intStateTreeDepth, uint256 _voteOptionTreeDepth) public view returns (struct SnarkCommon.VerifyingKey) -``` diff --git a/contracts/docs/crypto/Hasher.md b/contracts/docs/crypto/Hasher.md deleted file mode 100644 index 242e67e2ae..0000000000 --- a/contracts/docs/crypto/Hasher.md +++ /dev/null @@ -1,74 +0,0 @@ -# Solidity API - -## PoseidonT3 - -### poseidon - -```solidity -function poseidon(uint256[2] input) public pure returns (uint256) -``` - -## PoseidonT4 - -### poseidon - -```solidity -function poseidon(uint256[3] input) public pure returns (uint256) -``` - -## PoseidonT5 - -### poseidon - -```solidity -function poseidon(uint256[4] input) public pure returns (uint256) -``` - -## PoseidonT6 - -### poseidon - -```solidity -function poseidon(uint256[5] input) public pure returns (uint256) -``` - -## Hasher - -A SHA256 hash function for any number of input elements, and Poseidon hash -functions for 2, 3, 4, 5, and 12 input elements. - -### sha256Hash - -```solidity -function sha256Hash(uint256[] array) public pure returns (uint256) -``` - -### hash2 - -```solidity -function hash2(uint256[2] array) public pure returns (uint256) -``` - -### hash3 - -```solidity -function hash3(uint256[3] array) public pure returns (uint256) -``` - -### hash4 - -```solidity -function hash4(uint256[4] array) public pure returns (uint256) -``` - -### hash5 - -```solidity -function hash5(uint256[5] array) public pure returns (uint256) -``` - -### hashLeftRight - -```solidity -function hashLeftRight(uint256 _left, uint256 _right) public pure returns (uint256) -``` diff --git a/contracts/docs/crypto/Pairing.md b/contracts/docs/crypto/Pairing.md deleted file mode 100644 index 91c1a6f492..0000000000 --- a/contracts/docs/crypto/Pairing.md +++ /dev/null @@ -1,65 +0,0 @@ -# Solidity API - -## Pairing - -### PRIME_Q - -```solidity -uint256 PRIME_Q -``` - -### G1Point - -```solidity -struct G1Point { - uint256 x; - uint256 y; -} -``` - -### G2Point - -```solidity -struct G2Point { - uint256[2] x; - uint256[2] y; -} -``` - -### negate - -```solidity -function negate(struct Pairing.G1Point p) internal pure returns (struct Pairing.G1Point) -``` - -The negation of p, i.e. p.plus(p.negate()) should be zero. - -### plus - -```solidity -function plus(struct Pairing.G1Point p1, struct Pairing.G1Point p2) internal view returns (struct Pairing.G1Point r) -``` - -Returns the sum of two points of G1 - -### scalar_mul - -```solidity -function scalar_mul(struct Pairing.G1Point p, uint256 s) internal view returns (struct Pairing.G1Point r) -``` - -Return te product of a point on G1 and a scalar, i.e. -p == p.scalar_mul(1) and p.plus(p) == p.scalar_mul(2) for all -points p. - -### pairing - -```solidity -function pairing(struct Pairing.G1Point a1, struct Pairing.G2Point a2, struct Pairing.G1Point b1, struct Pairing.G2Point b2, struct Pairing.G1Point c1, struct Pairing.G2Point c2, struct Pairing.G1Point d1, struct Pairing.G2Point d2) internal view returns (bool) -``` - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [0] | bool | The result of computing the pairing check e(p1[0], p2[0]) _ .... _ e(p1[n], p2[n]) == 1 For example, pairing([P1(), P1().negate()], [P2(), P2()]) should return true. | diff --git a/contracts/docs/crypto/SnarkCommon.md b/contracts/docs/crypto/SnarkCommon.md deleted file mode 100644 index a766d45d68..0000000000 --- a/contracts/docs/crypto/SnarkCommon.md +++ /dev/null @@ -1,15 +0,0 @@ -# Solidity API - -## SnarkCommon - -### VerifyingKey - -```solidity -struct VerifyingKey { - struct Pairing.G1Point alpha1; - struct Pairing.G2Point beta2; - struct Pairing.G2Point gamma2; - struct Pairing.G2Point delta2; - struct Pairing.G1Point[] ic; -} -``` diff --git a/contracts/docs/crypto/SnarkConstants.md b/contracts/docs/crypto/SnarkConstants.md deleted file mode 100644 index 606b09a8ed..0000000000 --- a/contracts/docs/crypto/SnarkConstants.md +++ /dev/null @@ -1,27 +0,0 @@ -# Solidity API - -## SnarkConstants - -### SNARK_SCALAR_FIELD - -```solidity -uint256 SNARK_SCALAR_FIELD -``` - -### PAD_PUBKEY_X - -```solidity -uint256 PAD_PUBKEY_X -``` - -### PAD_PUBKEY_Y - -```solidity -uint256 PAD_PUBKEY_Y -``` - -### NOTHING_UP_MY_SLEEVE - -```solidity -uint256 NOTHING_UP_MY_SLEEVE -``` diff --git a/contracts/docs/crypto/Verifier.md b/contracts/docs/crypto/Verifier.md deleted file mode 100644 index d4a8a6ea47..0000000000 --- a/contracts/docs/crypto/Verifier.md +++ /dev/null @@ -1,65 +0,0 @@ -# Solidity API - -## IVerifier - -### verify - -```solidity -function verify(uint256[8], struct SnarkCommon.VerifyingKey, uint256) public view virtual returns (bool) -``` - -## MockVerifier - -### result - -```solidity -bool result -``` - -### verify - -```solidity -function verify(uint256[8], struct SnarkCommon.VerifyingKey, uint256) public view returns (bool) -``` - -## Verifier - -### Proof - -```solidity -struct Proof { - struct Pairing.G1Point a; - struct Pairing.G2Point b; - struct Pairing.G1Point c; -} -``` - -### PRIME_Q - -```solidity -uint256 PRIME_Q -``` - -### ERROR_PROOF_Q - -```solidity -string ERROR_PROOF_Q -``` - -### ERROR_INPUT_VAL - -```solidity -string ERROR_INPUT_VAL -``` - -### verify - -```solidity -function verify(uint256[8] _proof, struct SnarkCommon.VerifyingKey vk, uint256 input) public view returns (bool) -``` - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [0] | bool | Whether the proof is valid given the verifying key and public input. Note that this function only supports one public input. Refer to the Semaphore source code for a verifier that supports multiple public inputs. | diff --git a/contracts/docs/gatekeepers/FreeForAllSignUpGatekeeper.md b/contracts/docs/gatekeepers/FreeForAllSignUpGatekeeper.md deleted file mode 100644 index 0759a79aca..0000000000 --- a/contracts/docs/gatekeepers/FreeForAllSignUpGatekeeper.md +++ /dev/null @@ -1,17 +0,0 @@ -# Solidity API - -## FreeForAllGatekeeper - -### setMaciInstance - -```solidity -function setMaciInstance(contract MACI _maci) public -``` - -### register - -```solidity -function register(address, bytes) public -``` - -Registers the user without any restrictions. diff --git a/contracts/docs/gatekeepers/SignUpGatekeeper.md b/contracts/docs/gatekeepers/SignUpGatekeeper.md deleted file mode 100644 index 840f089e7b..0000000000 --- a/contracts/docs/gatekeepers/SignUpGatekeeper.md +++ /dev/null @@ -1,15 +0,0 @@ -# Solidity API - -## SignUpGatekeeper - -### setMaciInstance - -```solidity -function setMaciInstance(contract MACI _maci) public virtual -``` - -### register - -```solidity -function register(address _user, bytes _data) public virtual -``` diff --git a/contracts/docs/gatekeepers/SignUpTokenGatekeeper.md b/contracts/docs/gatekeepers/SignUpTokenGatekeeper.md deleted file mode 100644 index dce96be081..0000000000 --- a/contracts/docs/gatekeepers/SignUpTokenGatekeeper.md +++ /dev/null @@ -1,76 +0,0 @@ -# Solidity API - -## SignUpTokenGatekeeper - -### token - -```solidity -contract SignUpToken token -``` - -### maci - -```solidity -contract MACI maci -``` - -### registeredTokenIds - -```solidity -mapping(uint256 => bool) registeredTokenIds -``` - -### AlreadyRegistered - -```solidity -error AlreadyRegistered() -``` - -### NotTokenOwner - -```solidity -error NotTokenOwner() -``` - -### OnlyMACI - -```solidity -error OnlyMACI() -``` - -### constructor - -```solidity -constructor(contract SignUpToken _token) public -``` - -### setMaciInstance - -```solidity -function setMaciInstance(contract MACI _maci) public -``` - -Adds an uninitialised MACI instance to allow for token singups - -#### Parameters - -| Name | Type | Description | -| ------ | ------------- | ---------------------------------------- | -| \_maci | contract MACI | The MACI contract interface to be stored | - -### register - -```solidity -function register(address _user, bytes _data) public -``` - -Registers the user if they own the token with the token ID encoded in -\_data. Throws if the user is does not own the token or if the token has -already been used to sign up. - -#### Parameters - -| Name | Type | Description | -| ------ | ------- | ------------------------------------- | -| \_user | address | The user's Ethereum address. | -| \_data | bytes | The ABI-encoded tokenId as a uint256. | diff --git a/contracts/docs/initialVoiceCreditProxy/ConstantInitialVoiceCreditProxy.md b/contracts/docs/initialVoiceCreditProxy/ConstantInitialVoiceCreditProxy.md deleted file mode 100644 index 0910412f69..0000000000 --- a/contracts/docs/initialVoiceCreditProxy/ConstantInitialVoiceCreditProxy.md +++ /dev/null @@ -1,29 +0,0 @@ -# Solidity API - -## InitialVoiceCreditProxy - -### getVoiceCredits - -```solidity -function getVoiceCredits(address _user, bytes _data) public view virtual returns (uint256) -``` - -## ConstantInitialVoiceCreditProxy - -### balance - -```solidity -uint256 balance -``` - -### constructor - -```solidity -constructor(uint256 _balance) public -``` - -### getVoiceCredits - -```solidity -function getVoiceCredits(address, bytes) public view returns (uint256) -``` diff --git a/contracts/docs/initialVoiceCreditProxy/InitialVoiceCreditProxy.md b/contracts/docs/initialVoiceCreditProxy/InitialVoiceCreditProxy.md deleted file mode 100644 index 09a8838a4c..0000000000 --- a/contracts/docs/initialVoiceCreditProxy/InitialVoiceCreditProxy.md +++ /dev/null @@ -1,9 +0,0 @@ -# Solidity API - -## InitialVoiceCreditProxy - -### getVoiceCredits - -```solidity -function getVoiceCredits(address _user, bytes _data) public view virtual returns (uint256) -``` diff --git a/contracts/docs/trees/AccQueue.md b/contracts/docs/trees/AccQueue.md deleted file mode 100644 index 7da73414fa..0000000000 --- a/contracts/docs/trees/AccQueue.md +++ /dev/null @@ -1,593 +0,0 @@ -# Solidity API - -## AccQueue - -This contract defines a Merkle tree where each leaf insertion only updates a -subtree. To obtain the main tree root, the contract owner must merge the -subtrees together. Merging subtrees requires at least 2 operations: -mergeSubRoots(), and merge(). To get around the gas limit, -the mergeSubRoots() can be performed in multiple transactions. - -### MAX_DEPTH - -```solidity -uint256 MAX_DEPTH -``` - -### Queue - -```solidity -struct Queue { - uint256[4][33] levels; - uint256[33] indices; -} -``` - -### subDepth - -```solidity -uint256 subDepth -``` - -### hashLength - -```solidity -uint256 hashLength -``` - -### subTreeCapacity - -```solidity -uint256 subTreeCapacity -``` - -### isBinary - -```solidity -bool isBinary -``` - -### currentSubtreeIndex - -```solidity -uint256 currentSubtreeIndex -``` - -### leafQueue - -```solidity -struct AccQueue.Queue leafQueue -``` - -### subRootQueue - -```solidity -struct AccQueue.Queue subRootQueue -``` - -### subRoots - -```solidity -mapping(uint256 => uint256) subRoots -``` - -### mainRoots - -```solidity -uint256[33] mainRoots -``` - -### subTreesMerged - -```solidity -bool subTreesMerged -``` - -### treeMerged - -```solidity -bool treeMerged -``` - -### smallSRTroot - -```solidity -uint256 smallSRTroot -``` - -### nextSubRootIndex - -```solidity -uint256 nextSubRootIndex -``` - -### numLeaves - -```solidity -uint256 numLeaves -``` - -### SubDepthCannotBeZero - -```solidity -error SubDepthCannotBeZero() -``` - -### SubdepthTooLarge - -```solidity -error SubdepthTooLarge(uint256 _subDepth, uint256 max) -``` - -### InvalidHashLength - -```solidity -error InvalidHashLength() -``` - -### DepthCannotBeZero - -```solidity -error DepthCannotBeZero() -``` - -### SubTreesAlreadyMerged - -```solidity -error SubTreesAlreadyMerged() -``` - -### NothingToMerge - -```solidity -error NothingToMerge() -``` - -### SubTreesNotMerged - -```solidity -error SubTreesNotMerged() -``` - -### DepthTooLarge - -```solidity -error DepthTooLarge(uint256 _depth, uint256 max) -``` - -### DepthTooSmall - -```solidity -error DepthTooSmall(uint256 _depth, uint256 min) -``` - -### InvalidIndex - -```solidity -error InvalidIndex(uint256 _index) -``` - -### constructor - -```solidity -constructor(uint256 _subDepth, uint256 _hashLength) internal -``` - -### hashLevel - -```solidity -function hashLevel(uint256 _level, uint256 _leaf) internal virtual returns (uint256) -``` - -Hash the contents of the specified level and the specified leaf. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which require -different input array lengths. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | -------------------------------- | -| \_level | uint256 | The level to hash. | -| \_leaf | uint256 | The leaf include with the level. | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ------------------------------- | -| [0] | uint256 | The hash of the level and leaf. | - -### hashLevelLeaf - -```solidity -function hashLevelLeaf(uint256 _level, uint256 _leaf) public view virtual returns (uint256) -``` - -### getZero - -```solidity -function getZero(uint256 _level) internal virtual returns (uint256) -``` - -Returns the zero leaf at a specified level. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which will produce -different zero values (e.g. hashLeftRight(0, 0) vs -hash5([0, 0, 0, 0, 0]). Moreover, the zero value may be a -nothing-up-my-sleeve value. - -### enqueue - -```solidity -function enqueue(uint256 _leaf) public returns (uint256) -``` - -Add a leaf to the queue for the current subtree. - -#### Parameters - -| Name | Type | Description | -| ------ | ------- | ---------------- | -| \_leaf | uint256 | The leaf to add. | - -### \_enqueue - -```solidity -function _enqueue(uint256 _leaf, uint256 _level) internal -``` - -Updates the queue at a given level and hashes any subroots that need to -be hashed. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ------------------------------------- | -| \_leaf | uint256 | The leaf to add. | -| \_level | uint256 | The level at which to queue the leaf. | - -### fill - -```solidity -function fill() public -``` - -Fill any empty leaves of the current subtree with zeros and store the -resulting subroot. - -### \_fill - -```solidity -function _fill(uint256 _level) internal virtual -``` - -A function that queues zeros to the specified level, hashes, -the level, and enqueues the hash to the next level. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ---------------------------------- | -| \_level | uint256 | The level at which to queue zeros. | - -### insertSubTree - -```solidity -function insertSubTree(uint256 _subRoot) public -``` - -Insert a subtree. Used for batch enqueues. - -### calcMinHeight - -```solidity -function calcMinHeight() public view returns (uint256) -``` - -Calculate the lowest possible height of a tree with all the subroots -merged together. - -### mergeSubRoots - -```solidity -function mergeSubRoots(uint256 _numSrQueueOps) public -``` - -Merge all subtrees to form the shortest possible tree. -This function can be called either once to merge all subtrees in a -single transaction, or multiple times to do the same in multiple -transactions. If \_numSrQueueOps is set to 0, this function will attempt -to merge all subtrees in one go. If it is set to a number greater than -0, it will perform up to that number of queueSubRoot() operations. - -#### Parameters - -| Name | Type | Description | -| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| \_numSrQueueOps | uint256 | The number of times this function will call queueSubRoot(), up to the maximum number of times is necessary. If it is set to 0, it will call queueSubRoot() as many times as is necessary. Set this to a low number and call this function multiple times if there are many subroots to merge, or a single transaction would run out of gas. | - -### queueSubRoot - -```solidity -function queueSubRoot(uint256 _leaf, uint256 _level, uint256 _maxDepth) internal -``` - -Queues a subroot into the subroot tree. - -#### Parameters - -| Name | Type | Description | -| ---------- | ------- | ----------------------------------- | -| \_leaf | uint256 | The value to queue. | -| \_level | uint256 | The level at which to queue \_leaf. | -| \_maxDepth | uint256 | The depth of the tree. | - -### merge - -```solidity -function merge(uint256 _depth) public returns (uint256) -``` - -Merge all subtrees to form a main tree with a desired depth. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ------------------------------------------------------------------------------------ | -| \_depth | uint256 | The depth of the main tree. It must fit all the leaves or this function will revert. | - -### getSubRoot - -```solidity -function getSubRoot(uint256 _index) public view returns (uint256) -``` - -Returns the subroot at the specified index. Reverts if the index refers -to a subtree which has not been filled yet. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ------------------ | -| \_index | uint256 | The subroot index. | - -### getSmallSRTroot - -```solidity -function getSmallSRTroot() public view returns (uint256) -``` - -Returns the subroot tree (SRT) root. Its value must first be computed -using mergeSubRoots. - -### getMainRoot - -```solidity -function getMainRoot(uint256 _depth) public view returns (uint256) -``` - -Return the merged Merkle root of all the leaves at a desired depth. -merge() or merged(\_depth) must be called first. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ---------------------------------------------------------------------------------------- | -| \_depth | uint256 | The depth of the main tree. It must first be computed using mergeSubRoots() and merge(). | - -### getSrIndices - -```solidity -function getSrIndices() public view returns (uint256, uint256) -``` - -## AccQueueBinary - -### constructor - -```solidity -constructor(uint256 _subDepth) internal -``` - -### hashLevel - -```solidity -function hashLevel(uint256 _level, uint256 _leaf) internal returns (uint256) -``` - -Hash the contents of the specified level and the specified leaf. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which require -different input array lengths. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | -------------------------------- | -| \_level | uint256 | The level to hash. | -| \_leaf | uint256 | The leaf include with the level. | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ------------------------------- | -| [0] | uint256 | The hash of the level and leaf. | - -### hashLevelLeaf - -```solidity -function hashLevelLeaf(uint256 _level, uint256 _leaf) public view returns (uint256) -``` - -### \_fill - -```solidity -function _fill(uint256 _level) internal -``` - -A function that queues zeros to the specified level, hashes, -the level, and enqueues the hash to the next level. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ---------------------------------- | -| \_level | uint256 | The level at which to queue zeros. | - -## AccQueueQuinary - -### constructor - -```solidity -constructor(uint256 _subDepth) internal -``` - -### hashLevel - -```solidity -function hashLevel(uint256 _level, uint256 _leaf) internal returns (uint256) -``` - -Hash the contents of the specified level and the specified leaf. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which require -different input array lengths. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | -------------------------------- | -| \_level | uint256 | The level to hash. | -| \_leaf | uint256 | The leaf include with the level. | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ------------------------------- | -| [0] | uint256 | The hash of the level and leaf. | - -### hashLevelLeaf - -```solidity -function hashLevelLeaf(uint256 _level, uint256 _leaf) public view returns (uint256) -``` - -### \_fill - -```solidity -function _fill(uint256 _level) internal -``` - -A function that queues zeros to the specified level, hashes, -the level, and enqueues the hash to the next level. - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ---------------------------------- | -| \_level | uint256 | The level at which to queue zeros. | - -## AccQueueBinary0 - -### constructor - -```solidity -constructor(uint256 _subDepth) public -``` - -### getZero - -```solidity -function getZero(uint256 _level) internal view returns (uint256) -``` - -Returns the zero leaf at a specified level. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which will produce -different zero values (e.g. hashLeftRight(0, 0) vs -hash5([0, 0, 0, 0, 0]). Moreover, the zero value may be a -nothing-up-my-sleeve value. - -## AccQueueBinaryMaci - -### constructor - -```solidity -constructor(uint256 _subDepth) public -``` - -### getZero - -```solidity -function getZero(uint256 _level) internal view returns (uint256) -``` - -Returns the zero leaf at a specified level. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which will produce -different zero values (e.g. hashLeftRight(0, 0) vs -hash5([0, 0, 0, 0, 0]). Moreover, the zero value may be a -nothing-up-my-sleeve value. - -## AccQueueQuinary0 - -### constructor - -```solidity -constructor(uint256 _subDepth) public -``` - -### getZero - -```solidity -function getZero(uint256 _level) internal view returns (uint256) -``` - -Returns the zero leaf at a specified level. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which will produce -different zero values (e.g. hashLeftRight(0, 0) vs -hash5([0, 0, 0, 0, 0]). Moreover, the zero value may be a -nothing-up-my-sleeve value. - -## AccQueueQuinaryMaci - -### constructor - -```solidity -constructor(uint256 _subDepth) public -``` - -### getZero - -```solidity -function getZero(uint256 _level) internal view returns (uint256) -``` - -Returns the zero leaf at a specified level. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which will produce -different zero values (e.g. hashLeftRight(0, 0) vs -hash5([0, 0, 0, 0, 0]). Moreover, the zero value may be a -nothing-up-my-sleeve value. - -## AccQueueQuinaryBlankSl - -### constructor - -```solidity -constructor(uint256 _subDepth) public -``` - -### getZero - -```solidity -function getZero(uint256 _level) internal view returns (uint256) -``` - -Returns the zero leaf at a specified level. -This is a virtual function as the hash function which the overriding -contract uses will be either hashLeftRight or hash5, which will produce -different zero values (e.g. hashLeftRight(0, 0) vs -hash5([0, 0, 0, 0, 0]). Moreover, the zero value may be a -nothing-up-my-sleeve value. diff --git a/contracts/docs/trees/EmptyBallotRoots.md b/contracts/docs/trees/EmptyBallotRoots.md deleted file mode 100644 index 1a75c0900f..0000000000 --- a/contracts/docs/trees/EmptyBallotRoots.md +++ /dev/null @@ -1,15 +0,0 @@ -# Solidity API - -## EmptyBallotRoots - -### emptyBallotRoots - -```solidity -uint256[5] emptyBallotRoots -``` - -### constructor - -```solidity -constructor() internal -``` diff --git a/contracts/docs/utilities/Utility.md b/contracts/docs/utilities/Utility.md deleted file mode 100644 index 55b2b8368e..0000000000 --- a/contracts/docs/utilities/Utility.md +++ /dev/null @@ -1,29 +0,0 @@ -# Solidity API - -## CommonUtilities - -### VOTING_PERIOD_NOT_PASSED - -```solidity -error VOTING_PERIOD_NOT_PASSED() -``` - -### \_votingPeriodOver - -```solidity -function _votingPeriodOver(contract Poll _poll) internal view -``` - -## Utilities - -### padAndHashMessage - -```solidity -function padAndHashMessage(uint256[2] dataToPad, uint256 msgType) public pure returns (struct IMessage.Message, struct IPubKey.PubKey, uint256) -``` - -### hashMessageAndEncPubKey - -```solidity -function hashMessageAndEncPubKey(struct IMessage.Message _message, struct IPubKey.PubKey _encPubKey) public pure returns (uint256) -``` diff --git a/domainobjs/ts/__tests__/DomainObjs.test.ts b/domainobjs/ts/__tests__/DomainObjs.test.ts deleted file mode 100644 index cbd7bdadc1..0000000000 --- a/domainobjs/ts/__tests__/DomainObjs.test.ts +++ /dev/null @@ -1,286 +0,0 @@ -import * as path from "path"; -import * as fs from "fs"; -import { expect } from "chai"; -import { - StateLeaf, - PCommand, - Keypair, - PrivKey, - PubKey, - VerifyingKey, -} from "../"; - -import { genKeypair, unpackPubKey, genRandomSalt } from "maci-crypto"; - -describe("Domain objects", function () { - this.timeout(100000); - - const { privKey, pubKey } = new Keypair(); - const k = new Keypair(); - - const pubKey1 = k.pubKey; - - const newPubKey = k.pubKey; - - const ecdhSharedKey = Keypair.genEcdhSharedKey(privKey, pubKey1); - - const random50bitBigInt = (): bigint => { - return ( - ((BigInt(1) << BigInt(50)) - BigInt(1)) & - BigInt(`${genRandomSalt()}`) - ); - }; - - const command: PCommand = new PCommand( - random50bitBigInt(), - newPubKey, - random50bitBigInt(), - random50bitBigInt(), - random50bitBigInt(), - random50bitBigInt(), - genRandomSalt() - ); - - describe("Verifying keys", () => { - it("Should convert a JSON file from snarkjs to a VerifyingKey", () => { - const file = path.join(__dirname, "test_vk.json"); - const j = fs.readFileSync(file).toString(); - const d = JSON.parse(j); - const vk = VerifyingKey.fromJSON(j); - - expect(d.vk_alpha_1[0]).to.eq(vk.alpha1.x.toString()); - expect(d.vk_alpha_1[1]).to.eq(vk.alpha1.y.toString()); - - expect(d.vk_beta_2[0][0]).to.eq(vk.beta2.x[1].toString()); - expect(d.vk_beta_2[0][1]).to.eq(vk.beta2.x[0].toString()); - expect(d.vk_beta_2[1][0]).to.eq(vk.beta2.y[1].toString()); - expect(d.vk_beta_2[1][1]).to.eq(vk.beta2.y[0].toString()); - - expect(d.vk_gamma_2[0][0]).to.eq(vk.gamma2.x[1].toString()); - expect(d.vk_gamma_2[0][1]).to.eq(vk.gamma2.x[0].toString()); - expect(d.vk_gamma_2[1][0]).to.eq(vk.gamma2.y[1].toString()); - expect(d.vk_gamma_2[1][1]).to.eq(vk.gamma2.y[0].toString()); - - expect(d.vk_delta_2[0][0]).to.eq(vk.delta2.x[1].toString()); - expect(d.vk_delta_2[0][1]).to.eq(vk.delta2.x[0].toString()); - expect(d.vk_delta_2[1][0]).to.eq(vk.delta2.y[1].toString()); - expect(d.vk_delta_2[1][1]).to.eq(vk.delta2.y[0].toString()); - - expect(d.IC.length).to.eq(vk.ic.length); - for (let i = 0; i < d.IC.length; i++) { - expect(d.IC[i][0]).to.eq(vk.ic[i].x.toString()); - expect(d.IC[i][1]).to.eq(vk.ic[i].y.toString()); - } - }); - }); - - describe("State leaves", () => { - it("The serialize() and unserialize() functions should work correctly", () => { - const stateLeaf = new StateLeaf( - pubKey, - BigInt(123), - BigInt(1231267) - ); - - const serialized = stateLeaf.serialize(); - const unserialized = StateLeaf.deserialize(serialized); - - expect(unserialized.voiceCreditBalance.toString()).to.eq( - stateLeaf.voiceCreditBalance.toString() - ); - }); - }); - - describe("Keypairs", () => { - it("the Keypair constructor should generate a random keypair if not provided a private key", () => { - const k1 = new Keypair(); - const k2 = new Keypair(); - - expect(k1.equals(k2)).to.be.false; - - expect(k1.privKey.rawPrivKey).not.to.eq(k2.privKey.rawPrivKey); - }); - - it("the Keypair constructor should generate the correct public key given a private key", () => { - const rawKeyPair = genKeypair(); - const k = new Keypair(new PrivKey(rawKeyPair.privKey)); - expect(rawKeyPair.pubKey[0]).to.eq(k.pubKey.rawPubKey[0]); - expect(rawKeyPair.pubKey[1]).to.eq(k.pubKey.rawPubKey[1]); - }); - - it("PrivKey.serialize() and unserialize() should work correctly", () => { - const k = new Keypair(); - const sk1 = k.privKey; - - const s = sk1.serialize(); - expect(s.startsWith("macisk.")).to.be.true; - - const d = "0x" + s.slice(7); - expect(sk1.rawPrivKey.toString()).to.eq(BigInt(d).toString()); - - const c = PrivKey.deserialize(s); - expect(sk1.rawPrivKey.toString()).to.eq( - BigInt(`${c.rawPrivKey}`).toString() - ); - }); - - it("PrivKey.isValidSerializedPrivKey() should work correctly", () => { - const k = new Keypair(); - const s = k.privKey.serialize(); - - expect(PrivKey.isValidSerializedPrivKey(s)).to.be.true; - expect(PrivKey.isValidSerializedPrivKey(s.slice(1))).to.be.false; - }); - - it("PubKey.isValidSerializedPubKey() should work correctly", () => { - const k = new Keypair(); - const s = k.pubKey.serialize(); - - expect(PubKey.isValidSerializedPubKey(s)).to.be.true; - expect( - PubKey.isValidSerializedPubKey( - s + "ffffffffffffffffffffffffffffff" - ) - ).to.be.false; - expect(PubKey.isValidSerializedPubKey(s.slice(1))).to.be.false; - }); - - it("PubKey.serialize() and unserialize() should work correctly", () => { - const k = new Keypair(); - const pk1 = k.pubKey; - - const s = pk1.serialize(); - expect(s.startsWith("macipk.")).to.be.true; - - const d = s.slice(7); - const unpacked = unpackPubKey(Buffer.from(d, "hex")); - - expect(unpacked[0].toString()).to.eq(pk1.rawPubKey[0].toString()); - expect(unpacked[1].toString()).to.eq(pk1.rawPubKey[1].toString()); - }); - - it("PrivKey.copy() should produce a deep copy", () => { - const k = new Keypair(); - const sk1 = k.privKey; - - // shallow copy - const sk2 = sk1; - - expect(sk1.rawPrivKey.toString()).to.eq(sk2.rawPrivKey.toString()); - sk1.rawPrivKey = BigInt(0); - expect(sk1.rawPrivKey.toString()).to.eq(sk2.rawPrivKey.toString()); - - // deep copy - const k1 = new Keypair(); - const sk3 = k1.privKey; - const sk4 = sk3.copy(); - expect(sk3.rawPrivKey.toString()).to.eq(sk4.rawPrivKey.toString()); - sk4.rawPrivKey = BigInt(0); - expect(sk3.rawPrivKey.toString()).not.to.eq( - sk4.rawPrivKey.toString() - ); - }); - - it("PubKey.copy() should produce a deep copy", () => { - const k = new Keypair(); - const pk1 = k.pubKey; - - // shallow copy - const pk2 = pk1; - - expect(pk1.rawPubKey.toString()).to.eq(pk2.rawPubKey.toString()); - pk1.rawPubKey = [BigInt(0)]; - expect(pk1.rawPubKey.toString()).to.eq(pk2.rawPubKey.toString()); - - // deep copy - const k1 = new Keypair(); - const pk3 = k1.pubKey; - const pk4 = pk3.copy(); - expect(pk3.rawPubKey.toString()).to.eq(pk4.rawPubKey.toString()); - pk4.rawPubKey = [BigInt(0)]; - expect(pk3.rawPubKey.toString()).not.to.eq( - pk4.rawPubKey.toString() - ); - }); - - it("Keypair.copy() should produce a deep copy", () => { - const k1 = new Keypair(); - - // shallow copy - const k2 = k1; - - expect(k1.privKey.rawPrivKey.toString()).to.eq( - k2.privKey.rawPrivKey.toString() - ); - k1.privKey.rawPrivKey = BigInt(0); - expect(k1.privKey.rawPrivKey.toString()).to.eq( - k2.privKey.rawPrivKey.toString() - ); - - // deep copy - const k3 = new Keypair(); - const k4 = k3.copy(); - expect(k3.privKey.rawPrivKey.toString()).to.eq( - k4.privKey.rawPrivKey.toString() - ); - - k3.privKey.rawPrivKey = BigInt(0); - expect(k3.privKey.rawPrivKey.toString()).not.to.eq( - k4.privKey.rawPrivKey.toString() - ); - }); - }); - - describe("Commands and Messages", () => { - const signature = command.sign(privKey); - const message = command.encrypt(signature, ecdhSharedKey); - const decrypted = PCommand.decrypt(message, ecdhSharedKey); - - it("command.sign() should produce a valid signature", () => { - expect(command.verifySignature(signature, pubKey)).to.be.true; - }); - - it("A decrypted message should match the original command", () => { - expect(decrypted.command.equals(command)).to.be.true; - expect(decrypted.signature.R8[0].toString()).to.eq( - signature.R8[0].toString() - ); - expect(decrypted.signature.R8[1].toString()).to.eq( - signature.R8[1].toString() - ); - expect(decrypted.signature.S.toString()).to.eq( - signature.S.toString() - ); - }); - - it("A decrypted message should have a valid signature", () => { - const isValid = decrypted.command.verifySignature( - decrypted.signature, - pubKey - ); - expect(isValid).to.be.true; - }); - - it("Command.copy() should perform a deep copy", () => { - const c1: PCommand = new PCommand( - BigInt(10), - newPubKey, - BigInt(0), - BigInt(9), - BigInt(1), - BigInt(123) - ); - - // shallow copy - const c2 = c1; - c1.nonce = BigInt(9999); - expect(c1.nonce.toString()).to.eq(c2.nonce.toString()); - - // deep copy - const c3 = c1.copy(); - c1.nonce = BigInt(8888); - - expect(c1.nonce.toString()).not.to.eq(c3.nonce.toString()); - }); - }); -}); diff --git a/domainobjs/ts/__tests__/test_vk.json b/domainobjs/ts/__tests__/test_vk.json deleted file mode 100644 index c763cc2a2c..0000000000 --- a/domainobjs/ts/__tests__/test_vk.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "protocol": "groth16", - "curve": "bn128", - "nPublic": 1, - "vk_alpha_1": [ - "20491192805390485299153009773594534940189261866228447918068658471970481763042", - "9383485363053290200918347156157836566562967994039712273449902621266178545958", - "1" - ], - "vk_beta_2": [ - [ - "6375614351688725206403948262868962793625744043794305715222011528459656738731", - "4252822878758300859123897981450591353533073413197771768651442665752259397132" - ], - [ - "10505242626370262277552901082094356697409835680220590971873171140371331206856", - "21847035105528745403288232691147584728191162732299865338377159692350059136679" - ], - ["1", "0"] - ], - "vk_gamma_2": [ - [ - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634" - ], - [ - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" - ], - ["1", "0"] - ], - "vk_delta_2": [ - [ - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634" - ], - [ - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" - ], - ["1", "0"] - ], - "vk_alphabeta_12": [ - [ - [ - "2029413683389138792403550203267699914886160938906632433982220835551125967885", - "21072700047562757817161031222997517981543347628379360635925549008442030252106" - ], - [ - "5940354580057074848093997050200682056184807770593307860589430076672439820312", - "12156638873931618554171829126792193045421052652279363021382169897324752428276" - ], - [ - "7898200236362823042373859371574133993780991612861777490112507062703164551277", - "7074218545237549455313236346927434013100842096812539264420499035217050630853" - ] - ], - [ - [ - "7077479683546002997211712695946002074877511277312570035766170199895071832130", - "10093483419865920389913245021038182291233451549023025229112148274109565435465" - ], - [ - "4595479056700221319381530156280926371456704509942304414423590385166031118820", - "19831328484489333784475432780421641293929726139240675179672856274388269393268" - ], - [ - "11934129596455521040620786944827826205713621633706285934057045369193958244500", - "8037395052364110730298837004334506829870972346962140206007064471173334027475" - ] - ] - ], - "IC": [ - [ - "10217961970561191542644673983819768829937049061556810432559046731768416748444", - "6614275190456400384394041626145087414551326824635999101683327156828330915037", - "1" - ], - [ - "11971344866240172007938968889867162918709454623842568616296127157079254314975", - "10060981430167258432297298832690153434217272087448231305232740724870906593798", - "1" - ] - ] -}