nwaku/waku/v2/protocol/waku_rln_relay/contract.nim

108 lines
26 KiB
Nim
Raw Normal View History

chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
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);
# }
# }
# PoseidonHasherCode holds the bytecode of Poseidon hasher solidity smart contract:
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 21:09:18 +00:00
# https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/crypto/PoseidonHasher.sol
# the solidity contract is compiled separately and the resultant bytecode is copied here
const PoseidonHasherCode* = "0x608060405234801561001057600080fd5b50612142806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632c159a1a1461003b578063561558fe14610055575b600080fd5b6100436100a0565b60408051918252519081900360200190f35b6100436004803603604081101561006b57600080fd5b604080518082018252918301929181830191839060029083908390808284376000920191909152509194506100af9350505050565b60006100aa6100c0565b905090565b60006100ba826100e4565b92915050565b7f2ff267fd23782a5625e6d804f0a7fa700b8dc6084e2e7a5aff7cd4b1c506d30b90565b60007f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000016040517f165d45ae851912f9a33800b04cc6617b184bf67db11ce904dc82601244551ae281527f10fc284d0af588165f4fc650fe7c53b1d80fbaac16d30518bf142117f42f820460208201527f06b687bd3c688aa9a03545d0835bca75ae82c434bf7d5fb065a2818b5c74814f60408201527f01057eb8e4bba26f12f4ea819251708d72e0605e6de827e990c3ba4ae13f5ecd60608201527e23779a38eb9ef4a9beaf4dc0a2ab5233a28ce6d10ad2512230a275b83017c360808201527f012e5dfdd4f34081753b70c897773f5d2987c8bbae32ad202a27cd61d7fba2fb7f0d1807f022a8d80d9304a1522087b8692dc0acf7b43fea28782d2ae672c0b11f7f17d468d0e6541de501481931453ed1e4a250e5e301f27dc91fe3b4bd522aa53c7f1ea09a4bd33f14eafd75e775d85e568fa668938fdd2f16fad1d4d2d2b9862b007f061f2e832c23bee84c2f09d63d371cc5eda2f749cdbe9a6a6d20469e9fa36e8b8851017f061f2e832c23bee84c2f09d63d371cc5eda2f749cdbe9a6a6d20469e9fa36e8b60208a0151017f061f2e832c23bee84c2f09d63d371cc5eda2f749cdbe9a6a6d20469e9fa36e8b8883840989848b83840909935089838409905089838b83840909925089828309905089828b8384090991507f0e4d154ca9b7f5111958289f43ed5bbc4d4f6118d45d9aefeb778179d921a59b9050808a60408b015184098b60208c015186098c8c518809010101818b8a85098c60808d015187098d60608e01518909010101828c8886098d8a88098e8c8a0901010193508b82830992508b828d8586090991508b81820992508b818d8586090990508b84850992508b848d8586090993507f298d683000ab71c72fe4371cf6cd37bb584b6d816a653ee4bfea62518a337e079250828c60408d015186098d60208e015184098e8e5186090101019550828c8b86098d60808e015184098e60608f015186090101019450828c8886098d8a84098e8c860901010193508b86870992508b868d8586090995508b85860992508b858d8586090994508b84850992508b848d8586090993507f2f860295bc93d694e74905913ddcae47290b9b5abb43a537fe40d9305bd1e1679250828c60408d015186098d60208e015188098e8e518a090101019150828c8b86098d60808e015188098e60608f01518a090101019050828c8886098d8a88098e8c8a0901010193508b82830992508b828d8586090991508b81820992508b818d8586090990508b84850992508b848d8586090993507f1dd8b95942d95c7896be7f3f455e595cbfee5e1023c5d45e6573c8513f1f3dfa9250828c60408d015186098d60208e015184098e8e5186090101019550828c8b86098d60808e015184098e60608f015186090101019450828c8886098d8a84098e8c860901010193508b86870992508b868d8586090995507f189aa3023aeaa7267dd3c74e2c8b9cba363546619bb9c54bcb02b22fe64c51619250828c60408d015186098d60208e015188098e8e518a090101019150828c8b86098d60808e015188098e60608f01518a090101019050828c8886098d8a88098e8c8a0901010193508b82830992508b828d8586090991507f0da6b697fd05fe54a523131d91e2a7f6ac18184e237c1b20ab1936616f08e5239250828c60408d015186098d60208e015184098e8e5186090101019550828c8b86098d60808e015184098e60608f015186090101019450828c8886098d8a84098e8c860901010193508b86870992508b868d8586090995507f019df963bfafa7f0e34cf092f33ce93b38b9d130fb44f276196e59f16e63ac5a9250828c60408d015186098d60208e015188098e8e518a090101019150828c8b86098d60808e015188098e60608f01518a090101019050828c8886098d8a88098e8c8a0901010193508b82830992508b828d8586090991507f295332d5ab168bc3c5eb671528c9896b7bd5034fb02472ff2af4fa1087ae658f9250828c60408d015186098d60208e015184098e8e5186090101019550828c8b86098d60808e015184098e60608f015186090101019450828c8886098d8a84098e8c860901010193508b86870992508b868d8586090995507f0f423b84792458876c314228be9361a604c75010411b87add91b791df2f980fa9250828c60408d015186098d60208e015188098e8e518a090101019150828c8b86098d60808e015188098e60608f01518a090101019050828c8886098d8a88098e8c8a0901010193508b82830992508b828d8586090991507f1171744890a155b5ad9cde4f1f5c4eab878f3730a9fc71f546eb737c84abec5f9250828c60408d015186098d60208e015184098e8e5186090101019550828c8b86098d60808e015184098e60608f01518609010101945082
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 21:09:18 +00:00
# MembershipContractCode contains the bytecode of the membership solidity smart contract:
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 21:09:18 +00:00
# https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/RLN.sol
# the solidity contract is compiled separately and the resultant bytecode is copied here
const MembershipContractCode* = "0x60e06040526000805534801561001457600080fd5b50604051610c4f380380610c4f8339818101604052606081101561003757600080fd5b5080516020820151604090920151608082905260a08390526001831b60c0819052600280546001600160a01b0319166001600160a01b0390931692909217909155909190610b936100bc6000398061037a52806105c352806105e752806106eb52508061047f5250806103f2528061065d52806106c7528061087b5250610b936000f3fe6080604052600436106100915760003560e01c806398366e351161005957806398366e35146101c7578063a9d85eba146101dc578063d0383d68146102f7578063f207564e1461030c578063f220b9ec1461032957610091565b80630ad58d2f14610096578063331b6ab3146100d75780635daf08ca1461010857806361579a931461014457806369e4863f14610159575b600080fd5b3480156100a257600080fd5b506100d5600480360360608110156100b957600080fd5b50803590602081013590604001356001600160a01b031661033e565b005b3480156100e357600080fd5b506100ec61034e565b604080516001600160a01b039092168252519081900360200190f35b34801561011457600080fd5b506101326004803603602081101561012b57600080fd5b503561035d565b60408051918252519081900360200190f35b34801561015057600080fd5b5061013261036f565b6100d56004803603602081101561016f57600080fd5b810190602081018135600160201b81111561018957600080fd5b82018360208201111561019b57600080fd5b803590602001918460208302840111600160201b831117156101bc57600080fd5b509092509050610375565b3480156101d357600080fd5b5061013261047d565b3480156101e857600080fd5b506100d5600480360360608110156101ff57600080fd5b810190602081018135600160201b81111561021957600080fd5b82018360208201111561022b57600080fd5b803590602001918460208302840111600160201b8311171561024c57600080fd5b919390929091602081019035600160201b81111561026957600080fd5b82018360208201111561027b57600080fd5b803590602001918460208302840111600160201b8311171561029c57600080fd5b919390929091602081019035600160201b8111156102b957600080fd5b8201836020820111156102cb57600080fd5b803590602001918460208302840111600160201b831117156102ec57600080fd5b5090925090506104a1565b34801561030357600080fd5b506101326105c1565b6100d56004803603602081101561032257600080fd5b50356105e5565b34801561033557600080fd5b506101326106c5565b6103498383836106e9565b505050565b6002546001600160a01b031681565b60016020526000908152604090205481565b60005481565b6000547f000000000000000000000000000000000000000000000000000000000000000090820111156103ef576040805162461bcd60e51b815260206004820152601f60248201527f524c4e2c20726567697374657242617463683a207365742069732066756c6c00604482015290519081900360640190fd5b347f000000000000000000000000000000000000000000000000000000000000000082021461044f5760405162461bcd60e51b8152600401808060200182810382526037815260200180610a566037913960400191505060405180910390fd5b60005b818110156103495761047583838381811061046957fe5b90506020020135610902565b600101610452565b7f000000000000000000000000000000000000000000000000000000000000000081565b84806104de5760405162461bcd60e51b8152600401808060200182810382526023815260200180610a336023913960400191505060405180910390fd5b80841461051c5760405162461bcd60e51b81526004018080602001828103825260368152602001806109fd6036913960400191505060405180910390fd5b80821461055a5760405162461bcd60e51b8152600401808060200182810382526031815260200180610a8d6031913960400191505060405180910390fd5b60005b818110156105b7576105af88888381811061057457fe5b9050602002013587878481811061058757fe5b9050602002013586868581811061059a57fe5b905060200201356001600160a01b03166106e9565b60010161055d565b5050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f00000000000000000000000000000000000000000000000000000000000000006000541061065b576040805162461bcd60e51b815260206004820152601a60248201527f524c4e2c2072656769737465723a207365742069732066756c6c000000000000604482015290519081900360640190fd5b7f000000000000000000000000000000000000000000000000000000000000000034146106b95760405162461bcd60e51b8152600401808060200182810382526032815260200180610abe6032913960400191505060405180910390fd5b6106c281610902565b50565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000082106107475760405162461bcd60e51b8152600401808060200182810382526024815260200180