Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: group data #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on:
push:
branches:
- "main"
pull_request:
branches:
- "**"

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
with:
version: 7

- name: Install dependenciess
run: pnpm install --frozen-lockfile

- name: Download snark-artifacts
run: pnpm run download:snark-artifacts

- name: Start Hardhat node, Run Tests, and Shutdown Hardhat node
run: |
npx hardhat node &
HARDHAT_PID=$!
sleep 5 # Wait for Hardhat node to be fully up and running
pnpm test
kill $HARDHAT_PID
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
engine-strict=true
auto-install-peers=false
25 changes: 17 additions & 8 deletions contracts/CypherCity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
pragma abicoder v2;
pragma solidity ^0.8.4;

import "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";
import "./CypherCitySemaphore.sol";

contract CypherCity {
error IdentityAlreadyExists();

event NewMessage(string message);
event NewIdentity(uint256 identityCommitment);

ISemaphore public semaphore;
uint256 public constant ADD_TO_GROUP = uint256(keccak256(abi.encodePacked("add_to_group")));

CypherCitySemaphore public semaphore;

uint256 public groupId;
mapping(uint256 => bool) public registeredIdentities;

constructor(address semaphoreAddress, uint256 _groupId) {
semaphore = ISemaphore(semaphoreAddress);
semaphore = CypherCitySemaphore(semaphoreAddress);
groupId = _groupId;

semaphore.createGroup(groupId, 20, address(this));
Expand All @@ -33,8 +34,8 @@ contract CypherCity {
emit NewIdentity(identityCommitment);
}

function sendMessage(
string calldata message,
function addToGroup(
uint256 identityCommitment,
uint256 merkleTreeRoot,
uint256 nullifierHash,
uint256 externalNullifier,
Expand All @@ -43,12 +44,20 @@ contract CypherCity {
semaphore.verifyProof(
groupId,
merkleTreeRoot,
uint256(keccak256(abi.encodePacked(message))),
ADD_TO_GROUP,
nullifierHash,
externalNullifier,
proof
);

emit NewMessage(message);
this.joinGroup(identityCommitment);
}

function getMerkleRootCreationDate(uint256 merkleRoot) external view returns (uint256) {
return semaphore.getMerkleRootCreationDate(groupId, merkleRoot);
}

function getMerkleTreeRoot() external view returns (uint256) {
return semaphore.getMerkleTreeRoot(groupId);
}
}
13 changes: 13 additions & 0 deletions contracts/CypherCitySemaphore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;

import "@semaphore-protocol/contracts/Semaphore.sol";
import "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";

contract CypherCitySemaphore is Semaphore {
constructor(ISemaphoreVerifier _verifier) Semaphore(_verifier) {}

function getMerkleRootCreationDate(uint256 groupId, uint256 merkleRoot) external view returns (uint256) {
return groups[groupId].merkleRootCreationDates[merkleRoot];
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"dependencies": {
"@semaphore-protocol/contracts": "3.15.1",
"@semaphore-protocol/data": "^3.15.1",
"@zk-kit/incremental-merkle-tree.sol": "1.3.3"
},
"config": {
Expand Down
Loading