Skip to content

Commit

Permalink
fix(contracts): refactored the contracts and removed unuses parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Dozie2001 committed Jul 30, 2024
1 parent 4ebca0f commit 22ca14f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 97 deletions.
24 changes: 0 additions & 24 deletions packages/contracts/.eslintrc.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/contracts/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
20 changes: 5 additions & 15 deletions packages/contracts/contracts/SemaphoreVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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 {}
}
50 changes: 3 additions & 47 deletions packages/contracts/contracts/SemaphoreWhistleblowing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {}
}
9 changes: 3 additions & 6 deletions packages/contracts/contracts/interfaces/ISemaphoreVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ISemaphoreVoting {
struct Poll {
address coordinator;
PollState state;
mapping(uint256 => bool) nullifierHashes;
mapping(uint256 => bool) nullifier;
uint256 groupId;
}

Expand All @@ -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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 22ca14f

Please sign in to comment.