deploy: 8a6b1cfba6dbddd69da56765605199c4f6a441a3

This commit is contained in:
staheri14 2022-08-18 18:31:30 +00:00
parent 0cbd1267ce
commit 390360a9e4
6 changed files with 52 additions and 43 deletions

View File

@ -22,7 +22,7 @@ This transaction will also transfer `0.001` Ethers to the contract as membership
This amount plus the transaction fee will be deducted from the supplied Goerli account. This amount plus the transaction fee will be deducted from the supplied Goerli account.
Once the transaction is mined and the registration is successful, the registered credential will get displayed on the console of your chat2 client. Once the transaction is mined and the registration is successful, the registered credential will get displayed on the console of your chat2 client.
You may copy the displayed RLN credential and reuse them for the future execution of the chat2 application. You may copy the displayed RLN credential and reuse them for the future execution of the chat2 application.
Proper instructions in this regard is provided in the following [section](#how-to-reuse-rln-credential). Proper instructions in this regard is provided in the following [section](#how-to-persist-and-reuse-rln-credential).
If you choose not to reuse the same credential, then for each execution, a new registration will take place and more funds will get deducted from your Goerli account. If you choose not to reuse the same credential, then for each execution, a new registration will take place and more funds will get deducted from your Goerli account.
Under the hood, the chat2 client constantly listens to the membership contract and keeps itself updated with the latest state of the group. Under the hood, the chat2 client constantly listens to the membership contract and keeps itself updated with the latest state of the group.
@ -150,19 +150,15 @@ Once you are done with the test, make sure you close all the chat2 clients by ty
quitting... quitting...
``` ```
## How to reuse RLN credential ## How to persist and reuse RLN credential
You may reuse your old RLN credential using `rln-relay-membership-index`, `rln-relay-id` and `rln-relay-id-commitment` options. You may pass the `rln-relay-cred-path` config option to specify a path for 1) persisting RLN credential 2) retrieving persisted RLN credential.
For instance, if the previously generated credential are RLN credential is persisted in the `rlnCredentials.txt` file under the specified path.
``` If this file does not already exist under the supplied path, then a new credential is generated and persisted in the `rlnCredentials.txt` file.
your membership index is: xx Otherwise, the chat client does not generate new credential, instead uses the persisted RLN credential.
your rln identity key is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
your rln identity commitment key is: 6c6598126ba10d1b70100893b76d7f8d7343eeb8f5ecfd48371b421c5aa6f012
```
Then, the execution command will look like this (inspect the last three config options):
```
./build/chat2 --fleet:test --content-topic:/toy-chat/2/luzhou/proto --rln-relay:true --rln-relay-dynamic:true --eth-mem-contract-address:0x4252105670fe33d2947e8ead304969849e64f2a6 --eth-account-address:your_eth_account --eth-account-privatekey:your_eth_private_key --eth-client-address:your_goerli_node --ports-shift=1 --rln-relay-membership-index:63 --rln-relay-id:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --rln-relay-id-commitment:6c6598126ba10d1b70100893b76d7f8d7343eeb8f5ecfd48371b421c5aa6f012
```
./build/chat2 --fleet:test --content-topic:/toy-chat/2/luzhou/proto --rln-relay:true --rln-relay-dynamic:true --eth-mem-contract-address:0x4252105670fe33d2947e8ead304969849e64f2a6 --eth-account-address:your_eth_account --eth-account-privatekey:your_eth_private_key --eth-client-address:your_goerli_node --ports-shift=1 --rln-relay-cred-path:./
``` ```
# Sample test output # Sample test output

View File

@ -233,7 +233,12 @@ type
desc: "Enable spam protection through rln-relay: true|false", desc: "Enable spam protection through rln-relay: true|false",
defaultValue: false defaultValue: false
name: "rln-relay" }: bool name: "rln-relay" }: bool
rlnRelayCredPath* {.
desc: "The path for peristing rln-relay credential",
defaultValue: ""
name: "rln-relay-cred-path" }: string
rlnRelayMemIndex* {. rlnRelayMemIndex* {.
desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive", desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
defaultValue: MembershipIndex(0) defaultValue: MembershipIndex(0)

View File

@ -2,7 +2,7 @@
# libtool - Provide generalized library-building support services. # libtool - Provide generalized library-building support services.
# Generated automatically by config.status (libbacktrace) version-unused # Generated automatically by config.status (libbacktrace) version-unused
# Libtool was configured on host fv-az39-181: # Libtool was configured on host fv-az447-233:
# NOTE: Changes made to this file will be lost: look at ltmain.sh. # NOTE: Changes made to this file will be lost: look at ltmain.sh.
# #
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,

View File

@ -114,6 +114,11 @@ type
defaultValue: false defaultValue: false
name: "rln-relay" }: bool name: "rln-relay" }: bool
rlnRelayCredPath* {.
desc: "The path for peristing rln-relay credential",
defaultValue: ""
name: "rln-relay-cred-path" }: string
rlnRelayMemIndex* {. rlnRelayMemIndex* {.
desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive", desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
defaultValue: MembershipIndex(0) defaultValue: MembershipIndex(0)

View File

@ -148,7 +148,7 @@ type MessageValidationResult* {.pure.} = enum
# RLN membership key and index files path # RLN membership key and index files path
const const
RLN_CREDENTIALS_FILEPATH* = "rlnCredentials.txt" RLN_CREDENTIALS_FILENAME* = "rlnCredentials.txt"
# inputs of the membership contract constructor # inputs of the membership contract constructor
# TODO may be able to make these constants private and put them inside the waku_rln_relay_utils # TODO may be able to make these constants private and put them inside the waku_rln_relay_utils

View File

@ -998,15 +998,6 @@ proc mountRlnRelayDynamic*(node: WakuNode,
keyPair = memKeyPair.get() keyPair = memKeyPair.get()
rlnIndex = memIndex.get() rlnIndex = memIndex.get()
var
rlnMembershipCredentials = RlnMembershipCredentials(membershipKeyPair: keyPair, rlnIndex: rlnIndex)
# Since the files are stored as a raw text file, it is highly susceptible to theft.
# The files needs some encryption to resolve this.
# Write RLN credentials
writeFile(RLN_CREDENTIALS_FILEPATH, pretty(%rlnMembershipCredentials))
# create the WakuRLNRelay # create the WakuRLNRelay
var rlnPeer = WakuRLNRelay(membershipKeyPair: keyPair, var rlnPeer = WakuRLNRelay(membershipKeyPair: keyPair,
membershipIndex: rlnIndex, membershipIndex: rlnIndex,
@ -1075,7 +1066,7 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf|Chat2Conf, spamHandler: O
error "root mismatch: something went wrong not in Merkle tree construction" error "root mismatch: something went wrong not in Merkle tree construction"
debug "the calculated root", root debug "the calculated root", root
info "WakuRLNRelay is mounted successfully", pubsubtopic=conf.rlnRelayPubsubTopic, contentTopic=conf.rlnRelayContentTopic info "WakuRLNRelay is mounted successfully", pubsubtopic=conf.rlnRelayPubsubTopic, contentTopic=conf.rlnRelayContentTopic
else: else: # mount the rln relay protocol in the on-chain/dynamic mode
info " setting up waku-rln-relay in on-chain mode... " info " setting up waku-rln-relay in on-chain mode... "
# read related inputs to run rln-relay in on-chain mode and do type conversion when needed # read related inputs to run rln-relay in on-chain mode and do type conversion when needed
@ -1083,30 +1074,42 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf|Chat2Conf, spamHandler: O
ethAccountAddr = web3.fromHex(web3.Address, conf.rlnRelayEthAccount) ethAccountAddr = web3.fromHex(web3.Address, conf.rlnRelayEthAccount)
ethClientAddr = conf.rlnRelayEthClientAddress ethClientAddr = conf.rlnRelayEthClientAddress
ethMemContractAddress = web3.fromHex(web3.Address, conf.rlnRelayEthMemContractAddress) ethMemContractAddress = web3.fromHex(web3.Address, conf.rlnRelayEthMemContractAddress)
rlnRelayId = conf.rlnRelayIdKey
rlnRelayIdCommitmentKey = conf.rlnRelayIdCommitmentKey
rlnRelayIndex = conf.rlnRelayMemIndex
var ethAccountPrivKeyOpt = none(keys.PrivateKey) var ethAccountPrivKeyOpt = none(keys.PrivateKey)
if conf.rlnRelayEthAccountPrivKey != "": if conf.rlnRelayEthAccountPrivKey != "":
ethAccountPrivKeyOpt = some(keys.PrivateKey(SkSecretKey.fromHex(conf.rlnRelayEthAccountPrivKey).value)) ethAccountPrivKeyOpt = some(keys.PrivateKey(SkSecretKey.fromHex(conf.rlnRelayEthAccountPrivKey).value))
# check if the peer has provided its rln credentials
if rlnRelayIdCommitmentKey != "" and rlnRelayId != "": # if the rlnRelayCredPath config option is non-empty, then rln-relay credentials should be persisted
# type conversation from hex strings to MembershipKeyPair # if the path does not contain any credential file, then a new set is generated and pesisted in the same path
let keyPair = @[(rlnRelayId, rlnRelayIdCommitmentKey)] # if there is a credential file, then no new credentials are generated, instead the content of the file is read and used to mount rln-relay
let memKeyPair = keyPair.toMembershipKeyPairs()[0] if conf.rlnRelayCredPath != "":
# mount the rln relay protocol in the on-chain/dynamic mode let rlnRelayCredPath = joinPath(conf.rlnRelayCredPath, RLN_CREDENTIALS_FILENAME)
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, debug "rln-relay credential path", rlnRelayCredPath=rlnRelayCredPath
memKeyPair = some(memKeyPair), memIndex = some(rlnRelayIndex), ethAccAddr = ethAccountAddr, # check if there is an rln-relay credential file in the supplied path
ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler) if fileExists(rlnRelayCredPath):
elif fileExists(RLN_CREDENTIALS_FILEPATH): # retrieve rln-relay credential
var credentials = readPersistentRlnCredentials(RLN_CREDENTIALS_FILEPATH) var credentials = readPersistentRlnCredentials(rlnRelayCredPath)
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, # mount rln-relay with the provided rln-relay credential
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr,
memKeyPair = some(credentials.membershipKeyPair), memIndex = some(credentials.rlnIndex), ethAccAddr = ethAccountAddr, memKeyPair = some(credentials.membershipKeyPair), memIndex = some(credentials.rlnIndex), ethAccAddr = ethAccountAddr,
ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler) ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
else: # there is no credential file available in the supplied path
# mount the rln-relay protocol leaving rln-relay credentials arguments unassigned
# this infroms mountRlnRelayDynamic proc that new credentials should be generated and registered to the membership contract
info "no rln credential is provided"
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr,
ethAccAddr = ethAccountAddr, ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic,
contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
# Persist generated credentials
var rlnMembershipCredentials =
RlnMembershipCredentials(membershipKeyPair: node.wakuRlnRelay.membershipKeyPair, rlnIndex: node.wakuRlnRelay.membershipIndex)
# TODO should be replaced with key-store with proper encryption
# persist rln credential
writeFile(rlnRelayCredPath, pretty(%rlnMembershipCredentials))
else: else:
# no rln credential is provided # do not persist or use a persisted rln-relay credential
# mount the rln relay protocol in the on-chain/dynamic mode # a new credential will be generated during the mount process but will not be persisted
info "no rln credential is provided" info "no need to persist or use a persisted rln-relay credential"
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr,
ethAccAddr = ethAccountAddr, ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic, ethAccAddr = ethAccountAddr, ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic,
contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler) contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)