chore(rln-relay): confirm that the provided credential is correct using onchain query (#1980)

This commit is contained in:
Aaryamann Challani 2023-09-04 11:22:31 +05:30 committed by GitHub
parent 05c988645d
commit be48891f77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 14 deletions

View File

@ -244,7 +244,7 @@ suite "Onchain group manager":
require: require:
registrations.len == 1 registrations.len == 1
registrations[0].idCommitment == credentials.idCommitment registrations[0].idCommitment == credentials.idCommitment
registrations[0].index == 1 registrations[0].index == 0
fut.complete() fut.complete()
return callback return callback
@ -283,7 +283,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} = proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and if registrations.len == 1 and
registrations[0].idCommitment == credentials[futureIndex].idCommitment and registrations[0].idCommitment == credentials[futureIndex].idCommitment and
registrations[0].index == MembershipIndex(futureIndex + 1): registrations[0].index == MembershipIndex(futureIndex):
futs[futureIndex].complete() futs[futureIndex].complete()
futureIndex += 1 futureIndex += 1
return callback return callback
@ -373,7 +373,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} = proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and if registrations.len == 1 and
registrations[0].idCommitment == credentials.idCommitment and registrations[0].idCommitment == credentials.idCommitment and
registrations[0].index == 1: registrations[0].index == 0:
manager.idCredentials = some(credentials) manager.idCredentials = some(credentials)
manager.membershipIndex = some(registrations[0].index) manager.membershipIndex = some(registrations[0].index)
fut.complete() fut.complete()
@ -443,7 +443,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} = proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and if registrations.len == 1 and
registrations[0].idCommitment == credentials.idCommitment and registrations[0].idCommitment == credentials.idCommitment and
registrations[0].index == 1: registrations[0].index == 0:
manager.idCredentials = some(credentials) manager.idCredentials = some(credentials)
manager.membershipIndex = some(registrations[0].index) manager.membershipIndex = some(registrations[0].index)
fut.complete() fut.complete()
@ -527,7 +527,7 @@ suite "Onchain group manager":
proc callback(registrations: seq[Membership]): Future[void] {.async.} = proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and if registrations.len == 1 and
registrations[0].idCommitment == credentials[futureIndex].idCommitment and registrations[0].idCommitment == credentials[futureIndex].idCommitment and
registrations[0].index == MembershipIndex(futureIndex + 1): registrations[0].index == MembershipIndex(futureIndex):
futs[futureIndex].complete() futs[futureIndex].complete()
futureIndex += 1 futureIndex += 1
return callback return callback

File diff suppressed because one or more lines are too long

View File

@ -28,17 +28,26 @@ logScope:
topics = "waku rln_relay onchain_group_manager" topics = "waku rln_relay onchain_group_manager"
contract(WakuRlnRegistry): contract(WakuRlnRegistry):
# this describes the storage slot to use
proc usingStorageIndex(): Uint16 {.pure.} proc usingStorageIndex(): Uint16 {.pure.}
# this map contains the address of a given storage slot
proc storages(index: Uint16): Address {.pure.} proc storages(index: Uint16): Address {.pure.}
# this serves as an entrypoint into the rln storage contract
proc register(storageIndex: Uint16, idCommitment: Uint256) proc register(storageIndex: Uint16, idCommitment: Uint256)
# this creates a new storage on the rln registry
proc newStorage() proc newStorage()
# membership contract interface # membership contract interface
contract(RlnStorage): contract(RlnStorage):
# this event is raised when a new member is registered
proc MemberRegistered(idCommitment: Uint256, index: Uint256) {.event.} proc MemberRegistered(idCommitment: Uint256, index: Uint256) {.event.}
# this constant contains the membership deposit of the contract
proc MEMBERSHIP_DEPOSIT(): Uint256 {.pure.} 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.} proc idCommitmentIndex(): Uint256 {.view.}
# this constant describes the block number this contract was deployed on
proc deployedBlockNumber(): Uint256 {.view.} proc deployedBlockNumber(): Uint256 {.view.}
type type
@ -448,6 +457,17 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
if keystoreCredRes.isErr(): if keystoreCredRes.isErr():
raise newException(ValueError, "could not parse the keystore: " & $keystoreCredRes.error) raise newException(ValueError, "could not parse the keystore: " & $keystoreCredRes.error)
let keystoreCred = keystoreCredRes.get() 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) g.idCredentials = some(keystoreCred.identityCredential)
let metadataGetRes = g.rlnInstance.getMetadata() let metadataGetRes = g.rlnInstance.getMetadata()