mirror of
https://github.com/vacp2p/rln-interep-contract.git
synced 2025-02-28 06:00:43 +00:00
feat: verify proof using test verifier
This commit is contained in:
parent
4ab3a6f2fb
commit
e53e225493
@ -7,10 +7,30 @@ import "@semaphore-protocol/contracts/base/SemaphoreCore.sol";
|
||||
import "@semaphore-protocol/contracts/base/SemaphoreConstants.sol";
|
||||
|
||||
contract InterepTest is IInterep, SemaphoreCore {
|
||||
/// @dev Gets a tree depth and returns its verifier address.
|
||||
mapping(uint8 => IVerifier) public verifiers;
|
||||
|
||||
mapping(uint256 => Group) public groups;
|
||||
|
||||
/// @dev mimics https://github.com/interep-project/contracts/blob/main/contracts/Interep.sol but ignores the verification mechanism
|
||||
constructor() {}
|
||||
/// @dev Checks if there is a verifier for the given tree depth.
|
||||
/// @param depth: Depth of the tree.
|
||||
modifier onlySupportedDepth(uint8 depth) {
|
||||
require(
|
||||
address(verifiers[depth]) != address(0),
|
||||
"Interep: tree depth is not supported"
|
||||
);
|
||||
_;
|
||||
}
|
||||
|
||||
/// @dev Initializes the Semaphore verifiers used to verify the user's ZK proofs.
|
||||
/// @param _verifiers: List of Semaphore verifiers (address and related Merkle tree depth).
|
||||
constructor(Verifier[] memory _verifiers) {
|
||||
for (uint8 i = 0; i < _verifiers.length; i++) {
|
||||
verifiers[_verifiers[i].merkleTreeDepth] = IVerifier(
|
||||
_verifiers[i].contractAddress
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev See {IInterep-updateGroups}.
|
||||
function updateGroups(Group[] calldata _groups) external override {
|
||||
@ -50,11 +70,33 @@ contract InterepTest is IInterep, SemaphoreCore {
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev See {IInterep-verifyProof}.
|
||||
function verifyProof(
|
||||
uint256 groupId,
|
||||
bytes32 signal,
|
||||
uint256 nullifierHash,
|
||||
uint256 externalNullifier,
|
||||
uint256[8] calldata proof
|
||||
) external override {}
|
||||
) external override {
|
||||
uint256 root = getRoot(groupId);
|
||||
uint8 depth = getDepth(groupId);
|
||||
|
||||
require(depth != 0, "Interep: group does not exist");
|
||||
|
||||
IVerifier verifier = verifiers[depth];
|
||||
|
||||
_verifyProof(
|
||||
signal,
|
||||
root,
|
||||
nullifierHash,
|
||||
externalNullifier,
|
||||
proof,
|
||||
verifier
|
||||
);
|
||||
|
||||
// TODO: check if the nullifier is not used before
|
||||
// _saveNullifierHash(nullifierHash);
|
||||
|
||||
emit ProofVerified(groupId, signal);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.15;
|
||||
|
||||
import {IPoseidonHasher} from "./PoseidonHasher.sol";
|
||||
|
11
contracts/VerifierTest.sol
Normal file
11
contracts/VerifierTest.sol
Normal file
@ -0,0 +1,11 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.15;
|
||||
|
||||
contract VerifierTest {
|
||||
function verifyProof(
|
||||
uint[2] memory a,
|
||||
uint[2][2] memory b,
|
||||
uint[2] memory c,
|
||||
uint[4] memory input
|
||||
) public view {}
|
||||
}
|
24
deploy/002_deploy_verifier_test.ts
Normal file
24
deploy/002_deploy_verifier_test.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
||||
import { DeployFunction } from "hardhat-deploy/types";
|
||||
import { isDevNet } from "../common";
|
||||
|
||||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
||||
const { deployments, getUnnamedAccounts } = hre;
|
||||
const { deploy } = deployments;
|
||||
|
||||
const [deployer] = await getUnnamedAccounts();
|
||||
|
||||
await deploy("VerifierTest", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
});
|
||||
};
|
||||
export default func;
|
||||
func.tags = ["VerifierTest"];
|
||||
// skip when running on mainnet
|
||||
func.skip = async (hre: HardhatRuntimeEnvironment) => {
|
||||
if (isDevNet(hre.network.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
||||
import { DeployFunction } from "hardhat-deploy/types";
|
||||
import { getGroups, isDevNet } from "../common";
|
||||
import { getGroups, isDevNet, merkleTreeDepth } from "../common";
|
||||
|
||||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
||||
const { deployments, getUnnamedAccounts } = hre;
|
||||
@ -8,10 +8,19 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
||||
|
||||
const [deployer] = await getUnnamedAccounts();
|
||||
|
||||
const verifierAddress = (await deployments.get("VerifierTest")).address;
|
||||
|
||||
const interepTest = await deploy("InterepTest", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
args: [],
|
||||
args: [
|
||||
[
|
||||
{
|
||||
contractAddress: verifierAddress,
|
||||
merkleTreeDepth,
|
||||
},
|
||||
],
|
||||
],
|
||||
});
|
||||
|
||||
const contract = await hre.ethers.getContractAt(
|
||||
@ -24,6 +33,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
||||
};
|
||||
export default func;
|
||||
func.tags = ["InterepTest"];
|
||||
func.dependencies = ["VerifierTest"];
|
||||
// skip when running on mainnet
|
||||
func.skip = async (hre: HardhatRuntimeEnvironment) => {
|
||||
if (isDevNet(hre.network.name)) {
|
Loading…
x
Reference in New Issue
Block a user