Skip to content

Commit

Permalink
chore(rln-relay): confirm that the provided credential is correct usi…
Browse files Browse the repository at this point in the history
…ng onchain query
  • Loading branch information
rymnc committed Sep 1, 2023
1 parent 0c40588 commit 131934c
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 103 deletions.
178 changes: 89 additions & 89 deletions tests/all_tests_waku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,98 @@ import
./waku_core/test_peers


# Waku archive test suite
import
./waku_archive/test_driver_queue_index,
./waku_archive/test_driver_queue_pagination,
./waku_archive/test_driver_queue_query,
./waku_archive/test_driver_queue,
./waku_archive/test_driver_sqlite_query,
./waku_archive/test_driver_sqlite,
./waku_archive/test_retention_policy,
./waku_archive/test_waku_archive

const os* {.strdefine.} = ""
when os == "Linux":
# GitHub only supports container actions on Linux
# and we need to start a postgress database in a docker container
import
./waku_archive/test_driver_postgres_query,
./waku_archive/test_driver_postgres

# Waku store test suite
import
./waku_store/test_rpc_codec,
./waku_store/test_waku_store,
./waku_store/test_wakunode_store

when defined(waku_exp_store_resume):
# TODO: Review store resume test cases (#1282)
import ./waku_store/test_resume


# Waku relay test suite
import
./waku_relay/test_waku_relay,
./waku_relay/test_wakunode_relay

# Waku filter test suite
import
./waku_filter_v2/test_waku_filter,
./waku_filter_v2/test_waku_filter_protocol

import
# Waku v2 tests
./test_wakunode,
# Waku LightPush
./test_waku_lightpush,
./test_wakunode_lightpush,
# Waku Filter
./test_waku_filter,
./test_wakunode_filter,
./test_waku_peer_exchange,
./test_peer_store_extended,
./test_message_cache,
./test_peer_manager,
./test_peer_storage,
./test_waku_keepalive,
./test_waku_enr,
./test_waku_dnsdisc,
./test_waku_discv5,
./test_peer_exchange,
./test_waku_noise,
./test_waku_noise_sessions,
./test_waku_switch,
./test_waku_rendezvous

# Waku Keystore test suite
import
./test_waku_keystore_keyfile,
./test_waku_keystore

## Wakunode JSON-RPC API test suite
import
./wakunode_jsonrpc/test_jsonrpc_admin,
./wakunode_jsonrpc/test_jsonrpc_debug,
./wakunode_jsonrpc/test_jsonrpc_filter,
./wakunode_jsonrpc/test_jsonrpc_relay,
./wakunode_jsonrpc/test_jsonrpc_store

## Wakunode Rest API test suite
import
./wakunode_rest/test_rest_debug,
./wakunode_rest/test_rest_debug_serdes,
./wakunode_rest/test_rest_relay,
./wakunode_rest/test_rest_relay_serdes,
./wakunode_rest/test_rest_serdes,
./wakunode_rest/test_rest_store
# # Waku archive test suite
# import
# ./waku_archive/test_driver_queue_index,
# ./waku_archive/test_driver_queue_pagination,
# ./waku_archive/test_driver_queue_query,
# ./waku_archive/test_driver_queue,
# ./waku_archive/test_driver_sqlite_query,
# ./waku_archive/test_driver_sqlite,
# ./waku_archive/test_retention_policy,
# ./waku_archive/test_waku_archive

# const os* {.strdefine.} = ""
# when os == "Linux":
# # GitHub only supports container actions on Linux
# # and we need to start a postgress database in a docker container
# import
# ./waku_archive/test_driver_postgres_query,
# ./waku_archive/test_driver_postgres

# # Waku store test suite
# import
# ./waku_store/test_rpc_codec,
# ./waku_store/test_waku_store,
# ./waku_store/test_wakunode_store

# when defined(waku_exp_store_resume):
# # TODO: Review store resume test cases (#1282)
# import ./waku_store/test_resume


# # Waku relay test suite
# import
# ./waku_relay/test_waku_relay,
# ./waku_relay/test_wakunode_relay

# # Waku filter test suite
# import
# ./waku_filter_v2/test_waku_filter,
# ./waku_filter_v2/test_waku_filter_protocol

# import
# # Waku v2 tests
# ./test_wakunode,
# # Waku LightPush
# ./test_waku_lightpush,
# ./test_wakunode_lightpush,
# # Waku Filter
# ./test_waku_filter,
# ./test_wakunode_filter,
# ./test_waku_peer_exchange,
# ./test_peer_store_extended,
# ./test_message_cache,
# ./test_peer_manager,
# ./test_peer_storage,
# ./test_waku_keepalive,
# ./test_waku_enr,
# ./test_waku_dnsdisc,
# ./test_waku_discv5,
# ./test_peer_exchange,
# ./test_waku_noise,
# ./test_waku_noise_sessions,
# ./test_waku_switch,
# ./test_waku_rendezvous

# # Waku Keystore test suite
# import
# ./test_waku_keystore_keyfile,
# ./test_waku_keystore

# ## Wakunode JSON-RPC API test suite
# import
# ./wakunode_jsonrpc/test_jsonrpc_admin,
# ./wakunode_jsonrpc/test_jsonrpc_debug,
# ./wakunode_jsonrpc/test_jsonrpc_filter,
# ./wakunode_jsonrpc/test_jsonrpc_relay,
# ./wakunode_jsonrpc/test_jsonrpc_store

# ## Wakunode Rest API test suite
# import
# ./wakunode_rest/test_rest_debug,
# ./wakunode_rest/test_rest_debug_serdes,
# ./wakunode_rest/test_rest_relay,
# ./wakunode_rest/test_rest_relay_serdes,
# ./wakunode_rest/test_rest_serdes,
# ./wakunode_rest/test_rest_store


## Experimental

when defined(rln):
import
./waku_rln_relay/test_waku_rln_relay,
./waku_rln_relay/test_wakunode_rln_relay,
./waku_rln_relay/test_rln_group_manager_onchain,
./waku_rln_relay/test_rln_group_manager_static
# ./waku_rln_relay/test_waku_rln_relay,
# ./waku_rln_relay/test_wakunode_rln_relay,
./waku_rln_relay/test_rln_group_manager_onchain
# ./waku_rln_relay/test_rln_group_manager_static
10 changes: 5 additions & 5 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ suite "Onchain group manager":
require:
registrations.len == 1
registrations[0].idCommitment == credentials.idCommitment
registrations[0].index == 1
registrations[0].index == 0
fut.complete()
return callback

Expand Down Expand Up @@ -283,7 +283,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and
registrations[0].idCommitment == credentials[futureIndex].idCommitment and
registrations[0].index == MembershipIndex(futureIndex + 1):
registrations[0].index == MembershipIndex(futureIndex):
futs[futureIndex].complete()
futureIndex += 1
return callback
Expand Down Expand Up @@ -373,7 +373,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and
registrations[0].idCommitment == credentials.idCommitment and
registrations[0].index == 1:
registrations[0].index == 0:
manager.idCredentials = some(credentials)
manager.membershipIndex = some(registrations[0].index)
fut.complete()
Expand Down Expand Up @@ -443,7 +443,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and
registrations[0].idCommitment == credentials.idCommitment and
registrations[0].index == 1:
registrations[0].index == 0:
manager.idCredentials = some(credentials)
manager.membershipIndex = some(registrations[0].index)
fut.complete()
Expand Down Expand Up @@ -527,7 +527,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and
registrations[0].idCommitment == credentials[futureIndex].idCommitment and
registrations[0].index == MembershipIndex(futureIndex + 1):
registrations[0].index == MembershipIndex(futureIndex):
futs[futureIndex].complete()
futureIndex += 1
return callback
Expand Down
8 changes: 4 additions & 4 deletions waku/waku_rln_relay/contract.nim

Large diffs are not rendered by default.

30 changes: 25 additions & 5 deletions waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@ logScope:
topics = "waku rln_relay onchain_group_manager"

contract(WakuRlnRegistry):
# this describes the storage slot to use
proc usingStorageIndex(): Uint16 {.pure.}
# this map contains the address of a given storage slot
proc storages(index: Uint16): Address {.pure.}
proc register(storageIndex: Uint16, idCommitment: Uint256)
# this serves as an entrypoint into the rln storage contract
proc register(storageIndex: Uint16, idCommitment: Uint256)
# this creates a new storage on the rln registry
proc newStorage()

# membership contract interface
contract(RlnStorage):
# this event is raised when a new member is registered
proc MemberRegistered(idCommitment: Uint256, index: Uint256) {.event.}
# this constant contains the membership deposit of the contract
proc MEMBERSHIP_DEPOSIT(): Uint256 {.pure.}
proc members(idCommitment: Uint256): Uint256 {.view.}
# this map denotes existence of a given user
proc memberExists(idCommitment: Uint256): Uint256 {.view.}
# this constant describes the next index of a new member
proc idCommitmentIndex(): Uint256 {.view.}
# this constant describes the block number this contract was deployed on
proc deployedBlockNumber(): Uint256 {.view.}

type
Expand Down Expand Up @@ -448,6 +457,17 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
if keystoreCredRes.isErr():
raise newException(ValueError, "could not parse the keystore: " & $keystoreCredRes.error)
let keystoreCred = keystoreCredRes.get()
# now we check on the contract if the commitment actually has a membership
try:
let membershipExists = await rlnContract.memberExists(keystoreCred
.identityCredential
.idCommitment.toUInt256()).call()
if membershipExists == 0:
raise newException(CatchableError, "the provided commitment does not have a membership")
except CatchableError:
raise newException(CatchableError, "could not check if the commitment exists on the contract: " &
getCurrentExceptionMsg())

g.idCredentials = some(keystoreCred.identityCredential)

let metadataGetRes = g.rlnInstance.getMetadata()
Expand All @@ -458,7 +478,7 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
let metadata = metadataGetRes.get()
if metadata.chainId != uint64(g.chainId.get()):
raise newException(ValueError, "persisted data: chain id mismatch")

if metadata.contractAddress != g.ethContractAddress.toLower():
raise newException(ValueError, "persisted data: contract address mismatch")
g.latestProcessedBlock = metadata.lastProcessedBlock
Expand All @@ -469,15 +489,15 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
try:
membershipFee = await rlnContract.MEMBERSHIP_DEPOSIT().call()
except CatchableError:
raise newException(ValueError,
raise newException(ValueError,
"could not get the membership deposit: " & getCurrentExceptionMsg())
g.membershipFee = some(membershipFee)

var deployedBlockNumber: Uint256
try:
deployedBlockNumber = await rlnContract.deployedBlockNumber().call()
except CatchableError:
raise newException(ValueError,
raise newException(ValueError,
"could not get the deployed block number: " & getCurrentExceptionMsg())
g.rlnContractDeployedBlockNumber = cast[BlockNumber](deployedBlockNumber)

Expand Down

0 comments on commit 131934c

Please sign in to comment.