Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rln-relay-v2): use rln-v2 contract code #2381

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ clean: | clean-libbacktrace
.PHONY: librln

LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
ifeq ($(RLN_V2),true)
LIBRLN_VERSION := v0.4.1
else
LIBRLN_VERSION := v0.3.4
endif

ifeq ($(OS),Windows_NT)
LIBRLN_FILE := rln.lib
Expand All @@ -134,6 +138,10 @@ $(LIBRLN_FILE):

librln: | $(LIBRLN_FILE)
$(eval NIM_PARAMS += --passL:$(LIBRLN_FILE) --passL:-lm)
ifeq ($(RLN_V2),true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the impression that we won't test this in our CI. Shall we switch it manually in the future? To elaborate a bit more, I think we'd need to adapt the following somehow in the future:

make V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 POSTGRES=1 test testwakunode2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, at the moment rln-v2 is unstable in nwaku. when it's at a better state I'll add the flag similar to how we had it for experimental builds

$(eval NIM_PARAMS += -d:rln_v2)
endif


clean-librln:
cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml
Expand Down
113 changes: 74 additions & 39 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,91 @@ proc generateCredentials(rlnInstance: ptr RLN, n: int): seq[IdentityCredential]
credentials.add(generateCredentials(rlnInstance))
return credentials

# a util function used for testing purposes
# it deploys membership contract on Ganache (or any Eth client available on EthClient address)
# must be edited if used for a different contract than membership contract
proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
let web3 = await newWeb3(ethClientAddress)
debug "web3 connected to", ethClientAddress

# fetch the list of registered accounts
let accounts = await web3.provider.eth_accounts()
web3.defaultAccount = accounts[1]
let add = web3.defaultAccount
debug "contract deployer account address ", add
when defined(rln_v2):
# a util function used for testing purposes
# it deploys membership contract on Ganache (or any Eth client available on EthClient address)
# must be edited if used for a different contract than membership contract
# <the difference between this and rln-v1 is that there is no need to deploy the poseidon hasher contract>
proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
let web3 = await newWeb3(ethClientAddress)
debug "web3 connected to", ethClientAddress

# fetch the list of registered accounts
let accounts = await web3.provider.eth_accounts()
web3.defaultAccount = accounts[1]
let add = web3.defaultAccount
debug "contract deployer account address ", add

let balance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
debug "Initial account balance: ", balance

# deploy registry contract with its constructor inputs
let receipt = await web3.deployContract(RegistryContractCode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only difference between the two branches of the when defined(rln_v2). Thereafter, I think is better to perform the when validation in a narrower scope instead of duplicating so much code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will make that change 👍
wanted to make it easier to transition from v1 to v2 by deleting whole functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in b05815e

let contractAddress = receipt.contractAddress.get()
debug "Address of the deployed registry contract: ", contractAddress

let registryContract = web3.contractSender(WakuRlnRegistry, contractAddress)
let newStorageReceipt = await registryContract.newStorage().send()

debug "Receipt of the newStorage transaction: ", newStorageReceipt
let newBalance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
debug "Account balance after the contract deployment: ", newBalance

await web3.close()
debug "disconnected from ", ethClientAddress

return contractAddress
else:
# a util function used for testing purposes
# it deploys membership contract on Ganache (or any Eth client available on EthClient address)
# must be edited if used for a different contract than membership contract
proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
let web3 = await newWeb3(ethClientAddress)
debug "web3 connected to", ethClientAddress

# fetch the list of registered accounts
let accounts = await web3.provider.eth_accounts()
web3.defaultAccount = accounts[1]
let add = web3.defaultAccount
debug "contract deployer account address ", add

let balance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
debug "Initial account balance: ", balance
let balance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
debug "Initial account balance: ", balance

# deploy the poseidon hash contract and gets its address
let
hasherReceipt = await web3.deployContract(PoseidonHasherCode)
hasherAddress = hasherReceipt.contractAddress.get
debug "hasher address: ", hasherAddress
# deploy the poseidon hash contract and gets its address
let
hasherReceipt = await web3.deployContract(PoseidonHasherCode)
hasherAddress = hasherReceipt.contractAddress.get
debug "hasher address: ", hasherAddress


# encode registry contract inputs to 32 bytes zero-padded
let
hasherAddressEncoded = encode(hasherAddress).data
# this is the contract constructor input
contractInput = hasherAddressEncoded
# encode registry contract inputs to 32 bytes zero-padded
let
hasherAddressEncoded = encode(hasherAddress).data
# this is the contract constructor input
contractInput = hasherAddressEncoded


debug "encoded hasher address: ", hasherAddressEncoded
debug "encoded contract input:", contractInput
debug "encoded hasher address: ", hasherAddressEncoded
debug "encoded contract input:", contractInput

# deploy registry contract with its constructor inputs
let receipt = await web3.deployContract(RegistryContractCode,
contractInput = contractInput)
let contractAddress = receipt.contractAddress.get()
debug "Address of the deployed registry contract: ", contractAddress
# deploy registry contract with its constructor inputs
let receipt = await web3.deployContract(RegistryContractCode,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following my previous comment, this is the only diff (and its parameters.) Let's reduce the when scope if possible :)

contractInput = contractInput)
let contractAddress = receipt.contractAddress.get()
debug "Address of the deployed registry contract: ", contractAddress

let registryContract = web3.contractSender(WakuRlnRegistry, contractAddress)
let newStorageReceipt = await registryContract.newStorage().send()
let registryContract = web3.contractSender(WakuRlnRegistry, contractAddress)
let newStorageReceipt = await registryContract.newStorage().send()

debug "Receipt of the newStorage transaction: ", newStorageReceipt
let newBalance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
debug "Account balance after the contract deployment: ", newBalance
debug "Receipt of the newStorage transaction: ", newStorageReceipt
let newBalance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
debug "Account balance after the contract deployment: ", newBalance

await web3.close()
debug "disconnected from ", ethClientAddress
await web3.close()
debug "disconnected from ", ethClientAddress

return contractAddress
return contractAddress


proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
Expand Down
Loading
Loading