Skip to content

Commit

Permalink
Added Semaphore (#1)
Browse files Browse the repository at this point in the history
* Adding hardhat in the foundry project

* Added files
  • Loading branch information
jimmychu0807 authored Nov 6, 2024
1 parent 3ba7d58 commit 93dd66f
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 542 deletions.
26 changes: 1 addition & 25 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
[profile.default]
emv_version = "paris"
evm_version = "cancun"
src = "src"
out = "out"
script = "script"
libs = ["node_modules", "lib"]
fs_permissions = [{ access = "read", path = "out-optimized" }, { access = "read-write", path = "gas_calculations" }]
allow_paths = ["*", "/"]
remappings = [
"@ERC4337/=node_modules/@ERC4337/",
"@openzeppelin/=node_modules/@openzeppelin/",
"@prb/math/=node_modules/@prb/math/src/",
"@rhinestone/=node_modules/@rhinestone/",
"@safe-global/=node_modules/@safe-global/",
"@semaphore-protocol/=node_modules/@semaphore-protocol/contracts/",
"account-abstraction-v0.6/=node_modules/@ERC4337/account-abstraction-v0.6/contracts/",
"account-abstraction/=node_modules/@ERC4337/account-abstraction/contracts/",
"ds-test/=node_modules/ds-test/src/",
"erc4337-validation/=node_modules/@rhinestone/erc4337-validation/src/",
"erc7579/=node_modules/erc7579/src/",
"ExcessivelySafeCall/=node_modules/excessively-safe-call/src/",
"forge-std/=node_modules/forge-std/src/",
"kernel/=node_modules/@zerodev/kernel/src/",
"module-bases/=node_modules/@rhinestone/module-bases/src/",
"modulekit/=node_modules/@rhinestone/modulekit/src/",
"safe7579/=node_modules/@rhinestone/safe7579/src/",
"sentinellist/=node_modules/@rhinestone/sentinellist/src/",
"solady/=node_modules/solady/src/",
"solarray/=node_modules/solarray/src/"
]

# For simulation: https://docs.rhinestone.wtf/modulekit/testing/simulation
gas_limit = "18446744073709551615"
memory_limit = 2147483648
verbosity = 3
Expand Down
32 changes: 32 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "@nomicfoundation/hardhat-toolbox"
import "@nomicfoundation/hardhat-foundry"
import "@typechain/hardhat"
import { HardhatUserConfig } from "hardhat/config"

const hardhatConfig: HardhatUserConfig = {
solidity: {
version: "0.8.27",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
networks: {
hardhat: {
chainId: 31337,
allowUnlimitedContractSize: true
},
},
gasReporter: {
currency: "USD",
enabled: process.env.REPORT_GAS === "true",
coinmarketcap: process.env.COINMARKETCAP_API_KEY
},
typechain: {
target: "ethers-v6"
},
};

export default hardhatConfig;
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@rhinestone/module-template",
"name": "modulekit-tut",
"version": "0.4.1",
"description": "A Foundry template for building modules using the ModuleKit",
"license": "GPL-3.0",
Expand All @@ -25,11 +25,10 @@
"test:lite": "FOUNDRY_PROFILE=lite forge test",
"test:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge test"
},
"dependencies": {
"@rhinestone/modulekit": "^0.4.14",
"@semaphore-protocol/contracts": "github:jimmychu0807/semaphore.git#jc/caret-version&path:/packages/contracts/contracts",
"@semaphore-protocol/core": "github:jimmychu0807/semaphore.git#jc/caret-version&path:/packages/core",
"ethers": "5.4.0"
"devDependencies": {
"@rhinestone/modulekit": "^0.4.16",
"@semaphore-protocol/contracts": "github:semaphore-protocol/semaphore#main&path:/packages/contracts/contracts",
"@semaphore-protocol/core": "github:semaphore-protocol/semaphore#main&path:/packages/core"
},
"files": [
"src",
Expand Down
610 changes: 111 additions & 499 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@rhinestone/=node_modules/@rhinestone/
sentinellist/=node_modules/@rhinestone/sentinellist/src/
erc4337-validation/=node_modules/@rhinestone/erc4337-validation/src/
safe7579/=node_modules/@rhinestone/safe7579/src/
modulekit/=node_modules/@rhinestone/modulekit/src/
module-bases/=node_modules/@rhinestone/module-bases/src/
registry/=node_modules/@rhinestone/registry/src/

@ERC4337/=node_modules/@ERC4337/
account-abstraction/=node_modules/@ERC4337/account-abstraction/contracts/
account-abstraction-v0.6/=node_modules/@ERC4337/account-abstraction-v0.6/contracts/

@openzeppelin/=node_modules/@openzeppelin/
@safe-global/=node_modules/@safe-global/
ds-test/=node_modules/ds-test/src/
erc7579/=node_modules/erc7579/src/
forge-std/=node_modules/forge-std/src/
solady/=node_modules/solady/src/
solarray/=node_modules/solarray/src/
@prb/math/=node_modules/@prb/math/src/
kernel/=node_modules/@zerodev/kernel/src/
ExcessivelySafeCall/=node_modules/excessively-safe-call/src/

@semaphore-protocol/contracts/=node_modules/@semaphore-protocol/contracts/
6 changes: 3 additions & 3 deletions src/SemaphoreValidator.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
pragma solidity >=0.8.23 <=0.8.29;

import { ERC7579ValidatorBase } from "modulekit/Modules.sol";
import { PackedUserOperation } from "modulekit/external/ERC4337.sol";

import {ISemaphore} from "@semaphore-protocol/interfaces/ISemaphore.sol";
import {ISemaphoreGroups} from "@semaphore-protocol/interfaces/ISemaphoreGroups.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";
import {ISemaphoreGroups} from "@semaphore-protocol/contracts/interfaces/ISemaphoreGroups.sol";

import { console } from "forge-std/console.sol";

Expand Down
15 changes: 11 additions & 4 deletions src/ValidatorTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,18 @@ contract ValidatorTemplate is ERC7579ValidatorBase {
return EIP1271_FAILED;
}

/**
* Validates a signature with data
* @param hash The hash of the message
* @param signature The signature of the message
* @param data The data to validate the signature with
* @return validSig true if the signature is valid, false otherwise
*
*/
function validateSignatureWithData(
bytes32,
bytes calldata,
bytes calldata
bytes32 hash,
bytes calldata signature,
bytes calldata data
)
external
view
Expand All @@ -102,7 +110,6 @@ contract ValidatorTemplate is ERC7579ValidatorBase {
return false;
}


/*//////////////////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////////////////*/
Expand Down
18 changes: 13 additions & 5 deletions test/SemaphoreValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
} from "modulekit/ModuleKit.sol";
import { MODULE_TYPE_VALIDATOR } from "modulekit/external/ERC7579.sol";

import { Semaphore } from "@semaphore-protocol/Semaphore.sol";
import { ISemaphore } from "@semaphore-protocol/interfaces/ISemaphore.sol";
import { SemaphoreVerifier } from "@semaphore-protocol/base/SemaphoreVerifier.sol";
import { ISemaphoreVerifier } from "@semaphore-protocol/interfaces/ISemaphoreVerifier.sol";
import { Semaphore } from "@semaphore-protocol/contracts/Semaphore.sol";
import { ISemaphore } from "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";
import { ISemaphoreGroups } from "@semaphore-protocol/contracts/interfaces/ISemaphoreGroups.sol";
import { SemaphoreVerifier } from "@semaphore-protocol/contracts/base/SemaphoreVerifier.sol";
import { ISemaphoreVerifier } from "@semaphore-protocol/contracts/interfaces/ISemaphoreVerifier.sol";

import { SemaphoreValidator } from "src/SemaphoreValidator.sol";

Expand Down Expand Up @@ -65,13 +66,20 @@ contract SemaphoreValidatorTest is RhinestoneModuleKit, Test {
uint256 gId = semaphore.createGroup(admin.addr);
console.log("gId: %d", gId);

vm.prank(admin.addr);
// Test Add members
uint256[] memory members = new uint256[](3);
members[0] = uint256(uint160(admin.addr));
members[1] = uint256(2);
members[2] = uint256(3);

vm.prank(admin.addr);
semaphore.addMembers(gId, members);

// Test that non-admin cannot add members
vm.expectRevert(ISemaphoreGroups.Semaphore__CallerIsNotTheGroupAdmin.selector);
semaphore.addMember(gId, uint256(4));

// Test validations
}

function test_InstallSemaphoreValidator() public {
Expand Down

0 comments on commit 93dd66f

Please sign in to comment.