Skip to content

Commit

Permalink
chore(rln-relay-v2): use rln-v2 contract code (#2381)
Browse files Browse the repository at this point in the history
* chore(rln-relay-v2): use rln-v2 contract code

* fix: reduced duped code
  • Loading branch information
rymnc authored Jan 30, 2024
1 parent 761ce7b commit c55ca06
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 123 deletions.
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)
$(eval NIM_PARAMS += -d:rln_v2)
endif


clean-librln:
cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml
Expand Down
38 changes: 22 additions & 16 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ proc generateCredentials(rlnInstance: ptr RLN, n: int): seq[IdentityCredential]
# 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
Expand All @@ -53,27 +54,33 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
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
when defined(rln_v2):
# deploy registry contract with its constructor inputs
let receipt = await web3.deployContract(RegistryContractCode)
else:
# 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)
# 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

let registryContract = web3.contractSender(WakuRlnRegistry, contractAddress)
Expand All @@ -88,7 +95,6 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =

return contractAddress


proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
let web3 = await newWeb3(EthClient)
let accounts = await web3.provider.eth_accounts()
Expand Down
Loading

0 comments on commit c55ca06

Please sign in to comment.