From 22ca14fbed2b43108d1809d9332216c5ce99086c Mon Sep 17 00:00:00 2001 From: Dozie2001 Date: Tue, 30 Jul 2024 19:16:59 +0100 Subject: [PATCH] fix(contracts): refactored the contracts and removed unuses parameters --- packages/contracts/.eslintrc.json | 24 --------- packages/contracts/contracts/README.md | 3 -- .../contracts/contracts/SemaphoreVoting.sol | 20 ++------ .../contracts/SemaphoreWhistleblowing.sol | 50 ++----------------- .../contracts/interfaces/ISemaphoreVoting.sol | 9 ++-- .../interfaces/ISemaphoreWhistleblowing.sol | 4 +- 6 files changed, 13 insertions(+), 97 deletions(-) delete mode 100644 packages/contracts/.eslintrc.json diff --git a/packages/contracts/.eslintrc.json b/packages/contracts/.eslintrc.json deleted file mode 100644 index 29d2eba..0000000 --- a/packages/contracts/.eslintrc.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "root": true, - "env": { - "es6": true - }, - "extends": ["airbnb-base", "airbnb-typescript/base", "prettier"], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module", - "project": ["./tsconfig.json"] - }, - "plugins": ["@typescript-eslint"], - "rules": { - "no-underscore-dangle": "off", - "import/no-extraneous-dependencies": "off", - "no-bitwise": "off", - "no-await-in-loop": "off", - "no-restricted-syntax": "off", - "no-console": ["warn", { "allow": ["info", "warn", "error", "log"] }], - "@typescript-eslint/lines-between-class-members": "off", - "no-param-reassign": "off" - } -} diff --git a/packages/contracts/contracts/README.md b/packages/contracts/contracts/README.md index 2530d73..8a14b5d 100644 --- a/packages/contracts/contracts/README.md +++ b/packages/contracts/contracts/README.md @@ -96,8 +96,5 @@ Deploy the `SemaphoreVoting.sol` and `SemaphoreWhistleblowing.sol` contract with yarn deploy ``` -> **Note** -> You should at least set a valid Ethereum URL (e.g. Infura) and a private key with some ethers. - > **Warning** > The group id is a number! diff --git a/packages/contracts/contracts/SemaphoreVoting.sol b/packages/contracts/contracts/SemaphoreVoting.sol index 86d858a..69d7b90 100644 --- a/packages/contracts/contracts/SemaphoreVoting.sol +++ b/packages/contracts/contracts/SemaphoreVoting.sol @@ -34,16 +34,19 @@ contract SemaphoreVoting is ISemaphoreVoting, SemaphoreGroups { function createPoll(address coordinator) public { uint256 groupId = semaphore.createGroup(); + polls[groupId].coordinator = coordinator; + polls[groupId].state = PollState.Created; + emit PollCreated(groupId, coordinator); } /// @dev See {ISemaphoreVoting-addVoter}. - function addVoter(uint256 pollId, uint256 groupId, uint256 identityCommitment) public onlyCoordinator(pollId) { + function addVoter(uint256 pollId, uint256 identityCommitment) public onlyCoordinator(pollId) { if (polls[pollId].state != PollState.Created) { revert SemaphoreVoting__PollHasAlreadyBeenStarted(); } - semaphore.addMember(groupId, identityCommitment); + semaphore.addMember(pollId, identityCommitment); } /// @dev See {ISemaphoreVoting-startPoll}. @@ -72,17 +75,4 @@ contract SemaphoreVoting is ISemaphoreVoting, SemaphoreGroups { emit PollEnded(pollId, msg.sender, decryptionKey); } - - function createPoll(uint256 pollId, address coordinator, uint256 merkleTreeDepth) external {} - - function createPoll(uint256 pollId, address coordinator) external override {} - - function addVoter(uint256 pollId, uint256 identityCommitment) external override {} - - function castVote( - uint256 vote, - uint256 nullifierHash, - uint256 pollId, - uint256[8] calldata proof - ) external override {} } diff --git a/packages/contracts/contracts/SemaphoreWhistleblowing.sol b/packages/contracts/contracts/SemaphoreWhistleblowing.sol index a3450c3..e8418fb 100644 --- a/packages/contracts/contracts/SemaphoreWhistleblowing.sol +++ b/packages/contracts/contracts/SemaphoreWhistleblowing.sol @@ -8,7 +8,7 @@ import {SemaphoreGroups} from "@semaphore-protocol/contracts/base/SemaphoreGroup /// @title SemaphoreWhistleblowing /// @dev This contract uses the Semaphore base contracts to allow whistleblowers to leak information anonymously /// Leaks can be IPFS hashes, permanent links or other kinds of references. -contract SemaphoreWhistleblowing is ISemaphoreWhistleblowing, SemaphoreGroups { +abstract contract SemaphoreWhistleblowing is ISemaphoreWhistleblowing, SemaphoreGroups { ISemaphore public semaphore; /// @dev Gets an entity id and return its editor address. @@ -54,7 +54,7 @@ contract SemaphoreWhistleblowing is ISemaphoreWhistleblowing, SemaphoreGroups { /// @dev See {ISemaphoreWhistleblowing-publishLeak}. function publishLeak( uint256 leak, - uint256 nullifierHash, + uint256 nullifier, uint256 entityId, uint256[8] calldata proof ) external override { @@ -63,7 +63,7 @@ contract SemaphoreWhistleblowing is ISemaphoreWhistleblowing, SemaphoreGroups { ISemaphore.SemaphoreProof memory semaphoreProof = ISemaphore.SemaphoreProof({ merkleTreeDepth: 32, merkleTreeRoot: merkleTreeRoot, - nullifier: nullifierHash, + nullifier: nullifier, message: leak, scope: entityId, points: proof @@ -73,48 +73,4 @@ contract SemaphoreWhistleblowing is ISemaphoreWhistleblowing, SemaphoreGroups { emit LeakPublished(entityId, leak); } - - function groupCounter() external view override returns (uint256) {} - - function createGroup() external override returns (uint256) {} - - function createGroup(address admin) external override returns (uint256) {} - - function createGroup(address admin, uint256 merkleTreeDuration) external override returns (uint256) {} - - function updateGroupAdmin(uint256 groupId, address newAdmin) external override {} - - function acceptGroupAdmin(uint256 groupId) external override {} - - function updateGroupMerkleTreeDuration(uint256 groupId, uint256 newMerkleTreeDuration) external override {} - - function addMember(uint256 groupId, uint256 identityCommitment) external override {} - - function addMembers(uint256 groupId, uint256[] calldata identityCommitments) external override {} - - function updateMember( - uint256 groupId, - uint256 oldIdentityCommitment, - uint256 newIdentityCommitment, - uint256[] calldata merkleProofSiblings - ) external override {} - - function removeMember( - uint256 groupId, - uint256 identityCommitment, - uint256[] calldata merkleProofSiblings - ) external override {} - - function validateProof(uint256 groupId, SemaphoreProof calldata proof) external override {} - - function verifyProof(uint256 groupId, SemaphoreProof calldata proof) external view override returns (bool) {} - - function removeWhistleblower( - uint256 entityId, - uint256 identityCommitment, - uint256[] calldata proofSiblings, - uint8[] calldata proofPathIndices - ) external override {} - - function createEntity(uint256 entityId, address editor) external override {} } diff --git a/packages/contracts/contracts/interfaces/ISemaphoreVoting.sol b/packages/contracts/contracts/interfaces/ISemaphoreVoting.sol index f8b0f71..dbdf6a5 100644 --- a/packages/contracts/contracts/interfaces/ISemaphoreVoting.sol +++ b/packages/contracts/contracts/interfaces/ISemaphoreVoting.sol @@ -23,7 +23,7 @@ interface ISemaphoreVoting { struct Poll { address coordinator; PollState state; - mapping(uint256 => bool) nullifierHashes; + mapping(uint256 => bool) nullifier; uint256 groupId; } @@ -50,9 +50,8 @@ interface ISemaphoreVoting { event PollEnded(uint256 pollId, address indexed coordinator, uint256 decryptionKey); /// @dev Creates a poll and the associated Merkle tree/group. - /// @param pollId: Id of the poll. /// @param coordinator: Coordinator of the poll. - function createPoll(uint256 pollId, address coordinator) external; + function createPoll(address coordinator) external; /// @dev Adds a voter to a poll. /// @param pollId: Id of the poll. @@ -66,10 +65,8 @@ interface ISemaphoreVoting { /// @dev Casts an anonymous vote in a poll. /// @param vote: Encrypted vote. - /// @param nullifierHash: Nullifier hash. /// @param pollId: Id of the poll. - /// @param proof: Private zk-proof parameters. - function castVote(uint256 vote, uint256 nullifierHash, uint256 pollId, uint256[8] calldata proof) external; + function castVote(uint256 vote, uint256 pollId) external; /// @dev Ends a pull and publishes the key to decrypt the votes. /// @param pollId: Id of the poll. diff --git a/packages/contracts/contracts/interfaces/ISemaphoreWhistleblowing.sol b/packages/contracts/contracts/interfaces/ISemaphoreWhistleblowing.sol index 61819f8..c857248 100644 --- a/packages/contracts/contracts/interfaces/ISemaphoreWhistleblowing.sol +++ b/packages/contracts/contracts/interfaces/ISemaphoreWhistleblowing.sol @@ -41,8 +41,8 @@ interface ISemaphoreWhistleblowing is ISemaphore { /// @dev Allows whistleblowers to publish leaks anonymously. /// @param leak: News leak. - /// @param nullifierHash: Nullifier hash. + /// @param nullifier: Nullifier hash. /// @param entityId: Id of the entity. /// @param proof: Private zk-proof parameters. - function publishLeak(uint256 leak, uint256 nullifierHash, uint256 entityId, uint256[8] calldata proof) external; + function publishLeak(uint256 leak, uint256 nullifier, uint256 entityId, uint256[8] calldata proof) external; }