Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/crisp-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- name: Remove unnecessary files
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf "$AGENT_TOOLSDIRECTORY"

- name: Set environment variables for Docker Compose
Expand Down
3 changes: 2 additions & 1 deletion examples/CRISP/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --default-toolchain ${RUST_VERSION}
ENV PATH="/home/${USERNAME}/.cargo/bin:${PATH}"
RUN rustup component add rustfmt clippy

ENV RUSTFLAGS="-C debuginfo=0 -C strip=symbols" \
CARGO_TERM_COLOR=always
# ────────────────────────────────────────────────────────────────────────────────
# Foundry
# ────────────────────────────────────────────────────────────────────────────────
Expand Down
4 changes: 2 additions & 2 deletions examples/CRISP/apps/client/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VITE_ENCLAVE_API=http://127.0.0.1:4000
VITE_TWITTER_SERVERLESS_API=
VITE_WALLETCONNECT_PROJECT_ID=
VITE_E3_PROGRAM_ADDRESS=0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE # Default E3 program address from anvil
VITE_SEMAPHORE_ADDRESS=0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0
VITE_E3_PROGRAM_ADDRESS=0xc6e7DF5E7b4f2A278906862b61205850344D4e7d # Default E3 program address from anvil
VITE_SEMAPHORE_ADDRESS=0x0B306BF915C4d645ff596e518fAf3F9669b97016


6 changes: 4 additions & 2 deletions examples/CRISP/apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
"@aztec/bb.js": "^0.82.2",
"@emotion/babel-plugin": "^11.11.0",
"@emotion/react": "^11.11.4",
"@noir-lang/acvm_js": "1.0.0-beta.3",
"@noir-lang/noir_js": "1.0.0-beta.3",
"@noir-lang/noirc_abi": "1.0.0-beta.3",
"@phosphor-icons/react": "^2.1.4",
"@semaphore-protocol/core": "^4.9.2",
"@semaphore-protocol/core": "github:hmzakhalid/semaphore-noir#dist-core",
"@semaphore-protocol/data": "^4.9.2",
"@svgr/rollup": "^8.1.0",
"@tanstack/react-query": "^5.74.3",
Expand Down Expand Up @@ -62,4 +64,4 @@
"vite-plugin-wasm": "^3.3.0"
},
"packageManager": "pnpm@10.7.1+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808"
}
}
6 changes: 4 additions & 2 deletions examples/CRISP/apps/client/src/hooks/voting/useVoteCasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useVoteManagementContext } from '@/context/voteManagement';
import { useNotificationAlertContext } from '@/context/NotificationAlert/NotificationAlert.context.tsx';
import { Poll } from '@/model/poll.model';
import { BroadcastVoteRequest } from '@/model/vote.model';
import { Group, generateProof, SemaphoreProof } from '@semaphore-protocol/core';
import { Group, generateNoirProof, SemaphoreNoirProof, initSemaphoreNoirBackend } from '@semaphore-protocol/core';
import { encodeSemaphoreProof } from '@/utils/proof-encoding';

export const useVoteCasting = () => {
Expand Down Expand Up @@ -67,7 +67,9 @@ export const useVoteCasting = () => {
const group = new Group(currentGroupMembers);
const scope = String(roundState.id);
const message = String(pollSelected.value);
const fullProof: SemaphoreProof = await generateProof(semaphoreIdentity, group, message, scope);
const merkleTreeDepth = 10;
const noirBackend = await initSemaphoreNoirBackend(merkleTreeDepth);
const fullProof: SemaphoreNoirProof = await generateNoirProof(semaphoreIdentity, group, message, scope, noirBackend, true);
console.log("Full generated proof object:", fullProof);
const proofBytes = encodeSemaphoreProof(fullProof);

Expand Down
28 changes: 12 additions & 16 deletions examples/CRISP/apps/client/src/utils/proof-encoding.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { hexToBytes, encodeAbiParameters, parseAbiParameters } from 'viem';
import { type SemaphoreProof } from '@semaphore-protocol/core';
import { hexToBytes, encodeAbiParameters, parseAbiParameters, bytesToHex } from 'viem';
import { type SemaphoreNoirProof } from '@semaphore-protocol/core';

const abi = parseAbiParameters(
'uint256,uint256,uint256,uint256,uint256,uint256[8]'
'(uint256,uint256,uint256,uint256,uint256,bytes)'
);

type Tuple8<T> = readonly [T, T, T, T, T, T, T, T];

export function encodeSemaphoreProof(
{ merkleTreeDepth, merkleTreeRoot, nullifier, message, scope, points }: SemaphoreProof
{ merkleTreeDepth, merkleTreeRoot, nullifier, message, scope, proofBytes }: SemaphoreNoirProof
): Uint8Array {
if (points.length !== 8) {
throw new Error('Semaphore proof must have 8 points');
}

const hex = encodeAbiParameters(abi, [
BigInt(merkleTreeDepth),
BigInt(merkleTreeRoot),
BigInt(nullifier),
BigInt(message),
BigInt(scope),
points.map(BigInt) as unknown as Tuple8<bigint>,
[
BigInt(merkleTreeDepth),
BigInt(merkleTreeRoot),
BigInt(nullifier),
BigInt(message),
BigInt(scope),
bytesToHex(proofBytes),
]
]);

return hexToBytes(hex);
Expand Down
2 changes: 1 addition & 1 deletion examples/CRISP/apps/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CRON_API_KEY=1234567890
ENCLAVE_ADDRESS="0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
CIPHERNODE_REGISTRY_ADDRESS="0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
NAIVE_REGISTRY_FILTER_ADDRESS="0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
E3_PROGRAM_ADDRESS="0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE" # CRISPProgram Contract Address
E3_PROGRAM_ADDRESS="0xc6e7DF5E7b4f2A278906862b61205850344D4e7d" # CRISPProgram Contract Address

# E3 Config
E3_WINDOW_SIZE=40
Expand Down
6 changes: 3 additions & 3 deletions examples/CRISP/contracts/CRISPChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.27;

import {BaseChecker} from "@excubiae/contracts/checker/BaseChecker.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphoreNoir.sol";

/// @title CRISPChecker.
/// @notice Enclave Input Validator
Expand Down Expand Up @@ -45,9 +45,9 @@ contract CRISPChecker is BaseChecker {
) internal view override returns (bool) {
super._check(subject, evidence);

ISemaphore.SemaphoreProof memory proof = abi.decode(
ISemaphore.SemaphoreNoirProof memory proof = abi.decode(
evidence,
(ISemaphore.SemaphoreProof)
(ISemaphore.SemaphoreNoirProof)
);

// The proof scope encodes both the subject address and group ID to prevent front-running attacks.
Expand Down
6 changes: 3 additions & 3 deletions examples/CRISP/contracts/CRISPPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.27;

import {BasePolicy} from "@excubiae/contracts/policy/BasePolicy.sol";
import {BaseChecker} from "@excubiae/contracts/checker/BaseChecker.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphoreNoir.sol";

/// @title CRISPPolicy
/// @notice Policy contract for validating inputs based on Semaphore proofs and usage limits.
Expand Down Expand Up @@ -36,9 +36,9 @@ contract CRISPPolicy is BasePolicy {
address subject,
bytes calldata evidence
) internal override(BasePolicy) onlyTarget {
ISemaphore.SemaphoreProof memory proof = abi.decode(
ISemaphore.SemaphoreNoirProof memory proof = abi.decode(
evidence,
(ISemaphore.SemaphoreProof)
(ISemaphore.SemaphoreNoirProof)
);
uint256 n = proof.nullifier;
if (spentNullifiers[n]) revert AlreadyEnforced();
Expand Down
2 changes: 1 addition & 1 deletion examples/CRISP/contracts/CRISPProgram.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {IE3Program} from "@gnosis-guild/enclave/contracts/interfaces/IE3Program.
import {IBasePolicy} from "@excubiae/contracts/interfaces/IBasePolicy.sol";
import {IInputValidator} from "@gnosis-guild/enclave/contracts/interfaces/IInputValidator.sol";
import {IEnclave} from "@gnosis-guild/enclave/contracts/interfaces/IEnclave.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphoreNoir.sol";
import {CRISPCheckerFactory} from "./CRISPCheckerFactory.sol";
import {CRISPPolicyFactory} from "./CRISPPolicyFactory.sol";
import {CRISPInputValidatorFactory} from "./CRISPInputValidatorFactory.sol";
Expand Down
14 changes: 7 additions & 7 deletions examples/CRISP/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {CRISPPolicy} from "../contracts/CRISPPolicy.sol";
import {CRISPChecker} from "../contracts/CRISPChecker.sol";
import {IE3Program} from "@gnosis-guild/enclave/contracts/interfaces/IE3Program.sol";
import {IEnclave} from "@gnosis-guild/enclave/contracts/interfaces/IEnclave.sol";
import {Semaphore} from "@semaphore-protocol/contracts/Semaphore.sol";
import {SemaphoreVerifier} from "@semaphore-protocol/contracts/base/SemaphoreVerifier.sol";
import {ISemaphoreVerifier} from "@semaphore-protocol/contracts/interfaces/ISemaphoreVerifier.sol";
import {SemaphoreNoir} from "@semaphore-protocol/contracts/SemaphoreNoir.sol";
import {SemaphoreNoirVerifier} from "@semaphore-protocol/contracts/base/SemaphoreNoirVerifier.sol";
import {IVerifier} from "@semaphore-protocol/contracts/interfaces/ISemaphoreNoirVerifier.sol";
import {CRISPCheckerFactory} from "../contracts/CRISPCheckerFactory.sol";
import {CRISPPolicyFactory} from "../contracts/CRISPPolicyFactory.sol";
import {CRISPInputValidatorFactory} from "../contracts/CRISPInputValidatorFactory.sol";
Expand Down Expand Up @@ -159,14 +159,14 @@ contract CRISPProgramDeploy is Script {
console2.log("Enclave Address: ", address(enclave));
console2.log("Verifier Address: ", address(verifier));

SemaphoreVerifier semaphoreVerifier = new SemaphoreVerifier();
SemaphoreNoirVerifier semaphoreVerifier = new SemaphoreNoirVerifier();
console2.log(
"Deployed SemaphoreVerifier to",
"Deployed SemaphoreNoirVerifier to",
address(semaphoreVerifier)
);

Semaphore semaphore = new Semaphore(
ISemaphoreVerifier(address(semaphoreVerifier))
SemaphoreNoir semaphore = new SemaphoreNoir(
IVerifier(address(semaphoreVerifier))
);
console2.log("Deployed Semaphore to", address(semaphore));

Expand Down
4 changes: 2 additions & 2 deletions examples/CRISP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@excubiae/contracts": "^0.4.0",
"@gnosis-guild/enclave": "workspace:*",
"@semaphore-protocol/contracts": "^4.9.2",
"@semaphore-protocol/contracts": "github:hmzakhalid/semaphore-noir#dist-contracts",
"@zk-kit/lean-imt.sol": "2.0.0",
"poseidon-solidity": "^0.0.5",
"solady": "^0.1.13"
Expand Down Expand Up @@ -58,4 +58,4 @@
"wait-on": "^8.0.3"
},
"packageManager": "pnpm@10.7.1+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808"
}
}
Loading
Loading