-
Notifications
You must be signed in to change notification settings - Fork 54
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
feat(rln-relay-v2): rln-keystore-generator updates #2392
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b890551
chore: init rln-v2 in OnchainGroupManager
rymnc 0fd3ac2
chore: update wrappers
rymnc b4c0b0a
Merge branch 'master' into update-rln-keystore-generator-v2
rymnc 3be31f0
fix: units for userMessageLimit
rymnc ea8dd11
valueOr for error handling
rymnc 69bd411
fix: len usage
rymnc 1e3a3de
Merge branch 'master' into update-rln-keystore-generator-v2
rymnc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,8 +23,11 @@ export | |||||||||||||||||||||||||||
# It should also be used to sync the group state with the rest of the group members | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
type Membership* = object | ||||||||||||||||||||||||||||
idCommitment*: IDCommitment | ||||||||||||||||||||||||||||
index*: MembershipIndex | ||||||||||||||||||||||||||||
when defined(rln_v2): | ||||||||||||||||||||||||||||
rateCommitment*: RateCommitment | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
idCommitment*: IDCommitment | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
type OnRegisterCallback* = proc (registrations: seq[Membership]): Future[void] {.gcsafe.} | ||||||||||||||||||||||||||||
type OnWithdrawCallback* = proc (withdrawals: seq[Membership]): Future[void] {.gcsafe.} | ||||||||||||||||||||||||||||
|
@@ -41,6 +44,8 @@ type | |||||||||||||||||||||||||||
initialized*: bool | ||||||||||||||||||||||||||||
latestIndex*: MembershipIndex | ||||||||||||||||||||||||||||
validRoots*: Deque[MerkleNode] | ||||||||||||||||||||||||||||
when defined(rln_v2): | ||||||||||||||||||||||||||||
userMessageLimit*: Option[UserMessageLimit] | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# This proc is used to initialize the group manager | ||||||||||||||||||||||||||||
# Any initialization logic should be implemented here | ||||||||||||||||||||||||||||
|
@@ -55,20 +60,35 @@ method startGroupSync*(g: GroupManager): Future[void] {.base, async: (raises: [E | |||||||||||||||||||||||||||
# This proc is used to register a new identity commitment into the merkle tree | ||||||||||||||||||||||||||||
# The user may or may not have the identity secret to this commitment | ||||||||||||||||||||||||||||
# It should be used when detecting new members in the group, and syncing the group state | ||||||||||||||||||||||||||||
method register*(g: GroupManager, idCommitment: IDCommitment): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "register proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
when defined(rln_v2): | ||||||||||||||||||||||||||||
method register*(g: GroupManager, | ||||||||||||||||||||||||||||
rateCommitment: RateCommitment): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "register proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
method register*(g: GroupManager, idCommitment: IDCommitment): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "register proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# This proc is used to register a new identity commitment into the merkle tree | ||||||||||||||||||||||||||||
# The user should have the identity secret to this commitment | ||||||||||||||||||||||||||||
# It should be used when the user wants to join the group | ||||||||||||||||||||||||||||
method register*(g: GroupManager, credentials: IdentityCredential): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "register proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
when defined(rln_v2): | ||||||||||||||||||||||||||||
method register*(g: GroupManager, | ||||||||||||||||||||||||||||
credentials: IdentityCredential, | ||||||||||||||||||||||||||||
userMessageLimit: UserMessageLimit): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "register proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
method register*(g: GroupManager, credentials: IdentityCredential): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "register proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# This proc is used to register a batch of new identity commitments into the merkle tree | ||||||||||||||||||||||||||||
# The user may or may not have the identity secret to these commitments | ||||||||||||||||||||||||||||
# It should be used when detecting a batch of new members in the group, and syncing the group state | ||||||||||||||||||||||||||||
method registerBatch*(g: GroupManager, idCommitments: seq[IDCommitment]): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "registerBatch proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
when defined(rln_v2): | ||||||||||||||||||||||||||||
method registerBatch*(g: GroupManager, rateCommitments: seq[RateCommitment]): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "registerBatch proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
method registerBatch*(g: GroupManager, idCommitments: seq[IDCommitment]): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "registerBatch proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# This proc is used to set a callback that will be called when a new identity commitment is registered | ||||||||||||||||||||||||||||
# The callback may be called multiple times, and should be used to for any post processing | ||||||||||||||||||||||||||||
|
@@ -86,8 +106,16 @@ method withdrawBatch*(g: GroupManager, identitySecretHashes: seq[IdentitySecretH | |||||||||||||||||||||||||||
raise newException(CatchableError, "withdrawBatch proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# This proc is used to insert and remove a set of commitments from the merkle tree | ||||||||||||||||||||||||||||
method atomicBatch*(g: GroupManager, idCommitments: seq[IDCommitment], toRemoveIndices: seq[MembershipIndex]): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "atomicBatch proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
when defined(rln_v2): | ||||||||||||||||||||||||||||
method atomicBatch*(g: GroupManager, | ||||||||||||||||||||||||||||
rateCommitments: seq[RateCommitment], | ||||||||||||||||||||||||||||
toRemoveIndices: seq[MembershipIndex]): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "atomicBatch proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
method atomicBatch*(g: GroupManager, | ||||||||||||||||||||||||||||
idCommitments: seq[IDCommitment], | ||||||||||||||||||||||||||||
toRemoveIndices: seq[MembershipIndex]): Future[void] {.base,async: (raises: [Exception]).} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "atomicBatch proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
method stop*(g: GroupManager): Future[void] {.base,async.} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "stop proc for " & $g.type & " is not implemented yet") | ||||||||||||||||||||||||||||
|
@@ -135,45 +163,59 @@ template slideRootQueue*(g: GroupManager): untyped = | |||||||||||||||||||||||||||
discard rootBuffer.slideRootQueue(root) | ||||||||||||||||||||||||||||
rootBuffer | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
method verifyProof*(g: GroupManager, | ||||||||||||||||||||||||||||
input: openArray[byte], | ||||||||||||||||||||||||||||
proof: RateLimitProof): GroupManagerResult[bool] {.base,gcsafe,raises:[].} = | ||||||||||||||||||||||||||||
## verifies the proof against the input and the current merkle root | ||||||||||||||||||||||||||||
let proofVerifyRes = g.rlnInstance.proofVerify(input, proof, g.validRoots.items().toSeq()) | ||||||||||||||||||||||||||||
if proofVerifyRes.isErr(): | ||||||||||||||||||||||||||||
return err("proof verification failed: " & $proofVerifyRes.error()) | ||||||||||||||||||||||||||||
return ok(proofVerifyRes.value()) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
when defined(rln_v2): | ||||||||||||||||||||||||||||
method verifyProof*(g: GroupManager, | ||||||||||||||||||||||||||||
input: openArray[byte], | ||||||||||||||||||||||||||||
proof: RateLimitProof): GroupManagerResult[bool] {.base,gcsafe,raises:[].} = | ||||||||||||||||||||||||||||
## verifies the proof against the input and the current merkle root | ||||||||||||||||||||||||||||
## TODO: verify the external nullifier with provided RateLimitProof | ||||||||||||||||||||||||||||
let proofVerifyRes = g.rlnInstance.proofVerify(input, RateLimitProof(proof), g.validRoots.items().toSeq()) | ||||||||||||||||||||||||||||
if proofVerifyRes.isErr(): | ||||||||||||||||||||||||||||
return err("proof verification failed: " & $proofVerifyRes.error()) | ||||||||||||||||||||||||||||
return ok(proofVerifyRes.value()) | ||||||||||||||||||||||||||||
method generateProof*(g: GroupManager, | ||||||||||||||||||||||||||||
data: openArray[byte], | ||||||||||||||||||||||||||||
epoch: Epoch, | ||||||||||||||||||||||||||||
messageId: MessageId, | ||||||||||||||||||||||||||||
rlnIdentifier = DefaultRlnIdentifier): GroupManagerResult[RateLimitProof] {.base,gcsafe,raises:[].} = | ||||||||||||||||||||||||||||
## generates a proof for the given data and epoch | ||||||||||||||||||||||||||||
## the proof is generated using the current merkle root | ||||||||||||||||||||||||||||
if g.idCredentials.isNone(): | ||||||||||||||||||||||||||||
return err("identity credentials are not set") | ||||||||||||||||||||||||||||
if g.membershipIndex.isNone(): | ||||||||||||||||||||||||||||
return err("membership index is not set") | ||||||||||||||||||||||||||||
if g.userMessageLimit.isNone(): | ||||||||||||||||||||||||||||
return err("user message limit is not set") | ||||||||||||||||||||||||||||
waku_rln_proof_generation_duration_seconds.nanosecondTime: | ||||||||||||||||||||||||||||
let proofGenRes = proofGen(rlnInstance = g.rlnInstance, | ||||||||||||||||||||||||||||
data = data, | ||||||||||||||||||||||||||||
membership = g.idCredentials.get(), | ||||||||||||||||||||||||||||
userMessageLimit = g.userMessageLimit.get(), | ||||||||||||||||||||||||||||
messageId = messageId, | ||||||||||||||||||||||||||||
index = g.membershipIndex.get(), | ||||||||||||||||||||||||||||
epoch = epoch) | ||||||||||||||||||||||||||||
if proofGenRes.isErr(): | ||||||||||||||||||||||||||||
return err("proof generation failed: " & $proofGenRes.error()) | ||||||||||||||||||||||||||||
return ok(proofGenRes.value()) | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
method verifyProof*(g: GroupManager, | ||||||||||||||||||||||||||||
input: openArray[byte], | ||||||||||||||||||||||||||||
proof: RateLimitProof): GroupManagerResult[bool] {.base,gcsafe,raises:[].} = | ||||||||||||||||||||||||||||
## verifies the proof against the input and the current merkle root | ||||||||||||||||||||||||||||
let proofVerifyRes = g.rlnInstance.proofVerify(input, proof, g.validRoots.items().toSeq()) | ||||||||||||||||||||||||||||
if proofVerifyRes.isErr(): | ||||||||||||||||||||||||||||
return err("proof verification failed: " & $proofVerifyRes.error()) | ||||||||||||||||||||||||||||
return ok(proofVerifyRes.value()) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
method generateProof*(g: GroupManager, | ||||||||||||||||||||||||||||
data: openArray[byte], | ||||||||||||||||||||||||||||
epoch: Epoch): GroupManagerResult[RateLimitProof] {.base,gcsafe,raises:[].} = | ||||||||||||||||||||||||||||
## generates a proof for the given data and epoch | ||||||||||||||||||||||||||||
## the proof is generated using the current merkle root | ||||||||||||||||||||||||||||
if g.idCredentials.isNone(): | ||||||||||||||||||||||||||||
return err("identity credentials are not set") | ||||||||||||||||||||||||||||
if g.membershipIndex.isNone(): | ||||||||||||||||||||||||||||
return err("membership index is not set") | ||||||||||||||||||||||||||||
waku_rln_proof_generation_duration_seconds.nanosecondTime: | ||||||||||||||||||||||||||||
let proofGenRes = proofGen(rlnInstance = g.rlnInstance, | ||||||||||||||||||||||||||||
data = data, | ||||||||||||||||||||||||||||
memKeys = g.idCredentials.get(), | ||||||||||||||||||||||||||||
memIndex = g.membershipIndex.get(), | ||||||||||||||||||||||||||||
epoch = epoch) | ||||||||||||||||||||||||||||
if proofGenRes.isErr(): | ||||||||||||||||||||||||||||
return err("proof generation failed: " & $proofGenRes.error()) | ||||||||||||||||||||||||||||
return ok(proofGenRes.value()) | ||||||||||||||||||||||||||||
method generateProof*(g: GroupManager, | ||||||||||||||||||||||||||||
data: openArray[byte], | ||||||||||||||||||||||||||||
epoch: Epoch): GroupManagerResult[RateLimitProof] {.base,gcsafe,raises:[].} = | ||||||||||||||||||||||||||||
## generates a proof for the given data and epoch | ||||||||||||||||||||||||||||
## the proof is generated using the current merkle root | ||||||||||||||||||||||||||||
if g.idCredentials.isNone(): | ||||||||||||||||||||||||||||
return err("identity credentials are not set") | ||||||||||||||||||||||||||||
if g.membershipIndex.isNone(): | ||||||||||||||||||||||||||||
return err("membership index is not set") | ||||||||||||||||||||||||||||
waku_rln_proof_generation_duration_seconds.nanosecondTime: | ||||||||||||||||||||||||||||
let proofGenRes = proofGen(rlnInstance = g.rlnInstance, | ||||||||||||||||||||||||||||
data = data, | ||||||||||||||||||||||||||||
memKeys = g.idCredentials.get(), | ||||||||||||||||||||||||||||
memIndex = g.membershipIndex.get(), | ||||||||||||||||||||||||||||
epoch = epoch) | ||||||||||||||||||||||||||||
if proofGenRes.isErr(): | ||||||||||||||||||||||||||||
return err("proof generation failed: " & $proofGenRes.error()) | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR but the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed in ea8dd11 |
||||||||||||||||||||||||||||
return ok(proofGenRes.value()) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
method isReady*(g: GroupManager): Future[bool] {.base,async.} = | ||||||||||||||||||||||||||||
raise newException(CatchableError, "isReady proc for " & $g.type & " is not implemented yet") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick comment: shall we add the units to make it clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 3be31f0