From 577cdf030b9d963abb6b85f822224abf1f4ed9e4 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 22 Feb 2023 19:47:12 +0530 Subject: [PATCH] chore(rln-relay): bump zerokit and update ffi (#1571) fix(chat2): compilation --- apps/chat2/chat2.nim | 2 +- tests/v2/test_waku_rln_relay.nim | 6 +++--- vendor/zerokit | 2 +- .../protocol/waku_rln_relay/rln/rln_interface.nim | 15 ++++++++++++--- waku/v2/protocol/waku_rln_relay/rln/wrappers.nim | 12 ++++++------ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/apps/chat2/chat2.nim b/apps/chat2/chat2.nim index 93e1cb5da..d44fc99d1 100644 --- a/apps/chat2/chat2.nim +++ b/apps/chat2/chat2.nim @@ -117,7 +117,7 @@ proc toString*(message: Chat2Message): string = # Similarly as Status public chats now. proc generateSymKey(contentTopic: ContentTopic): SymKey = - var ctx: HMAC[sha256] + var ctx: HMAC[pbkdf2.sha256] var symKey: SymKey if pbkdf2(ctx, contentTopic.toBytes(), "", 65356, symKey) != sizeof(SymKey): raise (ref Defect)(msg: "Should not occur as array is properly sized") diff --git a/tests/v2/test_waku_rln_relay.nim b/tests/v2/test_waku_rln_relay.nim index 1def75f5e..60eb505b6 100644 --- a/tests/v2/test_waku_rln_relay.nim +++ b/tests/v2/test_waku_rln_relay.nim @@ -403,8 +403,8 @@ suite "Waku rln relay": # prepare other inputs to the hash function let outputBuffer = default(Buffer) - let hashSuccess = hash(rlnInstance.get(), unsafeAddr hashInputBuffer, - unsafeAddr outputBuffer) + let hashSuccess = sha256(unsafeAddr hashInputBuffer, + unsafeAddr outputBuffer) require: hashSuccess let outputArr = cast[ptr array[32, byte]](outputBuffer.`ptr`)[] @@ -429,7 +429,7 @@ suite "Waku rln relay": # prepare the input let msg = "Hello".toBytes() - let hash = rln.hash(msg) + let hash = sha256(msg) check: "1e32b3ab545c07c8b4a7ab1ca4f46bc31e4fdc29ac3b240ef1d54b4017a26e4c" == diff --git a/vendor/zerokit b/vendor/zerokit index 005393d69..a6145ab20 160000 --- a/vendor/zerokit +++ b/vendor/zerokit @@ -1 +1 @@ -Subproject commit 005393d69606d2893c9b2b7aed506d1920472688 +Subproject commit a6145ab2012a1e9b6bdd08963d6e1db09f06c88d diff --git a/waku/v2/protocol/waku_rln_relay/rln/rln_interface.nim b/waku/v2/protocol/waku_rln_relay/rln/rln_interface.nim index b3c175a5c..337e8691d 100644 --- a/waku/v2/protocol/waku_rln_relay/rln/rln_interface.nim +++ b/waku/v2/protocol/waku_rln_relay/rln/rln_interface.nim @@ -151,11 +151,20 @@ proc new_circuit_from_data*(tree_height: uint, circom_buffer: ptr Buffer, zkey_b ## ctx holds the final created rln object ## the return bool value indicates the success or failure of the operation -proc hash*(ctx: ptr RLN, - input_buffer: ptr Buffer, - output_buffer: ptr Buffer): bool {.importc: "hash".} +#-------------------------------- Hashing utils ------------------------------------------- + +proc sha256*(input_buffer: ptr Buffer, + output_buffer: ptr Buffer): bool {.importc: "hash".} ## it hashes (sha256) the plain text supplied in inputs_buffer and then maps it to a field element ## this proc is used to map arbitrary signals to field element for the sake of proof generation ## inputs_buffer holds the hash input as a byte seq ## the hash output is generated and populated inside output_buffer ## the output_buffer contains 32 bytes hash output + +proc poseidon*(input_buffer: ptr Buffer, + output_buffer: ptr Buffer): bool {.importc: "poseidon_hash".} +## it hashes (poseidon) the plain text supplied in inputs_buffer +## this proc is used to compute the identity secret hash, and external nullifier +## inputs_buffer holds the hash input as a byte seq +## the hash output is generated and populated inside output_buffer +## the output_buffer contains 32 bytes hash output diff --git a/waku/v2/protocol/waku_rln_relay/rln/wrappers.nim b/waku/v2/protocol/waku_rln_relay/rln/wrappers.nim index 1f660fc03..85840629e 100644 --- a/waku/v2/protocol/waku_rln_relay/rln/wrappers.nim +++ b/waku/v2/protocol/waku_rln_relay/rln/wrappers.nim @@ -78,21 +78,21 @@ proc createRLNInstance*(d: int = MerkleTreeDepth): RLNResult = res = createRLNInstanceLocal(d) return res -proc hash*(rlnInstance: ptr RLN, data: openArray[byte]): MerkleNode = - ## a thin layer on top of the Nim wrapper of the Poseidon hasher - debug "hash input", hashhex = data.toHex() +proc sha256*(data: openArray[byte]): MerkleNode = + ## a thin layer on top of the Nim wrapper of the sha256 hasher + debug "sha256 hash input", hashhex = data.toHex() var lenPrefData = appendLength(data) var hashInputBuffer = lenPrefData.toBuffer() outputBuffer: Buffer # will holds the hash output - debug "hash input buffer length", bufflen = hashInputBuffer.len + debug "sha256 hash input buffer length", bufflen = hashInputBuffer.len let - hashSuccess = hash(rlnInstance, addr hashInputBuffer, addr outputBuffer) + hashSuccess = sha256(addr hashInputBuffer, addr outputBuffer) # check whether the hash call is done successfully if not hashSuccess: - debug "error in hash" + debug "error in sha256 hash" return default(MerkleNode) let