2022-05-10 21:09:18 +00:00
|
|
|
# src: https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/RLN.sol
|
|
|
|
# pragma solidity 0.7.4;
|
|
|
|
|
|
|
|
# import { IPoseidonHasher } from "./crypto/PoseidonHasher.sol";
|
|
|
|
|
|
|
|
# contract RLN {
|
|
|
|
# uint256 public immutable MEMBERSHIP_DEPOSIT;
|
|
|
|
# uint256 public immutable DEPTH;
|
|
|
|
# uint256 public immutable SET_SIZE;
|
|
|
|
|
|
|
|
# uint256 public pubkeyIndex = 0;
|
|
|
|
# mapping(uint256 => uint256) public members;
|
|
|
|
|
|
|
|
# IPoseidonHasher public poseidonHasher;
|
|
|
|
|
|
|
|
# event MemberRegistered(uint256 pubkey, uint256 index);
|
|
|
|
# event MemberWithdrawn(uint256 pubkey, uint256 index);
|
|
|
|
|
|
|
|
# constructor(
|
|
|
|
# uint256 membershipDeposit,
|
|
|
|
# uint256 depth,
|
|
|
|
# address _poseidonHasher
|
|
|
|
# ) public {
|
|
|
|
# MEMBERSHIP_DEPOSIT = membershipDeposit;
|
|
|
|
# DEPTH = depth;
|
|
|
|
# SET_SIZE = 1 << depth;
|
|
|
|
# poseidonHasher = IPoseidonHasher(_poseidonHasher);
|
|
|
|
# }
|
|
|
|
|
|
|
|
# function register(uint256 pubkey) external payable {
|
|
|
|
# require(pubkeyIndex < SET_SIZE, "RLN, register: set is full");
|
|
|
|
# require(msg.value == MEMBERSHIP_DEPOSIT, "RLN, register: membership deposit is not satisfied");
|
|
|
|
# _register(pubkey);
|
|
|
|
# }
|
|
|
|
|
|
|
|
# function registerBatch(uint256[] calldata pubkeys) external payable {
|
|
|
|
# require(pubkeyIndex + pubkeys.length <= SET_SIZE, "RLN, registerBatch: set is full");
|
|
|
|
# require(msg.value == MEMBERSHIP_DEPOSIT * pubkeys.length, "RLN, registerBatch: membership deposit is not satisfied");
|
|
|
|
# for (uint256 i = 0; i < pubkeys.length; i++) {
|
|
|
|
# _register(pubkeys[i]);
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
|
|
|
# function _register(uint256 pubkey) internal {
|
|
|
|
# members[pubkeyIndex] = pubkey;
|
|
|
|
# emit MemberRegistered(pubkey, pubkeyIndex);
|
|
|
|
# pubkeyIndex += 1;
|
|
|
|
# }
|
|
|
|
|
|
|
|
# function withdrawBatch(
|
|
|
|
# uint256[] calldata secrets,
|
|
|
|
# uint256[] calldata pubkeyIndexes,
|
|
|
|
# address payable[] calldata receivers
|
|
|
|
# ) external {
|
|
|
|
# uint256 batchSize = secrets.length;
|
|
|
|
# require(batchSize != 0, "RLN, withdrawBatch: batch size zero");
|
|
|
|
# require(batchSize == pubkeyIndexes.length, "RLN, withdrawBatch: batch size mismatch pubkey indexes");
|
|
|
|
# require(batchSize == receivers.length, "RLN, withdrawBatch: batch size mismatch receivers");
|
|
|
|
# for (uint256 i = 0; i < batchSize; i++) {
|
|
|
|
# _withdraw(secrets[i], pubkeyIndexes[i], receivers[i]);
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
|
|
|
# function withdraw(
|
|
|
|
# uint256 secret,
|
|
|
|
# uint256 _pubkeyIndex,
|
|
|
|
# address payable receiver
|
|
|
|
# ) external {
|
|
|
|
# _withdraw(secret, _pubkeyIndex, receiver);
|
|
|
|
# }
|
|
|
|
|
|
|
|
# function _withdraw(
|
|
|
|
# uint256 secret,
|
|
|
|
# uint256 _pubkeyIndex,
|
|
|
|
# address payable receiver
|
|
|
|
# ) internal {
|
|
|
|
# require(_pubkeyIndex < SET_SIZE, "RLN, _withdraw: invalid pubkey index");
|
|
|
|
# require(members[_pubkeyIndex] != 0, "RLN, _withdraw: member doesn't exist");
|
|
|
|
# require(receiver != address(0), "RLN, _withdraw: empty receiver address");
|
|
|
|
|
|
|
|
# // derive public key
|
|
|
|
# uint256 pubkey = hash([secret, 0]);
|
|
|
|
# require(members[_pubkeyIndex] == pubkey, "RLN, _withdraw: not verified");
|
|
|
|
|
|
|
|
# // delete member
|
|
|
|
# members[_pubkeyIndex] = 0;
|
|
|
|
|
|
|
|
# // refund deposit
|
|
|
|
# receiver.transfer(MEMBERSHIP_DEPOSIT);
|
|
|
|
|
|
|
|
# emit MemberWithdrawn(pubkey, _pubkeyIndex);
|
|
|
|
# }
|
|
|
|
|
|
|
|
# function hash(uint256[2] memory input) internal view returns (uint256) {
|
|
|
|
# return poseidonHasher.hash(input);
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
2023-09-04 05:52:31 +00:00
|
|
|
# PoseidonHasherCode holds the bytecode of Poseidon hasher solidity smart contract:
|
|
|
|
# https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/crypto/PoseidonHasher.sol
|
2022-05-10 21:09:18 +00:00
|
|
|
# the solidity contract is compiled separately and the resultant bytecode is copied here
|
2023-08-25 17:18:52 +00:00
|
|
|
const PoseidonHasherCode* = "0x608060405234801561001057600080fd5b50613e58806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063b189fd4c1461003b578063e493ef8c1461006b575b600080fd5b61005560048036038101906100509190613dcb565b610089565b6040516100629190613e07565b60405180910390f35b61007361009b565b6040516100809190613e07565b60405180910390f35b6000610094826100bf565b9050919050565b7f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f000000181565b60007f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000017f09c46e9ec68e9bd4fe1faaba294cba38a71aa177534cdd1b6c7dc0dbd0abd7a77f0c0356530896eec42a97ed937f3135cfc5142b3ae405b8343c1d83ffa604cb81840182828309838385838409099250838283099050838285838409099150837f2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e88309847f066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad58509019050837f1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c88309847f0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff985090191508092507f1e28a1d935698ad1142e51182bb54cf4a00ea5aabd6268bd317ea977cc154a30830192507f27af2d831a9d2748080965db30e298e40e5757c3e008db964cf9e2b12b91251f82019150838384099050838385838409099250838283099050838285838409099150837f2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e88309847f066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad58509019050837f1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c88309847f0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff985090191508092507f1e6f11ce60fc8f513a6a3cfe16ae175a41291462f214cd0879aaf43545b74e03830192507f2a67384d3bbd5e438541819cb681f0be04462ed14c3613d8f719206268d142d382019150838384099050838385838409099250838283099050838285838409099150837f2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e88309847f066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad58509019050837f1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c88309847f0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff985090191508092507f0b66fdf356093a611609f8e12fbfecf0b985e381f025188936408f5d5c9f45d0830192507f012ee3ec1e78d470830c61093c2ade370b26c83cc5cebeeddaa6852dbdb09e2182019150838384099050838385838409099250838283099050838285838409099150837f2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e88309847f066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad58509019050837f1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c88309847f0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff985090191508092507f0252ba5f6760bfbdfd88f67f8175e3fd6cd1c431b099b6bb2d108e7b445bb1b9830192507f179474cceca5ff676c6bec3cef54296354391a8935ff71d6ef5aeaad7ca932f182019150838384099050838385838409099250837f2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e88309847f066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad58509019050837f1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c88309847f0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff985090191508092507f2c24261379a51bfa9228ff4a503fd4ed9c1f974a264969b37e1a2589bbed2b91830192507f1cc1d7b62692e63eac2f288bd0695b43c2f63f5001fc0fc553e66c0551801b0582019150838384099050838385838409099250837f2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e88309847f066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad58509019050837f1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c88309847f0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff985090191508092507f255059301aada98bb2ed55f852979e9600784dbf17fbacd05d9eff5fd9c91b56830192507f28437be3ac1cb2e479e1f5c0eccd32b3aea24234970a8193b11c29ce7e59efd982019150838384099050838385838409099250837f2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e88309847f066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad58509019050837f1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c88309847f0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff985090191508092507f28216a442f2e1f711ca4fa6b53766eb118548da8fb4f78d43387
|
2022-05-10 21:09:18 +00:00
|
|
|
|
2023-08-25 17:18:52 +00:00
|
|
|
# RegistryContractCode contains the bytecode of the membership solidity smart contract:
|
2023-09-04 05:52:31 +00:00
|
|
|
# https://github.com/waku-org/rln-contract/blob/fbafa7b0bb47c5233f50ba82992c572795e7e9a6/deployments/sepolia/WakuRlnRegistry.json
|
2022-05-10 21:09:18 +00:00
|
|
|
# the solidity contract is compiled separately and the resultant bytecode is copied here
|
2023-09-04 05:52:31 +00:00
|
|
|
const RegistryContractCode* = "0x60a06040526000600260006101000a81548161ffff021916908361ffff1602179055503480156200002f57600080fd5b5060405162002f2a38038062002f2a8339818101604052810190620000559190620001e6565b6200007562000069620000b060201b60201c565b620000b860201b60201c565b8073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250505062000218565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001ae8262000181565b9050919050565b620001c081620001a1565b8114620001cc57600080fd5b50565b600081519050620001e081620001b5565b92915050565b600060208284031215620001ff57620001fe6200017c565b5b60006200020f84828501620001cf565b91505092915050565b608051612ce862000242600039600081816103e2015281816104120152610ad80152612ce86000f3fe60806040523480156200001157600080fd5b5060043610620000e25760003560e01c8063ab02492a1162000099578063ef653d5e116200006f578063ef653d5e14620001d1578063f184ef4c14620001f1578063f2fde38b1462000213578063f5542147146200023357620000e2565b8063ab02492a1462000183578063cf61637414620001a3578063d44fda1f14620001c557620000e2565b806326e0fc1f14620000e7578063331b6ab3146200010757806342f542e21462000129578063715018a614620001355780637a34289d14620001415780638da5cb5b1462000161575b600080fd5b620001056004803603810190620000ff919062001045565b62000269565b005b62000111620003e0565b60405162000120919062001117565b60405180910390f35b6200013362000404565b005b6200013f6200048b565b005b6200015f6004803603810190620001599190620011a2565b620004a3565b005b6200016b6200075f565b6040516200017a91906200121c565b60405180910390f35b620001a160048036038101906200019b919062001239565b62000788565b005b620001ad6200088b565b604051620001bc9190620012b4565b60405180910390f35b620001cf6200089f565b005b620001ef6004803603810190620001e9919062001302565b62000a09565b005b620001fb62000c9e565b6040516200020a9190620012b4565b60405180910390f35b6200023160048036038101906200022b919062001302565b62000cb2565b005b6200025160048036038101906200024b919062001334565b62000d3c565b6040516200026091906200121c565b60405180910390f35b600060149054906101000a900461ffff1661ffff168261ffff1610620002bb576040517fd23276a200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000600167ffffffffffffffff811115620002db57620002da62001366565b5b6040519080825280602002602001820160405280156200030a5781602001602082028036833780820191505090505b509050818160008151811062000325576200032462001395565b5b602002602001018181525050600160008461ffff1661ffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637a34289d826040518263ffffffff1660e01b8152600401620003a7919062001492565b600060405180830381600087803b158015620003c257600080fd5b505af1158015620003d7573d6000803e3d6000fd5b50505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6200040e62000d6f565b60007f0000000000000000000000000000000000000000000000000000000000000000600060149054906101000a900461ffff16604051620004509062000fb3565b6200045d929190620014b6565b604051809103906000f0801580156200047a573d6000803e3d6000fd5b509050620004888162000df4565b50565b6200049562000d6f565b620004a1600062000ee7565b565b600060149054906101000a900461ffff1661ffff16600260009054906101000a900461ffff1661ffff161062000505576040517fd23276a200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5b6001156200075b5760016000600260009054906101000a900461ffff1661ffff1661ffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637a34289d83836040518363ffffffff1660e01b8152600401620005969291906200155a565b600060405180830381600087803b158015620005b157
|