From f5c67a5b686c7a54c4f34c7177a90bb72342e148 Mon Sep 17 00:00:00 2001 From: darshankabariya Date: Fri, 25 Apr 2025 21:40:45 +0530 Subject: [PATCH] chore: debug --- waku/waku_rln_relay/conversion_utils.nim | 12 +++++++++++- .../group_manager/group_manager_base.nim | 2 +- .../group_manager/on_chain/group_manager.nim | 3 --- waku/waku_rln_relay/protocol_types.nim | 16 +++++++++------- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/waku/waku_rln_relay/conversion_utils.nim b/waku/waku_rln_relay/conversion_utils.nim index 904980b8e..7393668e5 100644 --- a/waku/waku_rln_relay/conversion_utils.nim +++ b/waku/waku_rln_relay/conversion_utils.nim @@ -76,7 +76,17 @@ proc serialize*( return output proc serialize*(witness: RLNWitnessInput): seq[byte] = - ## Serializes the witness into a byte array according to the RLN protocol format + ## Serializes the RLN witness into a byte array following zerokit's expected format. + ## The serialized format includes: + ## - identity_secret (32 bytes, little-endian with zero padding) + ## - user_message_limit (32 bytes, little-endian with zero padding) + ## - message_id (32 bytes, little-endian with zero padding) + ## - merkle tree depth (8 bytes, little-endian) = path_elements.len / 32 + ## - path_elements (each 32 bytes, ordered bottom-to-top) + ## - merkle tree depth again (8 bytes, little-endian) + ## - identity_path_index (sequence of bits as bytes, 0 = left, 1 = right) + ## - x (32 bytes, little-endian with zero padding) + ## - external_nullifier (32 bytes, little-endian with zero padding) var buffer: seq[byte] buffer.add(@(witness.identity_secret)) buffer.add(@(witness.user_message_limit)) diff --git a/waku/waku_rln_relay/group_manager/group_manager_base.nim b/waku/waku_rln_relay/group_manager/group_manager_base.nim index 26e8548f5..4a1c84e55 100644 --- a/waku/waku_rln_relay/group_manager/group_manager_base.nim +++ b/waku/waku_rln_relay/group_manager/group_manager_base.nim @@ -4,7 +4,7 @@ import ../protocol_metrics, ../constants, ../rln -import options, chronos, results, std/[deques, sequtils], chronicles +import options, chronos, results, std/[deques, sequtils] export options, chronos, results, protocol_types, protocol_metrics, deques diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 5323e1846..90e3a056b 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -27,9 +27,6 @@ export group_manager_base logScope: topics = "waku rln_relay onchain_group_manager" -type UInt40* = StUint[40] -type UInt32* = StUint[32] - # using the when predicate does not work within the contract macro, hence need to dupe contract(WakuRlnContract): # this serves as an entrypoint into the rln membership set diff --git a/waku/waku_rln_relay/protocol_types.nim b/waku/waku_rln_relay/protocol_types.nim index 41372bef3..c6f52e00b 100644 --- a/waku/waku_rln_relay/protocol_types.nim +++ b/waku/waku_rln_relay/protocol_types.nim @@ -52,17 +52,19 @@ type RateLimitProof* = object ## the external nullifier used for the generation of the `proof` (derived from poseidon([epoch, rln_identifier])) externalNullifier*: ExternalNullifier -type - Fr = array[32, byte] # Field element representation (256 bits) +type UInt40* = StUint[40] +type UInt32* = StUint[32] +type + Field = array[32, byte] # Field element representation (256 bits) RLNWitnessInput* = object - identity_secret*: Fr - user_message_limit*: Fr - message_id*: Fr + identity_secret*: Field + user_message_limit*: Field + message_id*: Field path_elements*: seq[byte] identity_path_index*: seq[byte] - x*: Fr - external_nullifier*: Fr + x*: Field + external_nullifier*: Field type ProofMetadata* = object nullifier*: Nullifier