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:
registrations.len == 1
registrations[0].idCommitment == credentials.idCommitment
registrations[0].index == 1
registrations[0].index == 0
fut.complete()
return callback
@ -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
@ -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()
@ -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()
@ -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

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"
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
@ -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()
@ -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
@ -469,7 +489,7 @@ 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)
@ -477,7 +497,7 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
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)