Skip to content

Commit

Permalink
fix(contracts): added proof Validation and fixed contracts deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Dozie2001 committed Aug 5, 2024
1 parent 517ea8f commit 2a436b5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 15 deletions.
20 changes: 19 additions & 1 deletion packages/contracts/contracts/SemaphoreVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,29 @@ contract SemaphoreVoting is ISemaphoreVoting {
}

/// @dev See {ISemaphoreVoting-castVote}.
function castVote(uint256 vote, uint256 pollId) public {
function castVote(
uint256 vote,
uint256 pollId,
uint256 merkleTreeDepth,
uint256 nullifier,
uint256 merkleTreeRoot,
uint256[8] calldata proof
) public {
if (polls[pollId].state != PollState.Ongoing) {
revert SemaphoreVoting__PollIsNotOngoing();
}

ISemaphore.SemaphoreProof memory semaphoreProof = ISemaphore.SemaphoreProof({
merkleTreeDepth: merkleTreeDepth,
merkleTreeRoot: merkleTreeRoot,
nullifier: nullifier,
message: vote,
scope: pollId,
points: proof
});

semaphore.validateProof(pollId, semaphoreProof);
polls[pollId].nullifiers[nullifier] = true;
emit VoteAdded(pollId, vote);
}

Expand Down
17 changes: 12 additions & 5 deletions packages/contracts/contracts/SemaphoreWhistleblowing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,28 @@ contract SemaphoreWhistleblowing is ISemaphoreWhistleblowing {
uint256 leak,
uint256 nullifier,
uint256 entityId,
uint256 merkleTreeDepth,
uint256 merkleTreeRoot,
uint256[8] calldata proof
) external override {
uint256 merkleTreeRoot = getmerkleTreeDuration(entityId);

) external {
ISemaphore.SemaphoreProof memory semaphoreProof = ISemaphore.SemaphoreProof({
merkleTreeDepth: 32,
merkleTreeDepth: merkleTreeDepth,
merkleTreeRoot: merkleTreeRoot,
nullifier: nullifier,
message: leak,
scope: entityId,
points: proof
});

semaphore.verifyProof(entityId, semaphoreProof);
semaphore.validateProof(entityId, semaphoreProof);

emit LeakPublished(entityId, leak);
}

function removeWhistleblower(
uint256 entityId,
uint256 identityCommitment,
uint256[] calldata proofSiblings,
uint8[] calldata proofPathIndices
) external override {}
}
11 changes: 9 additions & 2 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) nullifier;
mapping(uint256 => bool) nullifiers;
uint256 groupId;
}

Expand Down Expand Up @@ -66,7 +66,14 @@ interface ISemaphoreVoting {
/// @dev Casts an anonymous vote in a poll.
/// @param vote: Encrypted vote.
/// @param pollId: Id of the poll.
function castVote(uint256 vote, uint256 pollId) external;
function castVote(
uint256 vote,
uint256 pollId,
uint256 nullifier,
uint256 merkleTreeDepth,
uint256 merkleTreeRoot,
uint256[8] calldata proof
) 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 @@ -16,9 +16,8 @@ interface ISemaphoreWhistleblowing {
event LeakPublished(uint256 indexed entityId, uint256 leak);

/// @dev Creates an entity and the associated Merkle tree/group.
/// @param entityId: Id of the entity.
/// @param editor: Editor of the entity.
function createEntity(uint256 entityId, address editor) external;
function createEntity(address editor) external;

/// @dev Adds a whistleblower to an entity.
/// @param entityId: Id of the entity.
Expand All @@ -42,5 +41,12 @@ interface ISemaphoreWhistleblowing {
/// @param nullifier: Nullifier hash.
/// @param entityId: Id of the entity.
/// @param proof: Private zk-proof parameters.
function publishLeak(uint256 leak, uint256 nullifier, uint256 entityId, uint256[8] calldata proof) external;
function publishLeak(
uint256 leak,
uint256 nullifier,
uint256 entityId,
uint256 merkleTreeDepth,
uint256 merkleTreeRoot,
uint256[8] calldata proof
) external;
}
2 changes: 1 addition & 1 deletion packages/contracts/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@semaphore-extensions/contracts",
"version": "0.1.0",
"description": "Semaphore extensions Contracts to manage anonymous voting and whistleblowing",
"description": "Solidity contracts to enhance Semaphore with extra features and customization",
"license": "MIT",
"files": [
"**/*.sol",
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"typechain": "^8.3.0",
"typescript": "^5.3.3"
},
"packageManager": "[email protected]",
"dependencies": {
"@semaphore-protocol/contracts": "4.0.0-beta.16",
"solhint-plugin-prettier": "^0.1.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/tasks/deploy-semaphore-whistle-blowing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ task("deploy:semaphore-whistleblowing", "Deploy a Semaphore whistleblowing cont
semaphoreAddress = await semaphore.getAddress()
}

const SemaphoreWhistleblowingFactory = await ethers.getContractFactory("SemaphoreWhistleblowing ")
const SemaphoreWhistleblowingFactory = await ethers.getContractFactory("SemaphoreWhistleblowing")

const SemaphoreWhistleblowingContract = await SemaphoreWhistleblowingFactory.deploy(semaphoreAddress)

if (logs) {
console.info(
`Semaphore Voting contract has been deployed to: ${await SemaphoreWhistleblowingContract.getAddress()}`
`Semaphore Whistleblowing contract has been deployed to: ${await SemaphoreWhistleblowingContract.getAddress()}`
)
}

Expand Down

0 comments on commit 2a436b5

Please sign in to comment.