mirror of
https://github.com/interep-project/contracts.git
synced 2026-01-10 05:47:59 -05:00
refactor: add verifier struct
This commit is contained in:
@@ -51,7 +51,7 @@ Please, visit our [web app](https://kovan.interep.link) or our [documentation we
|
||||
|
||||
| | Kovan | Goerli | Arbitrum One |
|
||||
| ------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------------ |
|
||||
| Interep | [0x9738...6D6D](https://kovan.etherscan.io/address/0x973863A2D7ddcCAfa9c2d98A3027C1fE0D056D6D) | [0xC0ae...F1c9](https://goerli.etherscan.io/address/0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9) | |
|
||||
| Interep | [0xF58D...53De](https://kovan.etherscan.io/address/0xF58D3b710cDD337df432e20a806Ad04f6CfE53De) | [0x9f44...eafb](https://goerli.etherscan.io/address/0x9f44be9F69aF1e049dCeCDb2d9296f36C49Ceafb) | |
|
||||
|
||||
---
|
||||
|
||||
@@ -128,14 +128,14 @@ yarn deploy:verifier # The resulting address will have to be used in the next st
|
||||
Deploy the Interep contract with one Semaphore verifier:
|
||||
|
||||
```bash
|
||||
yarn deploy:interep --verifiers '[[20, "0x5FbDB2315678afecb367f032d93F642f64180aa3"]]'
|
||||
yarn deploy:interep --verifiers '[{"merkleTreeDepth": 20, "contractAddress": "0x06bcD633988c1CE7Bd134DbE2C12119b6f3E4bD1"}]'
|
||||
```
|
||||
|
||||
If you want to deploy contracts in a specific network you can set up the `DEFAULT_NETWORK` variable in your `.env` file with the name of one of our supported networks (hardhat, localhost, goerli, kovan, arbitrum). Or you can specify it as option:
|
||||
|
||||
```bash
|
||||
yarn deploy:interep --verifiers '[[20, "0x06bcD633988c1CE7Bd134DbE2C12119b6f3E4bD1"]]' --network kovan
|
||||
yarn deploy:interep --verifiers '[[20, "0x5FbDB2315678afecb367f032d93F642f64180aa3"]]' --network localhost
|
||||
yarn deploy:interep --verifiers '[{"merkleTreeDepth": 20, "contractAddress": "0x5FbDB2315678afecb367f032d93F642f64180aa3"}]' --network kovan
|
||||
yarn deploy:interep --verifiers '[{"merkleTreeDepth": 20, "contractAddress": "0x06bcD633988c1CE7Bd134DbE2C12119b6f3E4bD1"}]' --network localhost
|
||||
```
|
||||
|
||||
If you want to deploy the contracts on Goerli, Kovan or Arbitrum remember to provide a valid private key and an Infura API in your `.env` file.
|
||||
|
||||
@@ -4,6 +4,11 @@ pragma solidity ^0.8.4;
|
||||
/// @title Interep interface.
|
||||
/// @dev Interface of a Interep contract.
|
||||
interface IInterep {
|
||||
struct Verifier {
|
||||
address contractAddress;
|
||||
uint8 merkleTreeDepth;
|
||||
}
|
||||
|
||||
struct Group {
|
||||
bytes32 provider;
|
||||
bytes32 name;
|
||||
|
||||
@@ -28,13 +28,20 @@ contract Interep is IInterep, Ownable, SemaphoreCore {
|
||||
}
|
||||
|
||||
/// @dev Initializes the Semaphore verifiers used to verify the user's ZK proofs.
|
||||
/// @param depths: Three depths associated with the verifiers.
|
||||
/// @param verifierAddresses: Verifier addresses.
|
||||
constructor(uint8[] memory depths, address[] memory verifierAddresses) {
|
||||
require(depths.length == verifierAddresses.length, "Interep: parameters lists does not have the same length");
|
||||
/// @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);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8 i = 0; i < depths.length; i++) {
|
||||
verifiers[depths[i]] = IVerifier(verifierAddresses[i]);
|
||||
/// @dev See {IInterep-updateGroups}.
|
||||
function updateGroups(Group[] calldata _groups) external override onlyOwner {
|
||||
for (uint8 i = 0; i < _groups.length; i++) {
|
||||
uint256 groupId = uint256(keccak256(abi.encodePacked(_groups[i].provider, _groups[i].name))) %
|
||||
SNARK_SCALAR_FIELD;
|
||||
|
||||
_updateGroup(groupId, _groups[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +56,7 @@ contract Interep is IInterep, Ownable, SemaphoreCore {
|
||||
uint256 root = getRoot(groupId);
|
||||
uint8 depth = getDepth(groupId);
|
||||
|
||||
require(depth != 0, "Interep: the group does not exist");
|
||||
require(depth != 0, "Interep: group does not exist");
|
||||
|
||||
IVerifier verifier = verifiers[depth];
|
||||
|
||||
@@ -60,16 +67,6 @@ contract Interep is IInterep, Ownable, SemaphoreCore {
|
||||
emit ProofVerified(groupId, signal);
|
||||
}
|
||||
|
||||
/// @dev See {IInterep-updateGroups}.
|
||||
function updateGroups(Group[] calldata offchainGroups) external override onlyOwner {
|
||||
for (uint8 i = 0; i < offchainGroups.length; i++) {
|
||||
uint256 groupId = uint256(keccak256(abi.encodePacked(offchainGroups[i].provider, offchainGroups[i].name))) %
|
||||
SNARK_SCALAR_FIELD;
|
||||
|
||||
_updateGroup(groupId, offchainGroups[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev See {IInterep-getRoot}.
|
||||
function getRoot(uint256 groupId) public view override returns (uint256) {
|
||||
return groups[groupId].root;
|
||||
|
||||
@@ -2,7 +2,10 @@ import { run } from "hardhat"
|
||||
|
||||
async function main() {
|
||||
const { address: verifierAddress } = await run("deploy:verifier", { logs: false })
|
||||
const { address: interepAddress } = await run("deploy:interep", { logs: false, verifiers: [[20, verifierAddress]] })
|
||||
const { address: interepAddress } = await run("deploy:interep", {
|
||||
logs: false,
|
||||
verifiers: [{ merkleTreeDepth: 20, contractAddress: verifierAddress }]
|
||||
})
|
||||
|
||||
console.log(`Interep contract has been deployed to: ${interepAddress}`)
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ task("deploy:interep", "Deploy an Interep contract")
|
||||
.setAction(async ({ logs, verifiers }, { ethers }): Promise<Contract> => {
|
||||
const ContractFactory = await ethers.getContractFactory("Interep")
|
||||
|
||||
const contract = await ContractFactory.deploy(
|
||||
verifiers.map((v: [number, number]) => v[0]),
|
||||
verifiers.map((v: [number, number]) => v[1])
|
||||
)
|
||||
const contract = await ContractFactory.deploy(verifiers)
|
||||
|
||||
await contract.deployed()
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ describe("Interep", () => {
|
||||
|
||||
before(async () => {
|
||||
const { address: verifierAddress } = await run("deploy:verifier", { logs: false })
|
||||
contract = await run("deploy:interep", { logs: false, verifiers: [[tree.depth, verifierAddress]] })
|
||||
contract = await run("deploy:interep", {
|
||||
logs: false,
|
||||
verifiers: [{ merkleTreeDepth: tree.depth, contractAddress: verifierAddress }]
|
||||
})
|
||||
})
|
||||
|
||||
describe("# updateGroups", () => {
|
||||
@@ -101,7 +104,7 @@ describe("Interep", () => {
|
||||
it("Should not verify a proof if the group does not exist", async () => {
|
||||
const transaction = contract.verifyProof(10, bytes32Signal, 0, 0, [0, 0, 0, 0, 0, 0, 0, 0])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("Interep: the group does not exist")
|
||||
await expect(transaction).to.be.revertedWith("Interep: group does not exist")
|
||||
})
|
||||
|
||||
it("Should throw an exception if the proof is not valid", async () => {
|
||||
|
||||
Reference in New Issue
Block a user