Skip to content

Commit

Permalink
use MACI v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed May 16, 2024
1 parent 3724763 commit d8cd50c
Show file tree
Hide file tree
Showing 52 changed files with 473 additions and 988 deletions.
4 changes: 2 additions & 2 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"dependencies": {
"@openzeppelin/merkle-tree": "^1.0.5",
"ethers": "^6.11.1",
"maci-crypto": "1.2.0",
"maci-domainobjs": "1.2.0"
"maci-crypto": "1.2.1",
"maci-domainobjs": "1.2.1"
},
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions common/src/__tests__/keypair.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai'
import { Keypair, PubKey } from '../keypair'
import { Wallet, sha256, randomBytes } from 'ethers'

describe.only('keypair', function () {
describe('keypair', function () {
for (let i = 0; i < 10; i++) {
it(`should generate key ${i} from seed successfully`, function () {
const wallet = Wallet.createRandom()
Expand All @@ -14,7 +14,8 @@ describe.only('keypair', function () {
}

it('should throw if pubKey is invalid', () => {
const pubKey = new PubKey([1n, 1n])
expect(() => pubKey.serialize()).to.throw('Invalid public key')
expect(() => {
new PubKey([1n, 1n])
}).to.throw('PubKey not on curve')
})
})
5 changes: 1 addition & 4 deletions common/src/keypair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ function genPrivKey(hash: string): PrivKey {
for (let counter = 1; pubKey === null; counter++) {
try {
const privKey = new PrivKey(rawPrivKey)
const keypair = new Keypair(privKey)

// this will throw 'Invalid public key' if key is not on the Baby Jubjub elliptic curve
keypair.pubKey.serialize()

const keypair = new Keypair(privKey)
pubKey = keypair.pubKey
} catch {
const data = concat([toBeArray(rawPrivKey), toBeArray(counter)])
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/AnyOldERC20Token.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/CloneFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

pragma solidity 0.8.10;
pragma solidity 0.8.20;

contract CloneFactory { // implementation of eip-1167 - see https://eips.ethereum.org/EIPS/eip-1167
function createClone(address target) internal returns (address result) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/ClrFund.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.10;
pragma solidity 0.8.20;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/ClrFundDeployer.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.10;
pragma solidity 0.8.20;

import {MACIFactory} from './MACIFactory.sol';
import {ClrFund} from './ClrFund.sol';
Expand All @@ -9,7 +9,7 @@ import {SignUpGatekeeper} from "maci-contracts/contracts/gatekeepers/SignUpGatek
import {InitialVoiceCreditProxy} from "maci-contracts/contracts/initialVoiceCreditProxy/InitialVoiceCreditProxy.sol";
import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';

contract ClrFundDeployer is CloneFactory, Ownable {
contract ClrFundDeployer is CloneFactory, Ownable(msg.sender) {
address public clrfundTemplate;
address public maciFactory;
address public roundFactory;
Expand Down
3 changes: 1 addition & 2 deletions contracts/contracts/ExternalContacts.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

/*
* These imports are just for hardhat to find the contracts for deployment
Expand All @@ -9,5 +9,4 @@ pragma solidity ^0.8.10;
import {Poll} from 'maci-contracts/contracts/Poll.sol';
import {PollFactory} from 'maci-contracts/contracts/PollFactory.sol';
import {TallyFactory} from 'maci-contracts/contracts/TallyFactory.sol';
import {SubsidyFactory} from 'maci-contracts/contracts/SubsidyFactory.sol';
import {MessageProcessorFactory} from 'maci-contracts/contracts/MessageProcessorFactory.sol';
12 changes: 6 additions & 6 deletions contracts/contracts/FundingRound.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.10;
pragma solidity 0.8.20;

import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
Expand All @@ -15,7 +15,7 @@ import {SignUpGatekeeper} from 'maci-contracts/contracts/gatekeepers/SignUpGatek
import {InitialVoiceCreditProxy} from 'maci-contracts/contracts/initialVoiceCreditProxy/InitialVoiceCreditProxy.sol';
import {CommonUtilities} from 'maci-contracts/contracts/utilities/CommonUtilities.sol';
import {SnarkCommon} from 'maci-contracts/contracts/crypto/SnarkCommon.sol';
import {ITallySubsidyFactory} from 'maci-contracts/contracts/interfaces/ITallySubsidyFactory.sol';
import {ITallyFactory} from 'maci-contracts/contracts/interfaces/ITallyFactory.sol';
import {IMessageProcessorFactory} from 'maci-contracts/contracts/interfaces/IMPFactory.sol';
import {IClrFund} from './interfaces/IClrFund.sol';
import {IMACIFactory} from './interfaces/IMACIFactory.sol';
Expand All @@ -25,7 +25,7 @@ import './userRegistry/IUserRegistry.sol';
import './recipientRegistry/IRecipientRegistry.sol';

contract FundingRound is
Ownable,
Ownable(msg.sender),
SignUpGatekeeper,
InitialVoiceCreditProxy,
DomainObjs,
Expand Down Expand Up @@ -221,10 +221,10 @@ contract FundingRound is
address vkRegistry = address(tally.vkRegistry());

IMessageProcessorFactory messageProcessorFactory = maci.messageProcessorFactory();
ITallySubsidyFactory tallyFactory = maci.tallyFactory();
ITallyFactory tallyFactory = maci.tallyFactory();

address mp = messageProcessorFactory.deploy(verifier, vkRegistry, address(poll), coordinator);
address newTally = tallyFactory.deploy(verifier, vkRegistry, address(poll), mp, coordinator);
address mp = messageProcessorFactory.deploy(verifier, vkRegistry, address(poll), coordinator, Mode.QV);
address newTally = tallyFactory.deploy(verifier, vkRegistry, address(poll), mp, coordinator, Mode.QV);
_setTally(newTally);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/FundingRoundFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

import {FundingRound} from './FundingRound.sol';
import {IClrFund} from './interfaces/IClrFund.sol';
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/MACICommon.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

/**
* @dev a contract that holds common MACI structures
Expand Down
24 changes: 13 additions & 11 deletions contracts/contracts/MACIFactory.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

import {MACI} from 'maci-contracts/contracts/MACI.sol';
import {IPollFactory} from 'maci-contracts/contracts/interfaces/IPollFactory.sol';
import {ITallySubsidyFactory} from 'maci-contracts/contracts/interfaces/ITallySubsidyFactory.sol';
import {ITallyFactory} from 'maci-contracts/contracts/interfaces/ITallyFactory.sol';
import {IMessageProcessorFactory} from 'maci-contracts/contracts/interfaces/IMPFactory.sol';
import {SignUpGatekeeper} from 'maci-contracts/contracts/gatekeepers/SignUpGatekeeper.sol';
import {InitialVoiceCreditProxy} from 'maci-contracts/contracts/initialVoiceCreditProxy/InitialVoiceCreditProxy.sol';
Expand All @@ -17,7 +17,7 @@ import {Params} from 'maci-contracts/contracts/utilities/Params.sol';
import {DomainObjs} from 'maci-contracts/contracts/utilities/DomainObjs.sol';
import {MACICommon} from './MACICommon.sol';

contract MACIFactory is Ownable, Params, SnarkCommon, DomainObjs, MACICommon {
contract MACIFactory is Ownable(msg.sender), Params, SnarkCommon, DomainObjs, MACICommon {

// Verifying Key Registry containing circuit parameters
VkRegistry public vkRegistry;
Expand Down Expand Up @@ -135,15 +135,17 @@ contract MACIFactory is Ownable, Params, SnarkCommon, DomainObjs, MACICommon {
_stateTreeDepth,
_treeDepths.messageTreeDepth,
_treeDepths.voteOptionTreeDepth,
messageBatchSize)
messageBatchSize,
Mode.QV)
) {
revert ProcessVkNotSet();
}

if (!vkRegistry.hasTallyVk(
_stateTreeDepth,
_treeDepths.intStateTreeDepth,
_treeDepths.voteOptionTreeDepth)
_treeDepths.voteOptionTreeDepth,
Mode.QV)
) {
revert TallyVkNotSet();
}
Expand Down Expand Up @@ -175,24 +177,25 @@ contract MACIFactory is Ownable, Params, SnarkCommon, DomainObjs, MACICommon {
stateTreeDepth,
treeDepths.messageTreeDepth,
treeDepths.voteOptionTreeDepth,
messageBatchSize)
messageBatchSize,
Mode.QV)
) {
revert ProcessVkNotSet();
}

if (!vkRegistry.hasTallyVk(
stateTreeDepth,
treeDepths.intStateTreeDepth,
treeDepths.voteOptionTreeDepth)
treeDepths.voteOptionTreeDepth,
Mode.QV)
) {
revert TallyVkNotSet();
}

_maci = new MACI(
IPollFactory(factories.pollFactory),
IMessageProcessorFactory(factories.messageProcessorFactory),
ITallySubsidyFactory(factories.tallyFactory),
ITallySubsidyFactory(factories.subsidyFactory),
ITallyFactory(factories.tallyFactory),
signUpGatekeeper,
initialVoiceCreditProxy,
TopupCredit(topupCredit),
Expand All @@ -205,8 +208,7 @@ contract MACIFactory is Ownable, Params, SnarkCommon, DomainObjs, MACICommon {
coordinatorPubKey,
address(verifier),
address(vkRegistry),
// pass false to not deploy the subsidy contract
false
Mode.QV
);

// transfer ownership to coordinator to run the tally scripts
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/OwnableUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

// NOTE: had to copy contracts over since OZ uses a higher pragma than we do in the one's they maintain.

Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/TopupToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
Expand All @@ -9,7 +9,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
* TopupToken is used by MACI Poll contract to validate the topup credits of a user
* In clrfund, this is only used as gateway to pass the topup amount to the Poll contract
*/
contract TopupToken is ERC20, Ownable {
contract TopupToken is ERC20, Ownable(msg.sender) {
constructor() ERC20("TopupCredit", "TopupCredit") {}

function airdrop(uint256 amount) public onlyOwner {
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/interfaces/IClrFund.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.10;
pragma solidity 0.8.20;

import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import {IUserRegistry} from '../userRegistry/IUserRegistry.sol';
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/interfaces/IFundingRound.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';

Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/interfaces/IFundingRoundFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';

Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/interfaces/IMACIFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.10;
pragma solidity 0.8.20;

import {IVkRegistry} from 'maci-contracts/contracts/interfaces/IVkRegistry.sol';
import {IVerifier} from 'maci-contracts/contracts/interfaces/IVerifier.sol';
Expand Down
Loading

0 comments on commit d8cd50c

Please sign in to comment.