chore: remove PoseidonHasher contract, incl Q in RLN
This commit is contained in:
parent
ea4a157a70
commit
7cca053b38
|
@ -1,19 +0,0 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.8.15;
|
||||
|
||||
import {PoseidonT3} from "poseidon-solidity/PoseidonT3.sol";
|
||||
|
||||
interface IPoseidonHasher {
|
||||
/// @notice Hashes the input using the Poseidon hash function, n = 2
|
||||
/// @param inputs The input to hash
|
||||
function hash(uint256[2] memory inputs) external pure returns (uint256 result);
|
||||
}
|
||||
|
||||
contract PoseidonHasher is IPoseidonHasher {
|
||||
uint256 public constant Q = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
|
||||
function hash(uint256[2] memory inputs) external pure override returns (uint256 result) {
|
||||
return PoseidonT3.hash(inputs);
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@ pragma solidity 0.8.15;
|
|||
import "./RlnBase.sol";
|
||||
|
||||
contract RLN is RlnBase {
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _poseidonHasher, address _verifier)
|
||||
RlnBase(membershipDeposit, depth, _poseidonHasher, _verifier)
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _verifier)
|
||||
RlnBase(membershipDeposit, depth, _verifier)
|
||||
{}
|
||||
|
||||
function _validateRegistration(uint256 idCommitment) internal pure override {}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
pragma solidity 0.8.15;
|
||||
|
||||
import {PoseidonHasher} from "./PoseidonHasher.sol";
|
||||
import {IVerifier} from "./IVerifier.sol";
|
||||
import {BinaryIMT, BinaryIMTData} from "@zk-kit/imt.sol/BinaryIMT.sol";
|
||||
|
||||
|
@ -42,6 +41,9 @@ error InsufficientContractBalance();
|
|||
error InvalidProof();
|
||||
|
||||
abstract contract RlnBase {
|
||||
/// @notice The Field
|
||||
uint256 public constant Q = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
|
||||
/// @notice The deposit amount required to register as a member
|
||||
uint256 public immutable MEMBERSHIP_DEPOSIT;
|
||||
|
||||
|
@ -68,9 +70,6 @@ abstract contract RlnBase {
|
|||
/// @notice The balance of each user that can be withdrawn
|
||||
mapping(address => uint256) public withdrawalBalance;
|
||||
|
||||
/// @notice The Poseidon hasher contract
|
||||
PoseidonHasher public immutable poseidonHasher;
|
||||
|
||||
/// @notice The groth16 verifier contract
|
||||
IVerifier public immutable verifier;
|
||||
|
||||
|
@ -95,11 +94,10 @@ abstract contract RlnBase {
|
|||
_;
|
||||
}
|
||||
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _poseidonHasher, address _verifier) {
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _verifier) {
|
||||
MEMBERSHIP_DEPOSIT = membershipDeposit;
|
||||
DEPTH = depth;
|
||||
SET_SIZE = 1 << depth;
|
||||
poseidonHasher = PoseidonHasher(_poseidonHasher);
|
||||
verifier = IVerifier(_verifier);
|
||||
deployedBlockNumber = uint32(block.number);
|
||||
BinaryIMT.initWithDefaultZeroes(imtData, 20);
|
||||
|
@ -198,8 +196,8 @@ abstract contract RlnBase {
|
|||
payable(msg.sender).transfer(amount);
|
||||
}
|
||||
|
||||
function isValidCommitment(uint256 idCommitment) public view returns (bool) {
|
||||
return idCommitment != 0 && idCommitment < poseidonHasher.Q();
|
||||
function isValidCommitment(uint256 idCommitment) public pure returns (bool) {
|
||||
return idCommitment != 0 && idCommitment < Q;
|
||||
}
|
||||
|
||||
/// @dev Groth16 proof verification
|
||||
|
|
|
@ -7,18 +7,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|||
|
||||
const [deployer] = await getUnnamedAccounts();
|
||||
|
||||
const deployRes = await deploy("PoseidonT3", {
|
||||
await deploy("PoseidonT3", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
});
|
||||
|
||||
await deploy("PoseidonHasher", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
libraries: {
|
||||
PoseidonT3: deployRes.address,
|
||||
},
|
||||
});
|
||||
};
|
||||
export default func;
|
||||
func.tags = ["PoseidonHasher"];
|
||||
func.tags = ["PoseidonT3"];
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
||||
import { DeployFunction } from "hardhat-deploy/types";
|
||||
|
||||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
||||
const { deployments, getUnnamedAccounts } = hre;
|
||||
const { deploy } = deployments;
|
||||
|
||||
const [deployer] = await getUnnamedAccounts();
|
||||
|
||||
await deploy("BinaryIMT", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
libraries: {
|
||||
PoseidonT3: (await deployments.get("PoseidonT3")).address,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export default func;
|
||||
func.tags = ["BinaryIMT"];
|
||||
func.dependencies = ["PoseidonT3"];
|
|
@ -7,28 +7,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|||
|
||||
const [deployer] = await getUnnamedAccounts();
|
||||
|
||||
const poseidonHasherAddress = (await deployments.get("PoseidonHasher"))
|
||||
.address;
|
||||
const rlnVerifierAddress = (await deployments.get("Verifier")).address;
|
||||
|
||||
const deployRes = await deploy("BinaryIMT", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
libraries: {
|
||||
PoseidonT3: (await deployments.get("PoseidonT3")).address,
|
||||
},
|
||||
});
|
||||
const binaryIMTAddress = (await deployments.get("BinaryIMT")).address;
|
||||
|
||||
await deploy("RLN", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
args: [1000000000000000, 20, poseidonHasherAddress, rlnVerifierAddress],
|
||||
args: [1000000000000000, 20, rlnVerifierAddress],
|
||||
libraries: {
|
||||
BinaryIMT: deployRes.address,
|
||||
BinaryIMT: binaryIMTAddress,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export default func;
|
||||
func.tags = ["Rln"];
|
||||
func.dependencies = ["PoseidonHasher", "RlnVerifier", "BinaryIMT"];
|
||||
func.tags = ["RLN"];
|
||||
func.dependencies = ["PoseidonT3", "RlnVerifier", "BinaryIMT"];
|
|
@ -545,7 +545,7 @@
|
|||
]
|
||||
},
|
||||
"RLN": {
|
||||
"address": "0x0EE706eAfC3cc76B28fc6607756234ada6a7c377",
|
||||
"address": "0xC568eF58009b8e5B8824d9fbB271141782545538",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
|
@ -559,11 +559,6 @@
|
|||
"name": "depth",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "_poseidonHasher",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "_verifier",
|
||||
|
@ -722,6 +717,19 @@
|
|||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "Q",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "SET_SIZE",
|
||||
|
@ -805,7 +813,7 @@
|
|||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
|
@ -846,19 +854,6 @@
|
|||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "poseidonHasher",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "contract PoseidonHasher",
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
|
@ -1016,7 +1011,7 @@
|
|||
"chainId": "11155111",
|
||||
"contracts": {
|
||||
"BinaryIMT": {
|
||||
"address": "0x9Eae140A17Fd002B2ffA3B5df76C13100CDF909d",
|
||||
"address": "0xAecbB25437eDa6B01048C3461902F0A522457C1f",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [],
|
||||
|
@ -1494,45 +1489,8 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"PoseidonHasher": {
|
||||
"address": "0x2092b99411d480b8Dd04BfD68EF1F0d545b0eB1D",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "Q",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "inputs",
|
||||
"type": "uint256[2]"
|
||||
}
|
||||
],
|
||||
"name": "hash",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "result",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
}
|
||||
]
|
||||
},
|
||||
"PoseidonT3": {
|
||||
"address": "0xbeeeAcde37Bce9011326137a49Bd5CA8153E9FCD",
|
||||
"address": "0xB792fc68f37747828e0e6dB443229d1C927a05d1",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
|
@ -1556,7 +1514,7 @@
|
|||
]
|
||||
},
|
||||
"RLN": {
|
||||
"address": "0xb4eb8135C8ba7Af1295EB9C363DddA996cdB813E",
|
||||
"address": "0xbE24C8d709754523D882D4b67C59e983107cf1E8",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
|
@ -1570,11 +1528,6 @@
|
|||
"name": "depth",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "_poseidonHasher",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "_verifier",
|
||||
|
@ -1733,6 +1686,19 @@
|
|||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "Q",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "SET_SIZE",
|
||||
|
@ -1816,7 +1782,7 @@
|
|||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
|
@ -1857,19 +1823,6 @@
|
|||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "poseidonHasher",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "contract PoseidonHasher",
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
|
@ -1980,7 +1933,7 @@
|
|||
]
|
||||
},
|
||||
"Verifier": {
|
||||
"address": "0xe36940B40aDe98F02a4829414F7e8d636CCf3663",
|
||||
"address": "0x4F33f2B18bb30bdF81c18E9C7a46e46187609511",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"address": "0xe36940B40aDe98F02a4829414F7e8d636CCf3663",
|
||||
"address": "0x4F33f2B18bb30bdF81c18E9C7a46e46187609511",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
|
@ -36,19 +36,19 @@
|
|||
"type": "function"
|
||||
}
|
||||
],
|
||||
"transactionHash": "0x280448aedc8db6088f35d7477aa682a387364950a80ddd609c3bebed8acae5aa",
|
||||
"transactionHash": "0x2410399e82218e668dd8a8a9b83663bf39aa2bad2b4a110860db014b3e5c14d6",
|
||||
"receipt": {
|
||||
"to": null,
|
||||
"from": "0x3F47b2a1dF96DE2e198d646b598C37251CCC3b98",
|
||||
"contractAddress": "0xe36940B40aDe98F02a4829414F7e8d636CCf3663",
|
||||
"transactionIndex": 37,
|
||||
"contractAddress": "0x4F33f2B18bb30bdF81c18E9C7a46e46187609511",
|
||||
"transactionIndex": 49,
|
||||
"gasUsed": "1117583",
|
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x05a7ffe1dc0bdb3c1d727efcb03598feffa5220b5493e027eebe47f34b026170",
|
||||
"transactionHash": "0x280448aedc8db6088f35d7477aa682a387364950a80ddd609c3bebed8acae5aa",
|
||||
"blockHash": "0xa021197b10f4cf6b113024b8761cd12de3813f300be9874bb6f011699137e852",
|
||||
"transactionHash": "0x2410399e82218e668dd8a8a9b83663bf39aa2bad2b4a110860db014b3e5c14d6",
|
||||
"logs": [],
|
||||
"blockNumber": 4794983,
|
||||
"cumulativeGasUsed": "8731883",
|
||||
"blockNumber": 4800009,
|
||||
"cumulativeGasUsed": "5736392",
|
||||
"status": 1,
|
||||
"byzantium": true
|
||||
},
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -8,50 +8,12 @@
|
|||
function verifyProof(uint256[2] a, uint256[2][2] b, uint256[2] c, uint256[2] input) external view returns (bool)
|
||||
```
|
||||
|
||||
## IPoseidonHasher
|
||||
|
||||
### hash
|
||||
|
||||
```solidity
|
||||
function hash(uint256[2] inputs) external pure returns (uint256 result)
|
||||
```
|
||||
|
||||
Hashes the input using the Poseidon hash function, n = 2
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------ | ---------- | ----------------- |
|
||||
| inputs | uint256[2] | The input to hash |
|
||||
|
||||
## PoseidonHasher
|
||||
|
||||
### Q
|
||||
|
||||
```solidity
|
||||
uint256 Q
|
||||
```
|
||||
|
||||
### hash
|
||||
|
||||
```solidity
|
||||
function hash(uint256[2] inputs) external pure returns (uint256 result)
|
||||
```
|
||||
|
||||
Hashes the input using the Poseidon hash function, n = 2
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------ | ---------- | ----------------- |
|
||||
| inputs | uint256[2] | The input to hash |
|
||||
|
||||
## RLN
|
||||
|
||||
### constructor
|
||||
|
||||
```solidity
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _poseidonHasher, address _verifier) public
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _verifier) public
|
||||
```
|
||||
|
||||
### \_validateRegistration
|
||||
|
@ -165,6 +127,14 @@ Invalid proof
|
|||
|
||||
## RlnBase
|
||||
|
||||
### Q
|
||||
|
||||
```solidity
|
||||
uint256 Q
|
||||
```
|
||||
|
||||
The Field
|
||||
|
||||
### MEMBERSHIP_DEPOSIT
|
||||
|
||||
```solidity
|
||||
|
@ -231,14 +201,6 @@ mapping(address => uint256) withdrawalBalance
|
|||
|
||||
The balance of each user that can be withdrawn
|
||||
|
||||
### poseidonHasher
|
||||
|
||||
```solidity
|
||||
contract PoseidonHasher poseidonHasher
|
||||
```
|
||||
|
||||
The Poseidon hasher contract
|
||||
|
||||
### verifier
|
||||
|
||||
```solidity
|
||||
|
@ -302,7 +264,7 @@ modifier onlyValidIdCommitment(uint256 idCommitment)
|
|||
### constructor
|
||||
|
||||
```solidity
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _poseidonHasher, address _verifier) internal
|
||||
constructor(uint256 membershipDeposit, uint256 depth, address _verifier) internal
|
||||
```
|
||||
|
||||
### register
|
||||
|
@ -392,7 +354,7 @@ Allows a user to withdraw funds allocated to them upon slashing a member
|
|||
### isValidCommitment
|
||||
|
||||
```solidity
|
||||
function isValidCommitment(uint256 idCommitment) public view returns (bool)
|
||||
function isValidCommitment(uint256 idCommitment) public pure returns (bool)
|
||||
```
|
||||
|
||||
### \_verifyProof
|
||||
|
|
|
@ -1,25 +1,17 @@
|
|||
// SPDX-License-Identifier: Unlicense
|
||||
pragma solidity ^0.8.15;
|
||||
|
||||
import "../contracts/PoseidonHasher.sol";
|
||||
import "poseidon-solidity/PoseidonT3.sol";
|
||||
import "forge-std/Test.sol";
|
||||
|
||||
contract PoseidonHasherTest is Test {
|
||||
PoseidonHasher public poseidon;
|
||||
|
||||
/// @dev Setup the testing environment.
|
||||
function setUp() public {
|
||||
poseidon = new PoseidonHasher();
|
||||
}
|
||||
function setUp() public {}
|
||||
|
||||
/// @dev Ensure that you can hash a value.
|
||||
function testHasher(uint256 value) public {
|
||||
assertEq(poseidon.hash([value, 0]), poseidon.hash([value, 0]));
|
||||
}
|
||||
|
||||
function testHasher() public {
|
||||
assertEq(
|
||||
poseidon.hash([19014214495641488759237505126948346942972912379615652741039992445865937985820, 0]),
|
||||
PoseidonT3.hash([19014214495641488759237505126948346942972912379615652741039992445865937985820, 0]),
|
||||
13164376930590487041313497514223288845711140604177161029957349518915056324115
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { expect } from "chai";
|
||||
import { ethers, deployments } from "hardhat";
|
||||
|
||||
describe("PoseidonHasher", () => {
|
||||
describe("PoseidonT3", () => {
|
||||
beforeEach(async () => {
|
||||
await deployments.fixture(["PoseidonHasher"]);
|
||||
await deployments.fixture(["PoseidonT3"]);
|
||||
});
|
||||
|
||||
it("should hash correctly", async function () {
|
||||
const poseidonHasher = await ethers.getContract("PoseidonHasher");
|
||||
const poseidonHasher = await ethers.getContract("PoseidonT3");
|
||||
|
||||
// We test hashing for a random number
|
||||
const hash = await poseidonHasher.hash([
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ethers, deployments } from "hardhat";
|
|||
|
||||
describe("Rln", () => {
|
||||
beforeEach(async () => {
|
||||
await deployments.fixture(["Rln"]);
|
||||
await deployments.fixture(["RLN"]);
|
||||
});
|
||||
|
||||
it("should register new memberships", async () => {
|
||||
|
|
Loading…
Reference in New Issue