feat(rln-relay): adds rln identifier to the RateLimitProof (#1219)

* adds rln identifier to the RateLimitProof

* enables rln-relay compilation for wakunode2

* unifies the two RateLimitProof types

* a minor update

Co-authored-by: G <28568419+s1fr0@users.noreply.github.com>
This commit is contained in:
Sanaz Taheri Boshrooyeh 2022-10-04 13:20:44 -07:00 committed by GitHub
parent dd1fe16568
commit fe3a3136a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 51 deletions

View File

@ -36,7 +36,7 @@ import
export export
wakunode2_types wakunode2_types
when defined(rln): when defined(rln) or defined(rlnzerokit):
import ../protocol/waku_rln_relay/waku_rln_relay_utils import ../protocol/waku_rln_relay/waku_rln_relay_utils
declarePublicCounter waku_node_messages, "number of messages received", ["type"] declarePublicCounter waku_node_messages, "number of messages received", ["type"]
@ -1066,7 +1066,7 @@ when isMainModule:
# Keepalive mounted on all nodes # Keepalive mounted on all nodes
waitFor mountLibp2pPing(node) waitFor mountLibp2pPing(node)
when defined(rln): when defined(rln) or defined(rlnzerokit):
if conf.rlnRelay: if conf.rlnRelay:
let res = node.mountRlnRelay(conf) let res = node.mountRlnRelay(conf)
if res.isErr(): if res.isErr():

View File

@ -32,6 +32,7 @@ type
MerkleNode* = array[32, byte] # Each node of the Merkle tee is a Poseidon hash which is a 32 byte value MerkleNode* = array[32, byte] # Each node of the Merkle tee is a Poseidon hash which is a 32 byte value
Nullifier* = array[32, byte] Nullifier* = array[32, byte]
Epoch* = array[32, byte] Epoch* = array[32, byte]
RlnIdentifier* = array[32, byte]
when defined(rln) or (not defined(rln) and not defined(rlnzerokit)): when defined(rln) or (not defined(rln) and not defined(rlnzerokit)):
type type
@ -39,7 +40,7 @@ when defined(rln) or (not defined(rln) and not defined(rlnzerokit)):
when defined(rlnzerokit): when defined(rlnzerokit):
type type
ZKSNARK* = array[128, byte] ZKSNARK* = array[128, byte]
RlnIdentifier* = array[32, byte]
# Custom data types defined for waku rln relay ------------------------- # Custom data types defined for waku rln relay -------------------------
type MembershipKeyPair* = object type MembershipKeyPair* = object
@ -51,27 +52,7 @@ type MembershipKeyPair* = object
# more details in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Membership # more details in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Membership
idCommitment*: IDCommitment idCommitment*: IDCommitment
when defined(rln) or (not defined(rln) and not defined(rlnzerokit)): type RateLimitProof* = object
type RateLimitProof* = object
## RateLimitProof holds the public inputs to rln circuit as
## defined in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Public-Inputs
## the `proof` field carries the actual zkSNARK proof
proof*: ZKSNARK
## the root of Merkle tree used for the generation of the `proof`
merkleRoot*: MerkleNode
## the epoch used for the generation of the `proof`
epoch*: Epoch
## shareX and shareY are shares of user's identity key
## these shares are created using Shamir secret sharing scheme
## see details in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Linear-Equation-amp-SSS
shareX*: MerkleNode
shareY*: MerkleNode
## nullifier enables linking two messages published during the same epoch
## see details in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Nullifiers
nullifier*: Nullifier
when defined(rlnzerokit):
type RateLimitProof* = object
## RateLimitProof holds the public inputs to rln circuit as ## RateLimitProof holds the public inputs to rln circuit as
## defined in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Public-Inputs ## defined in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Public-Inputs
## the `proof` field carries the actual zkSNARK proof ## the `proof` field carries the actual zkSNARK proof
@ -183,7 +164,6 @@ proc init*(T: type RateLimitProof, buffer: seq[byte]): ProtoResult[T] =
discard ? pb.getField(6, nullifier) discard ? pb.getField(6, nullifier)
discard nsp.nullifier.copyFrom(nullifier) discard nsp.nullifier.copyFrom(nullifier)
when defined(rlnzerokit):
var rlnIdentifier: seq[byte] var rlnIdentifier: seq[byte]
discard ? pb.getField(7, rlnIdentifier) discard ? pb.getField(7, rlnIdentifier)
discard nsp.rlnIdentifier.copyFrom(rlnIdentifier) discard nsp.rlnIdentifier.copyFrom(rlnIdentifier)
@ -199,8 +179,6 @@ proc encode*(nsp: RateLimitProof): ProtoBuffer =
output.write3(4, nsp.shareX) output.write3(4, nsp.shareX)
output.write3(5, nsp.shareY) output.write3(5, nsp.shareY)
output.write3(6, nsp.nullifier) output.write3(6, nsp.nullifier)
when defined(rlnzerokit):
output.write3(7, nsp.rlnIdentifier) output.write3(7, nsp.rlnIdentifier)
output.finish3() output.finish3()