From fe3a3136a3d236b835dc7826a865281214680760 Mon Sep 17 00:00:00 2001 From: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> Date: Tue, 4 Oct 2022 13:20:44 -0700 Subject: [PATCH] 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> --- waku/v2/node/wakunode2.nim | 4 +- .../waku_rln_relay/waku_rln_relay_types.nim | 76 +++++++------------ 2 files changed, 29 insertions(+), 51 deletions(-) diff --git a/waku/v2/node/wakunode2.nim b/waku/v2/node/wakunode2.nim index 0bae560a6..106f30fb5 100644 --- a/waku/v2/node/wakunode2.nim +++ b/waku/v2/node/wakunode2.nim @@ -36,7 +36,7 @@ import export wakunode2_types -when defined(rln): +when defined(rln) or defined(rlnzerokit): import ../protocol/waku_rln_relay/waku_rln_relay_utils declarePublicCounter waku_node_messages, "number of messages received", ["type"] @@ -1066,7 +1066,7 @@ when isMainModule: # Keepalive mounted on all nodes waitFor mountLibp2pPing(node) - when defined(rln): + when defined(rln) or defined(rlnzerokit): if conf.rlnRelay: let res = node.mountRlnRelay(conf) if res.isErr(): diff --git a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_types.nim b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_types.nim index d923772bf..59197fa8f 100644 --- a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_types.nim +++ b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_types.nim @@ -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 Nullifier* = array[32, byte] Epoch* = array[32, byte] + RlnIdentifier* = array[32, byte] when defined(rln) or (not defined(rln) and not defined(rlnzerokit)): type @@ -39,7 +40,7 @@ when defined(rln) or (not defined(rln) and not defined(rlnzerokit)): when defined(rlnzerokit): type ZKSNARK* = array[128, byte] - RlnIdentifier* = array[32, byte] + # Custom data types defined for waku rln relay ------------------------- type MembershipKeyPair* = object @@ -51,45 +52,25 @@ type MembershipKeyPair* = object # more details in https://hackmd.io/tMTLMYmTR5eynw2lwK9n1w?view#Membership idCommitment*: IDCommitment -when defined(rln) or (not defined(rln) and not defined(rlnzerokit)): - 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 - ## 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 - ## Application specific RLN Identifier - rlnIdentifier*: RlnIdentifier +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 + ## Application specific RLN Identifier + rlnIdentifier*: RlnIdentifier type MembershipIndex* = uint @@ -182,11 +163,10 @@ proc init*(T: type RateLimitProof, buffer: seq[byte]): ProtoResult[T] = var nullifier: seq[byte] discard ? pb.getField(6, nullifier) discard nsp.nullifier.copyFrom(nullifier) - - when defined(rlnzerokit): - var rlnIdentifier: seq[byte] - discard ? pb.getField(7, rlnIdentifier) - discard nsp.rlnIdentifier.copyFrom(rlnIdentifier) + + var rlnIdentifier: seq[byte] + discard ? pb.getField(7, rlnIdentifier) + discard nsp.rlnIdentifier.copyFrom(rlnIdentifier) return ok(nsp) @@ -199,10 +179,8 @@ proc encode*(nsp: RateLimitProof): ProtoBuffer = output.write3(4, nsp.shareX) output.write3(5, nsp.shareY) output.write3(6, nsp.nullifier) - - when defined(rlnzerokit): - output.write3(7, nsp.rlnIdentifier) + output.write3(7, nsp.rlnIdentifier) output.finish3() - return output \ No newline at end of file + return output