Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vacekj committed Apr 19, 2023
1 parent 0828bfb commit bfefd4f
Show file tree
Hide file tree
Showing 28 changed files with 1,232 additions and 75 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "packages/contracts/lib/semaphore"]
path = packages/contracts/lib/semaphore
url = https://github.com/semaphore-protocol/semaphore
[submodule "lib/semaphore"]
branch = v3.1.0
[submodule "packages/contracts/lib/openzeppelin-contracts"]
Expand Down
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pnpm install
# Copy & fill environments
# NOTE: Documentation of environment variables can be found in the according `.example` files
cp packages/frontend/.env.local.example packages/frontend/.env.local
cp packages/contracts/.env.example packages/contracts/.env
cp packages/semaphore/.env.example packages/semaphore/.env
```

## Development
Expand Down
Binary file modified packages/contracts/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/contracts/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: "Install the Node.js dependencies"
run: "yarn install --immutable"

- name: "Lint the contracts"
- name: "Lint the semaphore"
run: "yarn lint"

- name: "Add lint summary"
Expand All @@ -54,7 +54,7 @@ jobs:
- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Build the contracts and print their size"
- name: "Build the semaphore and print their size"
run: "forge build --sizes"

- name: "Add build summary"
Expand Down
Binary file modified packages/contracts/lib/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions packages/contracts/lib/forge-std/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ jobs:
# via-ir compilation time checks.
- name: Measure compilation time of Test with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of TestBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of Script with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir

test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/lib/forge-std/test/StdUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ contract StdUtilsForkTest is Test {
address internal USDC_HOLDER_1 = 0x3e67F4721E6d1c41a015f645eFa37BEd854fcf52;

function setUp() public {
// All tests of the `getTokenBalances` method are fork tests using live contracts.
// All tests of the `getTokenBalances` method are fork tests using live semaphore.
vm.createSelectFork({urlOrAlias: "mainnet", blockNumber: 16_428_900});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/lib/prb-math/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: "Install the Node.js dependencies"
run: "yarn install --immutable"

- name: "Lint the contracts"
- name: "Lint the semaphore"
run: "yarn lint"

- name: "Add lint summary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ jobs:
# via-ir compilation time checks.
- name: Measure compilation time of Test with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of TestBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of Script with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir
run: forge build --skip test --semaphore test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir

test:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: "Install the Node.js dependencies"
run: "yarn install --immutable"

- name: "Lint the contracts"
- name: "Lint the semaphore"
run: "yarn lint"

- name: "Add lint summary"
Expand All @@ -48,7 +48,7 @@ jobs:
- name: "Run the tests"
run: "forge test"

- name: "Build the contracts"
- name: "Build the semaphore"
run: |
forge --version
forge build --sizes
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/lib/prb-test/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: "Install the Node.js dependencies"
run: "yarn install --immutable"

- name: "Lint the contracts"
- name: "Lint the semaphore"
run: "yarn lint"

- name: "Add lint summary"
Expand All @@ -48,7 +48,7 @@ jobs:
- name: "Run the tests"
run: "forge test"

- name: "Build the contracts"
- name: "Build the semaphore"
run: |
forge --version
forge build --sizes
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/lib/semaphore
Submodule semaphore deleted from 243c50
1 change: 0 additions & 1 deletion packages/contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@prb/test/=lib/prb-test/src/
forge-std/=lib/forge-std/src/
src/=src/
semaphore/=lib/semaphore/packages/contracts/contracts/
@openzeppelin/=lib/openzeppelin-contracts/
@zk-kit/incremental-merkle-tree.sol/=lib/zk-kit/packages/incremental-merkle-tree.sol/contracts/
14 changes: 7 additions & 7 deletions packages/contracts/script/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
pragma solidity >=0.8.4;

import {Script} from "forge-std/Script.sol";
import {GroupManager} from "../src/GroupManager.sol";
import {Semaphore} from "semaphore/Semaphore.sol";
import {Pairing} from "semaphore/base/Pairing.sol";
import {SemaphoreVerifier} from "semaphore/base/SemaphoreVerifier.sol";
import {PetitionManager} from "../src/PetitionManager.sol";
import {Semaphore} from "../src/semaphore/Semaphore.sol";
import {Pairing} from "../src/semaphore/base/Pairing.sol";
import {SemaphoreVerifier} from "../src/semaphore/base/SemaphoreVerifier.sol";

/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract DeployFoo is Script {
address internal deployer;
GroupManager internal groupManager;
PetitionManager internal groupManager;
Semaphore internal semaphore;
SemaphoreVerifier internal semaphoreVerifier;

Expand All @@ -22,12 +22,12 @@ contract DeployFoo is Script {
function run() public {
vm.startBroadcast(deployer);

/*Deploy supporting contracts*/
/*Deploy supporting semaphore*/
semaphoreVerifier = new SemaphoreVerifier();

semaphore = new Semaphore(semaphoreVerifier);

groupManager = new GroupManager(address(semaphore), 1);
groupManager = new PetitionManager(address(semaphore));
vm.stopBroadcast();
}
}
46 changes: 0 additions & 46 deletions packages/contracts/src/GroupManager.sol

This file was deleted.

58 changes: 58 additions & 0 deletions packages/contracts/src/PetitionManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import "./semaphore/interfaces/ISemaphore.sol";

contract PetitionManager {
event NewUser(uint256 identityCommitment);
event PetitionCreated(uint256 petitionId);

struct Petition {
/// Allowed group IDs
uint256[] groupIds;
/// Metadata about the petition, stored on IPFS, Arweave etc.
string metadata;
}

ISemaphore public semaphore;
mapping(uint256 => bytes32) public users;
mapping(uint256 => Petition) public petitions;
uint256 petitionCount;

constructor(address semaphoreAddress) {
semaphore = ISemaphore(semaphoreAddress);
}

function createPetition(uint256[] calldata groupIds, string metadata) public {
petitions[++petitionCount] = Petition(groupIds, metadata);
emit PetitionCreated(petitionCount);
}

function joinGroup(uint256 identityCommitment, uint256 groupId) external {
/* TODO: provide a VC, verify that it's correct and corresponds to the group and add the user to the group*/
semaphore.addMember(groupId, identityCommitment);

emit NewUser(identityCommitment);
}

/// Sign a petition
/// @param groupId An eligible groupId that the user is claiming to
function sign(uint256 petitionId, uint256 id, uint256 groupId, uint256 nullifierHash, int256[8] calldata proof) public {

Petition petition = petitions[petitionId];

/* 1. Verify that the petition allows this particular groupId */
require(isInArray(petition.groupIds, groupId), "Group not allowed by petition");

semaphore.verifyProof(groupId, 1, nullifierHash, petitionId, proof);
}

function isInArray(uint256[] memory array, uint256 value) public pure returns (bool) {
for (uint i = 0; i < array.length; i++) {
if (array[i] == value) {
return true;
}
}
return false;
}
}
Loading

0 comments on commit bfefd4f

Please sign in to comment.